X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=n2vc%2Ftests%2Funit%2Ftest_n2vc_juju_conn.py;h=832400669efe91ed5b9e8abb5a364b21c61b913b;hb=refs%2Fchanges%2F92%2F12592%2F2;hp=ebf36d52e57aab615610f73545751e0fbbbf58db;hpb=01244641fdac89ce2afd5490e5c6d2bcf7ad05ae;p=osm%2FN2VC.git diff --git a/n2vc/tests/unit/test_n2vc_juju_conn.py b/n2vc/tests/unit/test_n2vc_juju_conn.py index ebf36d5..8324006 100644 --- a/n2vc/tests/unit/test_n2vc_juju_conn.py +++ b/n2vc/tests/unit/test_n2vc_juju_conn.py @@ -473,12 +473,14 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase): ] vnf_count = "" vdu_count = "" + vdu_id = None expected_result = "simple-ns-charm-abc-000-rrrr-nnnn-4444-h-ns" 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) @@ -490,12 +492,14 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase): vca_records = [] vnf_count = "" vdu_count = "" + vdu_id = None with self.assertRaises(N2VCException): self.n2vc._generate_application_name( charm_level, vnfrs, vca_records, vnf_count=vnf_count, + vdu_id=vdu_id, vdu_count=vdu_count, ) @@ -516,12 +520,14 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase): ] vnf_count = "1" vdu_count = "" + vdu_id = None expected_result = "simple-ee-ab-1-vnf111-xxx-y-vnf" 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) @@ -540,7 +546,7 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase): { "target_element": "vnf/vnf1/mgmtvm", "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", @@ -564,18 +570,20 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase): ] 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_wrong_vnfrs(self): + def test_generate_application_name_vdu_charm_vdu_id_none(self): charm_level = "vdu-level" vnfrs = { "member-vnf-index-ref": "vnf111-xxx-yyy-zzz", @@ -584,7 +592,7 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase): { "target_element": "vnf/vnf1/mgmtvm", "member-vnf-index": "vnf111-xxx-yyy-zzz", - "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", + "vdu_id": None, "kdu_name": None, "vdu_count_index": None, "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898", @@ -596,12 +604,14 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase): ] vnf_count = "2" vdu_count = "0" - with self.assertRaises(KeyError): + vdu_id = None + with self.assertRaises(N2VCException): self.n2vc._generate_application_name( charm_level, vnfrs, vca_records, vnf_count=vnf_count, + vdu_id=vdu_id, vdu_count=vdu_count, ) @@ -1011,7 +1021,7 @@ class GenerateApplicationNameTest(N2VCJujuConnTestCase): { "target_element": "vnf/vnf1/mgmtvm", "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", @@ -1058,6 +1068,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": "ldap", + "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-ldap-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"}