Reformat files according to new black validation
[osm/RO.git] / NG-RO / osm_ng_ro / tests / test_ns.py
1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
17
18 import unittest
19 from unittest.mock import MagicMock, Mock, patch
20
21 from jinja2 import (
22 Environment,
23 select_autoescape,
24 StrictUndefined,
25 TemplateError,
26 TemplateNotFound,
27 UndefinedError,
28 )
29 from osm_ng_ro.ns import Ns, NsException
30
31
32 __author__ = "Eduardo Sousa"
33 __date__ = "$19-NOV-2021 00:00:00$"
34
35
36 class TestNs(unittest.TestCase):
37 def setUp(self):
38 pass
39
40 def test__create_task_without_extra_dict(self):
41 expected_result = {
42 "target_id": "vim_openstack_1",
43 "action_id": "123456",
44 "nsr_id": "654321",
45 "task_id": "123456:1",
46 "status": "SCHEDULED",
47 "action": "CREATE",
48 "item": "test_item",
49 "target_record": "test_target_record",
50 "target_record_id": "test_target_record_id",
51 }
52 deployment_info = {
53 "action_id": "123456",
54 "nsr_id": "654321",
55 "task_index": 1,
56 }
57
58 task = Ns._create_task(
59 deployment_info=deployment_info,
60 target_id="vim_openstack_1",
61 item="test_item",
62 action="CREATE",
63 target_record="test_target_record",
64 target_record_id="test_target_record_id",
65 )
66
67 self.assertEqual(deployment_info.get("task_index"), 2)
68 self.assertDictEqual(task, expected_result)
69
70 def test__create_task(self):
71 expected_result = {
72 "target_id": "vim_openstack_1",
73 "action_id": "123456",
74 "nsr_id": "654321",
75 "task_id": "123456:1",
76 "status": "SCHEDULED",
77 "action": "CREATE",
78 "item": "test_item",
79 "target_record": "test_target_record",
80 "target_record_id": "test_target_record_id",
81 # values coming from extra_dict
82 "params": "test_params",
83 "find_params": "test_find_params",
84 "depends_on": "test_depends_on",
85 }
86 deployment_info = {
87 "action_id": "123456",
88 "nsr_id": "654321",
89 "task_index": 1,
90 }
91
92 task = Ns._create_task(
93 deployment_info=deployment_info,
94 target_id="vim_openstack_1",
95 item="test_item",
96 action="CREATE",
97 target_record="test_target_record",
98 target_record_id="test_target_record_id",
99 extra_dict={
100 "params": "test_params",
101 "find_params": "test_find_params",
102 "depends_on": "test_depends_on",
103 },
104 )
105
106 self.assertEqual(deployment_info.get("task_index"), 2)
107 self.assertDictEqual(task, expected_result)
108
109 @patch("osm_ng_ro.ns.time")
110 def test__create_ro_task(self, mock_time: Mock):
111 now = 1637324838.994551
112 mock_time.return_value = now
113 task = {
114 "target_id": "vim_openstack_1",
115 "action_id": "123456",
116 "nsr_id": "654321",
117 "task_id": "123456:1",
118 "status": "SCHEDULED",
119 "action": "CREATE",
120 "item": "test_item",
121 "target_record": "test_target_record",
122 "target_record_id": "test_target_record_id",
123 # values coming from extra_dict
124 "params": "test_params",
125 "find_params": "test_find_params",
126 "depends_on": "test_depends_on",
127 }
128 expected_result = {
129 "_id": "123456:1",
130 "locked_by": None,
131 "locked_at": 0.0,
132 "target_id": "vim_openstack_1",
133 "vim_info": {
134 "created": False,
135 "created_items": None,
136 "vim_id": None,
137 "vim_name": None,
138 "vim_status": None,
139 "vim_details": None,
140 "vim_message": None,
141 "refresh_at": None,
142 },
143 "modified_at": now,
144 "created_at": now,
145 "to_check_at": now,
146 "tasks": [task],
147 }
148
149 ro_task = Ns._create_ro_task(
150 target_id="vim_openstack_1",
151 task=task,
152 )
153
154 self.assertDictEqual(ro_task, expected_result)
155
156 def test__process_image_params_with_empty_target_image(self):
157 expected_result = {
158 "find_params": {},
159 }
160 target_image = {}
161
162 result = Ns._process_image_params(
163 target_image=target_image,
164 indata=None,
165 vim_info=None,
166 target_record_id=None,
167 )
168
169 self.assertDictEqual(expected_result, result)
170
171 def test__process_image_params_with_wrong_target_image(self):
172 expected_result = {
173 "find_params": {},
174 }
175 target_image = {
176 "no_image": "to_see_here",
177 }
178
179 result = Ns._process_image_params(
180 target_image=target_image,
181 indata=None,
182 vim_info=None,
183 target_record_id=None,
184 )
185
186 self.assertDictEqual(expected_result, result)
187
188 def test__process_image_params_with_image(self):
189 expected_result = {
190 "find_params": {
191 "filter_dict": {
192 "name": "cirros",
193 },
194 },
195 }
196 target_image = {
197 "image": "cirros",
198 }
199
200 result = Ns._process_image_params(
201 target_image=target_image,
202 indata=None,
203 vim_info=None,
204 target_record_id=None,
205 )
206
207 self.assertDictEqual(expected_result, result)
208
209 def test__process_image_params_with_vim_image_id(self):
210 expected_result = {
211 "find_params": {
212 "filter_dict": {
213 "id": "123456",
214 },
215 },
216 }
217 target_image = {
218 "vim_image_id": "123456",
219 }
220
221 result = Ns._process_image_params(
222 target_image=target_image,
223 indata=None,
224 vim_info=None,
225 target_record_id=None,
226 )
227
228 self.assertDictEqual(expected_result, result)
229
230 def test__process_image_params_with_image_checksum(self):
231 expected_result = {
232 "find_params": {
233 "filter_dict": {
234 "checksum": "e3fc50a88d0a364313df4b21ef20c29e",
235 },
236 },
237 }
238 target_image = {
239 "image_checksum": "e3fc50a88d0a364313df4b21ef20c29e",
240 }
241
242 result = Ns._process_image_params(
243 target_image=target_image,
244 indata=None,
245 vim_info=None,
246 target_record_id=None,
247 )
248
249 self.assertDictEqual(expected_result, result)
250
251 def test__get_resource_allocation_params_with_empty_target_image(self):
252 expected_result = {}
253 quota_descriptor = {}
254
255 result = Ns._get_resource_allocation_params(
256 quota_descriptor=quota_descriptor,
257 )
258
259 self.assertDictEqual(expected_result, result)
260
261 def test__get_resource_allocation_params_with_wrong_target_image(self):
262 expected_result = {}
263 quota_descriptor = {
264 "no_quota": "present_here",
265 }
266
267 result = Ns._get_resource_allocation_params(
268 quota_descriptor=quota_descriptor,
269 )
270
271 self.assertDictEqual(expected_result, result)
272
273 def test__get_resource_allocation_params_with_limit(self):
274 expected_result = {
275 "limit": 10,
276 }
277 quota_descriptor = {
278 "limit": "10",
279 }
280
281 result = Ns._get_resource_allocation_params(
282 quota_descriptor=quota_descriptor,
283 )
284
285 self.assertDictEqual(expected_result, result)
286
287 def test__get_resource_allocation_params_with_reserve(self):
288 expected_result = {
289 "reserve": 20,
290 }
291 quota_descriptor = {
292 "reserve": "20",
293 }
294
295 result = Ns._get_resource_allocation_params(
296 quota_descriptor=quota_descriptor,
297 )
298
299 self.assertDictEqual(expected_result, result)
300
301 def test__get_resource_allocation_params_with_shares(self):
302 expected_result = {
303 "shares": 30,
304 }
305 quota_descriptor = {
306 "shares": "30",
307 }
308
309 result = Ns._get_resource_allocation_params(
310 quota_descriptor=quota_descriptor,
311 )
312
313 self.assertDictEqual(expected_result, result)
314
315 def test__get_resource_allocation_params(self):
316 expected_result = {
317 "limit": 10,
318 "reserve": 20,
319 "shares": 30,
320 }
321 quota_descriptor = {
322 "limit": "10",
323 "reserve": "20",
324 "shares": "30",
325 }
326
327 result = Ns._get_resource_allocation_params(
328 quota_descriptor=quota_descriptor,
329 )
330
331 self.assertDictEqual(expected_result, result)
332
333 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
334 def test__process_guest_epa_quota_params_with_empty_quota_epa_cpu(
335 self,
336 resource_allocation,
337 ):
338 expected_result = {}
339 guest_epa_quota = {}
340 epa_vcpu_set = True
341
342 result = Ns._process_guest_epa_quota_params(
343 guest_epa_quota=guest_epa_quota,
344 epa_vcpu_set=epa_vcpu_set,
345 )
346
347 self.assertDictEqual(expected_result, result)
348 self.assertFalse(resource_allocation.called)
349
350 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
351 def test__process_guest_epa_quota_params_with_empty_quota_false_epa_cpu(
352 self,
353 resource_allocation,
354 ):
355 expected_result = {}
356 guest_epa_quota = {}
357 epa_vcpu_set = False
358
359 result = Ns._process_guest_epa_quota_params(
360 guest_epa_quota=guest_epa_quota,
361 epa_vcpu_set=epa_vcpu_set,
362 )
363
364 self.assertDictEqual(expected_result, result)
365 self.assertFalse(resource_allocation.called)
366
367 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
368 def test__process_guest_epa_quota_params_with_wrong_quota_epa_cpu(
369 self,
370 resource_allocation,
371 ):
372 expected_result = {}
373 guest_epa_quota = {
374 "no-quota": "nothing",
375 }
376 epa_vcpu_set = True
377
378 result = Ns._process_guest_epa_quota_params(
379 guest_epa_quota=guest_epa_quota,
380 epa_vcpu_set=epa_vcpu_set,
381 )
382
383 self.assertDictEqual(expected_result, result)
384 self.assertFalse(resource_allocation.called)
385
386 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
387 def test__process_guest_epa_quota_params_with_wrong_quota_false_epa_cpu(
388 self,
389 resource_allocation,
390 ):
391 expected_result = {}
392 guest_epa_quota = {
393 "no-quota": "nothing",
394 }
395 epa_vcpu_set = False
396
397 result = Ns._process_guest_epa_quota_params(
398 guest_epa_quota=guest_epa_quota,
399 epa_vcpu_set=epa_vcpu_set,
400 )
401
402 self.assertDictEqual(expected_result, result)
403 self.assertFalse(resource_allocation.called)
404
405 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
406 def test__process_guest_epa_quota_params_with_cpu_quota_epa_cpu(
407 self,
408 resource_allocation,
409 ):
410 expected_result = {}
411 guest_epa_quota = {
412 "cpu-quota": {
413 "limit": "10",
414 "reserve": "20",
415 "shares": "30",
416 },
417 }
418 epa_vcpu_set = True
419
420 result = Ns._process_guest_epa_quota_params(
421 guest_epa_quota=guest_epa_quota,
422 epa_vcpu_set=epa_vcpu_set,
423 )
424
425 self.assertDictEqual(expected_result, result)
426 self.assertFalse(resource_allocation.called)
427
428 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
429 def test__process_guest_epa_quota_params_with_cpu_quota_false_epa_cpu(
430 self,
431 resource_allocation,
432 ):
433 expected_result = {
434 "cpu-quota": {
435 "limit": 10,
436 "reserve": 20,
437 "shares": 30,
438 },
439 }
440 guest_epa_quota = {
441 "cpu-quota": {
442 "limit": "10",
443 "reserve": "20",
444 "shares": "30",
445 },
446 }
447 epa_vcpu_set = False
448
449 resource_allocation_param = {
450 "limit": "10",
451 "reserve": "20",
452 "shares": "30",
453 }
454 resource_allocation.return_value = {
455 "limit": 10,
456 "reserve": 20,
457 "shares": 30,
458 }
459
460 result = Ns._process_guest_epa_quota_params(
461 guest_epa_quota=guest_epa_quota,
462 epa_vcpu_set=epa_vcpu_set,
463 )
464
465 resource_allocation.assert_called_once_with(resource_allocation_param)
466 self.assertDictEqual(expected_result, result)
467
468 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
469 def test__process_guest_epa_quota_params_with_mem_quota_epa_cpu(
470 self,
471 resource_allocation,
472 ):
473 expected_result = {
474 "mem-quota": {
475 "limit": 10,
476 "reserve": 20,
477 "shares": 30,
478 },
479 }
480 guest_epa_quota = {
481 "mem-quota": {
482 "limit": "10",
483 "reserve": "20",
484 "shares": "30",
485 },
486 }
487 epa_vcpu_set = True
488
489 resource_allocation_param = {
490 "limit": "10",
491 "reserve": "20",
492 "shares": "30",
493 }
494 resource_allocation.return_value = {
495 "limit": 10,
496 "reserve": 20,
497 "shares": 30,
498 }
499
500 result = Ns._process_guest_epa_quota_params(
501 guest_epa_quota=guest_epa_quota,
502 epa_vcpu_set=epa_vcpu_set,
503 )
504
505 resource_allocation.assert_called_once_with(resource_allocation_param)
506 self.assertDictEqual(expected_result, result)
507
508 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
509 def test__process_guest_epa_quota_params_with_mem_quota_false_epa_cpu(
510 self,
511 resource_allocation,
512 ):
513 expected_result = {
514 "mem-quota": {
515 "limit": 10,
516 "reserve": 20,
517 "shares": 30,
518 },
519 }
520 guest_epa_quota = {
521 "mem-quota": {
522 "limit": "10",
523 "reserve": "20",
524 "shares": "30",
525 },
526 }
527 epa_vcpu_set = False
528
529 resource_allocation_param = {
530 "limit": "10",
531 "reserve": "20",
532 "shares": "30",
533 }
534 resource_allocation.return_value = {
535 "limit": 10,
536 "reserve": 20,
537 "shares": 30,
538 }
539
540 result = Ns._process_guest_epa_quota_params(
541 guest_epa_quota=guest_epa_quota,
542 epa_vcpu_set=epa_vcpu_set,
543 )
544
545 resource_allocation.assert_called_once_with(resource_allocation_param)
546 self.assertDictEqual(expected_result, result)
547
548 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
549 def test__process_guest_epa_quota_params_with_disk_io_quota_epa_cpu(
550 self,
551 resource_allocation,
552 ):
553 expected_result = {
554 "disk-io-quota": {
555 "limit": 10,
556 "reserve": 20,
557 "shares": 30,
558 },
559 }
560 guest_epa_quota = {
561 "disk-io-quota": {
562 "limit": "10",
563 "reserve": "20",
564 "shares": "30",
565 },
566 }
567 epa_vcpu_set = True
568
569 resource_allocation_param = {
570 "limit": "10",
571 "reserve": "20",
572 "shares": "30",
573 }
574 resource_allocation.return_value = {
575 "limit": 10,
576 "reserve": 20,
577 "shares": 30,
578 }
579
580 result = Ns._process_guest_epa_quota_params(
581 guest_epa_quota=guest_epa_quota,
582 epa_vcpu_set=epa_vcpu_set,
583 )
584
585 resource_allocation.assert_called_once_with(resource_allocation_param)
586 self.assertDictEqual(expected_result, result)
587
588 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
589 def test__process_guest_epa_quota_params_with_disk_io_quota_false_epa_cpu(
590 self,
591 resource_allocation,
592 ):
593 expected_result = {
594 "disk-io-quota": {
595 "limit": 10,
596 "reserve": 20,
597 "shares": 30,
598 },
599 }
600 guest_epa_quota = {
601 "disk-io-quota": {
602 "limit": "10",
603 "reserve": "20",
604 "shares": "30",
605 },
606 }
607 epa_vcpu_set = False
608
609 resource_allocation_param = {
610 "limit": "10",
611 "reserve": "20",
612 "shares": "30",
613 }
614 resource_allocation.return_value = {
615 "limit": 10,
616 "reserve": 20,
617 "shares": 30,
618 }
619
620 result = Ns._process_guest_epa_quota_params(
621 guest_epa_quota=guest_epa_quota,
622 epa_vcpu_set=epa_vcpu_set,
623 )
624
625 resource_allocation.assert_called_once_with(resource_allocation_param)
626 self.assertDictEqual(expected_result, result)
627
628 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
629 def test__process_guest_epa_quota_params_with_vif_quota_epa_cpu(
630 self,
631 resource_allocation,
632 ):
633 expected_result = {
634 "vif-quota": {
635 "limit": 10,
636 "reserve": 20,
637 "shares": 30,
638 },
639 }
640 guest_epa_quota = {
641 "vif-quota": {
642 "limit": "10",
643 "reserve": "20",
644 "shares": "30",
645 },
646 }
647 epa_vcpu_set = True
648
649 resource_allocation_param = {
650 "limit": "10",
651 "reserve": "20",
652 "shares": "30",
653 }
654 resource_allocation.return_value = {
655 "limit": 10,
656 "reserve": 20,
657 "shares": 30,
658 }
659
660 result = Ns._process_guest_epa_quota_params(
661 guest_epa_quota=guest_epa_quota,
662 epa_vcpu_set=epa_vcpu_set,
663 )
664
665 resource_allocation.assert_called_once_with(resource_allocation_param)
666 self.assertDictEqual(expected_result, result)
667
668 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
669 def test__process_guest_epa_quota_params_with_vif_quota_false_epa_cpu(
670 self,
671 resource_allocation,
672 ):
673 expected_result = {
674 "vif-quota": {
675 "limit": 10,
676 "reserve": 20,
677 "shares": 30,
678 },
679 }
680 guest_epa_quota = {
681 "vif-quota": {
682 "limit": "10",
683 "reserve": "20",
684 "shares": "30",
685 },
686 }
687 epa_vcpu_set = False
688
689 resource_allocation_param = {
690 "limit": "10",
691 "reserve": "20",
692 "shares": "30",
693 }
694 resource_allocation.return_value = {
695 "limit": 10,
696 "reserve": 20,
697 "shares": 30,
698 }
699
700 result = Ns._process_guest_epa_quota_params(
701 guest_epa_quota=guest_epa_quota,
702 epa_vcpu_set=epa_vcpu_set,
703 )
704
705 resource_allocation.assert_called_once_with(resource_allocation_param)
706 self.assertDictEqual(expected_result, result)
707
708 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
709 def test__process_guest_epa_quota_params_with_quota_epa_cpu(
710 self,
711 resource_allocation,
712 ):
713 expected_result = {
714 "mem-quota": {
715 "limit": 10,
716 "reserve": 20,
717 "shares": 30,
718 },
719 "disk-io-quota": {
720 "limit": 10,
721 "reserve": 20,
722 "shares": 30,
723 },
724 "vif-quota": {
725 "limit": 10,
726 "reserve": 20,
727 "shares": 30,
728 },
729 }
730 guest_epa_quota = {
731 "cpu-quota": {
732 "limit": "10",
733 "reserve": "20",
734 "shares": "30",
735 },
736 "mem-quota": {
737 "limit": "10",
738 "reserve": "20",
739 "shares": "30",
740 },
741 "disk-io-quota": {
742 "limit": "10",
743 "reserve": "20",
744 "shares": "30",
745 },
746 "vif-quota": {
747 "limit": "10",
748 "reserve": "20",
749 "shares": "30",
750 },
751 }
752 epa_vcpu_set = True
753
754 resource_allocation.return_value = {
755 "limit": 10,
756 "reserve": 20,
757 "shares": 30,
758 }
759
760 result = Ns._process_guest_epa_quota_params(
761 guest_epa_quota=guest_epa_quota,
762 epa_vcpu_set=epa_vcpu_set,
763 )
764
765 self.assertTrue(resource_allocation.called)
766 self.assertDictEqual(expected_result, result)
767
768 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
769 def test__process_guest_epa_quota_params_with_quota_epa_cpu_no_set(
770 self,
771 resource_allocation,
772 ):
773 expected_result = {
774 "cpu-quota": {
775 "limit": 10,
776 "reserve": 20,
777 "shares": 30,
778 },
779 "mem-quota": {
780 "limit": 10,
781 "reserve": 20,
782 "shares": 30,
783 },
784 "disk-io-quota": {
785 "limit": 10,
786 "reserve": 20,
787 "shares": 30,
788 },
789 "vif-quota": {
790 "limit": 10,
791 "reserve": 20,
792 "shares": 30,
793 },
794 }
795 guest_epa_quota = {
796 "cpu-quota": {
797 "limit": "10",
798 "reserve": "20",
799 "shares": "30",
800 },
801 "mem-quota": {
802 "limit": "10",
803 "reserve": "20",
804 "shares": "30",
805 },
806 "disk-io-quota": {
807 "limit": "10",
808 "reserve": "20",
809 "shares": "30",
810 },
811 "vif-quota": {
812 "limit": "10",
813 "reserve": "20",
814 "shares": "30",
815 },
816 }
817 epa_vcpu_set = False
818
819 resource_allocation.return_value = {
820 "limit": 10,
821 "reserve": 20,
822 "shares": 30,
823 }
824
825 result = Ns._process_guest_epa_quota_params(
826 guest_epa_quota=guest_epa_quota,
827 epa_vcpu_set=epa_vcpu_set,
828 )
829
830 self.assertTrue(resource_allocation.called)
831 self.assertDictEqual(expected_result, result)
832
833 def test__process_guest_epa_numa_params_with_empty_numa_params(self):
834 expected_numa_result = []
835 expected_epa_vcpu_set_result = False
836 guest_epa_quota = {}
837
838 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
839 guest_epa_quota=guest_epa_quota,
840 )
841 self.assertEqual(expected_numa_result, numa_result)
842 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
843
844 def test__process_guest_epa_numa_params_with_wrong_numa_params(self):
845 expected_numa_result = []
846 expected_epa_vcpu_set_result = False
847 guest_epa_quota = {"no_nume": "here"}
848
849 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
850 guest_epa_quota=guest_epa_quota,
851 )
852
853 self.assertEqual(expected_numa_result, numa_result)
854 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
855
856 def test__process_guest_epa_numa_params_with_numa_node_policy(self):
857 expected_numa_result = []
858 expected_epa_vcpu_set_result = False
859 guest_epa_quota = {"numa-node-policy": {}}
860
861 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
862 guest_epa_quota=guest_epa_quota,
863 )
864
865 self.assertEqual(expected_numa_result, numa_result)
866 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
867
868 def test__process_guest_epa_numa_params_with_no_node(self):
869 expected_numa_result = []
870 expected_epa_vcpu_set_result = False
871 guest_epa_quota = {
872 "numa-node-policy": {
873 "node": [],
874 },
875 }
876
877 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
878 guest_epa_quota=guest_epa_quota,
879 )
880
881 self.assertEqual(expected_numa_result, numa_result)
882 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
883
884 def test__process_guest_epa_numa_params_with_1_node_num_cores(self):
885 expected_numa_result = [{"cores": 3}]
886 expected_epa_vcpu_set_result = True
887 guest_epa_quota = {
888 "numa-node-policy": {
889 "node": [
890 {
891 "num-cores": 3,
892 },
893 ],
894 },
895 }
896
897 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
898 guest_epa_quota=guest_epa_quota,
899 )
900
901 self.assertEqual(expected_numa_result, numa_result)
902 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
903
904 def test__process_guest_epa_numa_params_with_1_node_paired_threads(self):
905 expected_numa_result = [{"paired_threads": 3}]
906 expected_epa_vcpu_set_result = True
907 guest_epa_quota = {
908 "numa-node-policy": {
909 "node": [
910 {
911 "paired-threads": {"num-paired-threads": "3"},
912 },
913 ],
914 },
915 }
916
917 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
918 guest_epa_quota=guest_epa_quota,
919 )
920
921 self.assertEqual(expected_numa_result, numa_result)
922 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
923
924 def test__process_guest_epa_numa_params_with_1_node_paired_threads_ids(self):
925 expected_numa_result = [
926 {
927 "paired-threads-id": [("0", "1"), ("4", "5")],
928 }
929 ]
930 expected_epa_vcpu_set_result = False
931 guest_epa_quota = {
932 "numa-node-policy": {
933 "node": [
934 {
935 "paired-threads": {
936 "paired-thread-ids": [
937 {
938 "thread-a": 0,
939 "thread-b": 1,
940 },
941 {
942 "thread-a": 4,
943 "thread-b": 5,
944 },
945 ],
946 },
947 },
948 ],
949 },
950 }
951
952 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
953 guest_epa_quota=guest_epa_quota,
954 )
955
956 self.assertEqual(expected_numa_result, numa_result)
957 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
958
959 def test__process_guest_epa_numa_params_with_1_node_num_threads(self):
960 expected_numa_result = [{"threads": 3}]
961 expected_epa_vcpu_set_result = True
962 guest_epa_quota = {
963 "numa-node-policy": {
964 "node": [
965 {
966 "num-threads": "3",
967 },
968 ],
969 },
970 }
971
972 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
973 guest_epa_quota=guest_epa_quota,
974 )
975
976 self.assertEqual(expected_numa_result, numa_result)
977 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
978
979 def test__process_guest_epa_numa_params_with_1_node_memory_mb(self):
980 expected_numa_result = [{"memory": 2}]
981 expected_epa_vcpu_set_result = False
982 guest_epa_quota = {
983 "numa-node-policy": {
984 "node": [
985 {
986 "memory-mb": 2048,
987 },
988 ],
989 },
990 }
991
992 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
993 guest_epa_quota=guest_epa_quota,
994 )
995
996 self.assertEqual(expected_numa_result, numa_result)
997 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
998
999 def test__process_guest_epa_numa_params_with_1_node_vcpu(self):
1000 expected_numa_result = [
1001 {
1002 "id": 0,
1003 "vcpu": [0, 1],
1004 }
1005 ]
1006 expected_epa_vcpu_set_result = False
1007 guest_epa_quota = {
1008 "numa-node-policy": {
1009 "node": [{"id": "0", "vcpu": [{"id": "0"}, {"id": "1"}]}],
1010 },
1011 }
1012
1013 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
1014 guest_epa_quota=guest_epa_quota,
1015 )
1016
1017 self.assertEqual(expected_numa_result, numa_result)
1018 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1019
1020 def test__process_guest_epa_numa_params_with_2_node_vcpu(self):
1021 expected_numa_result = [
1022 {
1023 "id": 0,
1024 "vcpu": [0, 1],
1025 },
1026 {
1027 "id": 1,
1028 "vcpu": [2, 3],
1029 },
1030 ]
1031
1032 expected_epa_vcpu_set_result = False
1033 guest_epa_quota = {
1034 "numa-node-policy": {
1035 "node": [
1036 {"id": "0", "vcpu": [{"id": "0"}, {"id": "1"}]},
1037 {"id": "1", "vcpu": [{"id": "2"}, {"id": "3"}]},
1038 ],
1039 },
1040 }
1041
1042 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
1043 guest_epa_quota=guest_epa_quota,
1044 )
1045
1046 self.assertEqual(expected_numa_result, numa_result)
1047 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1048
1049 def test__process_guest_epa_numa_params_with_1_node(self):
1050 expected_numa_result = [
1051 {
1052 # "id": 0,
1053 # "vcpu": [0, 1],
1054 "cores": 3,
1055 "paired_threads": 3,
1056 "paired-threads-id": [("0", "1"), ("4", "5")],
1057 "threads": 3,
1058 "memory": 2,
1059 }
1060 ]
1061 expected_epa_vcpu_set_result = True
1062 guest_epa_quota = {
1063 "numa-node-policy": {
1064 "node": [
1065 {
1066 "num-cores": 3,
1067 "paired-threads": {
1068 "num-paired-threads": "3",
1069 "paired-thread-ids": [
1070 {
1071 "thread-a": 0,
1072 "thread-b": 1,
1073 },
1074 {
1075 "thread-a": 4,
1076 "thread-b": 5,
1077 },
1078 ],
1079 },
1080 "num-threads": "3",
1081 "memory-mb": 2048,
1082 },
1083 ],
1084 },
1085 }
1086
1087 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
1088 guest_epa_quota=guest_epa_quota,
1089 )
1090
1091 self.assertEqual(expected_numa_result, numa_result)
1092 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1093
1094 def test__process_guest_epa_numa_params_with_2_nodes(self):
1095 expected_numa_result = [
1096 {
1097 "cores": 3,
1098 "paired_threads": 3,
1099 "paired-threads-id": [("0", "1"), ("4", "5")],
1100 "threads": 3,
1101 "memory": 2,
1102 },
1103 {
1104 "cores": 7,
1105 "paired_threads": 7,
1106 "paired-threads-id": [("2", "3"), ("5", "6")],
1107 "threads": 4,
1108 "memory": 4,
1109 },
1110 ]
1111 expected_epa_vcpu_set_result = True
1112 guest_epa_quota = {
1113 "numa-node-policy": {
1114 "node": [
1115 {
1116 "num-cores": 3,
1117 "paired-threads": {
1118 "num-paired-threads": "3",
1119 "paired-thread-ids": [
1120 {
1121 "thread-a": 0,
1122 "thread-b": 1,
1123 },
1124 {
1125 "thread-a": 4,
1126 "thread-b": 5,
1127 },
1128 ],
1129 },
1130 "num-threads": "3",
1131 "memory-mb": 2048,
1132 },
1133 {
1134 "num-cores": 7,
1135 "paired-threads": {
1136 "num-paired-threads": "7",
1137 "paired-thread-ids": [
1138 {
1139 "thread-a": 2,
1140 "thread-b": 3,
1141 },
1142 {
1143 "thread-a": 5,
1144 "thread-b": 6,
1145 },
1146 ],
1147 },
1148 "num-threads": "4",
1149 "memory-mb": 4096,
1150 },
1151 ],
1152 },
1153 }
1154
1155 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
1156 guest_epa_quota=guest_epa_quota,
1157 )
1158
1159 self.assertEqual(expected_numa_result, numa_result)
1160 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1161
1162 def test__process_guest_epa_cpu_pinning_params_with_empty_params(self):
1163 expected_numa_result = {}
1164 expected_epa_vcpu_set_result = False
1165 guest_epa_quota = {}
1166 vcpu_count = 0
1167 epa_vcpu_set = False
1168
1169 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params(
1170 guest_epa_quota=guest_epa_quota,
1171 vcpu_count=vcpu_count,
1172 epa_vcpu_set=epa_vcpu_set,
1173 )
1174
1175 self.assertDictEqual(expected_numa_result, numa_result)
1176 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1177
1178 def test__process_guest_epa_cpu_pinning_params_with_wrong_params(self):
1179 expected_numa_result = {}
1180 expected_epa_vcpu_set_result = False
1181 guest_epa_quota = {
1182 "no-cpu-pinning-policy": "here",
1183 }
1184 vcpu_count = 0
1185 epa_vcpu_set = False
1186
1187 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params(
1188 guest_epa_quota=guest_epa_quota,
1189 vcpu_count=vcpu_count,
1190 epa_vcpu_set=epa_vcpu_set,
1191 )
1192
1193 self.assertDictEqual(expected_numa_result, numa_result)
1194 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1195
1196 def test__process_guest_epa_cpu_pinning_params_with_epa_vcpu_set(self):
1197 expected_numa_result = {}
1198 expected_epa_vcpu_set_result = True
1199 guest_epa_quota = {
1200 "cpu-pinning-policy": "DEDICATED",
1201 }
1202 vcpu_count = 0
1203 epa_vcpu_set = True
1204
1205 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params(
1206 guest_epa_quota=guest_epa_quota,
1207 vcpu_count=vcpu_count,
1208 epa_vcpu_set=epa_vcpu_set,
1209 )
1210
1211 self.assertDictEqual(expected_numa_result, numa_result)
1212 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1213
1214 def test__process_guest_epa_cpu_pinning_params_with_threads(self):
1215 expected_numa_result = {"threads": 3}
1216 expected_epa_vcpu_set_result = True
1217 guest_epa_quota = {
1218 "cpu-pinning-policy": "DEDICATED",
1219 "cpu-thread-pinning-policy": "PREFER",
1220 }
1221 vcpu_count = 3
1222 epa_vcpu_set = False
1223
1224 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params(
1225 guest_epa_quota=guest_epa_quota,
1226 vcpu_count=vcpu_count,
1227 epa_vcpu_set=epa_vcpu_set,
1228 )
1229
1230 self.assertDictEqual(expected_numa_result, numa_result)
1231 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1232
1233 def test__process_guest_epa_cpu_pinning_params(self):
1234 expected_numa_result = {"cores": 3}
1235 expected_epa_vcpu_set_result = True
1236 guest_epa_quota = {
1237 "cpu-pinning-policy": "DEDICATED",
1238 }
1239 vcpu_count = 3
1240 epa_vcpu_set = False
1241
1242 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params(
1243 guest_epa_quota=guest_epa_quota,
1244 vcpu_count=vcpu_count,
1245 epa_vcpu_set=epa_vcpu_set,
1246 )
1247
1248 self.assertDictEqual(expected_numa_result, numa_result)
1249 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1250
1251 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1252 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1253 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1254 def test__process_guest_epa_params_with_empty_params(
1255 self,
1256 guest_epa_numa_params,
1257 guest_epa_cpu_pinning_params,
1258 guest_epa_quota_params,
1259 ):
1260 expected_result = {}
1261 target_flavor = {}
1262
1263 result = Ns._process_epa_params(
1264 target_flavor=target_flavor,
1265 )
1266
1267 self.assertDictEqual(expected_result, result)
1268 self.assertFalse(guest_epa_numa_params.called)
1269 self.assertFalse(guest_epa_cpu_pinning_params.called)
1270 self.assertFalse(guest_epa_quota_params.called)
1271
1272 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1273 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1274 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1275 def test__process_guest_epa_params_with_wrong_params(
1276 self,
1277 guest_epa_numa_params,
1278 guest_epa_cpu_pinning_params,
1279 guest_epa_quota_params,
1280 ):
1281 expected_result = {}
1282 target_flavor = {
1283 "no-guest-epa": "here",
1284 }
1285
1286 result = Ns._process_epa_params(
1287 target_flavor=target_flavor,
1288 )
1289
1290 self.assertDictEqual(expected_result, result)
1291 self.assertFalse(guest_epa_numa_params.called)
1292 self.assertFalse(guest_epa_cpu_pinning_params.called)
1293 self.assertFalse(guest_epa_quota_params.called)
1294
1295 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1296 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1297 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1298 def test__process_guest_epa_params(
1299 self,
1300 guest_epa_numa_params,
1301 guest_epa_cpu_pinning_params,
1302 guest_epa_quota_params,
1303 ):
1304 expected_result = {
1305 "mem-policy": "STRICT",
1306 }
1307 target_flavor = {
1308 "guest-epa": {
1309 "vcpu-count": 1,
1310 "numa-node-policy": {
1311 "mem-policy": "STRICT",
1312 },
1313 },
1314 }
1315
1316 guest_epa_numa_params.return_value = ({}, False)
1317 guest_epa_cpu_pinning_params.return_value = ({}, False)
1318 guest_epa_quota_params.return_value = {}
1319
1320 result = Ns._process_epa_params(
1321 target_flavor=target_flavor,
1322 )
1323
1324 self.assertDictEqual(expected_result, result)
1325 self.assertTrue(guest_epa_numa_params.called)
1326 self.assertTrue(guest_epa_cpu_pinning_params.called)
1327 self.assertTrue(guest_epa_quota_params.called)
1328
1329 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1330 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1331 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1332 def test__process_guest_epa_params_with_mempage_size(
1333 self,
1334 guest_epa_numa_params,
1335 guest_epa_cpu_pinning_params,
1336 guest_epa_quota_params,
1337 ):
1338 expected_result = {
1339 "mempage-size": "1G",
1340 "mem-policy": "STRICT",
1341 }
1342 target_flavor = {
1343 "guest-epa": {
1344 "vcpu-count": 1,
1345 "mempage-size": "1G",
1346 "numa-node-policy": {
1347 "mem-policy": "STRICT",
1348 },
1349 },
1350 }
1351
1352 guest_epa_numa_params.return_value = ({}, False)
1353 guest_epa_cpu_pinning_params.return_value = ({}, False)
1354 guest_epa_quota_params.return_value = {}
1355
1356 result = Ns._process_epa_params(
1357 target_flavor=target_flavor,
1358 )
1359
1360 self.assertDictEqual(expected_result, result)
1361 self.assertTrue(guest_epa_numa_params.called)
1362 self.assertTrue(guest_epa_cpu_pinning_params.called)
1363 self.assertTrue(guest_epa_quota_params.called)
1364
1365 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1366 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1367 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1368 def test__process_guest_epa_params_with_numa(
1369 self,
1370 guest_epa_numa_params,
1371 guest_epa_cpu_pinning_params,
1372 guest_epa_quota_params,
1373 ):
1374 expected_result = {
1375 "mempage-size": "1G",
1376 "cpu-pinning-policy": "DEDICATED",
1377 "cpu-thread-pinning-policy": "PREFER",
1378 "numas": [
1379 {
1380 "cores": 3,
1381 "memory": 2,
1382 "paired-threads": 3,
1383 "paired-threads-id": [("0", "1"), ("4", "5")],
1384 "threads": 3,
1385 }
1386 ],
1387 "cpu-quota": {"limit": 10, "reserve": 20, "shares": 30},
1388 "disk-io-quota": {"limit": 10, "reserve": 20, "shares": 30},
1389 "mem-quota": {"limit": 10, "reserve": 20, "shares": 30},
1390 "vif-quota": {"limit": 10, "reserve": 20, "shares": 30},
1391 }
1392 target_flavor = {
1393 "guest-epa": {
1394 "vcpu-count": 1,
1395 "mempage-size": "1G",
1396 "cpu-pinning-policy": "DEDICATED",
1397 "cpu-thread-pinning-policy": "PREFER",
1398 "numa-node-policy": {
1399 "node": [
1400 {
1401 "num-cores": 3,
1402 "paired-threads": {
1403 "num-paired-threads": "3",
1404 "paired-thread-ids": [
1405 {
1406 "thread-a": 0,
1407 "thread-b": 1,
1408 },
1409 {
1410 "thread-a": 4,
1411 "thread-b": 5,
1412 },
1413 ],
1414 },
1415 "num-threads": "3",
1416 "memory-mb": 2048,
1417 },
1418 ],
1419 },
1420 "cpu-quota": {
1421 "limit": "10",
1422 "reserve": "20",
1423 "shares": "30",
1424 },
1425 "mem-quota": {
1426 "limit": "10",
1427 "reserve": "20",
1428 "shares": "30",
1429 },
1430 "disk-io-quota": {
1431 "limit": "10",
1432 "reserve": "20",
1433 "shares": "30",
1434 },
1435 "vif-quota": {
1436 "limit": "10",
1437 "reserve": "20",
1438 "shares": "30",
1439 },
1440 },
1441 }
1442
1443 guest_epa_numa_params.return_value = (
1444 [
1445 {
1446 "cores": 3,
1447 "paired-threads": 3,
1448 "paired-threads-id": [("0", "1"), ("4", "5")],
1449 "threads": 3,
1450 "memory": 2,
1451 },
1452 ],
1453 True,
1454 )
1455 guest_epa_cpu_pinning_params.return_value = (
1456 {
1457 "threads": 3,
1458 },
1459 True,
1460 )
1461 guest_epa_quota_params.return_value = {
1462 "cpu-quota": {
1463 "limit": 10,
1464 "reserve": 20,
1465 "shares": 30,
1466 },
1467 "mem-quota": {
1468 "limit": 10,
1469 "reserve": 20,
1470 "shares": 30,
1471 },
1472 "disk-io-quota": {
1473 "limit": 10,
1474 "reserve": 20,
1475 "shares": 30,
1476 },
1477 "vif-quota": {
1478 "limit": 10,
1479 "reserve": 20,
1480 "shares": 30,
1481 },
1482 }
1483
1484 result = Ns._process_epa_params(
1485 target_flavor=target_flavor,
1486 )
1487 self.assertEqual(expected_result, result)
1488 self.assertTrue(guest_epa_numa_params.called)
1489 self.assertTrue(guest_epa_cpu_pinning_params.called)
1490 self.assertTrue(guest_epa_quota_params.called)
1491
1492 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1493 def test__process_flavor_params_with_empty_target_flavor(
1494 self,
1495 epa_params,
1496 ):
1497 target_flavor = {}
1498 indata = {
1499 "vnf": [
1500 {
1501 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1502 },
1503 ],
1504 }
1505 vim_info = {}
1506 target_record_id = ""
1507
1508 with self.assertRaises(KeyError):
1509 Ns._process_flavor_params(
1510 target_flavor=target_flavor,
1511 indata=indata,
1512 vim_info=vim_info,
1513 target_record_id=target_record_id,
1514 )
1515
1516 self.assertFalse(epa_params.called)
1517
1518 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1519 def test__process_flavor_params_with_wrong_target_flavor(
1520 self,
1521 epa_params,
1522 ):
1523 target_flavor = {
1524 "no-target-flavor": "here",
1525 }
1526 indata = {}
1527 vim_info = {}
1528 target_record_id = ""
1529
1530 with self.assertRaises(KeyError):
1531 Ns._process_flavor_params(
1532 target_flavor=target_flavor,
1533 indata=indata,
1534 vim_info=vim_info,
1535 target_record_id=target_record_id,
1536 )
1537
1538 self.assertFalse(epa_params.called)
1539
1540 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1541 def test__process_flavor_params_with_empty_indata(
1542 self,
1543 epa_params,
1544 ):
1545 expected_result = {
1546 "find_params": {
1547 "flavor_data": {
1548 "disk": 10,
1549 "ram": 1024,
1550 "vcpus": 2,
1551 },
1552 },
1553 "params": {
1554 "flavor_data": {
1555 "disk": 10,
1556 "name": "test",
1557 "ram": 1024,
1558 "vcpus": 2,
1559 },
1560 },
1561 }
1562 target_flavor = {
1563 "name": "test",
1564 "storage-gb": "10",
1565 "memory-mb": "1024",
1566 "vcpu-count": "2",
1567 }
1568 indata = {}
1569 vim_info = {}
1570 target_record_id = ""
1571
1572 epa_params.return_value = {}
1573
1574 result = Ns._process_flavor_params(
1575 target_flavor=target_flavor,
1576 indata=indata,
1577 vim_info=vim_info,
1578 target_record_id=target_record_id,
1579 )
1580
1581 self.assertTrue(epa_params.called)
1582 self.assertDictEqual(result, expected_result)
1583
1584 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1585 def test__process_flavor_params_with_wrong_indata(
1586 self,
1587 epa_params,
1588 ):
1589 expected_result = {
1590 "find_params": {
1591 "flavor_data": {
1592 "disk": 10,
1593 "ram": 1024,
1594 "vcpus": 2,
1595 },
1596 },
1597 "params": {
1598 "flavor_data": {
1599 "disk": 10,
1600 "name": "test",
1601 "ram": 1024,
1602 "vcpus": 2,
1603 },
1604 },
1605 }
1606 target_flavor = {
1607 "name": "test",
1608 "storage-gb": "10",
1609 "memory-mb": "1024",
1610 "vcpu-count": "2",
1611 }
1612 indata = {
1613 "no-vnf": "here",
1614 }
1615 vim_info = {}
1616 target_record_id = ""
1617
1618 epa_params.return_value = {}
1619
1620 result = Ns._process_flavor_params(
1621 target_flavor=target_flavor,
1622 indata=indata,
1623 vim_info=vim_info,
1624 target_record_id=target_record_id,
1625 )
1626
1627 self.assertTrue(epa_params.called)
1628 self.assertDictEqual(result, expected_result)
1629
1630 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1631 def test__process_flavor_params_with_ephemeral_disk(
1632 self,
1633 epa_params,
1634 ):
1635 db = MagicMock(name="database mock")
1636 kwargs = {
1637 "db": db,
1638 }
1639
1640 db.get_one.return_value = {
1641 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1642 "df": [
1643 {
1644 "id": "default-df",
1645 "vdu-profile": [
1646 {"id": "without_volumes-VM", "min-number-of-instances": 1}
1647 ],
1648 }
1649 ],
1650 "id": "without_volumes-vnf",
1651 "product-name": "without_volumes-vnf",
1652 "vdu": [
1653 {
1654 "id": "without_volumes-VM",
1655 "name": "without_volumes-VM",
1656 "sw-image-desc": "ubuntu20.04",
1657 "alternative-sw-image-desc": [
1658 "ubuntu20.04-aws",
1659 "ubuntu20.04-azure",
1660 ],
1661 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
1662 }
1663 ],
1664 "version": "1.0",
1665 "virtual-storage-desc": [
1666 {"id": "root-volume", "size-of-storage": "10"},
1667 {
1668 "id": "ephemeral-volume",
1669 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1670 "size-of-storage": "1",
1671 },
1672 ],
1673 "_admin": {
1674 "storage": {
1675 "fs": "mongo",
1676 "path": "/app/storage/",
1677 },
1678 "type": "vnfd",
1679 },
1680 }
1681 expected_result = {
1682 "find_params": {
1683 "flavor_data": {
1684 "disk": 10,
1685 "ram": 1024,
1686 "vcpus": 2,
1687 "ephemeral": 10,
1688 },
1689 },
1690 "params": {
1691 "flavor_data": {
1692 "disk": 10,
1693 "name": "test",
1694 "ram": 1024,
1695 "vcpus": 2,
1696 "ephemeral": 10,
1697 },
1698 },
1699 }
1700 target_flavor = {
1701 "id": "test_id",
1702 "name": "test",
1703 "storage-gb": "10",
1704 "memory-mb": "1024",
1705 "vcpu-count": "2",
1706 }
1707 indata = {
1708 "vnf": [
1709 {
1710 "vdur": [
1711 {
1712 "ns-flavor-id": "test_id",
1713 "virtual-storages": [
1714 {
1715 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1716 "size-of-storage": "10",
1717 },
1718 ],
1719 },
1720 ],
1721 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1722 },
1723 ],
1724 }
1725 vim_info = {}
1726 target_record_id = ""
1727
1728 epa_params.return_value = {}
1729
1730 result = Ns._process_flavor_params(
1731 target_flavor=target_flavor,
1732 indata=indata,
1733 vim_info=vim_info,
1734 target_record_id=target_record_id,
1735 **kwargs,
1736 )
1737
1738 self.assertTrue(epa_params.called)
1739 self.assertDictEqual(result, expected_result)
1740
1741 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1742 def test__process_flavor_params_with_swap_disk(
1743 self,
1744 epa_params,
1745 ):
1746 expected_result = {
1747 "find_params": {
1748 "flavor_data": {
1749 "disk": 10,
1750 "ram": 1024,
1751 "vcpus": 2,
1752 "swap": 20,
1753 },
1754 },
1755 "params": {
1756 "flavor_data": {
1757 "disk": 10,
1758 "name": "test",
1759 "ram": 1024,
1760 "vcpus": 2,
1761 "swap": 20,
1762 },
1763 },
1764 }
1765 target_flavor = {
1766 "id": "test_id",
1767 "name": "test",
1768 "storage-gb": "10",
1769 "memory-mb": "1024",
1770 "vcpu-count": "2",
1771 }
1772 indata = {
1773 "vnf": [
1774 {
1775 "vdur": [
1776 {
1777 "ns-flavor-id": "test_id",
1778 "virtual-storages": [
1779 {
1780 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
1781 "size-of-storage": "20",
1782 },
1783 ],
1784 },
1785 ],
1786 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1787 },
1788 ],
1789 }
1790 vim_info = {}
1791 target_record_id = ""
1792
1793 epa_params.return_value = {}
1794
1795 result = Ns._process_flavor_params(
1796 target_flavor=target_flavor,
1797 indata=indata,
1798 vim_info=vim_info,
1799 target_record_id=target_record_id,
1800 )
1801
1802 self.assertTrue(epa_params.called)
1803 self.assertDictEqual(result, expected_result)
1804
1805 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1806 def test__process_flavor_params_with_persistent_root_disk(
1807 self,
1808 epa_params,
1809 ):
1810 db = MagicMock(name="database mock")
1811
1812 kwargs = {
1813 "db": db,
1814 }
1815
1816 db.get_one.return_value = {
1817 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1818 "df": [
1819 {
1820 "id": "default-df",
1821 "vdu-profile": [
1822 {"id": "several_volumes-VM", "min-number-of-instances": 1}
1823 ],
1824 }
1825 ],
1826 "id": "several_volumes-vnf",
1827 "product-name": "several_volumes-vnf",
1828 "vdu": [
1829 {
1830 "id": "several_volumes-VM",
1831 "name": "several_volumes-VM",
1832 "sw-image-desc": "ubuntu20.04",
1833 "alternative-sw-image-desc": [
1834 "ubuntu20.04-aws",
1835 "ubuntu20.04-azure",
1836 ],
1837 "virtual-storage-desc": [
1838 "persistent-root-volume",
1839 ],
1840 }
1841 ],
1842 "version": "1.0",
1843 "virtual-storage-desc": [
1844 {
1845 "id": "persistent-root-volume",
1846 "type-of-storage": "persistent-storage:persistent-storage",
1847 "size-of-storage": "10",
1848 },
1849 ],
1850 "_admin": {
1851 "storage": {
1852 "fs": "mongo",
1853 "path": "/app/storage/",
1854 },
1855 "type": "vnfd",
1856 },
1857 }
1858 expected_result = {
1859 "find_params": {
1860 "flavor_data": {
1861 "disk": 0,
1862 "ram": 1024,
1863 "vcpus": 2,
1864 },
1865 },
1866 "params": {
1867 "flavor_data": {
1868 "disk": 0,
1869 "name": "test",
1870 "ram": 1024,
1871 "vcpus": 2,
1872 },
1873 },
1874 }
1875 target_flavor = {
1876 "id": "test_id",
1877 "name": "test",
1878 "storage-gb": "10",
1879 "memory-mb": "1024",
1880 "vcpu-count": "2",
1881 }
1882 indata = {
1883 "vnf": [
1884 {
1885 "vdur": [
1886 {
1887 "vdu-name": "several_volumes-VM",
1888 "ns-flavor-id": "test_id",
1889 "virtual-storages": [
1890 {
1891 "type-of-storage": "persistent-storage:persistent-storage",
1892 "size-of-storage": "10",
1893 },
1894 ],
1895 },
1896 ],
1897 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1898 },
1899 ],
1900 }
1901 vim_info = {}
1902 target_record_id = ""
1903
1904 epa_params.return_value = {}
1905
1906 result = Ns._process_flavor_params(
1907 target_flavor=target_flavor,
1908 indata=indata,
1909 vim_info=vim_info,
1910 target_record_id=target_record_id,
1911 **kwargs,
1912 )
1913
1914 self.assertTrue(epa_params.called)
1915 self.assertDictEqual(result, expected_result)
1916
1917 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1918 def test__process_flavor_params_with_epa_params(
1919 self,
1920 epa_params,
1921 ):
1922 expected_result = {
1923 "find_params": {
1924 "flavor_data": {
1925 "disk": 10,
1926 "ram": 1024,
1927 "vcpus": 2,
1928 "extended": {
1929 "numa": "there-is-numa-here",
1930 },
1931 },
1932 },
1933 "params": {
1934 "flavor_data": {
1935 "disk": 10,
1936 "name": "test",
1937 "ram": 1024,
1938 "vcpus": 2,
1939 "extended": {
1940 "numa": "there-is-numa-here",
1941 },
1942 },
1943 },
1944 }
1945 target_flavor = {
1946 "id": "test_id",
1947 "name": "test",
1948 "storage-gb": "10",
1949 "memory-mb": "1024",
1950 "vcpu-count": "2",
1951 }
1952 indata = {
1953 "vnf": [
1954 {
1955 "vdur": [
1956 {
1957 "ns-flavor-id": "test_id",
1958 },
1959 ],
1960 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1961 },
1962 ],
1963 }
1964 vim_info = {}
1965 target_record_id = ""
1966
1967 epa_params.return_value = {
1968 "numa": "there-is-numa-here",
1969 }
1970
1971 result = Ns._process_flavor_params(
1972 target_flavor=target_flavor,
1973 indata=indata,
1974 vim_info=vim_info,
1975 target_record_id=target_record_id,
1976 )
1977
1978 self.assertTrue(epa_params.called)
1979 self.assertDictEqual(result, expected_result)
1980
1981 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1982 def test__process_flavor_params(
1983 self,
1984 epa_params,
1985 ):
1986 db = MagicMock(name="database mock")
1987
1988 kwargs = {
1989 "db": db,
1990 }
1991
1992 db.get_one.return_value = {
1993 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1994 "df": [
1995 {
1996 "id": "default-df",
1997 "vdu-profile": [
1998 {"id": "without_volumes-VM", "min-number-of-instances": 1}
1999 ],
2000 }
2001 ],
2002 "id": "without_volumes-vnf",
2003 "product-name": "without_volumes-vnf",
2004 "vdu": [
2005 {
2006 "id": "without_volumes-VM",
2007 "name": "without_volumes-VM",
2008 "sw-image-desc": "ubuntu20.04",
2009 "alternative-sw-image-desc": [
2010 "ubuntu20.04-aws",
2011 "ubuntu20.04-azure",
2012 ],
2013 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
2014 }
2015 ],
2016 "version": "1.0",
2017 "virtual-storage-desc": [
2018 {"id": "root-volume", "size-of-storage": "10"},
2019 {
2020 "id": "ephemeral-volume",
2021 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2022 "size-of-storage": "1",
2023 },
2024 ],
2025 "_admin": {
2026 "storage": {
2027 "fs": "mongo",
2028 "path": "/app/storage/",
2029 },
2030 "type": "vnfd",
2031 },
2032 }
2033
2034 expected_result = {
2035 "find_params": {
2036 "flavor_data": {
2037 "disk": 10,
2038 "ram": 1024,
2039 "vcpus": 2,
2040 "ephemeral": 10,
2041 "swap": 20,
2042 "extended": {
2043 "numa": "there-is-numa-here",
2044 },
2045 },
2046 },
2047 "params": {
2048 "flavor_data": {
2049 "disk": 10,
2050 "name": "test",
2051 "ram": 1024,
2052 "vcpus": 2,
2053 "ephemeral": 10,
2054 "swap": 20,
2055 "extended": {
2056 "numa": "there-is-numa-here",
2057 },
2058 },
2059 },
2060 }
2061 target_flavor = {
2062 "id": "test_id",
2063 "name": "test",
2064 "storage-gb": "10",
2065 "memory-mb": "1024",
2066 "vcpu-count": "2",
2067 }
2068 indata = {
2069 "vnf": [
2070 {
2071 "vdur": [
2072 {
2073 "ns-flavor-id": "test_id",
2074 "virtual-storages": [
2075 {
2076 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2077 "size-of-storage": "10",
2078 },
2079 {
2080 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
2081 "size-of-storage": "20",
2082 },
2083 ],
2084 },
2085 ],
2086 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2087 },
2088 ],
2089 }
2090 vim_info = {}
2091 target_record_id = ""
2092
2093 epa_params.return_value = {
2094 "numa": "there-is-numa-here",
2095 }
2096
2097 result = Ns._process_flavor_params(
2098 target_flavor=target_flavor,
2099 indata=indata,
2100 vim_info=vim_info,
2101 target_record_id=target_record_id,
2102 **kwargs,
2103 )
2104
2105 self.assertTrue(epa_params.called)
2106 self.assertDictEqual(result, expected_result)
2107
2108 def test__ip_profile_to_ro_with_none(self):
2109 ip_profile = None
2110
2111 result = Ns._ip_profile_to_ro(
2112 ip_profile=ip_profile,
2113 )
2114
2115 self.assertIsNone(result)
2116
2117 def test__ip_profile_to_ro_with_empty_profile(self):
2118 ip_profile = {}
2119
2120 result = Ns._ip_profile_to_ro(
2121 ip_profile=ip_profile,
2122 )
2123
2124 self.assertIsNone(result)
2125
2126 def test__ip_profile_to_ro_with_wrong_profile(self):
2127 ip_profile = {
2128 "no-profile": "here",
2129 }
2130 expected_result = {
2131 "ip_version": "IPv4",
2132 "subnet_address": None,
2133 "gateway_address": None,
2134 "dhcp_enabled": False,
2135 "dhcp_start_address": None,
2136 "dhcp_count": None,
2137 }
2138
2139 result = Ns._ip_profile_to_ro(
2140 ip_profile=ip_profile,
2141 )
2142
2143 self.assertDictEqual(expected_result, result)
2144
2145 def test__ip_profile_to_ro_with_ipv4_profile(self):
2146 ip_profile = {
2147 "ip-version": "ipv4",
2148 "subnet-address": "192.168.0.0/24",
2149 "gateway-address": "192.168.0.254",
2150 "dhcp-params": {
2151 "enabled": True,
2152 "start-address": "192.168.0.10",
2153 "count": 25,
2154 },
2155 }
2156 expected_result = {
2157 "ip_version": "IPv4",
2158 "subnet_address": "192.168.0.0/24",
2159 "gateway_address": "192.168.0.254",
2160 "dhcp_enabled": True,
2161 "dhcp_start_address": "192.168.0.10",
2162 "dhcp_count": 25,
2163 }
2164
2165 result = Ns._ip_profile_to_ro(
2166 ip_profile=ip_profile,
2167 )
2168
2169 self.assertDictEqual(expected_result, result)
2170
2171 def test__ip_profile_to_ro_with_ipv6_profile(self):
2172 ip_profile = {
2173 "ip-version": "ipv6",
2174 "subnet-address": "2001:0200:0001::/48",
2175 "gateway-address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
2176 "dhcp-params": {
2177 "enabled": True,
2178 "start-address": "2001:0200:0001::0010",
2179 "count": 25,
2180 },
2181 }
2182 expected_result = {
2183 "ip_version": "IPv6",
2184 "subnet_address": "2001:0200:0001::/48",
2185 "gateway_address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
2186 "dhcp_enabled": True,
2187 "dhcp_start_address": "2001:0200:0001::0010",
2188 "dhcp_count": 25,
2189 }
2190
2191 result = Ns._ip_profile_to_ro(
2192 ip_profile=ip_profile,
2193 )
2194
2195 self.assertDictEqual(expected_result, result)
2196
2197 def test__ip_profile_to_ro_with_dns_server(self):
2198 ip_profile = {
2199 "ip-version": "ipv4",
2200 "subnet-address": "192.168.0.0/24",
2201 "gateway-address": "192.168.0.254",
2202 "dhcp-params": {
2203 "enabled": True,
2204 "start-address": "192.168.0.10",
2205 "count": 25,
2206 },
2207 "dns-server": [
2208 {
2209 "address": "8.8.8.8",
2210 },
2211 {
2212 "address": "1.1.1.1",
2213 },
2214 {
2215 "address": "1.0.0.1",
2216 },
2217 ],
2218 }
2219 expected_result = {
2220 "ip_version": "IPv4",
2221 "subnet_address": "192.168.0.0/24",
2222 "gateway_address": "192.168.0.254",
2223 "dhcp_enabled": True,
2224 "dhcp_start_address": "192.168.0.10",
2225 "dhcp_count": 25,
2226 "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
2227 }
2228
2229 result = Ns._ip_profile_to_ro(
2230 ip_profile=ip_profile,
2231 )
2232
2233 self.assertDictEqual(expected_result, result)
2234
2235 def test__ip_profile_to_ro_with_security_group(self):
2236 ip_profile = {
2237 "ip-version": "ipv4",
2238 "subnet-address": "192.168.0.0/24",
2239 "gateway-address": "192.168.0.254",
2240 "dhcp-params": {
2241 "enabled": True,
2242 "start-address": "192.168.0.10",
2243 "count": 25,
2244 },
2245 "security-group": {
2246 "some-security-group": "here",
2247 },
2248 }
2249 expected_result = {
2250 "ip_version": "IPv4",
2251 "subnet_address": "192.168.0.0/24",
2252 "gateway_address": "192.168.0.254",
2253 "dhcp_enabled": True,
2254 "dhcp_start_address": "192.168.0.10",
2255 "dhcp_count": 25,
2256 "security_group": {
2257 "some-security-group": "here",
2258 },
2259 }
2260
2261 result = Ns._ip_profile_to_ro(
2262 ip_profile=ip_profile,
2263 )
2264
2265 self.assertDictEqual(expected_result, result)
2266
2267 def test__ip_profile_to_ro(self):
2268 ip_profile = {
2269 "ip-version": "ipv4",
2270 "subnet-address": "192.168.0.0/24",
2271 "gateway-address": "192.168.0.254",
2272 "dhcp-params": {
2273 "enabled": True,
2274 "start-address": "192.168.0.10",
2275 "count": 25,
2276 },
2277 "dns-server": [
2278 {
2279 "address": "8.8.8.8",
2280 },
2281 {
2282 "address": "1.1.1.1",
2283 },
2284 {
2285 "address": "1.0.0.1",
2286 },
2287 ],
2288 "security-group": {
2289 "some-security-group": "here",
2290 },
2291 }
2292 expected_result = {
2293 "ip_version": "IPv4",
2294 "subnet_address": "192.168.0.0/24",
2295 "gateway_address": "192.168.0.254",
2296 "dhcp_enabled": True,
2297 "dhcp_start_address": "192.168.0.10",
2298 "dhcp_count": 25,
2299 "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
2300 "security_group": {
2301 "some-security-group": "here",
2302 },
2303 }
2304
2305 result = Ns._ip_profile_to_ro(
2306 ip_profile=ip_profile,
2307 )
2308
2309 self.assertDictEqual(expected_result, result)
2310
2311 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2312 def test__process_net_params_with_empty_params(
2313 self,
2314 ip_profile_to_ro,
2315 ):
2316 target_vld = {
2317 "name": "vld-name",
2318 }
2319 indata = {
2320 "name": "ns-name",
2321 }
2322 vim_info = {
2323 "provider_network": "some-profile-here",
2324 }
2325 target_record_id = ""
2326 expected_result = {
2327 "params": {
2328 "net_name": "ns-name-vld-name",
2329 "net_type": "bridge",
2330 "ip_profile": {
2331 "some_ip_profile": "here",
2332 },
2333 "provider_network_profile": "some-profile-here",
2334 }
2335 }
2336
2337 ip_profile_to_ro.return_value = {
2338 "some_ip_profile": "here",
2339 }
2340
2341 result = Ns._process_net_params(
2342 target_vld=target_vld,
2343 indata=indata,
2344 vim_info=vim_info,
2345 target_record_id=target_record_id,
2346 )
2347
2348 self.assertDictEqual(expected_result, result)
2349 self.assertTrue(ip_profile_to_ro.called)
2350
2351 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2352 def test__process_net_params_with_vim_info_sdn(
2353 self,
2354 ip_profile_to_ro,
2355 ):
2356 target_vld = {
2357 "name": "vld-name",
2358 }
2359 indata = {
2360 "name": "ns-name",
2361 }
2362 vim_info = {
2363 "sdn": "some-sdn",
2364 "sdn-ports": ["some", "ports", "here"],
2365 "vlds": ["some", "vlds", "here"],
2366 "type": "sdn-type",
2367 }
2368 target_record_id = "vld.sdn.something"
2369 expected_result = {
2370 "params": {
2371 "sdn-ports": ["some", "ports", "here"],
2372 "vlds": ["some", "vlds", "here"],
2373 "type": "sdn-type",
2374 }
2375 }
2376
2377 result = Ns._process_net_params(
2378 target_vld=target_vld,
2379 indata=indata,
2380 vim_info=vim_info,
2381 target_record_id=target_record_id,
2382 )
2383
2384 self.assertDictEqual(expected_result, result)
2385 self.assertFalse(ip_profile_to_ro.called)
2386
2387 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2388 def test__process_net_params_with_vim_info_sdn_target_vim(
2389 self,
2390 ip_profile_to_ro,
2391 ):
2392 target_vld = {
2393 "name": "vld-name",
2394 }
2395 indata = {
2396 "name": "ns-name",
2397 }
2398 vim_info = {
2399 "sdn": "some-sdn",
2400 "sdn-ports": ["some", "ports", "here"],
2401 "vlds": ["some", "vlds", "here"],
2402 "target_vim": "some-vim",
2403 "type": "sdn-type",
2404 }
2405 target_record_id = "vld.sdn.something"
2406 expected_result = {
2407 "depends_on": ["some-vim vld.sdn"],
2408 "params": {
2409 "sdn-ports": ["some", "ports", "here"],
2410 "vlds": ["some", "vlds", "here"],
2411 "target_vim": "some-vim",
2412 "type": "sdn-type",
2413 },
2414 }
2415
2416 result = Ns._process_net_params(
2417 target_vld=target_vld,
2418 indata=indata,
2419 vim_info=vim_info,
2420 target_record_id=target_record_id,
2421 )
2422
2423 self.assertDictEqual(expected_result, result)
2424 self.assertFalse(ip_profile_to_ro.called)
2425
2426 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2427 def test__process_net_params_with_vim_network_name(
2428 self,
2429 ip_profile_to_ro,
2430 ):
2431 target_vld = {
2432 "name": "vld-name",
2433 }
2434 indata = {
2435 "name": "ns-name",
2436 }
2437 vim_info = {
2438 "vim_network_name": "some-network-name",
2439 }
2440 target_record_id = "vld.sdn.something"
2441 expected_result = {
2442 "find_params": {
2443 "filter_dict": {
2444 "name": "some-network-name",
2445 },
2446 },
2447 }
2448
2449 result = Ns._process_net_params(
2450 target_vld=target_vld,
2451 indata=indata,
2452 vim_info=vim_info,
2453 target_record_id=target_record_id,
2454 )
2455
2456 self.assertDictEqual(expected_result, result)
2457 self.assertFalse(ip_profile_to_ro.called)
2458
2459 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2460 def test__process_net_params_with_vim_network_id(
2461 self,
2462 ip_profile_to_ro,
2463 ):
2464 target_vld = {
2465 "name": "vld-name",
2466 }
2467 indata = {
2468 "name": "ns-name",
2469 }
2470 vim_info = {
2471 "vim_network_id": "some-network-id",
2472 }
2473 target_record_id = "vld.sdn.something"
2474 expected_result = {
2475 "find_params": {
2476 "filter_dict": {
2477 "id": "some-network-id",
2478 },
2479 },
2480 }
2481
2482 result = Ns._process_net_params(
2483 target_vld=target_vld,
2484 indata=indata,
2485 vim_info=vim_info,
2486 target_record_id=target_record_id,
2487 )
2488
2489 self.assertDictEqual(expected_result, result)
2490 self.assertFalse(ip_profile_to_ro.called)
2491
2492 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2493 def test__process_net_params_with_mgmt_network(
2494 self,
2495 ip_profile_to_ro,
2496 ):
2497 target_vld = {
2498 "id": "vld-id",
2499 "name": "vld-name",
2500 "mgmt-network": "some-mgmt-network",
2501 }
2502 indata = {
2503 "name": "ns-name",
2504 }
2505 vim_info = {}
2506 target_record_id = "vld.sdn.something"
2507 expected_result = {
2508 "find_params": {
2509 "mgmt": True,
2510 "name": "vld-id",
2511 },
2512 }
2513
2514 result = Ns._process_net_params(
2515 target_vld=target_vld,
2516 indata=indata,
2517 vim_info=vim_info,
2518 target_record_id=target_record_id,
2519 )
2520
2521 self.assertDictEqual(expected_result, result)
2522 self.assertFalse(ip_profile_to_ro.called)
2523
2524 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2525 def test__process_net_params_with_underlay_eline(
2526 self,
2527 ip_profile_to_ro,
2528 ):
2529 target_vld = {
2530 "name": "vld-name",
2531 "underlay": "some-underlay-here",
2532 "type": "ELINE",
2533 }
2534 indata = {
2535 "name": "ns-name",
2536 }
2537 vim_info = {
2538 "provider_network": "some-profile-here",
2539 }
2540 target_record_id = ""
2541 expected_result = {
2542 "params": {
2543 "ip_profile": {
2544 "some_ip_profile": "here",
2545 },
2546 "net_name": "ns-name-vld-name",
2547 "net_type": "ptp",
2548 "provider_network_profile": "some-profile-here",
2549 }
2550 }
2551
2552 ip_profile_to_ro.return_value = {
2553 "some_ip_profile": "here",
2554 }
2555
2556 result = Ns._process_net_params(
2557 target_vld=target_vld,
2558 indata=indata,
2559 vim_info=vim_info,
2560 target_record_id=target_record_id,
2561 )
2562
2563 self.assertDictEqual(expected_result, result)
2564 self.assertTrue(ip_profile_to_ro.called)
2565
2566 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2567 def test__process_net_params_with_underlay_elan(
2568 self,
2569 ip_profile_to_ro,
2570 ):
2571 target_vld = {
2572 "name": "vld-name",
2573 "underlay": "some-underlay-here",
2574 "type": "ELAN",
2575 }
2576 indata = {
2577 "name": "ns-name",
2578 }
2579 vim_info = {
2580 "provider_network": "some-profile-here",
2581 }
2582 target_record_id = ""
2583 expected_result = {
2584 "params": {
2585 "ip_profile": {
2586 "some_ip_profile": "here",
2587 },
2588 "net_name": "ns-name-vld-name",
2589 "net_type": "data",
2590 "provider_network_profile": "some-profile-here",
2591 }
2592 }
2593
2594 ip_profile_to_ro.return_value = {
2595 "some_ip_profile": "here",
2596 }
2597
2598 result = Ns._process_net_params(
2599 target_vld=target_vld,
2600 indata=indata,
2601 vim_info=vim_info,
2602 target_record_id=target_record_id,
2603 )
2604
2605 self.assertDictEqual(expected_result, result)
2606 self.assertTrue(ip_profile_to_ro.called)
2607
2608 def test__get_cloud_init_exception(self):
2609 db_mock = MagicMock(name="database mock")
2610 fs_mock = None
2611
2612 location = ""
2613
2614 with self.assertRaises(NsException):
2615 Ns._get_cloud_init(db=db_mock, fs=fs_mock, location=location)
2616
2617 def test__get_cloud_init_file_fs_exception(self):
2618 db_mock = MagicMock(name="database mock")
2619 fs_mock = None
2620
2621 location = "vnfr_id_123456:file:test_file"
2622 db_mock.get_one.return_value = {
2623 "_admin": {
2624 "storage": {
2625 "folder": "/home/osm",
2626 "pkg-dir": "vnfr_test_dir",
2627 },
2628 },
2629 }
2630
2631 with self.assertRaises(NsException):
2632 Ns._get_cloud_init(db=db_mock, fs=fs_mock, location=location)
2633
2634 def test__get_cloud_init_file(self):
2635 db_mock = MagicMock(name="database mock")
2636 fs_mock = MagicMock(name="filesystem mock")
2637 file_mock = MagicMock(name="file mock")
2638
2639 location = "vnfr_id_123456:file:test_file"
2640 cloud_init_content = "this is a cloud init file content"
2641
2642 db_mock.get_one.return_value = {
2643 "_admin": {
2644 "storage": {
2645 "folder": "/home/osm",
2646 "pkg-dir": "vnfr_test_dir",
2647 },
2648 },
2649 }
2650 fs_mock.file_open.return_value = file_mock
2651 file_mock.__enter__.return_value.read.return_value = cloud_init_content
2652
2653 result = Ns._get_cloud_init(db=db_mock, fs=fs_mock, location=location)
2654
2655 self.assertEqual(cloud_init_content, result)
2656
2657 def test__get_cloud_init_vdu(self):
2658 db_mock = MagicMock(name="database mock")
2659 fs_mock = None
2660
2661 location = "vnfr_id_123456:vdu:0"
2662 cloud_init_content = "this is a cloud init file content"
2663
2664 db_mock.get_one.return_value = {
2665 "vdu": {
2666 0: {
2667 "cloud-init": cloud_init_content,
2668 },
2669 },
2670 }
2671
2672 result = Ns._get_cloud_init(db=db_mock, fs=fs_mock, location=location)
2673
2674 self.assertEqual(cloud_init_content, result)
2675
2676 @patch("jinja2.Environment.__init__")
2677 def test__parse_jinja2_undefined_error(self, env_mock: Mock):
2678 cloud_init_content = None
2679 params = None
2680 context = None
2681
2682 env_mock.side_effect = UndefinedError("UndefinedError occurred.")
2683
2684 with self.assertRaises(NsException):
2685 Ns._parse_jinja2(
2686 cloud_init_content=cloud_init_content, params=params, context=context
2687 )
2688
2689 @patch("jinja2.Environment.__init__")
2690 def test__parse_jinja2_template_error(self, env_mock: Mock):
2691 cloud_init_content = None
2692 params = None
2693 context = None
2694
2695 env_mock.side_effect = TemplateError("TemplateError occurred.")
2696
2697 with self.assertRaises(NsException):
2698 Ns._parse_jinja2(
2699 cloud_init_content=cloud_init_content, params=params, context=context
2700 )
2701
2702 @patch("jinja2.Environment.__init__")
2703 def test__parse_jinja2_template_not_found(self, env_mock: Mock):
2704 cloud_init_content = None
2705 params = None
2706 context = None
2707
2708 env_mock.side_effect = TemplateNotFound("TemplateNotFound occurred.")
2709
2710 with self.assertRaises(NsException):
2711 Ns._parse_jinja2(
2712 cloud_init_content=cloud_init_content, params=params, context=context
2713 )
2714
2715 def test_rendering_jinja2_temp_without_special_characters(self):
2716 cloud_init_content = """
2717 disk_setup:
2718 ephemeral0:
2719 table_type: {{type}}
2720 layout: True
2721 overwrite: {{is_override}}
2722 runcmd:
2723 - [ ls, -l, / ]
2724 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2725 """
2726 params = {
2727 "type": "mbr",
2728 "is_override": "False",
2729 "command": "; mkdir abc",
2730 }
2731 context = "cloud-init for VM"
2732 expected_result = """
2733 disk_setup:
2734 ephemeral0:
2735 table_type: mbr
2736 layout: True
2737 overwrite: False
2738 runcmd:
2739 - [ ls, -l, / ]
2740 - [ sh, -xc, "echo $(date) '; mkdir abc'" ]
2741 """
2742 result = Ns._parse_jinja2(
2743 cloud_init_content=cloud_init_content, params=params, context=context
2744 )
2745 self.assertEqual(result, expected_result)
2746
2747 def test_rendering_jinja2_temp_with_special_characters(self):
2748 cloud_init_content = """
2749 disk_setup:
2750 ephemeral0:
2751 table_type: {{type}}
2752 layout: True
2753 overwrite: {{is_override}}
2754 runcmd:
2755 - [ ls, -l, / ]
2756 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2757 """
2758 params = {
2759 "type": "mbr",
2760 "is_override": "False",
2761 "command": "& rm -rf",
2762 }
2763 context = "cloud-init for VM"
2764 expected_result = """
2765 disk_setup:
2766 ephemeral0:
2767 table_type: mbr
2768 layout: True
2769 overwrite: False
2770 runcmd:
2771 - [ ls, -l, / ]
2772 - [ sh, -xc, "echo $(date) '& rm -rf /'" ]
2773 """
2774 result = Ns._parse_jinja2(
2775 cloud_init_content=cloud_init_content, params=params, context=context
2776 )
2777 self.assertNotEqual(result, expected_result)
2778
2779 def test_rendering_jinja2_temp_with_special_characters_autoescape_is_false(self):
2780 with patch("osm_ng_ro.ns.Environment") as mock_environment:
2781 mock_environment.return_value = Environment(
2782 undefined=StrictUndefined,
2783 autoescape=select_autoescape(default_for_string=False, default=False),
2784 )
2785 cloud_init_content = """
2786 disk_setup:
2787 ephemeral0:
2788 table_type: {{type}}
2789 layout: True
2790 overwrite: {{is_override}}
2791 runcmd:
2792 - [ ls, -l, / ]
2793 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2794 """
2795 params = {
2796 "type": "mbr",
2797 "is_override": "False",
2798 "command": "& rm -rf /",
2799 }
2800 context = "cloud-init for VM"
2801 expected_result = """
2802 disk_setup:
2803 ephemeral0:
2804 table_type: mbr
2805 layout: True
2806 overwrite: False
2807 runcmd:
2808 - [ ls, -l, / ]
2809 - [ sh, -xc, "echo $(date) '& rm -rf /'" ]
2810 """
2811 result = Ns._parse_jinja2(
2812 cloud_init_content=cloud_init_content,
2813 params=params,
2814 context=context,
2815 )
2816 self.assertEqual(result, expected_result)
2817
2818 def test__process_vdu_params_empty_kargs(self):
2819 pass
2820
2821 def test__process_vdu_params_interface_ns_vld_id(self):
2822 pass
2823
2824 def test__process_vdu_params_interface_vnf_vld_id(self):
2825 pass
2826
2827 def test__process_vdu_params_interface_unknown(self):
2828 pass
2829
2830 def test__process_vdu_params_interface_port_security_enabled(self):
2831 pass
2832
2833 def test__process_vdu_params_interface_port_security_disable_strategy(self):
2834 pass
2835
2836 def test__process_vdu_params_interface_sriov(self):
2837 pass
2838
2839 def test__process_vdu_params_interface_pci_passthrough(self):
2840 pass
2841
2842 def test__process_vdu_params_interface_om_mgmt(self):
2843 pass
2844
2845 def test__process_vdu_params_interface_mgmt_interface(self):
2846 pass
2847
2848 def test__process_vdu_params_interface_mgmt_vnf(self):
2849 pass
2850
2851 def test__process_vdu_params_interface_bridge(self):
2852 pass
2853
2854 def test__process_vdu_params_interface_ip_address(self):
2855 pass
2856
2857 def test__process_vdu_params_interface_mac_address(self):
2858 pass
2859
2860 def test__process_vdu_params_vdu_cloud_init_missing(self):
2861 pass
2862
2863 def test__process_vdu_params_vdu_cloud_init_present(self):
2864 pass
2865
2866 def test__process_vdu_params_vdu_boot_data_drive(self):
2867 pass
2868
2869 def test__process_vdu_params_vdu_ssh_keys(self):
2870 pass
2871
2872 def test__process_vdu_params_vdu_ssh_access_required(self):
2873 pass
2874
2875 @patch("osm_ng_ro.ns.Ns._get_cloud_init")
2876 @patch("osm_ng_ro.ns.Ns._parse_jinja2")
2877 def test__process_vdu_params_vdu_persistent_root_volume(
2878 self, get_cloud_init, parse_jinja2
2879 ):
2880 db = MagicMock(name="database mock")
2881 kwargs = {
2882 "db": db,
2883 "vdu2cloud_init": {},
2884 "vnfr": {
2885 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2886 "member-vnf-index-ref": "vnf-several-volumes",
2887 },
2888 }
2889 get_cloud_init.return_value = {}
2890 parse_jinja2.return_value = {}
2891 db.get_one.return_value = {
2892 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2893 "df": [
2894 {
2895 "id": "default-df",
2896 "vdu-profile": [
2897 {"id": "several_volumes-VM", "min-number-of-instances": 1}
2898 ],
2899 }
2900 ],
2901 "id": "several_volumes-vnf",
2902 "product-name": "several_volumes-vnf",
2903 "vdu": [
2904 {
2905 "id": "several_volumes-VM",
2906 "name": "several_volumes-VM",
2907 "sw-image-desc": "ubuntu20.04",
2908 "alternative-sw-image-desc": [
2909 "ubuntu20.04-aws",
2910 "ubuntu20.04-azure",
2911 ],
2912 "virtual-storage-desc": [
2913 "persistent-root-volume",
2914 "persistent-volume2",
2915 "ephemeral-volume",
2916 ],
2917 }
2918 ],
2919 "version": "1.0",
2920 "virtual-storage-desc": [
2921 {
2922 "id": "persistent-volume2",
2923 "type-of-storage": "persistent-storage:persistent-storage",
2924 "size-of-storage": "10",
2925 },
2926 {
2927 "id": "persistent-root-volume",
2928 "type-of-storage": "persistent-storage:persistent-storage",
2929 "size-of-storage": "10",
2930 },
2931 {
2932 "id": "ephemeral-volume",
2933 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2934 "size-of-storage": "1",
2935 },
2936 ],
2937 "_admin": {
2938 "storage": {
2939 "fs": "mongo",
2940 "path": "/app/storage/",
2941 },
2942 "type": "vnfd",
2943 },
2944 }
2945
2946 target_vdu = {
2947 "_id": "09a0baa7-b7cb-4924-bd63-9f04a1c23960",
2948 "ns-flavor-id": "0",
2949 "ns-image-id": "0",
2950 "vdu-name": "several_volumes-VM",
2951 "interfaces": [
2952 {
2953 "name": "vdu-eth0",
2954 "ns-vld-id": "mgmtnet",
2955 }
2956 ],
2957 "virtual-storages": [
2958 {
2959 "id": "persistent-volume2",
2960 "size-of-storage": "10",
2961 "type-of-storage": "persistent-storage:persistent-storage",
2962 },
2963 {
2964 "id": "persistent-root-volume",
2965 "size-of-storage": "10",
2966 "type-of-storage": "persistent-storage:persistent-storage",
2967 },
2968 {
2969 "id": "ephemeral-volume",
2970 "size-of-storage": "1",
2971 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2972 },
2973 ],
2974 }
2975 indata = {
2976 "name": "sample_name",
2977 }
2978 expected_result = [{"image_id": "ubuntu20.04", "size": "10"}, {"size": "10"}]
2979 result = Ns._process_vdu_params(
2980 target_vdu, indata, vim_info=None, target_record_id=None, **kwargs
2981 )
2982 self.assertEqual(
2983 expected_result, result["params"]["disk_list"], "Wrong Disk List"
2984 )
2985
2986 @patch("osm_ng_ro.ns.Ns._get_cloud_init")
2987 @patch("osm_ng_ro.ns.Ns._parse_jinja2")
2988 def test__process_vdu_params_vdu_without_persistent_storage(
2989 self, get_cloud_init, parse_jinja2
2990 ):
2991 db = MagicMock(name="database mock")
2992 kwargs = {
2993 "db": db,
2994 "vdu2cloud_init": {},
2995 "vnfr": {
2996 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2997 "member-vnf-index-ref": "vnf-several-volumes",
2998 },
2999 }
3000 get_cloud_init.return_value = {}
3001 parse_jinja2.return_value = {}
3002 db.get_one.return_value = {
3003 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
3004 "df": [
3005 {
3006 "id": "default-df",
3007 "vdu-profile": [
3008 {"id": "without_volumes-VM", "min-number-of-instances": 1}
3009 ],
3010 }
3011 ],
3012 "id": "without_volumes-vnf",
3013 "product-name": "without_volumes-vnf",
3014 "vdu": [
3015 {
3016 "id": "without_volumes-VM",
3017 "name": "without_volumes-VM",
3018 "sw-image-desc": "ubuntu20.04",
3019 "alternative-sw-image-desc": [
3020 "ubuntu20.04-aws",
3021 "ubuntu20.04-azure",
3022 ],
3023 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
3024 }
3025 ],
3026 "version": "1.0",
3027 "virtual-storage-desc": [
3028 {"id": "root-volume", "size-of-storage": "10"},
3029 {
3030 "id": "ephemeral-volume",
3031 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
3032 "size-of-storage": "1",
3033 },
3034 ],
3035 "_admin": {
3036 "storage": {
3037 "fs": "mongo",
3038 "path": "/app/storage/",
3039 },
3040 "type": "vnfd",
3041 },
3042 }
3043
3044 target_vdu = {
3045 "_id": "09a0baa7-b7cb-4924-bd63-9f04a1c23960",
3046 "ns-flavor-id": "0",
3047 "ns-image-id": "0",
3048 "vdu-name": "without_volumes-VM",
3049 "interfaces": [
3050 {
3051 "name": "vdu-eth0",
3052 "ns-vld-id": "mgmtnet",
3053 }
3054 ],
3055 "virtual-storages": [
3056 {
3057 "id": "root-volume",
3058 "size-of-storage": "10",
3059 },
3060 {
3061 "id": "ephemeral-volume",
3062 "size-of-storage": "1",
3063 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
3064 },
3065 ],
3066 }
3067 indata = {
3068 "name": "sample_name",
3069 }
3070 expected_result = []
3071 result = Ns._process_vdu_params(
3072 target_vdu, indata, vim_info=None, target_record_id=None, **kwargs
3073 )
3074 self.assertEqual(
3075 expected_result, result["params"]["disk_list"], "Wrong Disk List"
3076 )
3077
3078 def test__process_vdu_params(self):
3079 pass
3080
3081 @patch("osm_ng_ro.ns.Ns._assign_vim")
3082 def test__rebuild_start_stop_task(self, assign_vim):
3083 self.ns = Ns()
3084 extra_dict = {}
3085 actions = ["start", "stop", "rebuild"]
3086 vdu_id = "bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3087 vnf_id = "665b4165-ce24-4320-bf19-b9a45bade49f"
3088 vdu_index = "0"
3089 action_id = "bb937f49-3870-4169-b758-9732e1ff40f3"
3090 nsr_id = "993166fe-723e-4680-ac4b-b1af2541ae31"
3091 task_index = 0
3092 target_vim = "vim:f9f370ac-0d44-41a7-9000-457f2332bc35"
3093 t = "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3094 for action in actions:
3095 expected_result = {
3096 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3097 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3098 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3099 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:0",
3100 "status": "SCHEDULED",
3101 "action": "EXEC",
3102 "item": "update",
3103 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.0",
3104 "target_record_id": t,
3105 "params": {
3106 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3107 "action": action,
3108 },
3109 }
3110 extra_dict["params"] = {
3111 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3112 "action": action,
3113 }
3114 task = self.ns.rebuild_start_stop_task(
3115 vdu_id,
3116 vnf_id,
3117 vdu_index,
3118 action_id,
3119 nsr_id,
3120 task_index,
3121 target_vim,
3122 extra_dict,
3123 )
3124 self.assertEqual(task.get("action_id"), action_id)
3125 self.assertEqual(task.get("nsr_id"), nsr_id)
3126 self.assertEqual(task.get("target_id"), target_vim)
3127 self.assertDictEqual(task, expected_result)
3128
3129 @patch("osm_ng_ro.ns.Ns._assign_vim")
3130 def test_verticalscale_task(self, assign_vim):
3131 self.ns = Ns()
3132 extra_dict = {}
3133 vdu_index = "1"
3134 action_id = "bb937f49-3870-4169-b758-9732e1ff40f3"
3135 nsr_id = "993166fe-723e-4680-ac4b-b1af2541ae31"
3136 task_index = 1
3137 target_record_id = (
3138 "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
3139 "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3140 )
3141
3142 expected_result = {
3143 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3144 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3145 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3146 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1",
3147 "status": "SCHEDULED",
3148 "action": "EXEC",
3149 "item": "verticalscale",
3150 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1",
3151 "target_record_id": target_record_id,
3152 "params": {
3153 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3154 "flavor_dict": "flavor_dict",
3155 },
3156 }
3157 vdu = {
3158 "id": "bb9c43f9-10a2-4569-a8a8-957c3528b6d1",
3159 "vim_info": {
3160 "vim:f9f370ac-0d44-41a7-9000-457f2332bc35": {"interfaces": []}
3161 },
3162 }
3163 vnf = {"_id": "665b4165-ce24-4320-bf19-b9a45bade49f"}
3164 extra_dict["params"] = {
3165 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3166 "flavor_dict": "flavor_dict",
3167 }
3168 task = self.ns.verticalscale_task(
3169 vdu, vnf, vdu_index, action_id, nsr_id, task_index, extra_dict
3170 )
3171
3172 self.assertDictEqual(task, expected_result)
3173
3174 @patch("osm_ng_ro.ns.Ns._assign_vim")
3175 def test_migrate_task(self, assign_vim):
3176 self.ns = Ns()
3177 extra_dict = {}
3178 vdu_index = "1"
3179 action_id = "bb937f49-3870-4169-b758-9732e1ff40f3"
3180 nsr_id = "993166fe-723e-4680-ac4b-b1af2541ae31"
3181 task_index = 1
3182 target_record_id = (
3183 "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
3184 "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3185 )
3186
3187 expected_result = {
3188 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3189 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3190 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3191 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1",
3192 "status": "SCHEDULED",
3193 "action": "EXEC",
3194 "item": "migrate",
3195 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1",
3196 "target_record_id": target_record_id,
3197 "params": {
3198 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3199 "migrate_host": "migrateToHost",
3200 },
3201 }
3202 vdu = {
3203 "id": "bb9c43f9-10a2-4569-a8a8-957c3528b6d1",
3204 "vim_info": {
3205 "vim:f9f370ac-0d44-41a7-9000-457f2332bc35": {"interfaces": []}
3206 },
3207 }
3208 vnf = {"_id": "665b4165-ce24-4320-bf19-b9a45bade49f"}
3209 extra_dict["params"] = {
3210 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3211 "migrate_host": "migrateToHost",
3212 }
3213 task = self.ns.migrate_task(
3214 vdu, vnf, vdu_index, action_id, nsr_id, task_index, extra_dict
3215 )
3216
3217 self.assertDictEqual(task, expected_result)