- it checks the vnfInstanceId, whether it's available under ns instance
- it checks the vnfdId whether it matches with the vnfd-id in the vnf-record of specified VNF.
Otherwise exception will be raised.
+ If updateType is REMOVE_VNF:
+ - it checks if the vnfInstanceId is available in the ns instance
+ - Otherwise exception will be raised.
Args:
indata: includes updateType such as CHANGE_VNFPKG,
),
http_code=HTTPStatus.UNPROCESSABLE_ENTITY,
)
+ elif indata["updateType"] == "REMOVE_VNF":
+ vnf_instance_id = indata["removeVnfInstanceId"]
+ ns_instance_id = indata["nsInstanceId"]
+ if vnf_instance_id not in nsr["constituent-vnfr-ref"]:
+ raise EngineException(
+ "Invalid VNF Instance Id. '{}' is not "
+ "present in the NS '{}'".format(vnf_instance_id, ns_instance_id)
+ )
except (
DbException,
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]
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,
"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):
"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):