X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_nbi%2Ftests%2Ftest_descriptor_topics.py;h=8ab74b8699fa92b007cabd577e7f7acee953a365;hb=10f814e5c393778cbad66346f79208b4c70be2ff;hp=dcde0a5cfde0dc5109a81e09885c338c1d8de95b;hpb=00f83aae0eb5dc138ac703b9ff37181baa082073;p=osm%2FNBI.git diff --git a/osm_nbi/tests/test_descriptor_topics.py b/osm_nbi/tests/test_descriptor_topics.py index dcde0a5..8ab74b8 100755 --- a/osm_nbi/tests/test_descriptor_topics.py +++ b/osm_nbi/tests/test_descriptor_topics.py @@ -32,6 +32,7 @@ from osm_nbi.tests.test_pkg_descriptors import ( db_nsds_text, vnfd_exploit_text, vnfd_exploit_fixed_text, + db_sfc_nsds_text, ) from osm_nbi.descriptor_topics import VnfdTopic, NsdTopic from osm_nbi.engine import EngineException @@ -578,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( @@ -698,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( @@ -2197,6 +2392,61 @@ class Test_NsdTopic(TestCase): "Wrong exception text", ) + def test_validate_vnffgd_descriptor_on_valid_descriptor(self): + indata = yaml.safe_load(db_sfc_nsds_text)[0] + vnffgd = indata.get("vnffgd") + fg = vnffgd[0] + self.topic.validate_vnffgd_data(fg, indata) + + def test_validate_vnffgd_descriptor_not_matching_nfp_position_element(self): + indata = yaml.safe_load(db_sfc_nsds_text)[0] + vnffgd = indata.get("vnffgd") + fg = vnffgd[0] + nfpd = fg.get("nfpd")[0] + with self.assertRaises(EngineException) as e: + fg.update({"nfp-position-element": [{"id": "test1"}]}) + self.topic.validate_vnffgd_data(fg, indata) + self.assertEqual( + e.exception.http_code, + HTTPStatus.UNPROCESSABLE_ENTITY, + "Wrong HTTP status code", + ) + self.assertIn( + norm( + "Error at vnffgd nfpd[id='{}']:nfp-position-element-id='{}' " + "does not match any nfp-position-element".format(nfpd["id"], "test") + ), + norm(str(e.exception)), + "Wrong exception text", + ) + + def test_validate_vnffgd_descriptor_not_matching_constituent_base_element_id( + self, + ): + indata = yaml.safe_load(db_sfc_nsds_text)[0] + vnffgd = indata.get("vnffgd") + fg = vnffgd[0] + fg["nfpd"][0]["position-desc-id"][0]["cp-profile-id"][0][ + "constituent-profile-elements" + ][0]["constituent-base-element-id"] = "error_vnf" + with self.assertRaises(EngineException) as e: + self.topic.validate_vnffgd_data(fg, indata) + self.assertEqual( + e.exception.http_code, + HTTPStatus.UNPROCESSABLE_ENTITY, + "Wrong HTTP status code", + ) + self.assertIn( + norm( + "Error at vnffgd constituent_profile[id='{}']:vnfd-id='{}' " + "does not match any constituent-base-element-id".format( + "vnf1", "error_vnf" + ) + ), + norm(str(e.exception)), + "Wrong exception text", + ) + if __name__ == "__main__": unittest.main()