from osm_lcm.ng_ro import NgRoClient
from osm_lcm.data_utils.database.database import Database
from osm_lcm.data_utils.filesystem.filesystem import Filesystem
-from osm_lcm.data_utils.vca import Relation, EERelation
+from osm_lcm.data_utils.vca import Relation, EERelation, DeployedVCA
from osm_lcm.data_utils.vnfd import find_software_version
from osm_lcm.lcm_utils import check_juju_bundle_existence, get_charm_artifact_path
from osm_lcm.lcm_utils import LcmException
):
if (
v.get("execution-environment-list")
- and "juju" in v["execution-environment-list"][k]
+ and "juju" in v["execution-environment-list"][0]
):
expected_value = self.db.get_list("nsrs")[i][
"vcaStatus"
]
await self.my_ns._on_update_n2vc_db(
- "nsrs", {"_id": nsr_id}, "_admin.deployed.VCA.0", {}
+ "nsrs",
+ {"_id": nsr_id},
+ "_admin.deployed.VCA.{}".format(k),
+ {},
)
return_value = self.db.get_list("nsrs")[i]["vcaStatus"]
self.assertEqual(return_value, expected_value)
self.assertTrue(await self.call_ns_add_relation())
+class TestGetVNFRelations(TestBaseNS):
+ async def setUp(self):
+ await super().setUp()
+ self.db_nsd = yaml.safe_load(descriptors.db_nsds_text)[0]
+
+ def test_ns_charm_vca_returns_empty_relations(self):
+ ns_charm_vca = {"member-vnf-index": None, "target_element": "ns"}
+ nsr_id = self.db_nsd["id"]
+ deployed_vca = DeployedVCA(nsr_id, ns_charm_vca)
+
+ expected_relations = []
+ self.assertEqual(
+ expected_relations,
+ self.my_ns._get_vnf_relations(
+ nsr_id=nsr_id, nsd=self.db_nsd, vca=deployed_vca, cached_vnfds={}
+ ),
+ )
+
+ def test_vnf_returns_relation(self):
+ vnf_vca = {
+ "member-vnf-index": "1",
+ "target_element": "vnf/0",
+ "ee_descriptor_id": "simple-ee",
+ "vdu_id": "mgmtVM",
+ }
+ nsr_id = self.db_nsd["id"]
+ deployed_vca = DeployedVCA(nsr_id, vnf_vca)
+
+ provider_dict = {
+ "nsr-id": nsr_id,
+ "vnf-profile-id": "1",
+ "vdu-profile-id": "mgmtVM",
+ "kdu-resource-profile-id": None,
+ "execution-environment-ref": "simple-ee",
+ "endpoint": "interface",
+ }
+
+ requirer_dict = {
+ "nsr-id": nsr_id,
+ "vnf-profile-id": "1",
+ "vdu-profile-id": "dataVM",
+ "kdu-resource-profile-id": None,
+ "execution-environment-ref": "simple-ee",
+ "endpoint": "interface",
+ }
+
+ provider = EERelation(provider_dict)
+ requirer = EERelation(requirer_dict)
+ relation = Relation("relation", provider, requirer)
+
+ relations_found = self.my_ns._get_vnf_relations(
+ nsr_id=nsr_id, nsd=self.db_nsd, vca=deployed_vca, cached_vnfds={}
+ )
+
+ self.assertEqual(1, len(relations_found))
+ self.assertEqual(relation, relations_found[0])
+
+
if __name__ == "__main__":
asynctest.main()