X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=NG-RO%2Fosm_ng_ro%2Fvalidation.py;h=2601e90c7dec64ed08d97cc58a5c9976caf8c1c1;hb=29a4c1a24050561a70f4f47b276a268d48c79067;hp=54d8eedc8a39a55b85460875903cf826a618bc9f;hpb=70eeb18e4fcbb8bc3c81c88f270b59966ae4d463;p=osm%2FRO.git diff --git a/NG-RO/osm_ng_ro/validation.py b/NG-RO/osm_ng_ro/validation.py index 54d8eedc..2601e90c 100644 --- a/NG-RO/osm_ng_ro/validation.py +++ b/NG-RO/osm_ng_ro/validation.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from jsonschema import validate as js_v, exceptions as js_e from http import HTTPStatus +from jsonschema import exceptions as js_e, validate as js_v + __author__ = "Alfonso Tierno " __version__ = "0.1" version_date = "Jun 2020" @@ -25,10 +26,18 @@ Validator of input data using JSON schemas """ # Basis schemas -name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"} +name_schema = { + "type": "string", + "minLength": 1, + "maxLength": 255, + "pattern": "^[^,;()'\"]+$", +} string_schema = {"type": "string", "minLength": 1, "maxLength": 255} ssh_key_schema = {"type": "string", "minLength": 1} -id_schema = {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"} +id_schema = { + "type": "string", + "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$", +} bool_schema = {"type": "boolean"} null_schema = {"type": "null"} object_schema = {"type": "object"} @@ -42,7 +51,7 @@ deploy_item_schema = { "vim_info": object_schema, "common_id": string_schema, }, - "additionalProperties": True + "additionalProperties": True, } deploy_item_list = { @@ -96,10 +105,27 @@ deploy_schema = { "type": "object", "properties": { "vld": deploy_item_list, - } + }, + }, + "affinity-or-anti-affinity-group": deploy_item_list, + }, + "additionalProperties": False, +} + +rebuild_schema = { + "$schema": "http://json-schema.org/draft-04/schema#", + "vm_rebuild": { + "type": "array", + "items": { + "type": "object", + "properties": { + "vdu-id": id_schema, + "vim_name": name_schema, + "member-vnf-index": name_schema, + }, }, + "additionalProperties": True, }, - "additionalProperties": False } @@ -119,12 +145,17 @@ def validate_input(indata, schema_to_use): try: if schema_to_use: js_v(indata, schema_to_use) + return None except js_e.ValidationError as e: if e.path: error_pos = "at '" + ":".join(map(str, e.path)) + "'" else: error_pos = "" + raise ValidationError("Format error {} '{}' ".format(error_pos, e.message)) except js_e.SchemaError: - raise ValidationError("Bad json schema {}".format(schema_to_use), http_code=HTTPStatus.INTERNAL_SERVER_ERROR) + raise ValidationError( + "Bad json schema {}".format(schema_to_use), + http_code=HTTPStatus.INTERNAL_SERVER_ERROR, + )