Bug 2210 NS instantiation fails in basic12 34/12834/8
authorPatricia Reinoso <patricia.reinoso@canonical.com>
Thu, 12 Jan 2023 09:40:53 +0000 (09:40 +0000)
committercubag <gcuba@whitestack.com>
Fri, 13 Jan 2023 20:15:09 +0000 (21:15 +0100)
An exception is raised during NS instantation
when we try to access vnf_profile_id of
a NS charm (VCA) which is None

Change-Id: I7e3a26c6877f117b4ad5834d2b1a86767e7b7756
Signed-off-by: Patricia Reinoso <patricia.reinoso@canonical.com>
osm_lcm/data_utils/vca.py
osm_lcm/ns.py
osm_lcm/tests/test_db_descriptors.py
osm_lcm/tests/test_ns.py

index 0f3ec17..ff52d22 100644 (file)
@@ -224,3 +224,7 @@ class DeployedVCA(DeployedComponent):
     @property
     def config_sw_installed(self) -> bool:
         return self.get("config_sw_installed", False)
+
+    @property
+    def target_element(self) -> str:
+        return self.get("target_element", "")
index 20e813f..8f2b192 100644 (file)
@@ -2999,6 +2999,9 @@ class NsLcm(LcmBase):
         cached_vnfds: Dict[str, Any],
     ) -> List[Relation]:
         relations = []
+        if vca.target_element == "ns":
+            self.logger.debug("VCA is a NS charm, not a VNF.")
+            return relations
         vnf_profile = get_vnf_profile(nsd, vca.vnf_profile_id)
         vnf_profile_id = vnf_profile["id"]
         vnfd_id = vnf_profile["vnfd-id"]
index 7f47231..4e2dedb 100644 (file)
@@ -2252,6 +2252,27 @@ db_vnfds_text = """
                     - data-type: STRING
                       default-value: <touch_filename2>
                       name: filename
+              relation:
+                - entities:
+                  - endpoint: interface
+                    id: mgmtVM
+                  - endpoint: interface
+                    id: dataVM
+                  name: relation
+            - id: mgmtVM
+              execution-environment-list:
+              - id: simple-ee
+                juju:
+                  charm: simple_mgmtVM
+                  proxy: false
+                external-connection-point-ref: mgmt
+            - id: dataVM
+              execution-environment-list:
+              - id: simple-ee
+                juju:
+                  charm: simple_dataVM
+                  proxy: false
+                external-connection-point-ref: mgmt
 
 -   _admin:
         created: 1575031727.5383403
index 2dbc006..7e72700 100644 (file)
@@ -31,7 +31,7 @@ from osm_lcm.lcm_utils import TaskRegistry
 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
@@ -514,13 +514,16 @@ class TestMyNS(TestBaseNS):
                         ):
                             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)
@@ -1625,5 +1628,63 @@ class TestInstantiateN2VC(TestBaseNS):
         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()