Fixing Bug 2181 Application name creation for Helm chart
[osm/N2VC.git] / n2vc / n2vc_juju_conn.py
index da09fdb..64e338c 100644 (file)
@@ -1288,6 +1288,23 @@ class N2VCJujuConnector(N2VCConnector):
         )
         return application_name
 
+    @staticmethod
+    def _get_vca_record(search_key: str, vca_records: list, vdu_id: str) -> dict:
+        """Get the correct VCA record dict depending on the search key
+
+        Args:
+            search_key  (str):      keyword to find the correct VCA record
+            vca_records (list):     All VCA records as list
+            vdu_id  (str):          VDU ID
+
+        Returns:
+            vca_record  (dict):     Dictionary which includes the correct VCA record
+
+        """
+        return next(
+            filter(lambda record: record[search_key] == vdu_id, vca_records), {}
+        )
+
     @staticmethod
     def _generate_application_name(
         charm_level: str,
@@ -1355,9 +1372,16 @@ class N2VCJujuConnector(N2VCConnector):
             # to first 12 characters.
             if not vdu_id:
                 raise N2VCException(message="vdu-id should be provided.")
-            vca_record = next(
-                filter(lambda record: record["vdu_id"] == vdu_id, vca_records), {}
+
+            vca_record = N2VCJujuConnector._get_vca_record(
+                "vdu_id", vca_records, vdu_id
             )
+
+            if not vca_record:
+                vca_record = N2VCJujuConnector._get_vca_record(
+                    "kdu_name", vca_records, vdu_id
+                )
+
             application_name = (
                 vca_record["ee_descriptor_id"][:12]
                 + "-"