2 # Licensed under the Apache License, Version 2.0 (the "License"); you may
3 # not use this file except in compliance with the License. You may obtain
4 # a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 # License for the specific language governing permissions and limitations
14 # For those usages not covered by the Apache License, Version 2.0 please
15 # contact: esousa@whitestack.com or alfonso.tiernosepulveda@telefonica.com
19 import asynctest
# pip3 install asynctest --user
24 from osm_lcm
.ns
import NsLcm
25 from osm_common
.dbmongo
import DbMongo
26 from osm_common
.msgkafka
import MsgKafka
27 from osm_common
.fslocal
import FsLocal
28 from osm_lcm
.lcm_utils
import TaskRegistry
29 from n2vc
.vnf
import N2VC
30 from uuid
import uuid4
32 __author__
= "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
34 """ Perform unittests using asynctest of osm_lcm.ns module
35 It allows, if some testing ENV are supplied, testing without mocking some external libraries for debugging:
36 OSMLCMTEST_NS_PUBKEY: public ssh-key returned by N2VC to inject to VMs
37 OSMLCMTEST_NS_NAME: change name of NS
38 OSMLCMTEST_PACKAGES_PATH: path where the vnf-packages are stored (de-compressed), each one on a 'vnfd_id' folder
39 OSMLCMTEST_NS_IPADDRESS: IP address where emulated VMs are reached. Comma separate list
40 OSMLCMTEST_RO_VIMID: VIM id of RO target vim IP. Obtain it with openmano datcenter-list on RO container
41 OSMLCMTEST_VCA_NOMOCK: Do no mock the VCA, N2VC library, for debugging it
42 OSMLCMTEST_RO_NOMOCK: Do no mock the ROClient library, for debugging it
43 OSMLCMTEST_DB_NOMOCK: Do no mock the database library, for debugging it
44 OSMLCMTEST_FS_NOMOCK: Do no mock the File Storage library, for debugging it
45 OSMLCMTEST_LOGGING_NOMOCK: Do no mock the logging
46 OSMLCM_VCA_XXX: configuration of N2VC
47 OSMLCM_RO_XXX: configuration of RO
51 vca_config
= { # TODO replace with os.get_env to get other configurations
52 "host": getenv("OSMLCM_VCA_HOST", "vca"),
53 "port": getenv("OSMLCM_VCA_PORT", 17070),
54 "user": getenv("OSMLCM_VCA_USER", "admin"),
55 "secret": getenv("OSMLCM_VCA_SECRET", "vca"),
56 "pubkey": getenv("OSMLCM_VCA_PUBKEY", None),
57 'cacert': getenv("OSMLCM_VCA_CACERT", None)
61 "endpoint_url": "http://{}:{}/openmano".format(getenv("OSMLCM_RO_HOST", "ro"), getenv("OSMLCM_RO_PORT", "9090")),
62 "tenant": getenv("OSMLCM_RO_TENANT", "osm"),
63 "logger_name": "lcm.ROclient",
67 db_vim_accounts_text
= """
70 created: 1566818150.3024442
73 RO: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
74 RO-account: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
76 modified: 1566818150.3024442
77 operationalState: ENABLED
79 - detailed-status: Done
80 lcmOperationType: create
82 operationState: COMPLETED
83 startTime: 1566818150.3025382
84 statusEnteredTime: 1566818150.3025382
87 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
89 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
90 _id: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
91 description: Openstack site 2, based on Mirantis, also called DSS9000-1, with
95 vim_password: 5g0yGX86qIhprX86YTMcpg==
98 vim_url: http://10.95.87.162:5000/v2.0
105 created: 1566823352.7154346
106 modified: 1566823353.9295402
107 onboardingState: ONBOARDED
108 operationalState: ENABLED
110 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
112 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
114 descriptor: hackfest_3charmed_vnfd/hackfest_3charmed_vnfd.yaml
115 folder: 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
118 pkg-dir: hackfest_3charmed_vnfd
119 zipfile: package.tar.gz
121 usageState: NOT_IN_USE
123 _id: 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
133 description: A VNF consisting of 2 VDUs connected to an internal VL, and one VDU
135 id: hackfest3charmed-vnf
138 internal-connection-point:
139 - id-ref: mgmtVM-internal
140 - id-ref: dataVM-internal
148 - aggregation-type: AVERAGE
151 vdu-monitoring-param:
152 vdu-monitoring-param-ref: dataVM_cpu_util
154 name: hackfest3charmed-vnf
155 scaling-group-descriptor:
156 - max-instance-count: 10
158 scaling-config-action:
159 - trigger: post-scale-out
160 vnf-config-primitive-name-ref: touch
161 - trigger: pre-scale-in
162 vnf-config-primitive-name-ref: touch
165 name: auto_cpu_util_above_threshold
167 - name: cpu_util_above_threshold
168 scale-in-relational-operation: LE
169 scale-in-threshold: '15.0000000000'
170 scale-out-relational-operation: GE
171 scale-out-threshold: '60.0000000000'
172 vnf-monitoring-param-ref: monitor1
173 scaling-type: automatic
178 short-name: hackfest3charmed-vnf
181 cloud-init-file: cloud-config.txt
183 image: hackfest3-mgmt
185 - external-connection-point-ref: vnf-mgmt
191 - internal-connection-point-ref: mgmtVM-internal
197 internal-connection-point:
198 - id: mgmtVM-internal
199 name: mgmtVM-internal
200 short-name: mgmtVM-internal
209 image: hackfest3-mgmt
211 - internal-connection-point-ref: dataVM-internal
217 - external-connection-point-ref: vnf-data
223 internal-connection-point:
224 - id: dataVM-internal
225 name: dataVM-internal
226 short-name: dataVM-internal
229 - id: dataVM_cpu_util
230 nfvi-metric: cpu_utilization
246 default-value: <touch_filename2>
248 initial-config-primitive:
261 value: <touch_filename>
270 created: 1566823353.971486
271 modified: 1566823353.971486
272 onboardingState: ONBOARDED
273 operationalState: ENABLED
275 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
277 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
279 descriptor: hackfest_3charmed_nsd/hackfest_3charmed_nsd.yaml
280 folder: 8c2f8b95-bb1b-47ee-8001-36dc090678da
283 pkg-dir: hackfest_3charmed_nsd
284 zipfile: package.tar.gz
285 usageState: NOT_IN_USE
287 _id: 8c2f8b95-bb1b-47ee-8001-36dc090678da
289 - member-vnf-index: '1'
290 vnfd-id-ref: hackfest3charmed-vnf
291 - member-vnf-index: '2'
292 vnfd-id-ref: hackfest3charmed-vnf
293 description: NS with 2 VNFs hackfest3charmed-vnf connected by datanet and mgmtnet
295 id: hackfest3charmed-ns
297 name: hackfest3charmed-ns
298 short-name: hackfest3charmed-ns
306 vim-network-name: mgmt
307 vnfd-connection-point-ref:
308 - member-vnf-index-ref: '1'
309 vnfd-connection-point-ref: vnf-mgmt
310 vnfd-id-ref: hackfest3charmed-vnf
311 - member-vnf-index-ref: '2'
312 vnfd-connection-point-ref: vnf-mgmt
313 vnfd-id-ref: hackfest3charmed-vnf
318 vnfd-connection-point-ref:
319 - member-vnf-index-ref: '1'
320 vnfd-connection-point-ref: vnf-data
321 vnfd-id-ref: hackfest3charmed-vnf
322 - member-vnf-index-ref: '2'
323 vnfd-connection-point-ref: vnf-data
324 vnfd-id-ref: hackfest3charmed-vnf
330 created: 1566823354.3716335
333 nsd_id: 876573b5-968d-40b9-b52b-91bf5c5844f7
334 nsr_id: c9fe9908-3180-430d-b633-fca2f68db008
337 - id: 1ab2a418-9fe3-4358-bf17-411e5155535f
338 member-vnf-index: '1'
339 - id: 0de348e3-c201-4f6a-91cc-7f957e2d5504
340 member-vnf-index: '2'
342 - application: alf-b-aa
343 detailed-status: Ready!
344 member-vnf-index: '1'
345 model: f48163a6-c807-47bc-9682-f72caef5af85
346 operational-status: active
348 ssh-public-key: ssh-rsa pub-key root@juju-145d3e-0
349 step: ssh-public-key-obtained
350 vdu_count_index: null
353 vnfd_id: hackfest3charmed-vnf
354 - application: alf-c-ab
355 detailed-status: Ready!
356 member-vnf-index: '2'
357 model: f48163a6-c807-47bc-9682-f72caef5af85
358 operational-status: active
360 ssh-public-key: ssh-rsa pub-key root@juju-145d3e-0
361 step: ssh-public-key-obtained
362 vdu_count_index: null
365 vnfd_id: hackfest3charmed-vnf
366 VCA-model-name: f48163a6-c807-47bc-9682-f72caef5af85
367 modified: 1566823354.3716335
368 nsState: INSTANTIATED
371 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
373 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
374 _id: f48163a6-c807-47bc-9682-f72caef5af85
375 additionalParamsForNs: null
376 admin-status: ENABLED
378 constituent-vnfr-ref:
379 - 88d90b0c-faff-4b9f-bccd-017f33985984
380 - 1ca3bb1a-b29b-49fe-bed6-5f3076d77434
381 create-time: 1566823354.36234
382 datacenter: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
383 description: default description
384 detailed-status: 'ERROR executing proxy charm initial primitives for member_vnf_index=1
385 vdu_id=None: charm error executing primitive verify-ssh-credentials for member_vnf_index=1
386 vdu_id=None: ''timeout after 600 seconds'''
387 id: f48163a6-c807-47bc-9682-f72caef5af85
389 nsDescription: default description
391 nsdId: 8c2f8b95-bb1b-47ee-8001-36dc090678da
392 vimAccountId: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
395 ns-instance-config-ref: f48163a6-c807-47bc-9682-f72caef5af85
398 created: 1566823353.971486
399 modified: 1566823353.971486
400 onboardingState: ONBOARDED
401 operationalState: ENABLED
403 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
405 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
407 descriptor: hackfest_3charmed_nsd/hackfest_3charmed_nsd.yaml
408 folder: 8c2f8b95-bb1b-47ee-8001-36dc090678da
411 pkg-dir: hackfest_3charmed_nsd
412 zipfile: package.tar.gz
413 usageState: NOT_IN_USE
415 _id: 8c2f8b95-bb1b-47ee-8001-36dc090678da
417 - member-vnf-index: '1'
418 vnfd-id-ref: hackfest3charmed-vnf
419 - member-vnf-index: '2'
420 vnfd-id-ref: hackfest3charmed-vnf
421 description: NS with 2 VNFs hackfest3charmed-vnf connected by datanet and
423 id: hackfest3charmed-ns
425 name: hackfest3charmed-ns
426 short-name: hackfest3charmed-ns
434 vim-network-name: mgmt
435 vnfd-connection-point-ref:
436 - member-vnf-index-ref: '1'
437 vnfd-connection-point-ref: vnf-mgmt
438 vnfd-id-ref: hackfest3charmed-vnf
439 - member-vnf-index-ref: '2'
440 vnfd-connection-point-ref: vnf-mgmt
441 vnfd-id-ref: hackfest3charmed-vnf
446 vnfd-connection-point-ref:
447 - member-vnf-index-ref: '1'
448 vnfd-connection-point-ref: vnf-data
449 vnfd-id-ref: hackfest3charmed-vnf
450 - member-vnf-index-ref: '2'
451 vnfd-connection-point-ref: vnf-data
452 vnfd-id-ref: hackfest3charmed-vnf
453 nsd-id: 8c2f8b95-bb1b-47ee-8001-36dc090678da
454 nsd-name-ref: hackfest3charmed-ns
455 nsd-ref: hackfest3charmed-ns
456 operational-events: []
457 operational-status: failed
458 orchestration-progress: {}
459 resource-orchestrator: osmopenmano
461 ssh-authorized-key: null
466 status-detailed: null
467 vim-id: f99ae780-0e2f-4985-af41-574eae6919c0
468 vim-network-name: mgmt
472 status-detailed: null
473 vim-id: c31364ba-f573-4ab6-bf1a-fed30ede39a8
475 - 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
478 db_nslcmops_text
= """
481 created: 1566823354.4148262
482 modified: 1566823354.4148262
484 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
486 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
488 _id: a639fac7-e0bb-4225-8ecb-c1f8efcc125e
489 detailed-status: 'FAILED executing proxy charm initial primitives for member_vnf_index=1
490 vdu_id=None: charm error executing primitive verify-ssh-credentials for member_vnf_index=1
491 vdu_id=None: ''timeout after 600 seconds'''
492 id: a639fac7-e0bb-4225-8ecb-c1f8efcc125e
493 isAutomaticInvocation: false
494 isCancelPending: false
495 lcmOperationType: instantiate
497 nsInstance: /osm/nslcm/v1/ns_instances/f48163a6-c807-47bc-9682-f72caef5af85
498 self: /osm/nslcm/v1/ns_lcm_op_occs/a639fac7-e0bb-4225-8ecb-c1f8efcc125e
499 nsInstanceId: f48163a6-c807-47bc-9682-f72caef5af85
501 additionalParamsForVnf:
503 touch_filename: /home/ubuntu/first-touch-1
504 touch_filename2: /home/ubuntu/second-touch-1
505 member-vnf-index: '1'
507 touch_filename: /home/ubuntu/first-touch-2
508 touch_filename2: /home/ubuntu/second-touch-2
509 member-vnf-index: '2'
510 lcmOperationType: instantiate
511 nsDescription: default description
512 nsInstanceId: f48163a6-c807-47bc-9682-f72caef5af85
514 nsdId: 8c2f8b95-bb1b-47ee-8001-36dc090678da
515 vimAccountId: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
516 operationState: FAILED
517 startTime: 1566823354.414689
518 statusEnteredTime: 1566824534.5112448
524 created: 1566823354.3668208
525 modified: 1566823354.3668208
526 nsState: NOT_INSTANTIATED
528 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
530 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
531 _id: 88d90b0c-faff-4b9f-bccd-017f33985984
532 additionalParamsForVnf:
533 touch_filename: /home/ubuntu/first-touch-1
534 touch_filename2: /home/ubuntu/second-touch-1
536 - connection-point-id: vnf-mgmt
539 - connection-point-id: vnf-data
542 created-time: 1566823354.36234
543 id: 88d90b0c-faff-4b9f-bccd-017f33985984
544 ip-address: 10.205.1.46
545 member-vnf-index-ref: '1'
546 nsr-id-ref: f48163a6-c807-47bc-9682-f72caef5af85
548 - _id: f0e7d7ce-2443-4dcb-ad0b-5ab9f3b13d37
551 - ip-address: 10.205.1.46
552 mac-address: fa:16:3e:b4:3e:b1
556 - ip-address: 192.168.54.2
557 mac-address: fa:16:3e:6e:7e:78
560 internal-connection-point:
561 - connection-point-id: mgmtVM-internal
563 name: mgmtVM-internal
564 ip-address: 10.205.1.46
567 status-detailed: null
569 vim-id: c2538499-4c30-41c0-acd5-80cb92f48061
570 - _id: ab453219-2d9a-45c2-864d-2c0788385028
573 - ip-address: 192.168.54.3
574 mac-address: fa:16:3e:d9:7a:5d
577 - ip-address: 192.168.24.3
578 mac-address: fa:16:3e:d1:6c:0d
581 internal-connection-point:
582 - connection-point-id: dataVM-internal
584 name: dataVM-internal
588 status-detailed: null
590 vim-id: 87973c3f-365d-4227-95c2-7a8abc74349c
591 vim-account-id: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
596 status-detailed: null
597 vim-id: ff181e6d-2597-4244-b40b-bb0174bdfeb6
598 vnfd-id: 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
599 vnfd-ref: hackfest3charmed-vnf
601 created: 1566823354.3703845
602 modified: 1566823354.3703845
603 nsState: NOT_INSTANTIATED
605 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
607 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
608 _id: 1ca3bb1a-b29b-49fe-bed6-5f3076d77434
609 additionalParamsForVnf:
610 touch_filename: /home/ubuntu/first-touch-2
611 touch_filename2: /home/ubuntu/second-touch-2
613 - connection-point-id: vnf-mgmt
616 - connection-point-id: vnf-data
619 created-time: 1566823354.36234
620 id: 1ca3bb1a-b29b-49fe-bed6-5f3076d77434
621 ip-address: 10.205.1.47
622 member-vnf-index-ref: '2'
623 nsr-id-ref: f48163a6-c807-47bc-9682-f72caef5af85
625 - _id: 190b4a2c-4f85-4cfe-9406-4cef7ffb1e67
628 - ip-address: 10.205.1.47
629 mac-address: fa:16:3e:cb:9f:c7
633 - ip-address: 192.168.231.1
634 mac-address: fa:16:3e:1a:89:24
637 internal-connection-point:
638 - connection-point-id: mgmtVM-internal
640 name: mgmtVM-internal
641 ip-address: 10.205.1.47
644 status-detailed: null
646 vim-id: 248077b2-e3b8-4a37-8b72-575abb8ed912
647 - _id: 889b874d-e1c3-4e75-aa45-53a9b0ddabd9
650 - ip-address: 192.168.231.3
651 mac-address: fa:16:3e:7e:ba:8c
654 - ip-address: 192.168.24.4
655 mac-address: fa:16:3e:d2:e1:f5
658 internal-connection-point:
659 - connection-point-id: dataVM-internal
661 name: dataVM-internal
665 status-detailed: null
667 vim-id: a4ce4372-e0ad-4ae3-8f9f-1c969f32e77b
668 vim-account-id: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
673 status-detailed: null
674 vim-id: ff181e6d-2597-4244-b40b-bb0174bdfeb6
675 vnfd-id: 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
676 vnfd-ref: hackfest3charmed-vnf
680 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
685 datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
686 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
689 related: c6bac394-fa27-4c43-bb34-42f621a9d343
690 sce_net_id: 8f215bab-c35e-41e6-a035-42bfaa07af9f
693 uuid: c6bac394-fa27-4c43-bb34-42f621a9d343
694 vim_info: "{vim_info: null}"
696 vim_net_id: f99ae780-0e2f-4985-af41-574eae6919c0
700 datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
701 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
703 ns_net_osm_id: datanet
704 related: 509d576c-120f-493a-99a1-5fea99dfe041
705 sce_net_id: 3d766bbc-33a8-41aa-a986-2f35e8d25c16
708 uuid: 509d576c-120f-493a-99a1-5fea99dfe041
709 vim_info: "{vim_info: null}"
710 vim_name: ALF-datanet
711 vim_net_id: c31364ba-f573-4ab6-bf1a-fed30ede39a8
715 datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
716 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
719 related: 277fed09-3220-4bfd-9052-b96b21a32daf
723 uuid: 277fed09-3220-4bfd-9052-b96b21a32daf
724 vim_info: "{vim_info: null}"
725 vim_name: ALF-internal
726 vim_net_id: ff181e6d-2597-4244-b40b-bb0174bdfeb6
727 vnf_net_id: 62e62fae-c12b-4ebc-9a9b-30031c6c16fa
728 vnf_net_osm_id: internal
730 datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
731 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
734 related: 92534d1a-e697-4372-a84d-aa0aa643b68a
738 uuid: 92534d1a-e697-4372-a84d-aa0aa643b68a
739 vim_info: "{vim_info: null}"
740 vim_name: ALF-internal
741 vim_net_id: 09655387-b639-421a-b5f6-72b26d685fb4
742 vnf_net_id: 13c6c77d-86a5-4914-832c-990d4ec7b54e
743 vnf_net_osm_id: internal
744 nsd_osm_id: f48163a6-c807-47bc-9682-f72caef5af85.2.hackfest3charmed-ns
745 scenario_id: 876573b5-968d-40b9-b52b-91bf5c5844f7
746 scenario_name: hackfest3charmed-ns
750 tenant_id: 0ea38bd0-2729-47a9-ae07-c6ce76115eb2
751 uuid: c9fe9908-3180-430d-b633-fca2f68db008
753 - datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
754 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
755 ip_address: 10.205.1.46
756 member_vnf_index: '1'
757 mgmt_access: '{interface_id: 61549ee3-cd6c-4930-8b90-eaad97fe345b, required: ''False'',
758 vm_id: 6cf4a48f-3b6c-4395-8221-119fa37de24a}
761 sce_vnf_id: 83be04a8-c513-42ba-9908-22728f686d31
762 uuid: 94724042-7576-4fb0-82ec-6a7ab642741c
764 - created_at: '2019-08-26T12:50:38'
767 - external_name: vnf-mgmt
768 instance_net_id: c6bac394-fa27-4c43-bb34-42f621a9d343
769 internal_name: mgmtVM-eth0
770 ip_address: 10.205.1.46
771 mac_address: fa:16:3e:b4:3e:b1
774 vim_info: "{vim_info: null}"
775 vim_interface_id: 4d3cb8fd-7040-4169-a0ad-2486d2b006a1
776 - external_name: null
777 instance_net_id: 277fed09-3220-4bfd-9052-b96b21a32daf
778 internal_name: mgmtVM-eth1
779 ip_address: 192.168.54.2
780 mac_address: fa:16:3e:6e:7e:78
783 vim_info: "{vim_info: null}"
784 vim_interface_id: 54ed68e2-9802-4dfe-b68a-280b3fc6e02d
785 ip_address: 10.205.1.46
787 related: d0b91293-a91d-4f08-b15f-0bf841216dfe
789 uuid: d0b91293-a91d-4f08-b15f-0bf841216dfe
791 vim_info: "{vim_info: null}"
792 vim_name: ALF-1-mgmtVM-1
793 vim_vm_id: c2538499-4c30-41c0-acd5-80cb92f48061
794 - created_at: '2019-08-26T12:50:38'
797 - external_name: null
798 instance_net_id: 277fed09-3220-4bfd-9052-b96b21a32daf
799 internal_name: dataVM-eth0
800 ip_address: 192.168.54.3
801 mac_address: fa:16:3e:d9:7a:5d
804 vim_info: "{vim_info: null}"
805 vim_interface_id: 1637f350-8840-4241-8ed0-4616bdcecfcf
806 - external_name: vnf-data
807 instance_net_id: 509d576c-120f-493a-99a1-5fea99dfe041
808 internal_name: dataVM-xe0
809 ip_address: 192.168.24.3
810 mac_address: fa:16:3e:d1:6c:0d
813 vim_info: "{vim_info: null}"
814 vim_interface_id: 54c73e83-7059-41fe-83a9-4c4ae997b481
816 related: 5c08253d-8a35-474f-b0d3-c5297d174c13
818 uuid: 5c08253d-8a35-474f-b0d3-c5297d174c13
820 vim_info: "{vim_info: null}"
821 vim_name: ALF-1-dataVM-1
822 vim_vm_id: 87973c3f-365d-4227-95c2-7a8abc74349c
823 - created_at: '2019-08-26T13:40:54'
826 - external_name: null
827 instance_net_id: 277fed09-3220-4bfd-9052-b96b21a32daf
828 internal_name: dataVM-eth0
829 ip_address: 192.168.54.5
830 mac_address: fa:16:3e:e4:17:45
833 vim_info: "{vim_info: null}"
834 vim_interface_id: 7e246e40-8710-4c33-9c95-78fc3c02bc5b
835 - external_name: vnf-data
836 instance_net_id: 509d576c-120f-493a-99a1-5fea99dfe041
837 internal_name: dataVM-xe0
838 ip_address: 192.168.24.5
839 mac_address: fa:16:3e:29:6f:a6
842 vim_info: "{vim_info: null}"
843 vim_interface_id: ce81af7a-9adf-494b-950e-6581fd04ecc4
845 related: 1ae5a0a2-c15a-49a4-a77c-2991d97f6dbe
847 uuid: 1ae5a0a2-c15a-49a4-a77c-2991d97f6dbe
849 vim_info: "{vim_info: null}"
850 vim_name: ALF-1-dataVM-2
851 vim_vm_id: 4916533e-36c6-4861-9fe3-366a8fb0a5f8
852 vnf_id: 1ab2a418-9fe3-4358-bf17-411e5155535f
853 vnf_name: hackfest3charmed-vnf.1
854 vnfd_osm_id: f48163a6-c807-47bc-9682-f72caef5af85.0.1
855 - datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
856 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
857 ip_address: 10.205.1.47
858 member_vnf_index: '2'
859 mgmt_access: '{interface_id: 538604c3-5c5e-41eb-8f84-c0239c7fabcd, required: ''False'',
860 vm_id: dd04d792-05c9-4ecc-bf28-f77384d00311}
863 sce_vnf_id: c4f3607a-08ff-4f75-893c-fce507e2f240
864 uuid: 00020403-e80f-4ef2-bb7e-b29669643035
866 - created_at: '2019-08-26T12:50:38'
869 - external_name: vnf-mgmt
870 instance_net_id: c6bac394-fa27-4c43-bb34-42f621a9d343
871 internal_name: mgmtVM-eth0
872 ip_address: 10.205.1.47
873 mac_address: fa:16:3e:cb:9f:c7
876 vim_info: "{vim_info: null}"
877 vim_interface_id: dcd6d2de-3c68-481c-883e-e9d38c671dc4
878 - external_name: null
879 instance_net_id: 92534d1a-e697-4372-a84d-aa0aa643b68a
880 internal_name: mgmtVM-eth1
881 ip_address: 192.168.231.1
882 mac_address: fa:16:3e:1a:89:24
885 vim_info: "{vim_info: null}"
886 vim_interface_id: 50e538e3-aba0-4652-93bb-20487f3f28e1
887 ip_address: 10.205.1.47
889 related: 4543ab5d-578c-427c-9df2-affd17e21b66
891 uuid: 4543ab5d-578c-427c-9df2-affd17e21b66
893 vim_info: "{vim_info: null}"
894 vim_name: ALF-2-mgmtVM-1
895 vim_vm_id: 248077b2-e3b8-4a37-8b72-575abb8ed912
896 - created_at: '2019-08-26T12:50:38'
899 - external_name: null
900 instance_net_id: 92534d1a-e697-4372-a84d-aa0aa643b68a
901 internal_name: dataVM-eth0
902 ip_address: 192.168.231.3
903 mac_address: fa:16:3e:7e:ba:8c
906 vim_info: "{vim_info: null}"
907 vim_interface_id: 15274862-14ea-4527-b405-101cae8bc1a0
908 - external_name: vnf-data
909 instance_net_id: 509d576c-120f-493a-99a1-5fea99dfe041
910 internal_name: dataVM-xe0
911 ip_address: 192.168.24.4
912 mac_address: fa:16:3e:d2:e1:f5
915 vim_info: "{vim_info: null}"
916 vim_interface_id: 253ebe4e-38d5-46be-8777-dbb57510a2ec
918 related: 6f03f16b-295a-47a1-9a69-2d069d574a33
920 uuid: 6f03f16b-295a-47a1-9a69-2d069d574a33
922 vim_info: "{vim_info: null}"
923 vim_name: ALF-2-dataVM-1
924 vim_vm_id: a4ce4372-e0ad-4ae3-8f9f-1c969f32e77b
925 vnf_id: 0de348e3-c201-4f6a-91cc-7f957e2d5504
926 vnf_name: hackfest3charmed-vnf.2
927 vnfd_osm_id: f48163a6-c807-47bc-9682-f72caef5af85.1.2
931 class TestMyNS(asynctest
.TestCase
):
933 def _db_get_one(self
, table
, q_filter
=None, fail_on_empty
=True, fail_on_more
=True):
934 if table
not in self
.db_content
:
935 self
.assertTrue(False, "db.get_one called with table={}".format(table
))
936 for db_item
in self
.db_content
[table
]:
937 if db_item
["_id"] == q_filter
["_id"]:
940 self
.assertTrue(False, "db.get_one, table={}, not found _id={}".format(table
, q_filter
["_id"]))
942 def _db_get_list(self
, table
, q_filter
=None):
943 if table
not in self
.db_content
:
944 self
.assertTrue(False, "db.get_list called with table={} not found".format(table
))
945 return self
.db_content
[table
]
947 def _db_set_one(self
, table
, q_filter
, update_dict
, fail_on_empty
=True, unset
=None, pull
=None, push
=None):
948 db_item
= self
._db
_get
_one
(table
, q_filter
, fail_on_empty
=fail_on_empty
)
949 for k
, v
in update_dict
.items():
951 k_list
= k
.split(".")
952 for k_nested
in k_list
[0:-1]:
953 if isinstance(db_nested
, list):
954 db_nested
= db_nested
[int(k_nested
)]
956 if k_nested
not in db_nested
:
957 db_nested
[k_nested
] = {}
958 db_nested
= db_nested
[k_nested
]
959 k_nested
= k_list
[-1]
960 if isinstance(db_nested
, list):
961 if int(k_nested
) < len(db_nested
):
962 db_nested
[int(k_nested
)] = v
964 db_nested
.insert(int(k_nested
), v
)
966 db_nested
[k_nested
] = v
968 async def _n2vc_DeployCharms(self
, model_name
, application_name
, vnfd
, charm_path
, params
={}, machine_spec
={},
969 callback
=None, *callback_args
):
971 for status
, message
in (("maintenance", "installing sofwware"), ("active", "Ready!")):
972 # call callback after some time
973 asyncio
.sleep(5, loop
=self
.loop
)
974 callback(model_name
, application_name
, status
, message
, *callback_args
)
977 def _n2vc_FormatApplicationName(*args
):
980 yield "app_name-{}".format(num_calls
)
983 def _n2vc_CreateExecutionEnvironment(self
, namespace
):
984 k_list
= namespace
.split(".")
985 ee_id
= k_list
[1] + "."
987 for k
in k_list
[2:4]:
993 def _ro_show(self
, *args
, **kwargs
):
994 ro_ns_desc
= yaml
.load(ro_ns_text
)
996 # if ip address provided, replace descriptor
997 ip_addresses
= getenv("OSMLCMTEST_NS_IPADDRESS", "")
999 ip_addresses_list
= ip_addresses
.split(",")
1000 for vnf
in ro_ns_desc
["vnfs"]:
1001 if not ip_addresses_list
:
1003 vnf
["ip_address"] = ip_addresses_list
[0]
1004 for vm
in vnf
["vms"]:
1005 if not ip_addresses_list
:
1007 vm
["ip_address"] = ip_addresses_list
.pop(0)
1011 for net
in ro_ns_desc
["nets"]:
1012 if net
["status"] != "ACTIVE":
1013 net
["status"] = "ACTIVE"
1016 for vnf
in ro_ns_desc
["vnfs"]:
1017 for vm
in vnf
["vms"]:
1018 if vm
["status"] != "ACTIVE":
1019 vm
["status"] = "ACTIVE"
1022 def _ro_create(self
, *args
, **kwargs
):
1024 yield {"uuid": str(uuid4())}
1026 def _return_uuid(self
, *args
, **kwargs
):
1029 async def setUp(self
):
1031 if not getenv("OSMLCMTEST_DB_NOMOCK"):
1032 self
.db
= asynctest
.Mock(DbMongo())
1033 self
.db
.get_one
.side_effect
= self
._db
_get
_one
1034 self
.db
.get_list
.side_effect
= self
._db
_get
_list
1035 self
.db
.set_one
.side_effect
= self
._db
_set
_one
1037 "nsrs": yaml
.load(db_nsrs_text
),
1038 "nslcmops": yaml
.load(db_nslcmops_text
),
1039 "vnfrs": yaml
.load(db_vnfrs_text
),
1040 "vnfds": yaml
.load(db_vnfds_text
),
1041 "vim_accounts": yaml
.load(db_vim_accounts_text
),
1043 self
.db_vim_accounts
= yaml
.load(db_vim_accounts_text
)
1046 self
.msg
= asynctest
.Mock(MsgKafka())
1049 if not getenv("OSMLCMTEST_FS_NOMOCK"):
1050 self
.fs
= asynctest
.Mock(FsLocal())
1051 self
.fs
.get_params
.return_value
= {"path": getenv("OSMLCMTEST_PACKAGES_PATH", "./test/temp/packages")}
1052 self
.fs
.file_open
= asynctest
.mock_open()
1053 # self.fs.file_open.return_value.__enter__.return_value = asynctest.MagicMock() # called on a python "with"
1054 # self.fs.file_open.return_value.__enter__.return_value.read.return_value = "" # empty file
1057 self
.lcm_tasks
= asynctest
.Mock(TaskRegistry())
1058 self
.lcm_tasks
.lock_HA
.return_value
= True
1059 self
.lcm_tasks
.waitfor_related_HA
.return_value
= None
1060 self
.lcm_tasks
.lookfor_related
.return_value
= ("", [])
1062 # Create NsLCM class
1063 self
.my_ns
= NsLcm(self
.db
, self
.msg
, self
.fs
, self
.lcm_tasks
, ro_config
, vca_config
, self
.loop
)
1066 if not getenv("OSMLCMTEST_LOGGING_NOMOCK"):
1067 self
.my_ns
.logger
= asynctest
.Mock(self
.my_ns
.logger
)
1070 if not getenv("OSMLCMTEST_VCA_NOMOCK"):
1071 pub_key
= getenv("OSMLCMTEST_NS_PUBKEY", "ssh-rsa test-pub-key t@osm.com")
1072 self
.my_ns
.n2vc
= asynctest
.Mock(N2VC())
1073 self
.my_ns
.n2vc
.GetPublicKey
.return_value
= getenv("OSMLCM_VCA_PUBKEY", "public_key")
1074 # allow several versions of n2vc
1075 self
.my_ns
.n2vc
.FormatApplicationName
= asynctest
.Mock(side_effect
=self
._n
2vc
_FormatApplicationName
())
1076 self
.my_ns
.n2vc
.DeployCharms
= asynctest
.CoroutineMock(side_effect
=self
._n
2vc
_DeployCharms
)
1077 self
.my_ns
.n2vc
.CreateExecutionEnvironment
= asynctest
.CoroutineMock(
1078 side_effect
=self
._n
2vc
_CreateExecutionEnvironment
)
1079 self
.my_ns
.n2vc
.InstallConfigurationSW
= asynctest
.CoroutineMock(return_value
=pub_key
)
1080 self
.my_ns
.n2vc
.ExecutePrimitive
= asynctest
.CoroutineMock(side_effect
=self
._return
_uuid
)
1081 self
.my_ns
.n2vc
.GetPrimitiveStatus
= asynctest
.CoroutineMock(return_value
="completed")
1082 self
.my_ns
.n2vc
.GetPrimitiveOutput
= asynctest
.CoroutineMock(return_value
={"result": "ok",
1086 if not getenv("OSMLCMTEST_RO_NOMOCK"):
1087 # self.my_ns.RO = asynctest.Mock(ROclient.ROClient(self.loop, **ro_config))
1088 # TODO first time should be empty list, following should return a dict
1089 self
.my_ns
.RO
.get_list
= asynctest
.CoroutineMock(self
.my_ns
.RO
.get_list
, return_value
=[])
1090 self
.my_ns
.RO
.create
= asynctest
.CoroutineMock(self
.my_ns
.RO
.create
, side_effect
=self
._ro
_create
())
1091 self
.my_ns
.RO
.show
= asynctest
.CoroutineMock(self
.my_ns
.RO
.show
, side_effect
=self
._ro
_show
())
1092 self
.my_ns
.RO
.create_action
= asynctest
.CoroutineMock(self
.my_ns
.RO
.create_action
,
1093 return_value
={"vm-id": {"vim_result": 200,
1094 "description": "done"}})
1096 @asynctest.fail_on(active_handles
=True) # all async tasks must be completed
1097 async def test_instantiate(self
):
1098 nsr_id
= self
.db_content
["nsrs"][0]["_id"]
1099 nslcmop_id
= self
.db_content
["nslcmops"][0]["_id"]
1100 print("Test instantiate started")
1102 # delete deployed information of database
1103 if not getenv("OSMLCMTEST_DB_NOMOCK"):
1104 if self
.db_content
["nsrs"][0]["_admin"].get("deployed"):
1105 del self
.db_content
["nsrs"][0]["_admin"]["deployed"]
1106 for db_vnfr
in self
.db_content
["vnfrs"]:
1107 db_vnfr
.pop("ip_address", None)
1108 for db_vdur
in db_vnfr
["vdur"]:
1109 db_vdur
.pop("ip_address", None)
1110 db_vdur
.pop("mac_address", None)
1111 if getenv("OSMLCMTEST_RO_VIMID"):
1112 self
.db_content
["vim_accounts"][0]["_admin"]["deployed"]["RO"] = getenv("OSMLCMTEST_RO_VIMID")
1113 if getenv("OSMLCMTEST_RO_VIMID"):
1114 self
.db_content
["nsrs"][0]["_admin"]["deployed"]["RO"] = getenv("OSMLCMTEST_RO_VIMID")
1116 await self
.my_ns
.instantiate(nsr_id
, nslcmop_id
)
1118 print("instantiate_result: {}".format(self
._db
_get
_one
("nslcmops", {"_id": nslcmop_id
}).get("detailed-status")))
1120 self
.msg
.aiowrite
.assert_called_once_with("ns", "instantiated",
1121 {"nsr_id": nsr_id
, "nslcmop_id": nslcmop_id
,
1122 "operationState": "COMPLETED"},
1124 self
.lcm_tasks
.lock_HA
.assert_called_once_with('ns', 'nslcmops', nslcmop_id
)
1125 if not getenv("OSMLCMTEST_LOGGING_NOMOCK"):
1126 self
.assertTrue(self
.my_ns
.logger
.debug
.called
, "Debug method not called")
1127 self
.my_ns
.logger
.error
.assert_not_called()
1128 self
.my_ns
.logger
.exception().assert_not_called()
1130 if not getenv("OSMLCMTEST_DB_NOMOCK"):
1131 self
.assertTrue(self
.db
.set_one
.called
, "db.set_one not called")
1133 # TODO add more checks of called methods
1134 # TODO add a terminate
1136 def test_ns_params_2_RO(self
):
1137 vim
= self
._db
_get
_list
("vim_accounts")[0]
1139 ro_vim_id
= vim
["_admin"]["deployed"]["RO"]
1140 ns_params
= {"vimAccountId": vim_id
}
1141 mgmt_interface
= {"cp": "cp"}
1142 vdu
= [{"id": "vdu_id", "interface": [{"external-connection-point-ref": "cp"}]}]
1144 "1": {"vdu": vdu
, "mgmt-interface": mgmt_interface
},
1145 "2": {"vdu": vdu
, "mgmt-interface": mgmt_interface
, "vnf-configuration": None},
1146 "3": {"vdu": vdu
, "mgmt-interface": mgmt_interface
, "vnf-configuration": {"config-access": None}},
1147 "4": {"vdu": vdu
, "mgmt-interface": mgmt_interface
,
1148 "vnf-configuration": {"config-access": {"ssh-access": None}}},
1149 "5": {"vdu": vdu
, "mgmt-interface": mgmt_interface
,
1150 "vnf-configuration": {"config-access": {"ssh-access": {"required": True, "default_user": "U"}}}},
1152 nsd
= {"constituent-vnfd": []}
1153 for k
in vnfd_dict
.keys():
1154 nsd
["constituent-vnfd"].append({"vnfd-id-ref": k
, "member-vnf-index": k
})
1156 n2vc_key_list
= ["key"]
1157 ro_ns_params
= self
.my_ns
.ns_params_2_RO(ns_params
, nsd
, vnfd_dict
, n2vc_key_list
)
1158 ro_params_expected
= {'wim_account': None, "datacenter": ro_vim_id
,
1159 "vnfs": {"5": {"vdus": {"vdu_id": {"mgmt_keys": n2vc_key_list
}}}}}
1160 self
.assertEqual(ro_ns_params
, ro_params_expected
)
1162 @asynctest.fail_on(active_handles
=True) # all async tasks must be completed
1163 async def test_scale(self
):
1167 if __name__
== '__main__':