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
):
385 vnf_id
= "dbfbd751-3de4-4e68-bd40-ec5ae0a53898"
388 super(GenerateApplicationNameTest
, self
).setUp()
389 self
.db
= MagicMock(DbMemory
)
392 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
393 **{"return_value": "random"}
395 def test_generate_backward_compatible_application_name(
396 self
, mock_generate_random_alfanum
400 expected_result
= "app-vnf-ec5ae0a53898-vdu-mgmtVM-cnt-0-random"
402 application_name
= self
.n2vc
._generate
_backward
_compatible
_application
_name
(
403 GenerateApplicationNameTest
.vnf_id
, vdu_id
, vdu_count
405 self
.assertEqual(application_name
, expected_result
)
408 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
409 **{"return_value": "random"}
411 def test_generate_backward_compatible_application_name_without_vnf_id_vdu_id(
412 self
, mock_generate_random_alfanum
417 expected_result
= "app--random"
418 application_name
= self
.n2vc
._generate
_backward
_compatible
_application
_name
(
419 vnf_id
, vdu_id
, vdu_count
422 self
.assertEqual(application_name
, expected_result
)
423 self
.assertLess(len(application_name
), 50)
425 def test_find_charm_level_with_vnf_id(self
):
427 expected_result
= "vnf-level"
428 charm_level
= self
.n2vc
._find
_charm
_level
(
429 GenerateApplicationNameTest
.vnf_id
, vdu_id
431 self
.assertEqual(charm_level
, expected_result
)
433 def test_find_charm_level_with_vdu_id(self
):
436 with self
.assertRaises(N2VCException
):
437 self
.n2vc
._find
_charm
_level
(vnf_id
, vdu_id
)
439 def test_find_charm_level_with_vnf_id_and_vdu_id(self
):
441 expected_result
= "vdu-level"
442 charm_level
= self
.n2vc
._find
_charm
_level
(
443 GenerateApplicationNameTest
.vnf_id
, vdu_id
445 self
.assertEqual(charm_level
, expected_result
)
447 def test_find_charm_level_without_vnf_id_and_vdu_id(self
):
450 expected_result
= "ns-level"
451 charm_level
= self
.n2vc
._find
_charm
_level
(vnf_id
, vdu_id
)
452 self
.assertEqual(charm_level
, expected_result
)
454 def test_generate_application_name_ns_charm(self
):
455 charm_level
= "ns-level"
459 "target_element": "ns",
460 "member-vnf-index": "",
463 "vdu_count_index": None,
466 "type": "proxy_charm",
467 "ee_descriptor_id": None,
468 "charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh",
471 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
477 expected_result
= "simple-ns-charm-abc-000-rrrr-nnnn-4444-h-ns"
478 application_name
= self
.n2vc
._generate
_application
_name
(
486 self
.assertEqual(application_name
, expected_result
)
487 self
.assertLess(len(application_name
), 50)
489 def test_generate_application_name_ns_charm_empty_vca_records(self
):
490 charm_level
= "ns-level"
496 with self
.assertRaises(N2VCException
):
497 self
.n2vc
._generate
_application
_name
(
506 def test_generate_application_name_vnf_charm(self
):
507 charm_level
= "vnf-level"
509 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
513 "target_element": "vnf/vnf1",
514 "member-vnf-index": "vnf111-xxx-yyy-zzz",
515 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
516 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
518 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
524 expected_result
= "simple-ee-ab-1-vnf111-xxx-y-vnf"
525 application_name
= self
.n2vc
._generate
_application
_name
(
533 self
.assertEqual(application_name
, expected_result
)
534 self
.assertLess(len(application_name
), 50)
536 def test_generate_application_name_vdu_charm_kdu_name_in_vca_record_is_none(self
):
537 charm_level
= "vdu-level"
539 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
541 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
542 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
547 "target_element": "vnf/vnf1/mgmtvm",
548 "member-vnf-index": "vnf111-xxx-yyy-zzz",
551 "vdu_count_index": None,
552 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
553 "vdu_name": "mgmtvm",
554 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
556 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
559 "target_element": "vnf/vnf1/dataVM",
560 "member-vnf-index": "vnf111-xxx-yyy-zzz",
563 "vdu_count_index": None,
564 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
565 "vdu_name": "datavm",
566 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
568 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
574 expected_result
= "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
575 application_name
= self
.n2vc
._generate
_application
_name
(
583 self
.assertEqual(application_name
, expected_result
)
584 self
.assertLess(len(application_name
), 50)
586 def test_generate_application_name_vdu_charm_vdu_id_kdu_name_in_vca_record_are_both_set(
589 charm_level
= "vdu-level"
591 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
593 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
594 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
599 "target_element": "vnf/vnf1/mgmtVM",
600 "member-vnf-index": "vnf111-xxx-yyy-zzz",
602 "kdu_name": "mgmtVM",
603 "vdu_count_index": None,
604 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
605 "vdu_name": "mgmtvm",
606 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
608 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
611 "target_element": "vnf/vnf1/dataVM",
612 "member-vnf-index": "vnf111-xxx-yyy-zzz",
615 "vdu_count_index": None,
616 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
617 "vdu_name": "datavm",
618 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
620 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
626 expected_result
= "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
627 application_name
= self
.n2vc
._generate
_application
_name
(
635 self
.assertEqual(application_name
, expected_result
)
636 self
.assertLess(len(application_name
), 50)
638 def test_generate_application_name_vdu_charm_both_vdu_id_kdu_name_in_vca_record_are_none(
641 charm_level
= "vdu-level"
643 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
647 "target_element": "vnf/vnf1/mgmtVM",
648 "member-vnf-index": "vnf111-xxx-yyy-zzz",
651 "vdu_count_index": None,
652 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
653 "vdu_name": "mgmtvm",
654 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
656 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
662 with self
.assertRaises(KeyError):
663 self
.n2vc
._generate
_application
_name
(
672 def test_generate_application_name_vdu_charm_given_vdu_id_is_none(self
):
673 charm_level
= "vdu-level"
675 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
679 "target_element": "vnf/vnf1/mgmtvVM",
680 "member-vnf-index": "vnf111-xxx-yyy-zzz",
682 "kdu_name": "mgmtVM",
683 "vdu_count_index": None,
684 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
685 "vdu_name": "mgmtvm",
686 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
688 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
694 with self
.assertRaises(N2VCException
):
695 self
.n2vc
._generate
_application
_name
(
704 def test_generate_application_name_vdu_charm_vdu_id_does_not_match_with_the_key_in_vca_record(
707 charm_level
= "vdu-level"
709 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
713 "target_element": "vnf/vnf1/mgmtVM",
714 "member-vnf-index": "vnf111-xxx-yyy-zzz",
716 "kdu_name": "mgmtVM",
717 "vdu_count_index": None,
718 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
719 "vdu_name": "mgmtvm",
720 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
722 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
728 with self
.assertRaises(KeyError):
729 self
.n2vc
._generate
_application
_name
(
738 def test_generate_application_name_vdu_charm_vdu_id_in_vca_record_is_none(self
):
739 charm_level
= "vdu-level"
741 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
745 "target_element": "vnf/vnf1/mgmtVM",
746 "member-vnf-index": "vnf111-xxx-yyy-zzz",
748 "kdu_name": "mgmtVM",
749 "vdu_count_index": None,
750 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
751 "vdu_name": "mgmtvm",
752 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
754 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
760 expected_result
= "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
761 application_name
= self
.n2vc
._generate
_application
_name
(
769 self
.assertEqual(application_name
, expected_result
)
770 self
.assertLess(len(application_name
), 50)
772 def test_get_vnf_count_db_vnfr_ns_charm(self
):
773 self
.db
.get_one
.return_value
= {"member-vnf-index-ref": "sample-ref"}
774 charm_level
= "ns-level"
775 vnf_id_and_count
= "m7fbd751-3de4-4e68-bd40-ec5ae0a53898-4"
776 with patch
.object(self
.n2vc
, "db", self
.db
):
777 vnf_count
, db_vnfr
= self
.n2vc
._get
_vnf
_count
_and
_record
(
778 charm_level
, vnf_id_and_count
780 self
.assertEqual(vnf_count
, "")
781 self
.assertEqual(db_vnfr
, {})
783 def test_get_vnf_count_db_vnfr_vnf_charm(self
):
784 self
.db
.get_one
.return_value
= {"member-vnf-index-ref": "sample-ref"}
785 charm_level
= "vnf-level"
786 vnf_id_and_count
= "m7fbd751-3de4-4e68-bd40-ec5ae0a53898-4"
787 with patch
.object(self
.n2vc
, "db", self
.db
):
788 vnf_count
, db_vnfr
= self
.n2vc
._get
_vnf
_count
_and
_record
(
789 charm_level
, vnf_id_and_count
791 self
.assertEqual(vnf_count
, "4")
792 self
.assertEqual(db_vnfr
, {"member-vnf-index-ref": "sample-ref"})
794 def test_get_vnf_count_db_vnfr_vdu_charm(self
):
795 self
.db
.get_one
.return_value
= {"member-vnf-index-ref": "sample-ref"}
796 charm_level
= "vdu-level"
797 vnf_id_and_count
= "m7fbd751-3de4-4e68-bd40-ec5ae0a53898-2"
798 with patch
.object(self
.n2vc
, "db", self
.db
):
799 vnf_count
, db_vnfr
= self
.n2vc
._get
_vnf
_count
_and
_record
(
800 charm_level
, vnf_id_and_count
802 self
.assertEqual(vnf_count
, "2")
803 self
.assertEqual(db_vnfr
, {"member-vnf-index-ref": "sample-ref"})
805 def test_get_vca_records_vdu_charm(self
):
806 charm_level
= "vdu-level"
808 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
810 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
811 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
819 "target_element": "vnf/vnf1/mgmtvm",
820 "member-vnf-index": "vnf111-xxx-yyy-zzz",
821 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
823 "vdu_count_index": None,
824 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
825 "vdu_name": "mgmtvm",
826 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
828 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
831 "target_element": "vnf/vnf2/datavm",
832 "member-vnf-index": "vnf222-xxx-yyy-zzz",
833 "vdu_id": "45512ff7-5bdd-4228-911f-c2bee259c44a",
835 "vdu_count_index": None,
836 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
837 "vdu_name": "datavm",
838 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
840 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
848 "target_element": "vnf/vnf1/mgmtvm",
849 "member-vnf-index": "vnf111-xxx-yyy-zzz",
850 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
852 "vdu_count_index": None,
853 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
854 "vdu_name": "mgmtvm",
855 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
857 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
860 vca_records
= self
.n2vc
._get
_vca
_records
(charm_level
, db_nsr
, db_vnfr
)
861 self
.assertEqual(vca_records
, expected_result
)
863 def test_get_vca_records_vnf_charm_member_vnf_index_mismatch(self
):
864 charm_level
= "vnf-level"
866 "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
873 "target_element": "vnf/vnf1/mgmtvm",
874 "member-vnf-index": "vnf111-xxx-yyy-zzz",
875 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
877 "vdu_count_index": None,
878 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
879 "vdu_name": "mgmtvm",
880 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
882 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
885 "target_element": "vnf/vnf1/mgmtvm",
886 "member-vnf-index": "vnf111-xxx-yyy-zzz",
887 "vdu_id": "45512ff7-5bdd-4228-911f-c2bee259c44a",
889 "vdu_count_index": None,
890 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
891 "vdu_name": "datavm",
892 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
894 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
901 vca_records
= self
.n2vc
._get
_vca
_records
(charm_level
, db_nsr
, db_vnfr
)
902 self
.assertEqual(vca_records
, expected_result
)
904 def test_get_vca_records_ns_charm(self
):
905 charm_level
= "ns-level"
907 "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
914 "target_element": "vnf/vnf1/mgmtvm",
915 "member-vnf-index": "vnf111-xxx-yyy-zzz",
916 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
918 "vdu_count_index": None,
919 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
920 "vdu_name": "mgmtvm",
921 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
923 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
926 "target_element": "ns",
927 "member-vnf-index": None,
930 "vdu_count_index": None,
933 "ee_descriptor_id": "",
934 "charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
935 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
943 "target_element": "ns",
944 "member-vnf-index": None,
947 "vdu_count_index": None,
950 "ee_descriptor_id": "",
951 "charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
952 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
955 vca_records
= self
.n2vc
._get
_vca
_records
(charm_level
, db_nsr
, db_vnfr
)
956 self
.assertEqual(vca_records
, expected_result
)
958 def test_get_vca_records_ns_charm_empty_charm_name(self
):
959 charm_level
= "ns-level"
961 "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
968 "target_element": "vnf/vnf1/mgmtvm",
969 "member-vnf-index": "vnf111-xxx-yyy-zzz",
970 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
972 "vdu_count_index": None,
973 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
974 "vdu_name": "mgmtvm",
975 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
977 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
980 "target_element": "ns",
981 "member-vnf-index": None,
984 "vdu_count_index": None,
987 "ee_descriptor_id": "",
989 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
997 "target_element": "ns",
998 "member-vnf-index": None,
1001 "vdu_count_index": None,
1004 "ee_descriptor_id": "",
1006 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1009 vca_records
= self
.n2vc
._get
_vca
_records
(charm_level
, db_nsr
, db_vnfr
)
1010 self
.assertEqual(vca_records
, expected_result
)
1012 def test_get_application_name_vnf_charm(self
):
1013 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1014 self
.db
.get_one
.return_value
= {
1019 "target_element": "vnf/vnf1/mgmtvm",
1020 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1021 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
1023 "vdu_count_index": None,
1024 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1025 "vdu_name": "mgmtvm",
1026 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1028 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1031 "target_element": "ns",
1032 "member-vnf-index": None,
1035 "vdu_count_index": None,
1038 "ee_descriptor_id": "",
1040 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1046 mock_vnf_count_and_record
= MagicMock()
1048 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
1051 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1052 expected_result
= "simple-ee-ab-z0-vnf111-xxx-y-vnf"
1053 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1054 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1056 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1057 self
.assertEqual(application_name
, expected_result
)
1058 self
.assertLess(len(application_name
), 50)
1059 mock_vnf_count_and_record
.assert_called_once_with(
1060 "vnf-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1062 self
.db
.get_one
.assert_called_once()
1065 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
1066 **{"return_value": "random"}
1068 def test_get_application_name_vnf_charm_old_naming(
1069 self
, mock_generate_random_alfanum
1071 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1072 self
.db
.get_one
.return_value
= {
1077 "target_element": "vnf/vnf1/mgmtvm",
1078 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1079 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
1081 "vdu_count_index": None,
1082 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1083 "vdu_name": "mgmtvm",
1084 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1085 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1088 "target_element": "ns",
1089 "member-vnf-index": None,
1092 "vdu_count_index": None,
1095 "ee_descriptor_id": "",
1096 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1102 mock_vnf_count_and_record
= MagicMock()
1104 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
1107 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1108 expected_result
= "app-vnf-eb3161eec0-z0-random"
1109 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1110 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1112 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1113 self
.assertEqual(application_name
, expected_result
)
1114 mock_vnf_count_and_record
.assert_called_once_with(
1115 "vnf-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1117 self
.db
.get_one
.assert_called_once()
1119 def test_get_application_name_vnf_charm_vnf_index_ref_mismatch(self
):
1120 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1121 self
.db
.get_one
.return_value
= {
1126 "target_element": "vnf/vnf1/mgmtvm",
1127 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1128 "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
1130 "vdu_count_index": None,
1131 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1132 "vdu_name": "mgmtvm",
1133 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1135 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1138 "target_element": "ns",
1139 "member-vnf-index": None,
1142 "vdu_count_index": None,
1145 "ee_descriptor_id": "",
1147 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1153 mock_vnf_count_and_record
= MagicMock()
1155 "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
1158 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1159 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1160 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1162 with self
.assertRaises(N2VCException
):
1163 self
.n2vc
._get
_application
_name
(namespace
)
1164 mock_vnf_count_and_record
.assert_called_once_with(
1165 "vnf-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1167 self
.db
.get_one
.assert_called_once()
1169 def test_get_application_name_vdu_charm(self
):
1170 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0.mgmtVM-0"
1171 self
.db
.get_one
.return_value
= {
1176 "target_element": "vnf/vnf1/mgmtvm",
1177 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1180 "vdu_count_index": None,
1181 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1182 "vdu_name": "mgmtvm",
1183 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1185 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1188 "target_element": "ns",
1189 "member-vnf-index": None,
1192 "vdu_count_index": None,
1195 "ee_descriptor_id": "",
1197 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1203 mock_vnf_count_and_record
= MagicMock()
1205 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
1207 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
1208 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
1212 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1213 expected_result
= "simple-ee-ab-z0-vnf111-xxx-y-mgmtvm-z0-vdu"
1214 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1215 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1217 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1218 self
.assertEqual(application_name
, expected_result
)
1219 self
.assertLess(len(application_name
), 50)
1220 mock_vnf_count_and_record
.assert_called_once_with(
1221 "vdu-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1223 self
.db
.get_one
.assert_called_once()
1225 def test_get_application_name_kdu_charm(self
):
1226 namespace
= ".82b11965-e580-47c0-9ee0-329f318a305b.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0.ldap"
1227 self
.db
.get_one
.return_value
= {
1232 "target_element": "vnf/openldap/kdu/ldap",
1233 "member-vnf-index": "openldap",
1236 "vdu_count_index": 0,
1237 "operational-status": "init",
1238 "detailed-status": "",
1239 "step": "initial-deploy",
1240 "vnfd_id": "openldap_knf",
1242 "type": "lxc_proxy_charm",
1243 "ee_descriptor_id": "openldap-ee",
1246 "application": "openldap-ee-z0-openldap-vdu",
1247 "model": "82b11965-e580-47c0-9ee0-329f318a305b",
1248 "config_sw_installed": True,
1254 mock_vnf_count_and_record
= MagicMock()
1256 "member-vnf-index-ref": "openldap",
1260 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1261 expected_result
= "openldap-ee-z0-openldap-ldap-vdu"
1262 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1263 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1265 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1266 self
.assertEqual(application_name
, expected_result
)
1267 self
.assertLess(len(application_name
), 50)
1268 mock_vnf_count_and_record
.assert_called_once_with(
1269 "vdu-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1271 self
.db
.get_one
.assert_called_once()
1274 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
1275 **{"return_value": "random"}
1277 def test_get_application_name_vdu_charm_old_naming(
1278 self
, mock_generate_random_alfanum
1280 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898.1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0.mgmtVM-0"
1281 self
.db
.get_one
.return_value
= {
1286 "target_element": "vnf/vnf1/mgmtVM",
1287 "member-vnf-index": "vnf111-xxx-yyy-zzz",
1290 "vdu_count_index": None,
1291 "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
1292 "vdu_name": "mgmtvm",
1293 "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1294 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1297 "target_element": "ns",
1298 "member-vnf-index": None,
1301 "vdu_count_index": None,
1304 "ee_descriptor_id": "",
1305 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1311 mock_vnf_count_and_record
= MagicMock()
1313 "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
1315 {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
1316 {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
1320 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1321 expected_result
= "app-vnf-eb3161eec0-z0-vdu-mgmtvm-cnt-z0-random"
1323 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1324 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1326 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1327 self
.assertEqual(application_name
, expected_result
)
1328 self
.assertLess(len(application_name
), 50)
1329 mock_vnf_count_and_record
.assert_called_once_with(
1330 "vdu-level", "1b6a4eb3-4fbf-415e-985c-4aeb3161eec0-0"
1332 self
.db
.get_one
.assert_called_once()
1334 def test_get_application_name_ns_charm(self
):
1335 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898"
1336 self
.db
.get_one
.return_value
= {
1341 "target_element": "ns",
1342 "member-vnf-index": None,
1345 "vdu_count_index": None,
1348 "ee_descriptor_id": "",
1349 "charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
1350 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1356 mock_vnf_count_and_record
= MagicMock()
1359 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1360 expected_result
= "simple-ns-charm-abc-z000-rrrr-nnnn-z4444-h-ns"
1361 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1362 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1364 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1365 self
.assertEqual(application_name
, expected_result
)
1366 self
.assertLess(len(application_name
), 50)
1367 mock_vnf_count_and_record
.assert_called_once_with("ns-level", None)
1368 self
.db
.get_one
.assert_called_once()
1370 def test_get_application_name_ns_charm_empty_charm_name(self
):
1371 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898"
1372 self
.db
.get_one
.return_value
= {
1377 "target_element": "ns",
1378 "member-vnf-index": None,
1381 "vdu_count_index": None,
1384 "ee_descriptor_id": "",
1386 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1392 mock_vnf_count_and_record
= MagicMock()
1395 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1396 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1397 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1399 with self
.assertRaises(N2VCException
):
1400 self
.n2vc
._get
_application
_name
(namespace
)
1401 mock_vnf_count_and_record
.assert_called_once_with("ns-level", None)
1402 self
.db
.get_one
.assert_called_once()
1405 "n2vc.n2vc_juju_conn.generate_random_alfanum_string",
1406 **{"return_value": "random"}
1408 def test_get_application_name_ns_charm_old_naming(
1409 self
, mock_generate_random_alfanum
1411 namespace
= ".dbfbd751-3de4-4e68-bd40-ec5ae0a53898"
1412 self
.db
.get_one
.return_value
= {
1417 "target_element": "ns",
1418 "member-vnf-index": None,
1421 "vdu_count_index": None,
1424 "ee_descriptor_id": "",
1425 "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
1431 mock_vnf_count_and_record
= MagicMock()
1434 mock_vnf_count_and_record
.return_value
= (vnf_count
, db_vnfr
)
1435 expected_result
= "app-random"
1436 with patch
.object(self
.n2vc
, "db", self
.db
), patch
.object(
1437 self
.n2vc
, "_get_vnf_count_and_record", mock_vnf_count_and_record
1439 application_name
= self
.n2vc
._get
_application
_name
(namespace
)
1440 self
.assertEqual(application_name
, expected_result
)
1441 self
.assertLess(len(application_name
), 50)
1442 mock_vnf_count_and_record
.assert_called_once_with("ns-level", None)
1443 self
.db
.get_one
.assert_called_once()