From: tierno Date: Wed, 27 Jun 2018 13:47:22 +0000 (+0200) Subject: Added NS parameter validation X-Git-Tag: BUILD_v4.0.1_1~5 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=commitdiff_plain;h=0da52259d5938703bcb71bb1f42cc1da345ff887;hp=db9dc589ca4ddb7fde50cff07c23b2ea863265cc Added NS parameter validation Change-Id: I788bc58e51cce7d73f9dc7c711abba4de262dfa8 Signed-off-by: tierno --- diff --git a/osm_nbi/engine.py b/osm_nbi/engine.py index 76b0f13..50d1bd1 100644 --- a/osm_nbi/engine.py +++ b/osm_nbi/engine.py @@ -538,6 +538,7 @@ class Engine(object): :param ns_request: params to be used for the nsr :return: the _id of nsr descriptor stored at database """ + rollback_index = len(rollback) step = "" try: # look for nsr @@ -649,7 +650,7 @@ class Engine(object): step = "creating nsr at database" self._format_new_data(session, "nsrs", nsr_descriptor) self.db.create("nsrs", nsr_descriptor) - rollback.insert(0, {"item": "nsrs", "_id": nsr_id}) + rollback.insert(rollback_index, {"item": "nsrs", "_id": nsr_id}) return nsr_id except Exception as e: raise EngineException("Error {}: {}".format(step, e)) diff --git a/osm_nbi/html_public/version b/osm_nbi/html_public/version index 63dd2ef..c9b57d9 100644 --- a/osm_nbi/html_public/version +++ b/osm_nbi/html_public/version @@ -1,3 +1,3 @@ -0.1.10 -2018-05-28 +0.1.11 +2018-06-27 diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index 4468f26..e34cfad 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -694,7 +694,7 @@ class Server(object): outdata = {"id": _id} elif item == "ns_instances_content": _id = self.engine.new_item(rollback, session, engine_item, indata, kwargs, force=force) - self.engine.ns_operation(rollback, session, _id, "instantiate", {}, None) + self.engine.ns_operation(rollback, session, _id, "instantiate", indata, None) self._set_location_header(topic, version, item, _id) outdata = {"id": _id} elif item == "ns_instances" and item2: diff --git a/osm_nbi/validation.py b/osm_nbi/validation.py index 91549e0..308d872 100644 --- a/osm_nbi/validation.py +++ b/osm_nbi/validation.py @@ -15,6 +15,7 @@ patern_name = "^[ -~]+$" passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60} nameshort_schema = {"type": "string", "minLength": 1, "maxLength": 60, "pattern": "^[^,;()'\"]+$"} name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"} +string_schema = {"type": "string", "minLength": 1, "maxLength": 255} xml_text_schema = {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"} description_schema = {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"} id_schema_fake = {"type": "string", "minLength": 2, @@ -51,7 +52,41 @@ ns_instantiate = { "title": "ns action instantiate input schema", "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", + "properties": { + "nsName": name_schema, + "nsDescription": description_schema, + "nsdId": id_schema, + "vimAccountId": id_schema, + "ssh_keys": {"type": "string"}, + "vnf": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "member-vnf-index": name_schema, + "vimAccountId": id_schema, + }, + "required": ["member-vnf-index"] + } + }, + "vld": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "name": string_schema, + "vim-network-name": {"OneOf": [string_schema, object_schema]}, + "ip-profile": object_schema, + }, + "required": ["name"] + } + }, + }, + "required": ["nsName", "nsdId", "vimAccountId"] } + ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution "title": "ns action update input schema", "$schema": "http://json-schema.org/draft-04/schema#", @@ -214,7 +249,7 @@ def validate_input(indata, item, new=True): return None except js_e.ValidationError as e: if e.path: - error_pos = "at '" + ":".join(e.path) + "'" + error_pos = "at '" + ":".join(map(str, e.path)) + "'" else: error_pos = "" raise ValidationError("Format error {} '{}' ".format(error_pos, e))