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
)
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"}