X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Ftests%2Ftest_instance_topics.py;h=2ad596d87b73f53c98b917b28376db356ed72715;hp=b05ee0c39f761b33833b4391e73b9ea62d307073;hb=c9c0339dee11c893b35e9eb05098554dbda751a3;hpb=544a2ae8b0b950b55f29c3f0a223ffe4874285e5 diff --git a/osm_nbi/tests/test_instance_topics.py b/osm_nbi/tests/test_instance_topics.py index b05ee0c..2ad596d 100644 --- a/osm_nbi/tests/test_instance_topics.py +++ b/osm_nbi/tests/test_instance_topics.py @@ -57,7 +57,6 @@ class TestNsLcmOpTopic(unittest.TestCase): self.db.create_list("vnfrs", yaml.load(db_vnfrs_text, Loader=yaml.Loader)) self.db.create_list("nsrs", yaml.load(db_nsrs_text, Loader=yaml.Loader)) self.db.create = Mock(return_value="created_id") - self.db.set_one = Mock(return_value={"updated": 1}) self.nsd = self.db.get_list("nsds")[0] self.nsd_id = self.nsd["_id"] self.nsr = self.db.get_list("nsrs")[0] @@ -68,6 +67,7 @@ class TestNsLcmOpTopic(unittest.TestCase): self.vim_id = self.vim["_id"] def test_create_instantiate(self): + self.db.set_one = Mock(return_value={"updated": 1}) session = { "force": False, "admin": False, @@ -228,6 +228,59 @@ class TestNsLcmOpTopic(unittest.TestCase): "Engine exception bad http_code with {}".format(indata_copy), ) + def test_update_remove_vnf(self): + vnfr_id = self.db.get_list("vnfrs")[0]["_id"] + session = {} + self.db.set_one( + "nsrs", + {"_id": self.nsr_id}, + {"_admin.nsState": "INSTANTIATED"}, + ) + indata = { + "lcmOperationType": "update", + "updateType": "REMOVE_VNF", + "nsInstanceId": self.nsr_id, + "removeVnfInstanceId": vnfr_id + } + + session = { + "force": False, + "admin": False, + "public": False, + "project_id": [self.nsr_project], + "method": "write", + } + rollback = [] + headers = {} + + nslcmop_id, _ = self.nslcmop_topic.new( + rollback, session, indata, kwargs=None, headers=headers + ) + + self.assertEqual( + self.db.create.call_count, + 1, + "database create not called, or called more than once", + ) + _call = self.db.create.call_args_list[0] + self.assertEqual( + _call[0][0], "nslcmops", "nslcmops entry must be created at database" + ) + created_nslcmop = _call[0][1] + self.assertEqual( + self.nsr_id, + created_nslcmop["nsInstanceId"], + "mismatch between nsId '_id' in created nslcmop and database nsr", + ) + self.assertTrue( + created_nslcmop["lcmOperationType"] == "update", + "Database record must contain 'lcmOperationType=update'", + ) + self.assertTrue( + created_nslcmop["operationParams"]["updateType"] == "REMOVE_VNF", + "Database record must contain 'updateType=REMOVE_VNF'", + ) + class TestNsLcmOpTopicWithMock(unittest.TestCase): def setUp(self): @@ -356,6 +409,20 @@ class TestNsLcmOpTopicWithMock(unittest.TestCase): "VNF instance: 88d90b0c-faff-4b9f-bccd-017f33985984", ) + with self.subTest(i=5, t="Ns update REMOVE_VNF request validated with no exception"): + test_vnfr = yaml.load(db_vnfrs_text, Loader=yaml.Loader) + test_vnfr[0]["revision"] = 2 + test_nsr = yaml.load(db_nsrs_text, Loader=yaml.Loader) + self.db.create_list("vnfrs", test_vnfr) + self.db.create_list("nsrs", test_nsr) + nsrs = self.db.get_list("nsrs")[1] + indata = { + "updateType": "REMOVE_VNF", + "removeVnfInstanceId": "88d90b0c-faff-4b9f-bccd-017f33985984", + "nsInstanceId": "f48163a6-c807-47bc-9682-f72caef5af85", + } + with self.assertNotRaises(EngineException): + self.nslcmop_topic._check_ns_operation(session, nsrs, "update", indata) class TestNsrTopic(unittest.TestCase): def setUp(self): @@ -464,6 +531,19 @@ class TestNsrTopic(unittest.TestCase): self.assertEqual( len(created_vnfrs), 2, "created a mismatch number of vnfr at database" ) + + self.assertEqual( + created_vnfrs[0]["vdur"][0]["interfaces"][0]["position"], + 1, + "vdur first interface position does not match", + ) + + self.assertEqual( + created_vnfrs[0]["vdur"][0]["interfaces"][1]["position"], + 2, + "vdur second interface position does not match", + ) + self.assertEqual( len(created_nsrs), 1, "Only one nsrs must be created at database" )