Fix Bug 2307 - Invalid references of vdu-id, monitoring-param, storage and compute...
[osm/NBI.git] / osm_nbi / tests / test_descriptor_topics.py
index f6d4001..8ab74b8 100755 (executable)
@@ -579,6 +579,49 @@ class Test_VnfdTopic(TestCase):
             "Wrong exception text",
         )
 
+    @patch("osm_nbi.descriptor_topics.shutil")
+    @patch("osm_nbi.descriptor_topics.os.rename")
+    def test_new_vnfd_check_input_validation_scaling_criteria_vdu_id(
+        self, mock_rename, mock_shutil
+    ):
+        """Testing input validation during new vnfd creation
+        for scaling criteria with invalid vdu-id"""
+        did, test_vnfd = self.prepare_vnfd_creation()
+        test_vnfd = self.prepare_test_vnfd(test_vnfd)
+        test_vnfd["df"][0]["scaling-aspect"][0]["aspect-delta-details"]["deltas"][0][
+            "vdu-delta"
+        ][0]["id"] = "vdudelta1"
+        affected_df = test_vnfd["df"][0]
+        sa = affected_df["scaling-aspect"][0]
+        delta = sa["aspect-delta-details"]["deltas"][0]
+        vdu_delta = delta["vdu-delta"][0]
+
+        with self.assertRaises(
+            EngineException, msg="Accepted invalid Scaling Group Policy Criteria"
+        ) 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(
+                "df[id='{}']:scaling-aspect[id='{}']:aspect-delta-details"
+                "[delta='{}']: "
+                "vdu-id='{}' not defined in vdu".format(
+                    affected_df["id"],
+                    sa["id"],
+                    delta["id"],
+                    vdu_delta["id"],
+                )
+            ),
+            norm(str(e.exception)),
+            "Wrong exception text",
+        )
+
     @patch("osm_nbi.descriptor_topics.shutil")
     @patch("osm_nbi.descriptor_topics.os.rename")
     def test_new_vnfd_check_input_validation_scaling_criteria_monitoring_param_ref(
@@ -699,6 +742,157 @@ class Test_VnfdTopic(TestCase):
             "Wrong exception text",
         )
 
+    @patch("osm_nbi.descriptor_topics.shutil")
+    @patch("osm_nbi.descriptor_topics.os.rename")
+    def test_new_vnfd_check_input_validation_healing_criteria_vdu_id(
+        self, mock_rename, mock_shutil
+    ):
+        """Testing input validation during new vnfd creation
+        for healing criteria with invalid vdu-id"""
+        did, test_vnfd = self.prepare_vnfd_creation()
+        test_vnfd = self.prepare_test_vnfd(test_vnfd)
+        test_vnfd["df"][0]["healing-aspect"][0]["healing-policy"][0][
+            "vdu-id"
+        ] = "vduid1"
+        affected_df = test_vnfd["df"][0]
+        ha = affected_df["healing-aspect"][0]
+        hp = ha["healing-policy"][0]
+        hp_vdu_id = hp["vdu-id"]
+
+        with self.assertRaises(
+            EngineException, msg="Accepted invalid Healing Group Policy Criteria"
+        ) 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(
+                "df[id='{}']:healing-aspect[id='{}']:healing-policy"
+                "[name='{}']: "
+                "vdu-id='{}' not defined in vdu".format(
+                    affected_df["id"],
+                    ha["id"],
+                    hp["event-name"],
+                    hp_vdu_id,
+                )
+            ),
+            norm(str(e.exception)),
+            "Wrong exception text",
+        )
+
+    @patch("osm_nbi.descriptor_topics.shutil")
+    @patch("osm_nbi.descriptor_topics.os.rename")
+    def test_new_vnfd_check_input_validation_alarm_criteria_monitoring_param_ref(
+        self, mock_rename, mock_shutil
+    ):
+        """Testing input validation during new vnfd creation
+        for alarm with invalid monitoring parameter reference"""
+        did, test_vnfd = self.prepare_vnfd_creation()
+        test_vnfd = self.prepare_test_vnfd(test_vnfd)
+        test_vnfd["vdu"][1]["alarm"][0]["vnf-monitoring-param-ref"] = "unit_test_alarm"
+        vdu = test_vnfd["vdu"][1]
+        alarm = vdu["alarm"][0]
+        alarm_monitoring_param = alarm["vnf-monitoring-param-ref"]
+
+        with self.assertRaises(
+            EngineException, msg="Accepted invalid Alarm Criteria"
+        ) 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(
+                "vdu[id='{}']:alarm[id='{}']:"
+                "vnf-monitoring-param-ref='{}' not defined in any monitoring-param".format(
+                    vdu["id"],
+                    alarm["alarm-id"],
+                    alarm_monitoring_param,
+                )
+            ),
+            norm(str(e.exception)),
+            "Wrong exception text",
+        )
+
+    @patch("osm_nbi.descriptor_topics.shutil")
+    @patch("osm_nbi.descriptor_topics.os.rename")
+    def test_new_vnfd_check_input_validation_storage_reference_criteria(
+        self, mock_rename, mock_shutil
+    ):
+        """Testing input validation during new vnfd creation
+        for invalid virtual-storge-desc reference"""
+        did, test_vnfd = self.prepare_vnfd_creation()
+        test_vnfd = self.prepare_test_vnfd(test_vnfd)
+        test_vnfd["vdu"][1]["virtual-storage-desc"] = "unit_test_storage"
+        vdu = test_vnfd["vdu"][1]
+        vsd_ref = vdu["virtual-storage-desc"]
+
+        with self.assertRaises(
+            EngineException, msg="Accepted invalid virtual-storage-desc"
+        ) 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(
+                "vdu[virtual-storage-desc='{}']"
+                "not defined in vnfd".format(
+                    vsd_ref,
+                )
+            ),
+            norm(str(e.exception)),
+            "Wrong exception text",
+        )
+
+    @patch("osm_nbi.descriptor_topics.shutil")
+    @patch("osm_nbi.descriptor_topics.os.rename")
+    def test_new_vnfd_check_input_validation_compute_reference_criteria(
+        self, mock_rename, mock_shutil
+    ):
+        """Testing input validation during new vnfd creation
+        for invalid virtual-compute-desc reference"""
+        did, test_vnfd = self.prepare_vnfd_creation()
+        test_vnfd = self.prepare_test_vnfd(test_vnfd)
+        test_vnfd["vdu"][1]["virtual-compute-desc"] = "unit_test_compute"
+        vdu = test_vnfd["vdu"][1]
+        vcd_ref = vdu["virtual-compute-desc"]
+
+        with self.assertRaises(
+            EngineException, msg="Accepted invalid virtual-compute-desc"
+        ) 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(
+                "vdu[virtual-compute-desc='{}']"
+                "not defined in vnfd".format(
+                    vcd_ref,
+                )
+            ),
+            norm(str(e.exception)),
+            "Wrong exception text",
+        )
+
     @patch("osm_nbi.descriptor_topics.shutil")
     @patch("osm_nbi.descriptor_topics.os.rename")
     def test_new_vnfd_check_input_validation_everything_right(