Modifications for test of feature 7953 02/8502/4
authormagnussonl <lars-goran.magnusson@arctoslabs.com>
Mon, 20 Jan 2020 17:38:18 +0000 (18:38 +0100)
committermagnussonl <lars-goran.magnusson@arctoslabs.com>
Thu, 6 Feb 2020 08:24:35 +0000 (09:24 +0100)
Updated after review
Resolved merge conflict in osm_nbi/__init__.py

Change-Id: Ie7fd9c21d3d3369986e96e48b6dc9d29b79b36af
Signed-off-by: magnussonl <lars-goran.magnusson@arctoslabs.com>
osm_nbi/instance_topics.py
osm_nbi/tests/test_instance_topics.py
osm_nbi/validation.py

index 09a8c1b..8ca35d0 100644 (file)
@@ -947,6 +947,19 @@ class NsLcmOpTopic(BaseTopic):
         }
         return nslcmop
 
+    def _get_enabled_vims(self, session):
+        """
+        Retrieve and return VIM accounts that are accessible by current user and has state ENABLE
+        :param session: current session with user information
+        """
+        db_filter = self._get_project_filter(session)
+        db_filter["_admin.operationalState"] = "ENABLED"
+        vims = self.db.get_list("vim_accounts", db_filter)
+        vimAccounts = []
+        for vim in vims:
+            vimAccounts.append(vim['_id'])
+        return vimAccounts
+
     def new(self, rollback, session, indata=None, kwargs=None, headers=None, slice_object=False):
         """
         Performs a new operation over a ns
@@ -1002,6 +1015,9 @@ class NsLcmOpTopic(BaseTopic):
             nslcmop_desc = self._create_nslcmop(nsInstanceId, operation, indata)
             _id = nslcmop_desc["_id"]
             self.format_on_new(nslcmop_desc, session["project_id"], make_public=session["public"])
+            if indata.get("placement-engine"):
+                # Save valid vim accounts in lcm operation descriptor
+                nslcmop_desc['operationParams']['validVimAccounts'] = self._get_enabled_vims(session)
             self.db.create("nslcmops", nslcmop_desc)
             rollback.append({"topic": "nslcmops", "_id": _id})
             if not slice_object:
index 5c91114..e6cc254 100644 (file)
@@ -80,7 +80,7 @@ class TestNsLcmOpTopic(unittest.TestCase):
         rollback = []
         headers = {}
 
-        nslcmop_id, _ = self.nslcmop_topic.new(rollback, session, indata=indata, kwargs=None, headers=headers)
+        nslcmop_id, _ = self.nslcmop_topic.new(rollback, session, indata=deepcopy(indata), kwargs=None, headers=headers)
 
         # check nslcmop is created at database
         self.assertEqual(self.db.create.call_count, 1, "database create not called, or called more than once")
index c398a00..69c42ae 100644 (file)
@@ -265,6 +265,8 @@ ns_instantiate = {
         "nsdId": id_schema,
         "vimAccountId": id_schema,
         "wimAccountId": {"OneOf": [id_schema, bool_schema, null_schema]},
+        "placement-engine": string_schema,
+        "placement-constraints": object_schema,
         "additionalParamsForNs": object_schema,
         "additionalParamsForVnf": additional_params_for_vnf,
         "ssh_keys": {"type": "array", "items": {"type": "string"}},