Fixing Bug 2181 Application name creation for Helm chart
[osm/N2VC.git] / n2vc / tests / unit / test_n2vc_juju_conn.py
index 8324006..7606b4a 100644 (file)
@@ -533,7 +533,7 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase):
         self.assertEqual(application_name, expected_result)
         self.assertLess(len(application_name), 50)
 
         self.assertEqual(application_name, expected_result)
         self.assertLess(len(application_name), 50)
 
-    def test_generate_application_name_vdu_charm(self):
+    def test_generate_application_name_vdu_charm_kdu_name_in_vca_record_is_none(self):
         charm_level = "vdu-level"
         vnfrs = {
             "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
         charm_level = "vdu-level"
         vnfrs = {
             "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
@@ -556,9 +556,9 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase):
                 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
             },
             {
                 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
             },
             {
-                "target_element": "vnf/vnf1/datavm",
+                "target_element": "vnf/vnf1/dataVM",
                 "member-vnf-index": "vnf111-xxx-yyy-zzz",
                 "member-vnf-index": "vnf111-xxx-yyy-zzz",
-                "vdu_id": "45512ff7-5bdd-4228-911f-c2bee259c44a",
+                "vdu_id": "dataVM",
                 "kdu_name": None,
                 "vdu_count_index": None,
                 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
                 "kdu_name": None,
                 "vdu_count_index": None,
                 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
@@ -583,14 +583,68 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase):
         self.assertEqual(application_name, expected_result)
         self.assertLess(len(application_name), 50)
 
         self.assertEqual(application_name, expected_result)
         self.assertLess(len(application_name), 50)
 
