From: aticig Date: Fri, 19 Aug 2022 16:58:13 +0000 (+0300) Subject: Fixing charm application name creation if DU is Helm Chart/KDU X-Git-Tag: release-v13.0-start~14 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F70%2F12470%2F2;p=osm%2FN2VC.git Fixing charm application name creation if DU is Helm Chart/KDU If deployment unit is a Helm chart/KDU, vdu_profile_id and vdu_count will be empty string. Change-Id: Ifb6aed0f08f2d7687d0cd6a31506268926ac7f63 Signed-off-by: aticig --- diff --git a/n2vc/n2vc_juju_conn.py b/n2vc/n2vc_juju_conn.py index 5dc394c..f0569b1 100644 --- a/n2vc/n2vc_juju_conn.py +++ b/n2vc/n2vc_juju_conn.py @@ -1338,7 +1338,18 @@ class N2VCJujuConnector(N2VCConnector): elif charm_level == "vdu-level": if len(vca_records) < 1: raise N2VCException(message="One or more VCA record is expected.") - vdu_profile_id = vnfrs["vdur"][int(vdu_count)]["vdu-id-ref"] + + # Charms are also used for deployments with Helm charts. + # If deployment unit is a Helm chart/KDU, + # vdu_profile_id and vdu_count will be empty string. + vdu_profile_id = "" + + if vdu_count is None: + vdu_count = "" + + elif vdu_count: + vdu_profile_id = vnfrs["vdur"][int(vdu_count)]["vdu-id-ref"] + # If vnf/vdu is scaled, more than one VCA record may be included in vca_records # but ee_descriptor_id is same. # Shorten the ee_descriptor_id, member-vnf-index-ref and vdu_profile_id diff --git a/n2vc/tests/unit/test_n2vc_juju_conn.py b/n2vc/tests/unit/test_n2vc_juju_conn.py index ebf36d5..8720d96 100644 --- a/n2vc/tests/unit/test_n2vc_juju_conn.py +++ b/n2vc/tests/unit/test_n2vc_juju_conn.py @@ -1058,6 +1058,54 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase): ) self.db.get_one.assert_called_once() + def test_get_application_name_kdu_charm(self): + namespace = ".82b11965-e580-47c0-9ee0-329f318a305b.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0.ldap" + self.db.get_one.return_value = { + "_admin": { + "deployed": { + "VCA": [ + { + "target_element": "vnf/openldap/kdu/ldap", + "member-vnf-index": "openldap", + "vdu_id": None, + "kdu_name": "ldap", + "vdu_count_index": 0, + "operational-status": "init", + "detailed-status": "", + "step": "initial-deploy", + "vnfd_id": "openldap_knf", + "vdu_name": None, + "type": "lxc_proxy_charm", + "ee_descriptor_id": "openldap-ee", + "charm_name": "", + "ee_id": "", + "application": "openldap-ee-z0-openldap-vdu", + "model": "82b11965-e580-47c0-9ee0-329f318a305b", + "config_sw_installed": True, + }, + ] + } + } + } + mock_vnf_count_and_record = MagicMock() + db_vnfr = { + "member-vnf-index-ref": "openldap", + "vdur": {}, + } + vnf_count = "0" + mock_vnf_count_and_record.return_value = (vnf_count, db_vnfr) + expected_result = "openldap-ee-z0-openldap-vdu" + with patch.object(self.n2vc, "db", self.db), patch.object( + self.n2vc, "_get_vnf_count_and_record", mock_vnf_count_and_record + ): + application_name = self.n2vc._get_application_name(namespace) + self.assertEqual(application_name, expected_result) + self.assertLess(len(application_name), 50) + mock_vnf_count_and_record.assert_called_once_with( + "vdu-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0" + ) + self.db.get_one.assert_called_once() + @patch( "n2vc.n2vc_juju_conn.generate_random_alfanum_string", **{"return_value": "random"}