From f576eb9b45f9b1e12adbc503681a2194b8ec85aa Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Sun, 18 Apr 2021 20:54:13 +0000 Subject: [PATCH 1/1] Fix bug 1479 to check conflicts on deleting vnpkg This change affects descriptor_topics.py, specifically the method check_conflict_on_del of class VnfdTopic. When deleting a NF package, several checks are required. One of them is the search of NS packages using that NF package. The filter used for that search was not updated when moving to SOL006 descriptors. That filter is updated by this change. In addition, this change updates the messages returned in case of conflicts. The terms 'instance' and 'package' are added for clarification. Change-Id: I312e9955347c7b79286a0fb33970441edfc17ff0 Signed-off-by: garciadeblas --- osm_nbi/descriptor_topics.py | 12 +++++++----- osm_nbi/tests/test_descriptor_topics.py | 14 +++++++------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index d6b2884..df218cc 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -539,13 +539,14 @@ class VnfdTopic(DescriptorTopic): # check vnfrs using this vnfd _filter["vnfd-id"] = _id if self.db.get_list("vnfrs", _filter): - raise EngineException("There is at least one VNF using this descriptor", http_code=HTTPStatus.CONFLICT) + raise EngineException("There is at least one VNF instance using this descriptor", + http_code=HTTPStatus.CONFLICT) # check NSD referencing this VNFD del _filter["vnfd-id"] - _filter["constituent-vnfd.ANYINDEX.vnfd-id-ref"] = descriptor_id + _filter["vnfd-id"] = descriptor_id if self.db.get_list("nsds", _filter): - raise EngineException("There is at least one NSD referencing this descriptor", + raise EngineException("There is at least one NS package referencing this descriptor", http_code=HTTPStatus.CONFLICT) def _validate_input_new(self, indata, storage_params, force=False): @@ -1019,7 +1020,8 @@ class NsdTopic(DescriptorTopic): _filter = self._get_project_filter(session) _filter["nsd-id"] = _id if self.db.get_list("nsrs", _filter): - raise EngineException("There is at least one NS using this descriptor", http_code=HTTPStatus.CONFLICT) + raise EngineException("There is at least one NS instance using this descriptor", + http_code=HTTPStatus.CONFLICT) # check NSD referenced by NST del _filter["nsd-id"] @@ -1170,7 +1172,7 @@ class PduTopic(BaseTopic): _filter = self._get_project_filter(session) _filter["vdur.pdu-id"] = _id if self.db.get_list("vnfrs", _filter): - raise EngineException("There is at least one VNF using this PDU", http_code=HTTPStatus.CONFLICT) + raise EngineException("There is at least one VNF instance using this PDU", http_code=HTTPStatus.CONFLICT) class VnfPkgOpTopic(BaseTopic): diff --git a/osm_nbi/tests/test_descriptor_topics.py b/osm_nbi/tests/test_descriptor_topics.py index b52b6e0..0b1d800 100755 --- a/osm_nbi/tests/test_descriptor_topics.py +++ b/osm_nbi/tests/test_descriptor_topics.py @@ -426,8 +426,8 @@ class Test_VnfdTopic(TestCase): self.assertEqual(db_gl_calls[0][0][0], "vnfrs", "Wrong DB topic") # self.assertEqual(db_gl_calls[0][0][1]["vnfd-id"], did, "Wrong DB VNFD ID") # Filter changed after call self.assertEqual(db_gl_calls[1][0][0], "nsds", "Wrong DB topic") - self.assertEqual(db_gl_calls[1][0][1]["constituent-vnfd.ANYINDEX.vnfd-id-ref"], db_vnfd_content["id"], - "Wrong DB NSD constituent-vnfd id-ref") + self.assertEqual(db_gl_calls[1][0][1]["vnfd-id"], db_vnfd_content["id"], + "Wrong DB NSD vnfd-id") self.db.set_one.assert_not_called() fs_del_calls = self.fs.file_delete.call_args_list @@ -438,14 +438,14 @@ class Test_VnfdTopic(TestCase): with self.assertRaises(EngineException, msg="Accepted VNFD in use by VNFR") as e: self.topic.delete(fake_session, did) self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code") - self.assertIn("there is at least one vnf using this descriptor", norm(str(e.exception)), + self.assertIn("there is at least one vnf instance using this descriptor", norm(str(e.exception)), "Wrong exception text") with self.subTest(i=3, t='Conflict on Delete - VNFD in use by NSD'): self.db.get_list.side_effect = [[], [{"_id": str(uuid4()), "name": "fake-nsd"}]] with self.assertRaises(EngineException, msg="Accepted VNFD in use by NSD") as e: self.topic.delete(fake_session, did) self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code") - self.assertIn("there is at least one nsd referencing this descriptor", norm(str(e.exception)), + self.assertIn("there is at least one ns package referencing this descriptor", norm(str(e.exception)), "Wrong exception text") with self.subTest(i=4, t='Non-existent VNFD'): excp_msg = "Not found any {} with filter='{}'".format("VNFD", {"_id": did}) @@ -805,11 +805,11 @@ class Test_NsdTopic(TestCase): norm(str(e.exception)), "Wrong exception text") finally: del df['virtual-link-profile'] - with self.subTest(i=6, t='Check Descriptor Dependencies: constituent-vnfd[vnfd-id-ref]'): + with self.subTest(i=6, t='Check Descriptor Dependencies: vnfd-id[]'): self.db.get_one.side_effect = [{"_id": did, "_admin": db_nsd_content["_admin"]}, None] self.db.get_list.return_value = [] try: - with self.assertRaises(EngineException, msg="Accepted wrong constituent VNFD ID reference") as e: + with self.assertRaises(EngineException, msg="Accepted wrong VNFD ID reference") as e: self.topic.upload_content(fake_session, did, test_nsd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code") self.assertIn(norm("'vnfd-id'='{}' references a non existing vnfd".format(test_nsd['vnfd-id'][0])), @@ -919,7 +919,7 @@ class Test_NsdTopic(TestCase): with self.assertRaises(EngineException, msg="Accepted NSD in use by NSR") as e: self.topic.delete(fake_session, did) self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code") - self.assertIn("there is at least one ns using this descriptor", norm(str(e.exception)), + self.assertIn("there is at least one ns instance using this descriptor", norm(str(e.exception)), "Wrong exception text") with self.subTest(i=3, t='Conflict on Delete - NSD in use by NST'): self.db.get_list.side_effect = [[], [{"_id": str(uuid4()), "name": "fake-nst"}]] -- 2.17.1