fix(model): adaptations to allow new configuration containers
[osm/NBI.git] / osm_nbi / tests / test_descriptor_topics.py
index 516c178..7f07d96 100755 (executable)
@@ -112,11 +112,11 @@ class Test_VnfdTopic(TestCase):
             self.assertEqual(db_args[1]["_admin"]["projects_read"], [test_pid], "Wrong read-only project list")
             self.assertEqual(db_args[1]["_admin"]["projects_write"], [test_pid], "Wrong read-write project list")
             tmp1 = test_vnfd["vdu"][0]["cloud-init-file"]
-            tmp2 = test_vnfd["vnf-configuration"][0]["juju"]
+            tmp2 = test_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"]["day1-2"][0]["juju"]
             del test_vnfd["vdu"][0]["cloud-init-file"]
-            del test_vnfd["vnf-configuration"][0]["juju"]
+            del test_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"]["day1-2"][0]["juju"]
             try:
-                self.db.get_one.side_effect = [{"_id": did, "_admin": db_vnfd_content["_admin"]}, None]
+                self.db.get_one.side_effect = [{"_id": did, "_admin": deepcopy(db_vnfd_content["_admin"])}, None]
                 self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []})
                 msg_args = self.msg.write.call_args[0]
                 test_vnfd["_id"] = did
@@ -130,7 +130,7 @@ class Test_VnfdTopic(TestCase):
                 self.assertEqual(db_args[0], self.topic.topic, "Wrong DB topic")
                 self.assertEqual(db_args[1], did, "Wrong DB VNFD id")
                 admin = db_args[2]["_admin"]
-                db_admin = db_vnfd_content["_admin"]
+                db_admin = deepcopy(db_vnfd_content["_admin"])
                 self.assertEqual(admin["type"], "vnfd", "Wrong descriptor type")
                 self.assertEqual(admin["created"], db_admin["created"], "Wrong creation time")
                 self.assertGreater(admin["modified"], db_admin["created"], "Wrong modification time")
@@ -145,9 +145,9 @@ class Test_VnfdTopic(TestCase):
                 compare_desc(self, test_vnfd, db_args[2], "VNFD")
             finally:
                 test_vnfd["vdu"][0]["cloud-init-file"] = tmp1
-                test_vnfd["vnf-configuration"][0]["juju"] = tmp2
+                test_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"]["day1-2"][0]["juju"] = tmp2
         self.db.get_one.side_effect = lambda table, filter, fail_on_empty=None, fail_on_more=None: \
-            {"_id": did, "_admin": db_vnfd_content["_admin"]}
+            {"_id": did, "_admin": deepcopy(db_vnfd_content["_admin"])}
         with self.subTest(i=2, t='Check Pyangbind Validation: additional properties'):
             test_vnfd["extra-property"] = 0
             try:
@@ -178,14 +178,14 @@ class Test_VnfdTopic(TestCase):
             self.assertIn(norm("{} defined in vnf[id={}]:vdu[id={}] but not present in package"
                                .format("cloud-init", test_vnfd["id"], test_vnfd["vdu"][0]["id"])),
                           norm(str(e.exception)), "Wrong exception text")
-        with self.subTest(i=5, t='Check Input Validation: vnf-configuration[juju]'):
+        with self.subTest(i=5, t='Check Input Validation: day1-2 configuration[juju]'):
             del test_vnfd["vdu"][0]["cloud-init-file"]
             with self.assertRaises(EngineException, msg="Accepted non-existent charm in VNF configuration") as e:
                 self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []})
             self.assertEqual(e.exception.http_code, HTTPStatus.BAD_REQUEST, "Wrong HTTP status code")
             self.assertIn(norm("{} defined in vnf[id={}] but not present in package".format("charm", test_vnfd["id"])),
                           norm(str(e.exception)), "Wrong exception text")
-            del test_vnfd["vnf-configuration"][0]["juju"]
+            del test_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"]["day1-2"][0]["juju"]
         with self.subTest(i=6, t='Check Input Validation: mgmt-cp'):
             tmp = test_vnfd["mgmt-cp"]
             del test_vnfd["mgmt-cp"]
