allow ns-terminate parameters 18/8718/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 24 Mar 2020 11:51:39 +0000 (11:51 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 24 Mar 2020 13:44:56 +0000 (13:44 +0000)
Change-Id: I29d4415e1d6af3a86639739eb38a0b92e1349cac
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_nbi/base_topic.py
osm_nbi/instance_topics.py
osm_nbi/nbi.py
osm_nbi/validation.py

index 52e02af..228e29d 100644 (file)
@@ -19,6 +19,7 @@ from http import HTTPStatus
 from time import time
 from osm_common.dbbase import deep_update_rfc7396
 from osm_nbi.validation import validate_input, ValidationError, is_valid_uuid
+from yaml import safe_load, YAMLError
 
 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
 
@@ -301,11 +302,12 @@ class BaseTopic:
         pass
 
     @staticmethod
-    def _update_input_with_kwargs(desc, kwargs):
+    def _update_input_with_kwargs(desc, kwargs, yaml_format=False):
         """
         Update descriptor with the kwargs. It contains dot separated keys
         :param desc: dictionary to be updated
         :param kwargs: plain dictionary to be used for updating.
+        :param yaml_format: get kwargs values as yaml format.
         :return: None, 'desc' is modified. It raises EngineException.
         """
         if not kwargs:
@@ -325,7 +327,7 @@ class BaseTopic:
                     else:
                         raise EngineException(
                             "Invalid query string '{}'. Descriptor is not a list nor dict at '{}'".format(k, kitem))
-                update_content[kitem_old] = v
+                update_content[kitem_old] = v if not yaml_format else safe_load(v)
         except KeyError:
             raise EngineException(
                 "Invalid query string '{}'. Descriptor does not contain '{}'".format(k, kitem_old))
@@ -335,6 +337,8 @@ class BaseTopic:
         except IndexError:
             raise EngineException(
                 "Invalid query string '{}'. Index '{}' out of  range".format(k, kitem_old))
+        except YAMLError:
+            raise EngineException("Invalid query string '{}' yaml format".format(k))
 
     def show(self, session, _id):
         """
index c9be059..776edc1 100644 (file)
@@ -18,7 +18,8 @@ from uuid import uuid4
 from http import HTTPStatus
 from time import time
 from copy import copy, deepcopy
-from osm_nbi.validation import validate_input, ValidationError, ns_instantiate, ns_action, ns_scale, nsi_instantiate
+from osm_nbi.validation import validate_input, ValidationError, ns_instantiate, ns_terminate, ns_action, ns_scale,\
+    nsi_instantiate
 from osm_nbi.base_topic import BaseTopic, EngineException, get_iterable, deep_get
 # from descriptor_topics import DescriptorTopic
 from yaml import safe_dump
@@ -485,7 +486,7 @@ class NsLcmOpTopic(BaseTopic):
         "instantiate": ns_instantiate,
         "action": ns_action,
         "scale": ns_scale,
-        "terminate": None,
+        "terminate": ns_terminate,
     }
 
     def __init__(self, db, fs, msg, auth):
@@ -984,7 +985,7 @@ class NsLcmOpTopic(BaseTopic):
 
         try:
             # Override descriptor with query string kwargs
-            self._update_input_with_kwargs(indata, kwargs)
+            self._update_input_with_kwargs(indata, kwargs, yaml_format=True)
             operation = indata["lcmOperationType"]
             nsInstanceId = indata["nsInstanceId"]
 
index c9d33b5..2d2d635 100644 (file)
@@ -1103,7 +1103,7 @@ class Server(object):
                             "nsInstanceId": _id,
                             "autoremove": True
                         }
-                        opp_id, _ = self.engine.new_item(rollback, engine_session, "nslcmops", nslcmop_desc, None)
+                        opp_id, _ = self.engine.new_item(rollback, engine_session, "nslcmops", nslcmop_desc, kwargs)
                         if opp_id:
                             delete_in_process = True
                             outdata = {"_id": opp_id}
index d40814e..9cfd9a6 100644 (file)
@@ -350,6 +350,20 @@ ns_instantiate = {
     "additionalProperties": False
 }
 
+ns_terminate = {
+    "title": "ns terminate input schema",
+    "$schema": "http://json-schema.org/draft-04/schema#",
+    "type": "object",
+    "properties": {
+        "lcmOperationType": string_schema,
+        "nsInstanceId": id_schema,
+        "autoremove": bool_schema,
+        "timeout_ns_terminate": integer1_schema,
+        "skip_terminate_primitives": bool_schema,
+    },
+    "additionalProperties": False
+}
+
 ns_action = {   # TODO for the moment it is only contemplated the vnfd primitive execution
     "title": "ns action input schema",
     "$schema": "http://json-schema.org/draft-04/schema#",