+class TestInstantiateN2VC(TestBaseNS):
+ async def setUp(self):
+ await super().setUp()
+ self.db_nsr = yaml.safe_load(descriptors.db_nsrs_text)[0]
+ self.db_vnfr = yaml.safe_load(descriptors.db_vnfrs_text)[0]
+ self.vca_index = 1
+ self.my_ns._write_configuration_status = Mock()
+
+ async def call_instantiate_N2VC(self):
+ logging_text = "N2VC Instantiation"
+ config_descriptor = {"config-access": {"ssh-access": {"default-user": "admin"}}}
+ base_folder = {"pkg-dir": "", "folder": "~"}
+ stage = ["Stage", "Message"]
+
+ await self.my_ns.instantiate_N2VC(
+ logging_text=logging_text,
+ vca_index=self.vca_index,
+ nsi_id="nsi_id",
+ db_nsr=self.db_nsr,
+ db_vnfr=self.db_vnfr,
+ vdu_id=None,
+ kdu_name=None,
+ vdu_index=None,
+ kdu_index=None,
+ config_descriptor=config_descriptor,
+ deploy_params={},
+ base_folder=base_folder,
+ nslcmop_id="nslcmop_id",
+ stage=stage,
+ vca_type="native_charm",
+ vca_name="vca_name",
+ ee_config_descriptor={},
+ )
+
+ def check_config_status(self, expected_status):
+ self.my_ns._write_configuration_status.assert_called_with(
+ nsr_id=self.db_nsr["_id"], vca_index=self.vca_index, status=expected_status
+ )
+
+ async def call_ns_add_relation(self):
+ ee_relation = EERelation(
+ {
+ "nsr-id": self.db_nsr["_id"],
+ "vdu-profile-id": None,
+ "kdu-resource-profile-id": None,
+ "vnf-profile-id": "hackfest_vnf1",
+ "execution-environment-ref": "f48163a6-c807-47bc-9682-f72caef5af85.alf-c-ab",
+ "endpoint": "127.0.0.1",
+ }
+ )
+
+ relation = Relation("relation-name", ee_relation, ee_relation)
+ cached_vnfrs = {"hackfest_vnf1": self.db_vnfr}
+
+ return await self.my_ns._add_relation(
+ relation=relation,
+ vca_type="native_charm",
+ db_nsr=self.db_nsr,
+ cached_vnfds={},
+ cached_vnfrs=cached_vnfrs,
+ )
+
+ async def test_add_relation_ok(self):
+ await self.call_instantiate_N2VC()
+ self.check_config_status(expected_status="READY")
+
+ async def test_add_relation_returns_false_raises_exception(self):
+ self.my_ns._add_vca_relations = asynctest.CoroutineMock(return_value=False)
+
+ with self.assertRaises(LcmException) as exception:
+ await self.call_instantiate_N2VC()
+
+ exception_msg = "Relations could not be added to VCA."
+ self.assertTrue(exception_msg in str(exception.exception))
+ self.check_config_status(expected_status="BROKEN")
+
+ async def test_add_relation_raises_lcm_exception(self):
+ exception_msg = "Relations FAILED"
+ self.my_ns._add_vca_relations = asynctest.CoroutineMock(
+ side_effect=LcmException(exception_msg)
+ )
+
+ with self.assertRaises(LcmException) as exception:
+ await self.call_instantiate_N2VC()
+
+ self.assertTrue(exception_msg in str(exception.exception))
+ self.check_config_status(expected_status="BROKEN")
+
+ async def test_n2vc_add_relation_fails_raises_exception(self):
+ exception_msg = "N2VC failed to add relations"
+ self.my_ns.n2vc.add_relation = asynctest.CoroutineMock(
+ side_effect=N2VCException(exception_msg)
+ )
+ with self.assertRaises(LcmException) as exception:
+ await self.call_ns_add_relation()
+ self.assertTrue(exception_msg in str(exception.exception))
+
+ async def test_n2vc_add_relation_ok_returns_true(self):
+ self.my_ns.n2vc.add_relation = asynctest.CoroutineMock(return_value=None)
+ self.assertTrue(await self.call_ns_add_relation())
+
+