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
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_PACKAGES_PATH: path where the vnf-packages are stored (de-compressed), each one on a 'vnfd_id' folder
38 OSMLCMTEST_NS_IPADDRESS: IP address where emulated VMs are reached. Comma separate list
39 OSMLCMTEST_VCA_NOMOCK: Do no mock the VCA, N2VC library, for debugging it
40 OSMLCMTEST_RO_NOMOCK: Do no mock the ROClient library, for debugging it
41 OSMLCMTEST_DB_NOMOCK: Do no mock the database library, for debugging it
42 OSMLCMTEST_FS_NOMOCK: Do no mock the File Sorage library, for debugging it
43 OSMLCMTEST_LOGGING_NOMOCK: Do no mock the logging
44 OSMLCM_VCA_XXX: configuration of N2VC
45 OSMLCM_RO_XXX: configuration of RO
49 vca_config
= { # TODO replace with os.get_env to get other configurations
50 "host": getenv("OSMLCM_VCA_HOST", "vca"),
57 "endpoint_url": "http://{}:{}/openmano".format(getenv("OSMLCM_RO_HOST", "ro"), getenv("OSMLCM_RO_PORT", "9090")),
58 "tenant": getenv("OSMLCM_RO_TENANT", "osm"),
59 "logger_name": "lcm.ROclient",
63 db_vim_accounts_text
= """
66 created: 1566818150.3024442
69 RO: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
70 RO-account: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
72 modified: 1566818150.3024442
73 operationalState: ENABLED
75 - detailed-status: Done
76 lcmOperationType: create
78 operationState: COMPLETED
79 startTime: 1566818150.3025382
80 statusEnteredTime: 1566818150.3025382
83 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
85 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
86 _id: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
87 description: Openstack site 2, based on Mirantis, also called DSS9000-1, with
91 vim_password: 5g0yGX86qIhprX86YTMcpg==
94 vim_url: http://10.95.87.162:5000/v2.0
101 created: 1566823352.7154346
102 modified: 1566823353.9295402
103 onboardingState: ONBOARDED
104 operationalState: ENABLED
106 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
108 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
110 descriptor: hackfest_3charmed_vnfd/hackfest_3charmed_vnfd.yaml
111 folder: 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
114 pkg-dir: hackfest_3charmed_vnfd
115 zipfile: package.tar.gz
117 usageState: NOT_IN_USE
119 _id: 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
129 description: A VNF consisting of 2 VDUs connected to an internal VL, and one VDU
131 id: hackfest3charmed-vnf
134 internal-connection-point:
135 - id-ref: mgmtVM-internal
136 - id-ref: dataVM-internal
144 - aggregation-type: AVERAGE
147 vdu-monitoring-param:
148 vdu-monitoring-param-ref: dataVM_cpu_util
150 name: hackfest3charmed-vnf
151 scaling-group-descriptor:
152 - max-instance-count: 10
154 scaling-config-action:
155 - trigger: post-scale-out
156 vnf-config-primitive-name-ref: touch
157 - trigger: pre-scale-in
158 vnf-config-primitive-name-ref: touch
161 name: auto_cpu_util_above_threshold
163 - name: cpu_util_above_threshold
164 scale-in-relational-operation: LE
165 scale-in-threshold: '15.0000000000'
166 scale-out-relational-operation: GE
167 scale-out-threshold: '60.0000000000'
168 vnf-monitoring-param-ref: monitor1
169 scaling-type: automatic
174 short-name: hackfest3charmed-vnf
177 cloud-init-file: cloud-config.txt
179 image: hackfest3-mgmt
181 - external-connection-point-ref: vnf-mgmt
187 - internal-connection-point-ref: mgmtVM-internal
193 internal-connection-point:
194 - id: mgmtVM-internal
195 name: mgmtVM-internal
196 short-name: mgmtVM-internal
205 image: hackfest3-mgmt
207 - internal-connection-point-ref: dataVM-internal
213 - external-connection-point-ref: vnf-data
219 internal-connection-point:
220 - id: dataVM-internal
221 name: dataVM-internal
222 short-name: dataVM-internal
225 - id: dataVM_cpu_util
226 nfvi-metric: cpu_utilization
238 default-value: <touch_filename2>
240 initial-config-primitive:
253 value: <touch_filename>
262 created: 1566823353.971486
263 modified: 1566823353.971486
264 onboardingState: ONBOARDED
265 operationalState: ENABLED
267 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
269 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
271 descriptor: hackfest_3charmed_nsd/hackfest_3charmed_nsd.yaml
272 folder: 8c2f8b95-bb1b-47ee-8001-36dc090678da
275 pkg-dir: hackfest_3charmed_nsd
276 zipfile: package.tar.gz
277 usageState: NOT_IN_USE
279 _id: 8c2f8b95-bb1b-47ee-8001-36dc090678da
281 - member-vnf-index: '1'
282 vnfd-id-ref: hackfest3charmed-vnf
283 - member-vnf-index: '2'
284 vnfd-id-ref: hackfest3charmed-vnf
285 description: NS with 2 VNFs hackfest3charmed-vnf connected by datanet and mgmtnet
287 id: hackfest3charmed-ns
289 name: hackfest3charmed-ns
290 short-name: hackfest3charmed-ns
298 vim-network-name: mgmt
299 vnfd-connection-point-ref:
300 - member-vnf-index-ref: '1'
301 vnfd-connection-point-ref: vnf-mgmt
302 vnfd-id-ref: hackfest3charmed-vnf
303 - member-vnf-index-ref: '2'
304 vnfd-connection-point-ref: vnf-mgmt
305 vnfd-id-ref: hackfest3charmed-vnf
310 vnfd-connection-point-ref:
311 - member-vnf-index-ref: '1'
312 vnfd-connection-point-ref: vnf-data
313 vnfd-id-ref: hackfest3charmed-vnf
314 - member-vnf-index-ref: '2'
315 vnfd-connection-point-ref: vnf-data
316 vnfd-id-ref: hackfest3charmed-vnf
322 created: 1566823354.3716335
325 nsd_id: 876573b5-968d-40b9-b52b-91bf5c5844f7
326 nsr_id: c9fe9908-3180-430d-b633-fca2f68db008
329 - id: 1ab2a418-9fe3-4358-bf17-411e5155535f
330 member-vnf-index: '1'
331 - id: 0de348e3-c201-4f6a-91cc-7f957e2d5504
332 member-vnf-index: '2'
334 - application: alf-b-aa
335 detailed-status: Ready!
336 member-vnf-index: '1'
337 model: f48163a6-c807-47bc-9682-f72caef5af85
338 operational-status: active
340 ssh-public-key: ssh-rsa pub-key root@juju-145d3e-0
341 step: ssh-public-key-obtained
342 vdu_count_index: null
345 vnfd_id: hackfest3charmed-vnf
346 - application: alf-c-ab
347 detailed-status: Ready!
348 member-vnf-index: '2'
349 model: f48163a6-c807-47bc-9682-f72caef5af85
350 operational-status: active
352 ssh-public-key: ssh-rsa pub-key root@juju-145d3e-0
353 step: ssh-public-key-obtained
354 vdu_count_index: null
357 vnfd_id: hackfest3charmed-vnf
358 VCA-model-name: f48163a6-c807-47bc-9682-f72caef5af85
359 modified: 1566823354.3716335
360 nsState: INSTANTIATED
363 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
365 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
366 _id: f48163a6-c807-47bc-9682-f72caef5af85
367 additionalParamsForNs: null
368 admin-status: ENABLED
370 constituent-vnfr-ref:
371 - 88d90b0c-faff-4b9f-bccd-017f33985984
372 - 1ca3bb1a-b29b-49fe-bed6-5f3076d77434
373 create-time: 1566823354.36234
374 datacenter: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
375 description: default description
376 detailed-status: 'ERROR executing proxy charm initial primitives for member_vnf_index=1
377 vdu_id=None: charm error executing primitive verify-ssh-credentials for member_vnf_index=1
378 vdu_id=None: ''timeout after 600 seconds'''
379 id: f48163a6-c807-47bc-9682-f72caef5af85
381 nsDescription: default description
383 nsdId: 8c2f8b95-bb1b-47ee-8001-36dc090678da
384 vimAccountId: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
387 ns-instance-config-ref: f48163a6-c807-47bc-9682-f72caef5af85
390 created: 1566823353.971486
391 modified: 1566823353.971486
392 onboardingState: ONBOARDED
393 operationalState: ENABLED
395 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
397 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
399 descriptor: hackfest_3charmed_nsd/hackfest_3charmed_nsd.yaml
400 folder: 8c2f8b95-bb1b-47ee-8001-36dc090678da
403 pkg-dir: hackfest_3charmed_nsd
404 zipfile: package.tar.gz
405 usageState: NOT_IN_USE
407 _id: 8c2f8b95-bb1b-47ee-8001-36dc090678da
409 - member-vnf-index: '1'
410 vnfd-id-ref: hackfest3charmed-vnf
411 - member-vnf-index: '2'
412 vnfd-id-ref: hackfest3charmed-vnf
413 description: NS with 2 VNFs hackfest3charmed-vnf connected by datanet and
415 id: hackfest3charmed-ns
417 name: hackfest3charmed-ns
418 short-name: hackfest3charmed-ns
426 vim-network-name: mgmt
427 vnfd-connection-point-ref:
428 - member-vnf-index-ref: '1'
429 vnfd-connection-point-ref: vnf-mgmt
430 vnfd-id-ref: hackfest3charmed-vnf
431 - member-vnf-index-ref: '2'
432 vnfd-connection-point-ref: vnf-mgmt
433 vnfd-id-ref: hackfest3charmed-vnf
438 vnfd-connection-point-ref:
439 - member-vnf-index-ref: '1'
440 vnfd-connection-point-ref: vnf-data
441 vnfd-id-ref: hackfest3charmed-vnf
442 - member-vnf-index-ref: '2'
443 vnfd-connection-point-ref: vnf-data
444 vnfd-id-ref: hackfest3charmed-vnf
445 nsd-id: 8c2f8b95-bb1b-47ee-8001-36dc090678da
446 nsd-name-ref: hackfest3charmed-ns
447 nsd-ref: hackfest3charmed-ns
448 operational-events: []
449 operational-status: failed
450 orchestration-progress: {}
451 resource-orchestrator: osmopenmano
453 ssh-authorized-key: null
458 status-detailed: null
459 vim-id: f99ae780-0e2f-4985-af41-574eae6919c0
460 vim-network-name: mgmt
464 status-detailed: null
465 vim-id: c31364ba-f573-4ab6-bf1a-fed30ede39a8
467 - 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
470 db_nslcmops_text
= """
473 created: 1566823354.4148262
474 modified: 1566823354.4148262
476 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
478 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
480 _id: a639fac7-e0bb-4225-8ecb-c1f8efcc125e
481 detailed-status: 'FAILED executing proxy charm initial primitives for member_vnf_index=1
482 vdu_id=None: charm error executing primitive verify-ssh-credentials for member_vnf_index=1
483 vdu_id=None: ''timeout after 600 seconds'''
484 id: a639fac7-e0bb-4225-8ecb-c1f8efcc125e
485 isAutomaticInvocation: false
486 isCancelPending: false
487 lcmOperationType: instantiate
489 nsInstance: /osm/nslcm/v1/ns_instances/f48163a6-c807-47bc-9682-f72caef5af85
490 self: /osm/nslcm/v1/ns_lcm_op_occs/a639fac7-e0bb-4225-8ecb-c1f8efcc125e
491 nsInstanceId: f48163a6-c807-47bc-9682-f72caef5af85
493 additionalParamsForVnf:
495 touch_filename: /home/ubuntu/first-touch-1
496 touch_filename2: /home/ubuntu/second-touch-1
497 member-vnf-index: '1'
499 touch_filename: /home/ubuntu/first-touch-2
500 touch_filename2: /home/ubuntu/second-touch-2
501 member-vnf-index: '2'
502 lcmOperationType: instantiate
503 nsDescription: default description
504 nsInstanceId: f48163a6-c807-47bc-9682-f72caef5af85
506 nsdId: 8c2f8b95-bb1b-47ee-8001-36dc090678da
507 vimAccountId: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
508 operationState: FAILED
509 startTime: 1566823354.414689
510 statusEnteredTime: 1566824534.5112448
516 created: 1566823354.3668208
517 modified: 1566823354.3668208
518 nsState: NOT_INSTANTIATED
520 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
522 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
523 _id: 88d90b0c-faff-4b9f-bccd-017f33985984
524 additionalParamsForVnf:
525 touch_filename: /home/ubuntu/first-touch-1
526 touch_filename2: /home/ubuntu/second-touch-1
528 - connection-point-id: vnf-mgmt
531 - connection-point-id: vnf-data
534 created-time: 1566823354.36234
535 id: 88d90b0c-faff-4b9f-bccd-017f33985984
536 ip-address: 10.205.1.46
537 member-vnf-index-ref: '1'
538 nsr-id-ref: f48163a6-c807-47bc-9682-f72caef5af85
540 - _id: f0e7d7ce-2443-4dcb-ad0b-5ab9f3b13d37
543 - ip-address: 10.205.1.46
544 mac-address: fa:16:3e:b4:3e:b1
548 - ip-address: 192.168.54.2
549 mac-address: fa:16:3e:6e:7e:78
552 internal-connection-point:
553 - connection-point-id: mgmtVM-internal
555 name: mgmtVM-internal
556 ip-address: 10.205.1.46
559 status-detailed: null
561 vim-id: c2538499-4c30-41c0-acd5-80cb92f48061
562 - _id: ab453219-2d9a-45c2-864d-2c0788385028
565 - ip-address: 192.168.54.3
566 mac-address: fa:16:3e:d9:7a:5d
569 - ip-address: 192.168.24.3
570 mac-address: fa:16:3e:d1:6c:0d
573 internal-connection-point:
574 - connection-point-id: dataVM-internal
576 name: dataVM-internal
580 status-detailed: null
582 vim-id: 87973c3f-365d-4227-95c2-7a8abc74349c
583 vim-account-id: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
588 status-detailed: null
589 vim-id: ff181e6d-2597-4244-b40b-bb0174bdfeb6
590 vnfd-id: 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
591 vnfd-ref: hackfest3charmed-vnf
593 created: 1566823354.3703845
594 modified: 1566823354.3703845
595 nsState: NOT_INSTANTIATED
597 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
599 - 25b5aebf-3da1-49ed-99de-1d2b4a86d6e4
600 _id: 1ca3bb1a-b29b-49fe-bed6-5f3076d77434
601 additionalParamsForVnf:
602 touch_filename: /home/ubuntu/first-touch-2
603 touch_filename2: /home/ubuntu/second-touch-2
605 - connection-point-id: vnf-mgmt
608 - connection-point-id: vnf-data
611 created-time: 1566823354.36234
612 id: 1ca3bb1a-b29b-49fe-bed6-5f3076d77434
613 ip-address: 10.205.1.47
614 member-vnf-index-ref: '2'
615 nsr-id-ref: f48163a6-c807-47bc-9682-f72caef5af85
617 - _id: 190b4a2c-4f85-4cfe-9406-4cef7ffb1e67
620 - ip-address: 10.205.1.47
621 mac-address: fa:16:3e:cb:9f:c7
625 - ip-address: 192.168.231.1
626 mac-address: fa:16:3e:1a:89:24
629 internal-connection-point:
630 - connection-point-id: mgmtVM-internal
632 name: mgmtVM-internal
633 ip-address: 10.205.1.47
636 status-detailed: null
638 vim-id: 248077b2-e3b8-4a37-8b72-575abb8ed912
639 - _id: 889b874d-e1c3-4e75-aa45-53a9b0ddabd9
642 - ip-address: 192.168.231.3
643 mac-address: fa:16:3e:7e:ba:8c
646 - ip-address: 192.168.24.4
647 mac-address: fa:16:3e:d2:e1:f5
650 internal-connection-point:
651 - connection-point-id: dataVM-internal
653 name: dataVM-internal
657 status-detailed: null
659 vim-id: a4ce4372-e0ad-4ae3-8f9f-1c969f32e77b
660 vim-account-id: ea958ba5-4e58-4405-bf42-6e3be15d4c3a
665 status-detailed: null
666 vim-id: ff181e6d-2597-4244-b40b-bb0174bdfeb6
667 vnfd-id: 7637bcf8-cf14-42dc-ad70-c66fcf1e6e77
668 vnfd-ref: hackfest3charmed-vnf
672 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
677 datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
678 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
681 related: c6bac394-fa27-4c43-bb34-42f621a9d343
682 sce_net_id: 8f215bab-c35e-41e6-a035-42bfaa07af9f
685 uuid: c6bac394-fa27-4c43-bb34-42f621a9d343
686 vim_info: "{vim_info: null}"
688 vim_net_id: f99ae780-0e2f-4985-af41-574eae6919c0
692 datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
693 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
695 ns_net_osm_id: datanet
696 related: 509d576c-120f-493a-99a1-5fea99dfe041
697 sce_net_id: 3d766bbc-33a8-41aa-a986-2f35e8d25c16
700 uuid: 509d576c-120f-493a-99a1-5fea99dfe041
701 vim_info: "{vim_info: null}"
702 vim_name: ALF-datanet
703 vim_net_id: c31364ba-f573-4ab6-bf1a-fed30ede39a8
707 datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
708 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
711 related: 277fed09-3220-4bfd-9052-b96b21a32daf
715 uuid: 277fed09-3220-4bfd-9052-b96b21a32daf
716 vim_info: "{vim_info: null}"
717 vim_name: ALF-internal
718 vim_net_id: ff181e6d-2597-4244-b40b-bb0174bdfeb6
719 vnf_net_id: 62e62fae-c12b-4ebc-9a9b-30031c6c16fa
720 vnf_net_osm_id: internal
722 datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
723 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
726 related: 92534d1a-e697-4372-a84d-aa0aa643b68a
730 uuid: 92534d1a-e697-4372-a84d-aa0aa643b68a
731 vim_info: "{vim_info: null}"
732 vim_name: ALF-internal
733 vim_net_id: 09655387-b639-421a-b5f6-72b26d685fb4
734 vnf_net_id: 13c6c77d-86a5-4914-832c-990d4ec7b54e
735 vnf_net_osm_id: internal
736 nsd_osm_id: f48163a6-c807-47bc-9682-f72caef5af85.2.hackfest3charmed-ns
737 scenario_id: 876573b5-968d-40b9-b52b-91bf5c5844f7
738 scenario_name: hackfest3charmed-ns
742 tenant_id: 0ea38bd0-2729-47a9-ae07-c6ce76115eb2
743 uuid: c9fe9908-3180-430d-b633-fca2f68db008
745 - datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
746 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
747 ip_address: 10.205.1.46
748 member_vnf_index: '1'
749 mgmt_access: '{interface_id: 61549ee3-cd6c-4930-8b90-eaad97fe345b, required: ''False'',
750 vm_id: 6cf4a48f-3b6c-4395-8221-119fa37de24a}
753 sce_vnf_id: 83be04a8-c513-42ba-9908-22728f686d31
754 uuid: 94724042-7576-4fb0-82ec-6a7ab642741c
756 - created_at: '2019-08-26T12:50:38'
759 - external_name: vnf-mgmt
760 instance_net_id: c6bac394-fa27-4c43-bb34-42f621a9d343
761 internal_name: mgmtVM-eth0
762 ip_address: 10.205.1.46
763 mac_address: fa:16:3e:b4:3e:b1
766 vim_info: "{vim_info: null}"
767 vim_interface_id: 4d3cb8fd-7040-4169-a0ad-2486d2b006a1
768 - external_name: null
769 instance_net_id: 277fed09-3220-4bfd-9052-b96b21a32daf
770 internal_name: mgmtVM-eth1
771 ip_address: 192.168.54.2
772 mac_address: fa:16:3e:6e:7e:78
775 vim_info: "{vim_info: null}"
776 vim_interface_id: 54ed68e2-9802-4dfe-b68a-280b3fc6e02d
777 ip_address: 10.205.1.46
779 related: d0b91293-a91d-4f08-b15f-0bf841216dfe
781 uuid: d0b91293-a91d-4f08-b15f-0bf841216dfe
783 vim_info: "{vim_info: null}"
784 vim_name: ALF-1-mgmtVM-1
785 vim_vm_id: c2538499-4c30-41c0-acd5-80cb92f48061
786 - created_at: '2019-08-26T12:50:38'
789 - external_name: null
790 instance_net_id: 277fed09-3220-4bfd-9052-b96b21a32daf
791 internal_name: dataVM-eth0
792 ip_address: 192.168.54.3
793 mac_address: fa:16:3e:d9:7a:5d
796 vim_info: "{vim_info: null}"
797 vim_interface_id: 1637f350-8840-4241-8ed0-4616bdcecfcf
798 - external_name: vnf-data
799 instance_net_id: 509d576c-120f-493a-99a1-5fea99dfe041
800 internal_name: dataVM-xe0
801 ip_address: 192.168.24.3
802 mac_address: fa:16:3e:d1:6c:0d
805 vim_info: "{vim_info: null}"
806 vim_interface_id: 54c73e83-7059-41fe-83a9-4c4ae997b481
808 related: 5c08253d-8a35-474f-b0d3-c5297d174c13
810 uuid: 5c08253d-8a35-474f-b0d3-c5297d174c13
812 vim_info: "{vim_info: null}"
813 vim_name: ALF-1-dataVM-1
814 vim_vm_id: 87973c3f-365d-4227-95c2-7a8abc74349c
815 - created_at: '2019-08-26T13:40:54'
818 - external_name: null
819 instance_net_id: 277fed09-3220-4bfd-9052-b96b21a32daf
820 internal_name: dataVM-eth0
821 ip_address: 192.168.54.5
822 mac_address: fa:16:3e:e4:17:45
825 vim_info: "{vim_info: null}"
826 vim_interface_id: 7e246e40-8710-4c33-9c95-78fc3c02bc5b
827 - external_name: vnf-data
828 instance_net_id: 509d576c-120f-493a-99a1-5fea99dfe041
829 internal_name: dataVM-xe0
830 ip_address: 192.168.24.5
831 mac_address: fa:16:3e:29:6f:a6
834 vim_info: "{vim_info: null}"
835 vim_interface_id: ce81af7a-9adf-494b-950e-6581fd04ecc4
837 related: 1ae5a0a2-c15a-49a4-a77c-2991d97f6dbe
839 uuid: 1ae5a0a2-c15a-49a4-a77c-2991d97f6dbe
841 vim_info: "{vim_info: null}"
842 vim_name: ALF-1-dataVM-2
843 vim_vm_id: 4916533e-36c6-4861-9fe3-366a8fb0a5f8
844 vnf_id: 1ab2a418-9fe3-4358-bf17-411e5155535f
845 vnf_name: hackfest3charmed-vnf.1
846 vnfd_osm_id: f48163a6-c807-47bc-9682-f72caef5af85.0.1
847 - datacenter_id: dc51ce6c-c7f2-11e9-b9c0-02420aff0004
848 datacenter_tenant_id: dc5c67fa-c7f2-11e9-b9c0-02420aff0004
849 ip_address: 10.205.1.47
850 member_vnf_index: '2'
851 mgmt_access: '{interface_id: 538604c3-5c5e-41eb-8f84-c0239c7fabcd, required: ''False'',
852 vm_id: dd04d792-05c9-4ecc-bf28-f77384d00311}
855 sce_vnf_id: c4f3607a-08ff-4f75-893c-fce507e2f240
856 uuid: 00020403-e80f-4ef2-bb7e-b29669643035
858 - created_at: '2019-08-26T12:50:38'
861 - external_name: vnf-mgmt
862 instance_net_id: c6bac394-fa27-4c43-bb34-42f621a9d343
863 internal_name: mgmtVM-eth0
864 ip_address: 10.205.1.47
865 mac_address: fa:16:3e:cb:9f:c7
868 vim_info: "{vim_info: null}"
869 vim_interface_id: dcd6d2de-3c68-481c-883e-e9d38c671dc4
870 - external_name: null
871 instance_net_id: 92534d1a-e697-4372-a84d-aa0aa643b68a
872 internal_name: mgmtVM-eth1
873 ip_address: 192.168.231.1
874 mac_address: fa:16:3e:1a:89:24
877 vim_info: "{vim_info: null}"
878 vim_interface_id: 50e538e3-aba0-4652-93bb-20487f3f28e1
879 ip_address: 10.205.1.47
881 related: 4543ab5d-578c-427c-9df2-affd17e21b66
883 uuid: 4543ab5d-578c-427c-9df2-affd17e21b66
885 vim_info: "{vim_info: null}"
886 vim_name: ALF-2-mgmtVM-1
887 vim_vm_id: 248077b2-e3b8-4a37-8b72-575abb8ed912
888 - created_at: '2019-08-26T12:50:38'
891 - external_name: null
892 instance_net_id: 92534d1a-e697-4372-a84d-aa0aa643b68a
893 internal_name: dataVM-eth0
894 ip_address: 192.168.231.3
895 mac_address: fa:16:3e:7e:ba:8c
898 vim_info: "{vim_info: null}"
899 vim_interface_id: 15274862-14ea-4527-b405-101cae8bc1a0
900 - external_name: vnf-data
901 instance_net_id: 509d576c-120f-493a-99a1-5fea99dfe041
902 internal_name: dataVM-xe0
903 ip_address: 192.168.24.4
904 mac_address: fa:16:3e:d2:e1:f5
907 vim_info: "{vim_info: null}"
908 vim_interface_id: 253ebe4e-38d5-46be-8777-dbb57510a2ec
910 related: 6f03f16b-295a-47a1-9a69-2d069d574a33
912 uuid: 6f03f16b-295a-47a1-9a69-2d069d574a33
914 vim_info: "{vim_info: null}"
915 vim_name: ALF-2-dataVM-1
916 vim_vm_id: a4ce4372-e0ad-4ae3-8f9f-1c969f32e77b
917 vnf_id: 0de348e3-c201-4f6a-91cc-7f957e2d5504
918 vnf_name: hackfest3charmed-vnf.2
919 vnfd_osm_id: f48163a6-c807-47bc-9682-f72caef5af85.1.2
923 class TestMyNS(asynctest
.TestCase
):
925 def _db_get_one(self
, table
, q_filter
=None, fail_on_empty
=True, fail_on_more
=True):
926 if table
not in self
.db_content
:
927 self
.assertTrue(False, "db.get_one called with table={}".format(table
))
928 for db_item
in self
.db_content
[table
]:
929 if db_item
["_id"] == q_filter
["_id"]:
932 self
.assertTrue(False, "db.get_one, table={}, not found _id={}".format(table
, q_filter
["_id"]))
934 def _db_get_list(self
, table
, q_filter
=None):
935 if table
not in self
.db_content
:
936 self
.assertTrue(False, "db.get_list called with table={} not found".format(table
))
937 return self
.db_content
[table
]
939 def _db_set_one(self
, table
, q_filter
, update_dict
, fail_on_empty
=True, unset
=None, pull
=None, push
=None):
940 db_item
= self
._db
_get
_one
(table
, q_filter
, fail_on_empty
=fail_on_empty
)
941 for k
, v
in update_dict
.items():
943 k_list
= k
.split(".")
944 for k_nested
in k_list
[0:-1]:
945 if isinstance(db_nested
, list):
946 db_nested
= db_nested
[int(k_nested
)]
948 if k_nested
not in db_nested
:
949 db_nested
[k_nested
] = {}
950 db_nested
= db_nested
[k_nested
]
951 k_nested
= k_list
[-1]
952 if isinstance(db_nested
, list):
953 if int(k_nested
) < len(db_nested
):
954 db_nested
[int(k_nested
)] = v
956 db_nested
.insert(int(k_nested
), v
)
958 db_nested
[k_nested
] = v
960 async def _n2vc_DeployCharms(self
, model_name
, application_name
, vnfd
, charm_path
, params
={}, machine_spec
={},
961 callback
=None, *callback_args
):
963 for status
, message
in (("maintenance", "installing sofwware"), ("active", "Ready!")):
964 # call callback after some time
965 asyncio
.sleep(5, loop
=self
.loop
)
966 callback(model_name
, application_name
, status
, message
, *callback_args
)
969 def _n2vc_FormatApplicationName(*args
):
972 yield "app_name-{}".format(num_calls
)
975 def _n2vc_CreateExecutionEnvironment(self
, namespace
):
976 k_list
= namespace
.split(".")
977 ee_id
= k_list
[1] + "."
979 for k
in k_list
[2:4]:
985 def _ro_show(self
, *args
, **kwargs
):
986 ro_ns_desc
= yaml
.load(ro_ns_text
)
988 # if ip address provided, replace descriptor
989 ip_addresses
= getenv("OSMLCMTEST_NS_IPADDRESS", "")
991 ip_addresses_list
= ip_addresses
.split(",")
992 for vnf
in ro_ns_desc
["vnfs"]:
993 if not ip_addresses_list
:
995 vnf
["ip_address"] = ip_addresses_list
[0]
996 for vm
in vnf
["vms"]:
997 if not ip_addresses_list
:
999 vm
["ip_address"] = ip_addresses_list
.pop(0)
1003 for net
in ro_ns_desc
["nets"]:
1004 if net
["status"] != "ACTIVE":
1005 net
["status"] = "ACTIVE"
1008 for vnf
in ro_ns_desc
["vnfs"]:
1009 for vm
in vnf
["vms"]:
1010 if vm
["status"] != "ACTIVE":
1011 vm
["status"] = "ACTIVE"
1014 def _ro_create(self
, *args
, **kwargs
):
1016 yield {"uuid": str(uuid4())}
1018 def _return_uuid(self
, *args
, **kwargs
):
1021 async def setUp(self
):
1023 if not getenv("OSMLCMTEST_DB_NOMOCK"):
1024 self
.db
= asynctest
.Mock(DbMongo())
1025 self
.db
.get_one
.side_effect
= self
._db
_get
_one
1026 self
.db
.get_list
.side_effect
= self
._db
_get
_list
1027 self
.db
.set_one
.side_effect
= self
._db
_set
_one
1029 "nsrs": yaml
.load(db_nsrs_text
),
1030 "nslcmops": yaml
.load(db_nslcmops_text
),
1031 "vnfrs": yaml
.load(db_vnfrs_text
),
1032 "vnfds": yaml
.load(db_vnfds_text
),
1033 "vim_accounts": yaml
.load(db_vim_accounts_text
),
1035 self
.db_vim_accounts
= yaml
.load(db_vim_accounts_text
)
1038 self
.msg
= asynctest
.Mock(MsgKafka())
1041 if not getenv("OSMLCMTEST_FS_NOMOCK"):
1042 self
.fs
= asynctest
.Mock(FsLocal())
1043 self
.fs
.get_params
.return_value
= {"path": getenv("OSMLCMTEST_PACKAGES_PATH", "./test/temp/packages")}
1044 self
.fs
.file_open
= asynctest
.mock_open()
1045 # self.fs.file_open.return_value.__enter__.return_value = asynctest.MagicMock() # called on a python "with"
1046 # self.fs.file_open.return_value.__enter__.return_value.read.return_value = "" # empty file
1049 self
.lcm_tasks
= asynctest
.Mock(TaskRegistry())
1050 self
.lcm_tasks
.lock_HA
.return_value
= True
1051 self
.lcm_tasks
.waitfor_related_HA
.return_value
= None
1052 self
.lcm_tasks
.lookfor_related
.return_value
= ("", [])
1054 # Create NsLCM class
1055 self
.my_ns
= NsLcm(self
.db
, self
.msg
, self
.fs
, self
.lcm_tasks
, ro_config
, vca_config
, self
.loop
)
1058 if not getenv("OSMLCMTEST_LOGGING_NOMOCK"):
1059 self
.my_ns
.logger
= asynctest
.Mock(self
.my_ns
.logger
)
1062 if not getenv("OSMLCMTEST_VCA_NOMOCK"):
1063 pub_key
= getenv("OSMLCMTEST_NS_PUBKEY", "ssh-rsa test-pub-key t@osm.com")
1064 self
.my_ns
.n2vc
= asynctest
.Mock(N2VC())
1065 self
.my_ns
.n2vc
.GetPublicKey
.return_value
= getenv("OSMLCM_VCA_PUBKEY", "public_key")
1066 # allow several versions of n2vc
1067 self
.my_ns
.n2vc
.FormatApplicationName
= asynctest
.Mock(side_effect
=self
._n
2vc
_FormatApplicationName
())
1068 self
.my_ns
.n2vc
.DeployCharms
= asynctest
.CoroutineMock(side_effect
=self
._n
2vc
_DeployCharms
)
1069 self
.my_ns
.n2vc
.CreateExecutionEnvironment
= asynctest
.CoroutineMock(
1070 side_effect
=self
._n
2vc
_CreateExecutionEnvironment
)
1071 self
.my_ns
.n2vc
.InstallConfigurationSW
= asynctest
.CoroutineMock(return_value
=pub_key
)
1072 self
.my_ns
.n2vc
.ExecutePrimitive
= asynctest
.CoroutineMock(side_effect
=self
._return
_uuid
)
1073 self
.my_ns
.n2vc
.GetPrimitiveStatus
= asynctest
.CoroutineMock(return_value
="completed")
1074 self
.my_ns
.n2vc
.GetPrimitiveOutput
= asynctest
.CoroutineMock(return_value
={"result": "ok",
1078 if not getenv("OSMLCMTEST_RO_NOMOCK"):
1079 # self.my_ns.RO = asynctest.Mock(ROclient.ROClient(self.loop, **ro_config))
1080 # TODO first time should be empty list, following should return a dict
1081 self
.my_ns
.RO
.get_list
= asynctest
.CoroutineMock(self
.my_ns
.RO
.get_list
, return_value
=[])
1082 self
.my_ns
.RO
.create
= asynctest
.CoroutineMock(self
.my_ns
.RO
.create
, side_effect
=self
._ro
_create
())
1083 self
.my_ns
.RO
.show
= asynctest
.CoroutineMock(self
.my_ns
.RO
.show
, side_effect
=self
._ro
_show
())
1085 @asynctest.fail_on(active_handles
=True) # all async tasks must be completed
1086 async def test_instantiate(self
):
1087 nsr_id
= self
.db_content
["nsrs"][0]["_id"]
1088 nslcmop_id
= self
.db_content
["nslcmops"][0]["_id"]
1089 print("Test instantiate started")
1091 # delete deployed information of database
1092 if not getenv("OSMLCMTEST_DB_NOMOCK"):
1093 if self
.db_content
["nsrs"][0]["_admin"].get("deployed"):
1094 del self
.db_content
["nsrs"][0]["_admin"]["deployed"]
1095 for db_vnfr
in self
.db_content
["vnfrs"]:
1096 db_vnfr
.pop("ip_address", None)
1097 for db_vdur
in db_vnfr
["vdur"]:
1098 db_vdur
.pop("ip_address", None)
1099 db_vdur
.pop("mac_address", None)
1101 await self
.my_ns
.instantiate(nsr_id
, nslcmop_id
)
1103 print("instantiate_result: {}".format(self
._db
_get
_one
("nslcmops", {"_id": nslcmop_id
}).get("detailed-status")))
1105 self
.msg
.aiowrite
.assert_called_once_with("ns", "instantiated",
1106 {"nsr_id": nsr_id
, "nslcmop_id": nslcmop_id
,
1107 "operationState": "COMPLETED"},
1109 self
.lcm_tasks
.lock_HA
.assert_called_once_with('ns', 'nslcmops', nslcmop_id
)
1110 if not getenv("OSMLCMTEST_LOGGING_NOMOCK"):
1111 self
.assertTrue(self
.my_ns
.logger
.debug
.called
, "Debug method not called")
1112 self
.my_ns
.logger
.error
.assert_not_called()
1113 self
.my_ns
.logger
.exception().assert_not_called()
1115 if not getenv("OSMLCMTEST_DB_NOMOCK"):
1116 self
.assertTrue(self
.db
.set_one
.called
, "db.set_one not called")
1118 # TODO add more checks of called methods
1119 # TODO add a terminate
1121 @asynctest.fail_on(active_handles
=True) # all async tasks must be completed
1122 async def test_scale(self
):
1126 if __name__
== '__main__':