@@ -280,22 +280,30 @@ class Test_VnfdTopic(TestCase):
                 vdu['monitoring-parameter'] = tmp
         with self.subTest(i=13, t='Check Input Validation: scaling-aspect vnf-configuration'):
             df = test_vnfd['df'][0]
-            tmp = test_vnfd.pop('vnf-configuration')
+            tmp = test_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"]["day1-2"].pop()
             try:
                 with self.assertRaises(EngineException, msg="Accepted non-existent Scaling Group VDU ID Reference") \
                         as e:
                     self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []})
                 self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code")
-                self.assertIn(norm("'vnf-configuration' not defined in the descriptor but it is referenced "
+                self.assertIn(norm("'day1-2 configuration' not defined in the descriptor but it is referenced "
                                    "by df[id='{}']:scaling-aspect[id='{}']:scaling-config-action"
                                    .format(df["id"], df['scaling-aspect'][0]["id"])),
                               norm(str(e.exception)), "Wrong exception text")
             finally:
-                test_vnfd["vnf-configuration"] = tmp
+                test_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"]["day1-2"].append(tmp)
         with self.subTest(i=14, t='Check Input Validation: scaling-config-action'):
             df = test_vnfd['df'][0]
-            tmp = test_vnfd['vnf-configuration'][0]['config-primitive']
-            test_vnfd['vnf-configuration'][0]['config-primitive'] = [{'name': 'wrong-primitive'}]
+            tmp = test_vnfd["df"][0].get(
+                "lcm-operations-configuration"
+            ).get(
+                "operate-vnf-op-config"
+            )["day1-2"][0]['config-primitive']
+            test_vnfd["df"][0].get(
+                "lcm-operations-configuration"
+            ).get(
+                "operate-vnf-op-config"
+            )["day1-2"][0]['config-primitive'] = [{'name': 'wrong-primitive'}]
             try:
                 with self.assertRaises(EngineException,
                                        msg="Accepted non-existent Scaling Group VDU ID Reference") as e:
@@ -303,15 +311,24 @@ class Test_VnfdTopic(TestCase):
                 self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code")
                 self.assertIn(norm("df[id='{}']:scaling-aspect[id='{}']:scaling-config-action:vnf-"
                                    "config-primitive-name-ref='{}' does not match any "
-                                   "vnf-configuration:config-primitive:name"
+                                   "day1-2 configuration:config-primitive:name"
                                    .format(df["id"], df['scaling-aspect'][0]["id"],
                                            sa['scaling-config-action'][0]['vnf-config-primitive-name-ref'])),
                               norm(str(e.exception)), "Wrong exception text")
             finally:
-                test_vnfd['vnf-configuration'][0]['config-primitive'] = tmp
+                test_vnfd["df"][0].get(
+                    "lcm-operations-configuration"
+                ).get(
+                    "operate-vnf-op-config"
+                )["day1-2"][0]['config-primitive'] = tmp
         with self.subTest(i=15, t='Check Input Validation: everything right'):
             test_vnfd["id"] = "fake-vnfd-id"
-            self.db.get_one.side_effect = [{"_id": did, "_admin": db_vnfd_content["_admin"]}, None]
+            test_vnfd["df"][0].get(
+                "lcm-operations-configuration"
+            ).get(
+                "operate-vnf-op-config"
+            )["day1-2"][0]["id"] = "fake-vnfd-id"
+            self.db.get_one.side_effect = [{"_id": did, "_admin": deepcopy(db_vnfd_content["_admin"])}, None]
             rc = self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []})
             self.assertTrue(rc, "Input Validation: Unexpected failure")
         return
@@ -323,8 +340,10 @@ class Test_VnfdTopic(TestCase):
         self.fs.dir_ls.return_value = True
         with self.subTest(i=1, t='Normal Edition'):
             now = time()
-            self.db.get_one.side_effect = [vnfd_content, None]
-            data = {"id": "new-vnfd-id", "product-name": "new-vnfd-name"}
+            self.db.get_one.side_effect = [deepcopy(vnfd_content), None]
+            data = {
+                "product-name": "new-vnfd-name"
+            }
             self.topic.edit(fake_session, did, data)
             db_args = self.db.replace.call_args[0]
             msg_args = self.msg.write.call_args[0]
