1 # Copyright 2020 Canonical Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from unittest
.mock
import Mock
, MagicMock
19 from unittest
.mock
import patch
23 from n2vc
.definitions
import Offer
, RelationEndpoint
24 from n2vc
.n2vc_juju_conn
import N2VCJujuConnector
25 from osm_common
import fslocal
26 from osm_common
.dbmemory
import DbMemory
27 from n2vc
.exceptions
import (
28 N2VCBadArgumentsException
,
30 JujuApplicationNotFound
,
32 from n2vc
.tests
.unit
.utils
import AsyncMock
33 from n2vc
.vca
.connection_data
import ConnectionData
34 from n2vc
.tests
.unit
.testdata
import test_db_descriptors
as descriptors
38 class N2VCJujuConnTestCase(asynctest
.TestCase
):
39 @asynctest.mock
.patch("n2vc.n2vc_juju_conn.MotorStore")
40 @asynctest.mock
.patch("n2vc.n2vc_juju_conn.get_connection")
41 @asynctest.mock
.patch("n2vc.vca.connection_data.base64_to_cacert")
44 mock_base64_to_cacert
=None,
45 mock_get_connection
=None,
48 self
.loop
= asyncio
.get_event_loop()
50 mock_base64_to_cacert
.return_value
= """
51 -----BEGIN CERTIFICATE-----
53 -----END CERTIFICATE-----"""
54 mock_store
.return_value
= AsyncMock()
55 mock_vca_connection
= Mock()
56 mock_get_connection
.return_value
= mock_vca_connection
57 mock_vca_connection
.data
.return_value
= ConnectionData(
59 "endpoints": ["1.2.3.4:17070"],
65 "lxd-credentials": "credentials",
66 "k8s-cloud": "k8s_cloud",
67 "k8s-credentials": "k8s_credentials",
69 "api-proxy": "api_proxy",
72 logging
.disable(logging
.CRITICAL
)
74 N2VCJujuConnector
.get_public_key
= Mock()
75 self
.n2vc
= N2VCJujuConnector(
82 N2VCJujuConnector
.get_public_key
.assert_not_called()
83 self
.n2vc
.libjuju
= Mock()
86 class GetMetricssTest(N2VCJujuConnTestCase
):
88 super(GetMetricssTest
, self
).setUp()
89 self
.n2vc
.libjuju
.get_metrics
= AsyncMock()
91 def test_success(self
):
92 _
= self
.loop
.run_until_complete(self
.n2vc
.get_metrics("model", "application"))
93 self
.n2vc
.libjuju
.get_metrics
.assert_called_once()
95 def test_except(self
):
96 self
.n2vc
.libjuju
.get_metrics
.side_effect
= Exception()
97 with self
.assertRaises(Exception):
98 _
= self
.loop
.run_until_complete(
99 self
.n2vc
.get_metrics("model", "application")
101 self
.n2vc
.libjuju
.get_metrics
.assert_called_once()
104 class UpdateVcaStatusTest(N2VCJujuConnTestCase
):
106 super(UpdateVcaStatusTest
, self
).setUp()
107 self
.n2vc
.libjuju
.get_controller
= AsyncMock()
108 self
.n2vc
.libjuju
.get_model
= AsyncMock()
109 self
.n2vc
.libjuju
.get_executed_actions
= AsyncMock()
110 self
.n2vc
.libjuju
.get_actions
= AsyncMock()
111 self
.n2vc
.libjuju
.get_application_configs
= AsyncMock()
112 self
.n2vc
.libjuju
._get
_application
= AsyncMock()
117 self
.loop
.run_until_complete(
118 self
.n2vc
.update_vca_status(
119 {"model": {"applications": {"app": {"actions": {}}}}}
122 self
.n2vc
.libjuju
.get_executed_actions
.assert_called_once()
123 self
.n2vc
.libjuju
.get_actions
.assert_called_once()
124 self
.n2vc
.libjuju
.get_application_configs
.assert_called_once()
126 def test_exception(self
):
127 self
.n2vc
.libjuju
.get_model
.return_value
= None
128 self
.n2vc
.libjuju
.get_executed_actions
.side_effect
= Exception()
129 with self
.assertRaises(Exception):
130 self
.loop
.run_until_complete(
131 self
.n2vc
.update_vca_status(
132 {"model": {"applications": {"app": {"actions": {}}}}}
135 self
.n2vc
.libjuju
.get_executed_actions
.assert_not_called()
136 self
.n2vc
.libjuju
.get_actions
.assert_not_called_once()
137 self
.n2vc
.libjuju
.get_application_configs
.assert_not_called_once()
140 class K8sProxyCharmsTest(N2VCJujuConnTestCase
):
142 super(K8sProxyCharmsTest
, self
).setUp()
143 self
.n2vc
.libjuju
.model_exists
= AsyncMock()
144 self
.n2vc
.libjuju
.add_model
= AsyncMock()
145 self
.n2vc
.libjuju
.deploy_charm
= AsyncMock()
146 self
.n2vc
.libjuju
.model_exists
.return_value
= False
148 self
.fs
= fslocal
.FsLocal()
150 self
.n2vc
.fs
= self
.fs
151 self
.n2vc
.db
= self
.db
152 self
.db
.create_list("nsrs", yaml
.safe_load(descriptors
.db_nsrs_text
))
153 self
.db
.create_list("vnfrs", yaml
.safe_load(descriptors
.db_vnfrs_text
))
156 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
157 **{"return_value": "random"}
161 mock_generate_random_alfanum_string
,
163 self
.n2vc
.fs
.file_exists
= MagicMock(create_autospec
=True)
164 self
.n2vc
.fs
.file_exists
.return_value
= True
165 ee_id
= self
.loop
.run_until_complete(
166 self
.n2vc
.install_k8s_proxy_charm(
168 ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0",
174 self
.n2vc
.libjuju
.add_model
.assert_called_once()
175 self
.n2vc
.libjuju
.deploy_charm
.assert_called_once_with(
176 model_name
="dbfbd751-3de4-4e68-bd40-ec5ae0a53898-k8s",
177 application_name
="simple-ee-z0-vnf1-vnf",
181 progress_timeout
=None,
186 ee_id
, "dbfbd751-3de4-4e68-bd40-ec5ae0a53898-k8s.simple-ee-z0-vnf1-vnf.k8s"
189 def test_no_artifact_path(
192 with self
.assertRaises(N2VCBadArgumentsException
):
193 ee_id
= self
.loop
.run_until_complete(
194 self
.n2vc
.install_k8s_proxy_charm(
196 ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0",
201 self
.assertIsNone(ee_id
)
206 with self
.assertRaises(N2VCBadArgumentsException
):
207 ee_id
= self
.loop
.run_until_complete(
208 self
.n2vc
.install_k8s_proxy_charm(
210 ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0",
215 self
.assertIsNone(ee_id
)
217 def test_file_not_exists(
220 self
.n2vc
.fs
.file_exists
= MagicMock(create_autospec
=True)
221 self
.n2vc
.fs
.file_exists
.return_value
= False
222 with self
.assertRaises(N2VCBadArgumentsException
):
223 ee_id
= self
.loop
.run_until_complete(
224 self
.n2vc
.install_k8s_proxy_charm(
226 ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0",
231 self
.assertIsNone(ee_id
)
236 self
.n2vc
.fs
.file_exists
= MagicMock(create_autospec
=True)
237 self
.n2vc
.fs
.file_exists
.return_value
= True
238 self
.n2vc
.fs
.path
= MagicMock(create_autospec
=True)
239 self
.n2vc
.fs
.path
.return_value
= "path"
240 self
.n2vc
.libjuju
.deploy_charm
.side_effect
= Exception()
241 with self
.assertRaises(N2VCException
):
242 ee_id
= self
.loop
.run_until_complete(
243 self
.n2vc
.install_k8s_proxy_charm(
245 ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0",
250 self
.assertIsNone(ee_id
)
253 class AddRelationTest(N2VCJujuConnTestCase
):
255 super(AddRelationTest
, self
).setUp()
256 self
.n2vc
.libjuju
.add_relation
= AsyncMock()
257 self
.n2vc
.libjuju
.offer
= AsyncMock()
258 self
.n2vc
.libjuju
.get_controller
= AsyncMock()
259 self
.n2vc
.libjuju
.consume
= AsyncMock()
261 def test_standard_relation(self
):
262 relation_endpoint_1
= RelationEndpoint("model-1.app1.0", None, "endpoint")
263 relation_endpoint_2
= RelationEndpoint("model-1.app2.1", None, "endpoint")
264 self
.loop
.run_until_complete(
265 self
.n2vc
.add_relation(relation_endpoint_1
, relation_endpoint_2
)
267 self
.n2vc
.libjuju
.add_relation
.assert_called_once_with(
268 model_name
="model-1", endpoint_1
="app1:endpoint", endpoint_2
="app2:endpoint"
270 self
.n2vc
.libjuju
.offer
.assert_not_called()
271 self
.n2vc
.libjuju
.consume
.assert_not_called()
273 def test_cmr_relation_same_controller(self
):
274 relation_endpoint_1
= RelationEndpoint("model-1.app1.0", None, "endpoint")
275 relation_endpoint_2
= RelationEndpoint("model-2.app2.1", None, "endpoint")
276 offer
= Offer("admin/model-1.app1")
277 self
.n2vc
.libjuju
.offer
.return_value
= offer
278 self
.n2vc
.libjuju
.consume
.return_value
= "saas"
279 self
.loop
.run_until_complete(
280 self
.n2vc
.add_relation(relation_endpoint_1
, relation_endpoint_2
)
282 self
.n2vc
.libjuju
.offer
.assert_called_once_with(relation_endpoint_1
)
283 self
.n2vc
.libjuju
.consume
.assert_called_once()
284 self
.n2vc
.libjuju
.add_relation
.assert_called_once_with(
285 "model-2", "app2:endpoint", "saas"
288 def test_relation_exception(self
):
289 relation_endpoint_1
= RelationEndpoint("model-1.app1.0", None, "endpoint")
290 relation_endpoint_2
= RelationEndpoint("model-2.app2.1", None, "endpoint")
291 self
.n2vc
.libjuju
.offer
.side_effect
= Exception()
292 with self
.assertRaises(N2VCException
):
293 self
.loop
.run_until_complete(
294 self
.n2vc
.add_relation(relation_endpoint_1
, relation_endpoint_2
)
298 class UpgradeCharmTest(N2VCJujuConnTestCase
):
300 super(UpgradeCharmTest
, self
).setUp()
301 self
.n2vc
._get
_libjuju
= AsyncMock(return_value
=self
.n2vc
.libjuju
)
302 N2VCJujuConnector
._get
_ee
_id
_components
= Mock()
303 self
.n2vc
.libjuju
.upgrade_charm
= AsyncMock()
305 def test_empty_ee_id(self
):
306 with self
.assertRaises(N2VCBadArgumentsException
):
307 self
.loop
.run_until_complete(
308 self
.n2vc
.upgrade_charm(
309 "", "/sample_charm_path", "sample_charm_id", "native-charm", None
312 self
.n2vc
._get
_libjuju
.assert_called()
313 self
.n2vc
._get
_ee
_id
_components
.assert_not_called()
314 self
.n2vc
.libjuju
.upgrade_charm
.assert_not_called()
316 def test_wrong_ee_id(self
):
317 N2VCJujuConnector
._get
_ee
_id
_components
.side_effect
= Exception
318 with self
.assertRaises(N2VCBadArgumentsException
):
319 self
.loop
.run_until_complete(
320 self
.n2vc
.upgrade_charm(
321 "ns-id-k8s.app-vnf-vnf-id-vdu-vdu-random.k8s",
322 "/sample_charm_path",
328 self
.n2vc
._get
_libjuju
.assert_called()
329 self
.n2vc
._get
_ee
_id
_components
.assert_called()
330 self
.n2vc
.libjuju
.upgrade_charm
.assert_not_called()
332 def test_charm_upgrade_succeded(self
):
333 N2VCJujuConnector
._get
_ee
_id
_components
.return_value
= (
338 self
.loop
.run_until_complete(
339 self
.n2vc
.upgrade_charm(
340 "ns-id-k8s.app-vnf-vnf-id-vdu-vdu-random.k8s",
341 "/sample_charm_path",
347 self
.n2vc
._get
_libjuju
.assert_called()
348 self
.n2vc
._get
_ee
_id
_components
.assert_called()
349 self
.n2vc
.libjuju
.upgrade_charm
.assert_called_with(
350 application_name
="sample_app",
351 path
="/sample_charm_path",
352 model_name
="sample_model",
356 def test_charm_upgrade_failed(self
):
357 N2VCJujuConnector
._get
_ee
_id
_components
.return_value
= (
362 self
.n2vc
.libjuju
.upgrade_charm
.side_effect
= JujuApplicationNotFound
363 with self
.assertRaises(N2VCException
):
364 self
.loop
.run_until_complete(
365 self
.n2vc
.upgrade_charm(
366 "ns-id-k8s.app-vnf-vnf-id-vdu-vdu-random.k8s",
367 "/sample_charm_path",
373 self
.n2vc
._get
_libjuju
.assert_called()
374 self
.n2vc
._get
_ee
_id
_components
.assert_called()
375 self
.n2vc
.libjuju
.upgrade_charm
.assert_called_with(
376 application_name
="sample_app",
377 path
="/sample_charm_path",
378 model_name
="sample_model",
383 class GenerateApplicationNameTest(N2VCJujuConnTestCase
):
384 vnf_id
= "dbfbd751-3de4-4e68-bd40-ec5ae0a53898"
387 super(GenerateApplicationNameTest
, self
).setUp()
388 self
.db
= MagicMock(DbMemory
)
391 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
392 **{"return_value": "random"}
394 def test_generate_backward_compatible_application_name(
395 self
, mock_generate_random_alfanum
399 expected_result
= "app-vnf-ec5ae0a53898-vdu-mgmtVM-cnt-0-random"
401 application_name
= self
.n2vc
._generate
_backward
_compatible
_application
_name
(
402 GenerateApplicationNameTest
.vnf_id
, vdu_id
, vdu_count
404 self
.assertEqual(application_name
, expected_result
)
407 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
408 **{"return_value": "random"}
410 def test_generate_backward_compatible_application_name_without_vnf_id_vdu_id(
411 self
, mock_generate_random_alfanum
416 expected_result
= "app--random"
417 application_name
= self
.n2vc
._generate
_backward
_compatible
_application
_name
(
418 vnf_id
, vdu_id
, vdu_count
421 self
.assertEqual(application_name
, expected_result
)
422 self
.assertLess(len(application_name
), 50)
424 def test_find_charm_level_with_vnf_id(self
):
426 expected_result
= "vnf-level"
427 charm_level
= self
.n2vc
._find
_charm
_level
(
428 GenerateApplicationNameTest
.vnf_id
, vdu_id
430 self
.assertEqual(charm_level
, expected_result
)
432 def test_find_charm_level_with_vdu_id(self
):
435 with self
.assertRaises(N2VCException
):
436 self
.n2vc
._find
_charm
_level
(vnf_id
, vdu_id
)
438 def test_find_charm_level_with_vnf_id_and_vdu_id(self
):
440 expected_result
= "vdu-level"
441 charm_level
= self
.n2vc
._find
_charm
_level
(
442 GenerateApplicationNameTest
.vnf_id
, vdu_id
444 self
.assertEqual(charm_level
, expected_result
)
446 def test_find_charm_level_without_vnf_id_and_vdu_id(self
):
449 expected_result
= "ns-level"
450 charm_level
= self
.n2vc
._find
_charm
_level
(vnf_id
, vdu_id
)
451 self
.assertEqual(charm_level
, expected_result
)
453 def test_generate_application_name_ns_charm(self
):
454 charm_level
= "ns-level"
458 "target_element": "ns",
459 "member-vnf-index": "",
462 "vdu_count_index": None,
465 "type": "proxy_charm",
466 "ee_descriptor_id": None,
467 "charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh",
470 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
476 expected_result
= "simple-ns-charm-abc-000-rrrr-nnnn-4444-h-ns"
477 application_name
= self
.n2vc
._generate
_application
_name
(
485 self
.assertEqual(application_name
, expected_result
)
486 self
.assertLess(len(application_name
), 50)
488 def test_generate_application_name_ns_charm_empty_vca_records(self
):
489 charm_level
= "ns-level"
495 with self
.assertRaises(N2VCException
):
496 self
.n2vc
._generate
_application
_name
(
505 def test_generate_application_name_vnf_charm(self
):
506 charm_level
= "vnf-level"
508 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
512 "target_element": "vnf/vnf1",
513 "member-vnf-index": "vnf111-xxx-yyy-zzz",
514 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
515 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
517 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
523 expected_result
= "simple-ee-ab-1-vnf111-xxx-y-vnf"
524 application_name
= self
.n2vc
._generate
_application
_name
(
532 self
.assertEqual(application_name
, expected_result
)
533 self
.assertLess(len(application_name
), 50)
535 def test_generate_application_name_vdu_charm_kdu_name_in_vca_record_is_none(self
):
536 charm_level
= "vdu-level"
538 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
540 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
541 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
546 "target_element": "vnf/vnf1/mgmtvm",
547 "member-vnf-index": "vnf111-xxx-yyy-zzz",
550 "vdu_count_index": None,
551 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
552 "vdu_name": "mgmtvm",
553 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
555 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
558 "target_element": "vnf/vnf1/dataVM",
559 "member-vnf-index": "vnf111-xxx-yyy-zzz",
562 "vdu_count_index": None,
563 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
564 "vdu_name": "datavm",
565 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
567 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
573 expected_result
= "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
574 application_name
= self
.n2vc
._generate
_application
_name
(
582 self
.assertEqual(application_name
, expected_result
)
583 self
.assertLess(len(application_name
), 50)
585 def test_generate_application_name_vdu_charm_vdu_id_kdu_name_in_vca_record_are_both_set(
588 charm_level
= "vdu-level"
590 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
592 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
593 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
598 "target_element": "vnf/vnf1/mgmtVM",
599 "member-vnf-index": "vnf111-xxx-yyy-zzz",
601 "kdu_name": "mgmtVM",
602 "vdu_count_index": None,
603 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
604 "vdu_name": "mgmtvm",
605 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
607 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
610 "target_element": "vnf/vnf1/dataVM",
611 "member-vnf-index": "vnf111-xxx-yyy-zzz",
614 "vdu_count_index": None,
615 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
616 "vdu_name": "datavm",
617 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
619 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
625 expected_result
= "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
626 application_name
= self
.n2vc
._generate
_application
_name
(
634 self
.assertEqual(application_name
, expected_result
)
635 self
.assertLess(len(application_name
), 50)
637 def test_generate_application_name_vdu_charm_both_vdu_id_kdu_name_in_vca_record_are_none(
640 charm_level
= "vdu-level"
642 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
646 "target_element": "vnf/vnf1/mgmtVM",
647 "member-vnf-index": "vnf111-xxx-yyy-zzz",
650 "vdu_count_index": None,
651 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
652 "vdu_name": "mgmtvm",
653 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
655 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
661 with self
.assertRaises(KeyError):
662 self
.n2vc
._generate
_application
_name
(
671 def test_generate_application_name_vdu_charm_given_vdu_id_is_none(self
):
672 charm_level
= "vdu-level"
674 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
678 "target_element": "vnf/vnf1/mgmtvVM",
679 "member-vnf-index": "vnf111-xxx-yyy-zzz",
681 "kdu_name": "mgmtVM",
682 "vdu_count_index": None,
683 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
684 "vdu_name": "mgmtvm",
685 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
687 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
693 with self
.assertRaises(N2VCException
):
694 self
.n2vc
._generate
_application
_name
(
703 def test_generate_application_name_vdu_charm_vdu_id_does_not_match_with_the_key_in_vca_record(
706 charm_level
= "vdu-level"
708 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
712 "target_element": "vnf/vnf1/mgmtVM",
713 "member-vnf-index": "vnf111-xxx-yyy-zzz",
715 "kdu_name": "mgmtVM",
716 "vdu_count_index": None,
717 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
718 "vdu_name": "mgmtvm",
719 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
721 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
727 with self
.assertRaises(KeyError):
728 self
.n2vc
._generate
_application
_name
(
737 def test_generate_application_name_vdu_charm_vdu_id_in_vca_record_is_none(self
):
738 charm_level
= "vdu-level"
740 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
744 "target_element": "vnf/vnf1/mgmtVM",
745 "member-vnf-index": "vnf111-xxx-yyy-zzz",
747 "kdu_name": "mgmtVM",
748 "vdu_count_index": None,
749 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
750 "vdu_name": "mgmtvm",
751 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
753 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
759 expected_result
= "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
760 application_name
= self
.n2vc
._generate
_application
_name
(
768 self
.assertEqual(application_name
, expected_result
)
769 self
.assertLess(len(application_name
), 50)
771 def test_get_vnf_count_db_vnfr_ns_charm(self
):
772 self
.db
.get_one
.return_value
= {"member-vnf-index-ref": "sample-ref"}
773 charm_level
= "ns-level"
774 vnf_id_and_count
= "m7fbd751-3de4-4e68-bd40-ec5ae0a53898-4"
775 with patch
.object(self
.n2vc
, "db", self
.db
):
776 vnf_count
, db_vnfr
= self
.n2vc
._get
_vnf
_count
_and
_record
(
777 charm_level
, vnf_id_and_count
779 self
.assertEqual(vnf_count
, "")
780 self
.assertEqual(db_vnfr
, {})
782 def test_get_vnf_count_db_vnfr_vnf_charm(self
):
783 self
.db
.get_one
.return_value
= {"member-vnf-index-ref": "sample-ref"}
784 charm_level
= "vnf-level"
785 vnf_id_and_count
= "m7fbd751-3de4-4e68-bd40-ec5ae0a53898-4"
786 with patch
.object(self
.n2vc
, "db", self
.db
):
787 vnf_count
, db_vnfr
= self
.n2vc
._get
_vnf
_count
_and
_record
(
788 charm_level
, vnf_id_and_count
790 self
.assertEqual(vnf_count
, "4")
791 self
.assertEqual(db_vnfr
, {"member-vnf-index-ref": "sample-ref"})
793 def test_get_vnf_count_db_vnfr_vdu_charm(self
):
794 self
.db
.get_one
.return_value
= {"member-vnf-index-ref": "sample-ref"}
795 charm_level
= "vdu-level"
796 vnf_id_and_count
= "m7fbd751-3de4-4e68-bd40-ec5ae0a53898-2"
797 with patch
.object(self
.n2vc
, "db", self
.db
):
798 vnf_count
, db_vnfr
= self
.n2vc
._get
_vnf
_count
_and
_record
(
799 charm_level
, vnf_id_and_count
801 self
.assertEqual(vnf_count
, "2")
802 self
.assertEqual(db_vnfr
, {"member-vnf-index-ref": "sample-ref"})
804 def test_get_vca_records_vdu_charm(self
):
805 charm_level
= "vdu-level"
807 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
809 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
810 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
818 "target_element": "vnf/vnf1/mgmtvm",
819 "member-vnf-index": "vnf111-xxx-yyy-zzz",
820 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
822 "vdu_count_index": None,
823 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
824 "vdu_name": "mgmtvm",
825 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
827 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
830 "target_element": "vnf/vnf2/datavm",
831 "member-vnf-index": "vnf222-xxx-yyy-zzz",
832 "vdu_id": "45512ff7-5bdd-4228-911f-c2bee259c44a",
834 "vdu_count_index": None,
835 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
836 "vdu_name": "datavm",
837 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
839 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
847 "target_element": "vnf/vnf1/mgmtvm",
848 "member-vnf-index": "vnf111-xxx-yyy-zzz",
849 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
851 "vdu_count_index": None,
852 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
853 "vdu_name": "mgmtvm",
854 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
856 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
859 vca_records
= self
.n2vc
._get
_vca
_records
(charm_level
, db_nsr
, db_vnfr
)
860 self
.assertEqual(vca_records
, expected_result
)
862 def test_get_vca_records_vnf_charm_member_vnf_index_mismatch(self
):
863 charm_level
= "vnf-level"
865 "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
872 "target_element": "vnf/vnf1/mgmtvm",
873 "member-vnf-index": "vnf111-xxx-yyy-zzz",
874 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
876 "vdu_count_index": None,
877 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
878 "vdu_name": "mgmtvm",
879 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
881 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
884 "target_element": "vnf/vnf1/mgmtvm",
885 "member-vnf-index": "vnf111-xxx-yyy-zzz",
886 "vdu_id": "45512ff7-5bdd-4228-911f-c2bee259c44a",
888 "vdu_count_index": None,
889 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
890 "vdu_name": "datavm",
891 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
893 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
900 vca_records
= self
.n2vc
._get
_vca
_records
(charm_level
, db_nsr
, db_vnfr
)
901 self
.assertEqual(vca_records
, expected_result
)
903 def test_get_vca_records_ns_charm(self
):
904 charm_level
= "ns-level"
906 "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
913 "target_element": "vnf/vnf1/mgmtvm",
914 "member-vnf-index": "vnf111-xxx-yyy-zzz",
915 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
917 "vdu_count_index": None,
918 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
919 "vdu_name": "mgmtvm",
920 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
922 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
925 "target_element": "ns",
926 "member-vnf-index": None,
929 "vdu_count_index": None,
932 "ee_descriptor_id": "",
933 "charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
934 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
942 "target_element": "ns",
943 "member-vnf-index": None,
946 "vdu_count_index": None,
949 "ee_descriptor_id": "",
950 "charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
951 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
954 vca_records
= self
.n2vc
._get
_vca
_records
(charm_level
, db_nsr
, db_vnfr
)
955 self
.assertEqual(vca_records
, expected_result
)
957 def test_get_vca_records_ns_charm_empty_charm_name(self
):
958 charm_level
= "ns-level"
960 "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
967 "target_element": "vnf/vnf1/mgmtvm",
968 "member-vnf-index": "vnf111-xxx-yyy-zzz",
969 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
971 "vdu_count_index": None,
972 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
973 "vdu_name": "mgmtvm",
974 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
976 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
979 "target_element": "ns",
980 "member-vnf-index": None,
983 "vdu_count_index": None,
986 "ee_descriptor_id": "",
988 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
996 "target_element": "ns",
997 "member-vnf-index": None,
1000 "vdu_count_index": None,
1003 "ee_descriptor_id": "",
1005 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1008 vca_records
= self
.n2vc
._get
_vca
_records
(charm_level
, db_nsr
, db_vnfr
)
1009 self
.assertEqual(vca_records
, expected_result
)
1011 def test_get_application_name_vnf_charm(self
):
1012 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1013 self
.db
.get_one
.return_value
= {
1018 "target_element": "vnf/vnf1/mgmtvm",
1019 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1020 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
1022 "vdu_count_index": None,
1023 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1024 "vdu_name": "mgmtvm",
1025 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1027 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1030 "target_element": "ns",
1031 "member-vnf-index": None,
1034 "vdu_count_index": None,
1037 "ee_descriptor_id": "",
1039 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1045 mock_vnf_count_and_record
= MagicMock()
1047 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
1050 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1051 expected_result
= "simple-ee-ab-z0-vnf111-xxx-y-vnf"
1052 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1053 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1055 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1056 self
.assertEqual(application_name
, expected_result
)
1057 self
.assertLess(len(application_name
), 50)
1058 mock_vnf_count_and_record
.assert_called_once_with(
1059 "vnf-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1061 self
.db
.get_one
.assert_called_once()
1064 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
1065 **{"return_value": "random"}
1067 def test_get_application_name_vnf_charm_old_naming(
1068 self
, mock_generate_random_alfanum
1070 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1071 self
.db
.get_one
.return_value
= {
1076 "target_element": "vnf/vnf1/mgmtvm",
1077 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1078 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
1080 "vdu_count_index": None,
1081 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1082 "vdu_name": "mgmtvm",
1083 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1084 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1087 "target_element": "ns",
1088 "member-vnf-index": None,
1091 "vdu_count_index": None,
1094 "ee_descriptor_id": "",
1095 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1101 mock_vnf_count_and_record
= MagicMock()
1103 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
1106 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1107 expected_result
= "app-vnf-eb3161eec0-z0-random"
1108 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1109 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1111 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1112 self
.assertEqual(application_name
, expected_result
)
1113 mock_vnf_count_and_record
.assert_called_once_with(
1114 "vnf-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1116 self
.db
.get_one
.assert_called_once()
1118 def test_get_application_name_vnf_charm_vnf_index_ref_mismatch(self
):
1119 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1120 self
.db
.get_one
.return_value
= {
1125 "target_element": "vnf/vnf1/mgmtvm",
1126 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1127 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
1129 "vdu_count_index": None,
1130 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1131 "vdu_name": "mgmtvm",
1132 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1134 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1137 "target_element": "ns",
1138 "member-vnf-index": None,
1141 "vdu_count_index": None,
1144 "ee_descriptor_id": "",
1146 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1152 mock_vnf_count_and_record
= MagicMock()
1154 "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
1157 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1158 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1159 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1161 with self
.assertRaises(N2VCException
):
1162 self
.n2vc
._get
_application
_name
(namespace
)
1163 mock_vnf_count_and_record
.assert_called_once_with(
1164 "vnf-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1166 self
.db
.get_one
.assert_called_once()
1168 def test_get_application_name_vdu_charm(self
):
1169 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0.mgmtVM-0"
1170 self
.db
.get_one
.return_value
= {
1175 "target_element": "vnf/vnf1/mgmtvm",
1176 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1179 "vdu_count_index": None,
1180 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1181 "vdu_name": "mgmtvm",
1182 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1184 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1187 "target_element": "ns",
1188 "member-vnf-index": None,
1191 "vdu_count_index": None,
1194 "ee_descriptor_id": "",
1196 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1202 mock_vnf_count_and_record
= MagicMock()
1204 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
1206 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
1207 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
1211 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1212 expected_result
= "simple-ee-ab-z0-vnf111-xxx-y-mgmtvm-z0-vdu"
1213 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1214 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1216 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1217 self
.assertEqual(application_name
, expected_result
)
1218 self
.assertLess(len(application_name
), 50)
1219 mock_vnf_count_and_record
.assert_called_once_with(
1220 "vdu-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1222 self
.db
.get_one
.assert_called_once()
1224 def test_get_application_name_kdu_charm(self
):
1225 namespace
= ".82b11965-e580-47c0-9ee0-329f318a305b.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0.ldap"
1226 self
.db
.get_one
.return_value
= {
1231 "target_element": "vnf/openldap/kdu/ldap",
1232 "member-vnf-index": "openldap",
1235 "vdu_count_index": 0,
1236 "operational-status": "init",
1237 "detailed-status": "",
1238 "step": "initial-deploy",
1239 "vnfd_id": "openldap_knf",
1241 "type": "lxc_proxy_charm",
1242 "ee_descriptor_id": "openldap-ee",
1245 "application": "openldap-ee-z0-openldap-vdu",
1246 "model": "82b11965-e580-47c0-9ee0-329f318a305b",
1247 "config_sw_installed": True,
1253 mock_vnf_count_and_record
= MagicMock()
1255 "member-vnf-index-ref": "openldap",
1259 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1260 expected_result
= "openldap-ee-z0-openldap-ldap-vdu"
1261 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1262 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1264 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1265 self
.assertEqual(application_name
, expected_result
)
1266 self
.assertLess(len(application_name
), 50)
1267 mock_vnf_count_and_record
.assert_called_once_with(
1268 "vdu-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1270 self
.db
.get_one
.assert_called_once()
1273 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
1274 **{"return_value": "random"}
1276 def test_get_application_name_vdu_charm_old_naming(
1277 self
, mock_generate_random_alfanum
1279 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0.mgmtVM-0"
1280 self
.db
.get_one
.return_value
= {
1285 "target_element": "vnf/vnf1/mgmtVM",
1286 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1289 "vdu_count_index": None,
1290 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1291 "vdu_name": "mgmtvm",
1292 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1293 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1296 "target_element": "ns",
1297 "member-vnf-index": None,
1300 "vdu_count_index": None,
1303 "ee_descriptor_id": "",
1304 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1310 mock_vnf_count_and_record
= MagicMock()
1312 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
1314 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
1315 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
1319 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1320 expected_result
= "app-vnf-eb3161eec0-z0-vdu-mgmtvm-cnt-z0-random"
1322 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1323 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1325 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1326 self
.assertEqual(application_name
, expected_result
)
1327 self
.assertLess(len(application_name
), 50)
1328 mock_vnf_count_and_record
.assert_called_once_with(
1329 "vdu-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1331 self
.db
.get_one
.assert_called_once()
1333 def test_get_application_name_ns_charm(self
):
1334 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898"
1335 self
.db
.get_one
.return_value
= {
1340 "target_element": "ns",
1341 "member-vnf-index": None,
1344 "vdu_count_index": None,
1347 "ee_descriptor_id": "",
1348 "charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1349 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1355 mock_vnf_count_and_record
= MagicMock()
1358 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1359 expected_result
= "simple-ns-charm-abc-z000-rrrr-nnnn-z4444-h-ns"
1360 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1361 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1363 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1364 self
.assertEqual(application_name
, expected_result
)
1365 self
.assertLess(len(application_name
), 50)
1366 mock_vnf_count_and_record
.assert_called_once_with("ns-level", None)
1367 self
.db
.get_one
.assert_called_once()
1369 def test_get_application_name_ns_charm_empty_charm_name(self
):
1370 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898"
1371 self
.db
.get_one
.return_value
= {
1376 "target_element": "ns",
1377 "member-vnf-index": None,
1380 "vdu_count_index": None,
1383 "ee_descriptor_id": "",
1385 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1391 mock_vnf_count_and_record
= MagicMock()
1394 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1395 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1396 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1398 with self
.assertRaises(N2VCException
):
1399 self
.n2vc
._get
_application
_name
(namespace
)
1400 mock_vnf_count_and_record
.assert_called_once_with("ns-level", None)
1401 self
.db
.get_one
.assert_called_once()
1404 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
1405 **{"return_value": "random"}
1407 def test_get_application_name_ns_charm_old_naming(
1408 self
, mock_generate_random_alfanum
1410 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898"
1411 self
.db
.get_one
.return_value
= {
1416 "target_element": "ns",
1417 "member-vnf-index": None,
1420 "vdu_count_index": None,
1423 "ee_descriptor_id": "",
1424 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1430 mock_vnf_count_and_record
= MagicMock()
1433 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1434 expected_result
= "app-random"
1435 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1436 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1438 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1439 self
.assertEqual(application_name
, expected_result
)
1440 self
.assertLess(len(application_name
), 50)
1441 mock_vnf_count_and_record
.assert_called_once_with("ns-level", None)
1442 self
.db
.get_one
.assert_called_once()