Skip to content

Commit

Permalink
update blockbreaker.py and the associated schemas to have consistent/…
Browse files Browse the repository at this point in the history
…universal handling of numbers/number ranges/list of number ranges

- for example, these would all be treated similarly no matter where
  they are being specified:

  1
  1-3
  1-3+5-7
  • Loading branch information
k-rister committed Dec 12, 2023
1 parent 24ef0c9 commit c1a9a12
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 91 deletions.
49 changes: 29 additions & 20 deletions util/JSON/schema-k8s.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,10 @@
"type": "integer"
},
"client": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
}
]
"$ref": "#/definitions/number-lists"
},
"server": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
}
]
"$ref": "#/definitions/number-lists"
},
"config": {
"type": "array",
Expand All @@ -64,8 +48,7 @@
"enum": [ "client", "server" ]
},
"ids": {
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
"$ref": "#/definitions/number-lists"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -117,6 +100,32 @@
}
},
"additionalProperties": true
},
"number-lists": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
},
{
"type": "array",
"minItems": 1,
"items": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)$"
},
{
"type": "integer"
}
]
}
}
]
}
}
}
49 changes: 29 additions & 20 deletions util/JSON/schema-kvm.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,10 @@
"type": "integer"
},
"client": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
}
]
"$ref": "#/definitions/number-lists"
},
"server": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
}
]
"$ref": "#/definitions/number-lists"
},
"config": {
"type": "array",
Expand All @@ -58,8 +42,7 @@
"enum": [ "client", "server" ]
},
"ids": {
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
"$ref": "#/definitions/number-lists"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -97,6 +80,32 @@
"settings": {
"type": "object",
"additionalProperties": true
},
"number-lists": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
},
{
"type": "array",
"minItems": 1,
"items": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)$"
},
{
"type": "integer"
}
]
}
}
]
}
}
}
49 changes: 29 additions & 20 deletions util/JSON/schema-osp.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,10 @@
"type": "integer"
},
"client": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
}
]
"$ref": "#/definitions/number-lists"
},
"server": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
}
]
"$ref": "#/definitions/number-lists"
},
"config": {
"type": "array",
Expand All @@ -61,8 +45,7 @@
"enum": [ "client", "server" ]
},
"ids": {
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
"$ref": "#/definitions/number-lists"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -101,6 +84,32 @@
"settings": {
"type": "object",
"additionalProperties": true
},
"number-lists": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
},
{
"type": "array",
"minItems": 1,
"items": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)$"
},
{
"type": "integer"
}
]
}
}
]
}
}
}
59 changes: 30 additions & 29 deletions util/JSON/schema-remotehost.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,13 @@
"type": "string"
},
"client": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
}
]
"$ref": "#/definitions/number-lists"
},
"server": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
}
]
"$ref": "#/definitions/number-lists"
},
"profiler": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
}
]
"$ref": "#/definitions/number-lists"
},
"config": {
"type": "array",
Expand All @@ -69,8 +45,7 @@
"enum": [ "client", "server", "profiler" ]
},
"ids": {
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
"$ref": "#/definitions/number-lists"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -108,6 +83,32 @@
"settings": {
"type": "object",
"additionalProperties": true
},
"number-lists": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)(\\+(([1-9][0-9]*)(-[1-9][0-9]*)?))*$"
},
{
"type": "integer"
},
{
"type": "array",
"minItems": 1,
"items": {
"anyOf": [
{
"type": "string",
"pattern": "^(([1-9][0-9]*)(-[1-9][0-9]*)?)$"
},
{
"type": "integer"
}
]
}
}
]
}
}
}
19 changes: 17 additions & 2 deletions util/blockbreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ def json_to_stream(json_obj, cfg, idx):
tg_list = [ targets ]
elif isinstance(targets, list):
for tg in targets:
tg_name = tg['role'] + '-' + str(tg['ids'])
tg_name = tg['role'] + '-'
if isinstance(tg['ids'], str) or isinstance(tg['ids'], int):
tg_name += str(tg['ids'])
elif isinstance(tg['ids'], list):
for idx in range(len(tg['ids'])):
tg_name += str(tg['ids'][idx]) + '+'
# remove last '+'
tg_name = tg_name[:-1]
tg_list.append(tg_name)

# get the individual sections e.g. 'securityContext'
Expand All @@ -181,7 +188,15 @@ def json_to_stream(json_obj, cfg, idx):
stream += st + ':' + tg_name + ':' + str(st_val) + ','
else:
val = json_blk[key]
if isinstance(val, list):
if key in ("client", "server", "profile") and isinstance(val, list):
stream += key + ':'
for idx in range(len(val)):
item_val = str(val[idx])
stream += item_val + '+'
# remove last '+'
stream = stream[:-1]
stream += ','
elif isinstance(val, list):
for idx in range(len(val)):
item_val = val[idx]
stream += key + ':' + item_val + ','
Expand Down

0 comments on commit c1a9a12

Please sign in to comment.