@@ -342,11 +361,10 @@ class Test_VnfdTopic(TestCase):
                              "Wrong read-only project list")
             self.assertEqual(db_args[2]["_admin"]["projects_write"], vnfd_content["_admin"]["projects_write"],
                              "Wrong read-write project list")
-            self.assertEqual(db_args[2]["id"], data["id"], "Wrong VNFD ID")
             self.assertEqual(db_args[2]["product-name"], data["product-name"], "Wrong VNFD Name")
         with self.subTest(i=2, t='Conflict on Edit'):
-            data = {"id": "fake-vnfd-id", "product-name": "new-vnfd-name"}
-            self.db.get_one.side_effect = [vnfd_content, {"_id": str(uuid4()), "id": data["id"]}]
+            data = {"id": "hackfest3charmed-vnf", "product-name": "new-vnfd-name"}
+            self.db.get_one.side_effect = [deepcopy(vnfd_content), {"_id": str(uuid4()), "id": data["id"]}]
             with self.assertRaises(EngineException, msg="Accepted existing VNFD ID") as e:
                 self.topic.edit(fake_session, did, data)
             self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code")
@@ -613,11 +631,11 @@ class Test_VnfdTopic(TestCase):
         indata = deepcopy(db_vnfd_content)
         df = indata['df'][0]
         affected_sa = df['scaling-aspect'][0]
-        indata.pop('vnf-configuration')
+        indata["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"]["day1-2"].pop()
         with self.assertRaises(EngineException) as e:
             self.topic.validate_scaling_group_descriptor(indata)
         self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code")
-        self.assertIn(norm("'vnf-configuration' not defined in the descriptor but it is referenced "
+        self.assertIn(norm("'day1-2 configuration' not defined in the descriptor but it is referenced "
                            "by df[id='{}']:scaling-aspect[id='{}']:scaling-config-action"
                            .format(df["id"], affected_sa["id"])),
                       norm(str(e.exception)), "Wrong exception text")
@@ -627,13 +645,13 @@ class Test_VnfdTopic(TestCase):
         df = indata['df'][0]
         affected_sa = df['scaling-aspect'][0]
         affected_sca_primitive = affected_sa['scaling-config-action'][0]['vnf-config-primitive-name-ref']
-        indata['vnf-configuration'][0]['config-primitive'] = []
+        df["lcm-operations-configuration"]["operate-vnf-op-config"]["day1-2"][0]['config-primitive'] = []
         with self.assertRaises(EngineException) as e:
             self.topic.validate_scaling_group_descriptor(indata)
         self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code")
         self.assertIn(norm("df[id='{}']:scaling-aspect[id='{}']:scaling-config-action:vnf-"
                            "config-primitive-name-ref='{}' does not match any "
-                           "vnf-configuration:config-primitive:name"
+                           "day1-2 configuration:config-primitive:name"
                            .format(df["id"], affected_sa["id"], affected_sca_primitive)),
                       norm(str(e.exception)), "Wrong exception text")
 
@@ -804,7 +822,7 @@ class Test_NsdTopic(TestCase):
         self.fs.dir_ls.return_value = True
         with self.subTest(i=1, t='Normal Edition'):
             now = time()
-            self.db.get_one.side_effect = [nsd_content, None]
+            self.db.get_one.side_effect = [deepcopy(nsd_content), None]
             self.db.get_list.return_value = [db_vnfd_content]
             data = {"id": "new-nsd-id", "name": "new-nsd-name"}
             self.topic.edit(fake_session, did, data)
@@ -989,7 +1007,7 @@ class Test_NsdTopic(TestCase):
         nsd_descriptor['df'][0]['vnf-profile'][1]['vnfd-id'] = invalid_vnfd_id
         with self.assertRaises(EngineException) as e:
             self.db.get_list.return_value = []
-            self.topic.check_conflict_on_edit(fake_session, nsd_descriptor, [], 'id')
+            nsd_descriptor = self.topic.check_conflict_on_edit(fake_session, nsd_descriptor, [], 'id')
         self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code")
         self.assertIn(norm("Descriptor error at 'vnfd-id'='{}' references a non "
                            "existing vnfd".format(invalid_vnfd_id)),