-    def test_generate_application_name_vdu_charm_vdu_id_none(self):
+    def test_generate_application_name_vdu_charm_vdu_id_kdu_name_in_vca_record_are_both_set(
+        self,
+    ):
         charm_level = "vdu-level"
         vnfrs = {
             "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
         charm_level = "vdu-level"
         vnfrs = {
             "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
+            "vdur": [
+                {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
+                {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
+            ],
         }
         vca_records = [
             {
         }
         vca_records = [
             {
-                "target_element": "vnf/vnf1/mgmtvm",
+                "target_element": "vnf/vnf1/mgmtVM",
+                "member-vnf-index": "vnf111-xxx-yyy-zzz",
+                "vdu_id": "mgmtVM",
+                "kdu_name": "mgmtVM",
+                "vdu_count_index": None,
+                "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+                "vdu_name": "mgmtvm",
+                "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
+                "charm_name": "",
+                "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+            },
+            {
+                "target_element": "vnf/vnf1/dataVM",
+                "member-vnf-index": "vnf111-xxx-yyy-zzz",
+                "vdu_id": "dataVM",
+                "kdu_name": None,
+                "vdu_count_index": None,
+                "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+                "vdu_name": "datavm",
+                "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
+                "charm_name": "",
+                "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+            },
+        ]
+        vnf_count = "2"
+        vdu_count = "0"
+        vdu_id = "mgmtVM"
+        expected_result = "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
+        application_name = self.n2vc._generate_application_name(
+            charm_level,
+            vnfrs,
+            vca_records,
+            vnf_count=vnf_count,
+            vdu_id=vdu_id,
+            vdu_count=vdu_count,
+        )
+        self.assertEqual(application_name, expected_result)
+        self.assertLess(len(application_name), 50)
+
+    def test_generate_application_name_vdu_charm_both_vdu_id_kdu_name_in_vca_record_are_none(
+        self,
+    ):
+        charm_level = "vdu-level"
+        vnfrs = {
+            "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
+        }
+        vca_records = [
+            {
+                "target_element": "vnf/vnf1/mgmtVM",
                 "member-vnf-index": "vnf111-xxx-yyy-zzz",
                 "vdu_id": None,
                 "kdu_name": None,
                 "member-vnf-index": "vnf111-xxx-yyy-zzz",
                 "vdu_id": None,
                 "kdu_name": None,
@@ -604,6 +658,38 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase):
         ]
         vnf_count = "2"
         vdu_count = "0"
         ]
         vnf_count = "2"
         vdu_count = "0"
+        vdu_id = "mgmtVM"
+        with self.assertRaises(KeyError):
+            self.n2vc._generate_application_name(
+                charm_level,
+                vnfrs,
+                vca_records,
+                vnf_count=vnf_count,
+                vdu_id=vdu_id,
+                vdu_count=vdu_count,
+            )
+
+    def test_generate_application_name_vdu_charm_given_vdu_id_is_none(self):
+        charm_level = "vdu-level"
+        vnfrs = {
+            "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
+        }
+        vca_records = [
+            {
+                "target_element": "vnf/vnf1/mgmtvVM",
+                "member-vnf-index": "vnf111-xxx-yyy-zzz",
+                "vdu_id": None,
+                "kdu_name": "mgmtVM",
+                "vdu_count_index": None,
+                "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+                "vdu_name": "mgmtvm",
+                "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
+                "charm_name": "",
+                "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+            },
+        ]
+        vnf_count = "2"
+        vdu_count = "0"
         vdu_id = None
         with self.assertRaises(N2VCException):
             self.n2vc._generate_application_name(
         vdu_id = None
         with self.assertRaises(N2VCException):
             self.n2vc._generate_application_name(
@@ -615,6 +701,74 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase):
                 vdu_count=vdu_count,
             )
 
                 vdu_count=vdu_count,
             )
 
+    def test_generate_application_name_vdu_charm_vdu_id_does_not_match_with_the_key_in_vca_record(
+        self,
+    ):
+        charm_level = "vdu-level"
+        vnfrs = {
+            "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
+        }
+        vca_records = [
+            {
+                "target_element": "vnf/vnf1/mgmtVM",
+                "member-vnf-index": "vnf111-xxx-yyy-zzz",
+                "vdu_id": None,
+                "kdu_name": "mgmtVM",
+                "vdu_count_index": None,
+                "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+                "vdu_name": "mgmtvm",
+                "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
+                "charm_name": "",
+                "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+            },
+        ]
+        vnf_count = "2"
+        vdu_count = "0"
+        vdu_id = "mgmtvm"
+        with self.assertRaises(KeyError):
+            self.n2vc._generate_application_name(
+                charm_level,
+                vnfrs,
+                vca_records,
+                vnf_count=vnf_count,
+                vdu_id=vdu_id,
+                vdu_count=vdu_count,
+            )
+
+    def test_generate_application_name_vdu_charm_vdu_id_in_vca_record_is_none(self):
+        charm_level = "vdu-level"
+        vnfrs = {
+            "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
+        }
+        vca_records = [
+            {
+                "target_element": "vnf/vnf1/mgmtVM",
+                "member-vnf-index": "vnf111-xxx-yyy-zzz",
+                "vdu_id": None,
+                "kdu_name": "mgmtVM",
+                "vdu_count_index": None,
+                "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+                "vdu_name": "mgmtvm",
+                "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
+                "charm_name": "",
+                "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+            },
+        ]
+        vnf_count = "2"
+        vdu_count = "0"
+        vdu_id = "mgmtVM"
+        expected_result = "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
+        application_name = self.n2vc._generate_application_name(
+            charm_level,
+            vnfrs,
+            vca_records,
+            vnf_count=vnf_count,
+            vdu_id=vdu_id,
+            vdu_count=vdu_count,
+        )
+        self.assertEqual(application_name, expected_result)
+        self.assertLess(len(application_name), 50)
+
     def test_get_vnf_count_db_vnfr_ns_charm(self):
         self.db.get_one.return_value = {"member-vnf-index-ref": "sample-ref"}
         charm_level = "ns-level"
     def test_get_vnf_count_db_vnfr_ns_charm(self):
         self.db.get_one.return_value = {"member-vnf-index-ref": "sample-ref"}
         charm_level = "ns-level"
@@ -1077,7 +1231,7 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase):
                         {
                             "target_element": "vnf/openldap/kdu/ldap",
                             "member-vnf-index": "openldap",
                         {
                             "target_element": "vnf/openldap/kdu/ldap",
                             "member-vnf-index": "openldap",
-                            "vdu_id": "ldap",
+                            "vdu_id": None,
                             "kdu_name": "ldap",
                             "vdu_count_index": 0,
                             "operational-status": "init",
                             "kdu_name": "ldap",
                             "vdu_count_index": 0,
                             "operational-status": "init",
@@ -1129,9 +1283,9 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase):
                 "deployed": {
                     "VCA": [
                         {
                 "deployed": {
                     "VCA": [
                         {
-                            "target_element": "vnf/vnf1/mgmtvm",
+                            "target_element": "vnf/vnf1/mgmtVM",
                             "member-vnf-index": "vnf111-xxx-yyy-zzz",
                             "member-vnf-index": "vnf111-xxx-yyy-zzz",
-                            "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
+                            "vdu_id": "mgmtVM",
                             "kdu_name": None,
                             "vdu_count_index": None,
                             "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
                             "kdu_name": None,
                             "vdu_count_index": None,
                             "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",