Bug 2180 fixed
[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
1498 target_flavor = {}
1499 indata = {
1500 "vnf": [
1501 {
1502 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1503 },
1504 ],
1505 }
1506 vim_info = {}
1507 target_record_id = ""
1508
1509 with self.assertRaises(KeyError):
1510 Ns._process_flavor_params(
1511 target_flavor=target_flavor,
1512 indata=indata,
1513 vim_info=vim_info,
1514 target_record_id=target_record_id,
1515 )
1516
1517 self.assertFalse(epa_params.called)
1518
1519 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1520 def test__process_flavor_params_with_wrong_target_flavor(
1521 self,
1522 epa_params,
1523 ):
1524
1525 target_flavor = {
1526 "no-target-flavor": "here",
1527 }
1528 indata = {}
1529 vim_info = {}
1530 target_record_id = ""
1531
1532 with self.assertRaises(KeyError):
1533 Ns._process_flavor_params(
1534 target_flavor=target_flavor,
1535 indata=indata,
1536 vim_info=vim_info,
1537 target_record_id=target_record_id,
1538 )
1539
1540 self.assertFalse(epa_params.called)
1541
1542 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1543 def test__process_flavor_params_with_empty_indata(
1544 self,
1545 epa_params,
1546 ):
1547
1548 expected_result = {
1549 "find_params": {
1550 "flavor_data": {
1551 "disk": 10,
1552 "ram": 1024,
1553 "vcpus": 2,
1554 },
1555 },
1556 "params": {
1557 "flavor_data": {
1558 "disk": 10,
1559 "name": "test",
1560 "ram": 1024,
1561 "vcpus": 2,
1562 },
1563 },
1564 }
1565 target_flavor = {
1566 "name": "test",
1567 "storage-gb": "10",
1568 "memory-mb": "1024",
1569 "vcpu-count": "2",
1570 }
1571 indata = {}
1572 vim_info = {}
1573 target_record_id = ""
1574
1575 epa_params.return_value = {}
1576
1577 result = Ns._process_flavor_params(
1578 target_flavor=target_flavor,
1579 indata=indata,
1580 vim_info=vim_info,
1581 target_record_id=target_record_id,
1582 )
1583
1584 self.assertTrue(epa_params.called)
1585 self.assertDictEqual(result, expected_result)
1586
1587 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1588 def test__process_flavor_params_with_wrong_indata(
1589 self,
1590 epa_params,
1591 ):
1592
1593 expected_result = {
1594 "find_params": {
1595 "flavor_data": {
1596 "disk": 10,
1597 "ram": 1024,
1598 "vcpus": 2,
1599 },
1600 },
1601 "params": {
1602 "flavor_data": {
1603 "disk": 10,
1604 "name": "test",
1605 "ram": 1024,
1606 "vcpus": 2,
1607 },
1608 },
1609 }
1610 target_flavor = {
1611 "name": "test",
1612 "storage-gb": "10",
1613 "memory-mb": "1024",
1614 "vcpu-count": "2",
1615 }
1616 indata = {
1617 "no-vnf": "here",
1618 }
1619 vim_info = {}
1620 target_record_id = ""
1621
1622 epa_params.return_value = {}
1623
1624 result = Ns._process_flavor_params(
1625 target_flavor=target_flavor,
1626 indata=indata,
1627 vim_info=vim_info,
1628 target_record_id=target_record_id,
1629 )
1630
1631 self.assertTrue(epa_params.called)
1632 self.assertDictEqual(result, expected_result)
1633
1634 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1635 def test__process_flavor_params_with_ephemeral_disk(
1636 self,
1637 epa_params,
1638 ):
1639 db = MagicMock(name="database mock")
1640 kwargs = {
1641 "db": db,
1642 }
1643
1644 db.get_one.return_value = {
1645 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1646 "df": [
1647 {
1648 "id": "default-df",
1649 "vdu-profile": [
1650 {"id": "without_volumes-VM", "min-number-of-instances": 1}
1651 ],
1652 }
1653 ],
1654 "id": "without_volumes-vnf",
1655 "product-name": "without_volumes-vnf",
1656 "vdu": [
1657 {
1658 "id": "without_volumes-VM",
1659 "name": "without_volumes-VM",
1660 "sw-image-desc": "ubuntu20.04",
1661 "alternative-sw-image-desc": [
1662 "ubuntu20.04-aws",
1663 "ubuntu20.04-azure",
1664 ],
1665 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
1666 }
1667 ],
1668 "version": "1.0",
1669 "virtual-storage-desc": [
1670 {"id": "root-volume", "size-of-storage": "10"},
1671 {
1672 "id": "ephemeral-volume",
1673 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1674 "size-of-storage": "1",
1675 },
1676 ],
1677 "_admin": {
1678 "storage": {
1679 "fs": "mongo",
1680 "path": "/app/storage/",
1681 },
1682 "type": "vnfd",
1683 },
1684 }
1685 expected_result = {
1686 "find_params": {
1687 "flavor_data": {
1688 "disk": 10,
1689 "ram": 1024,
1690 "vcpus": 2,
1691 "ephemeral": 10,
1692 },
1693 },
1694 "params": {
1695 "flavor_data": {
1696 "disk": 10,
1697 "name": "test",
1698 "ram": 1024,
1699 "vcpus": 2,
1700 "ephemeral": 10,
1701 },
1702 },
1703 }
1704 target_flavor = {
1705 "id": "test_id",
1706 "name": "test",
1707 "storage-gb": "10",
1708 "memory-mb": "1024",
1709 "vcpu-count": "2",
1710 }
1711 indata = {
1712 "vnf": [
1713 {
1714 "vdur": [
1715 {
1716 "ns-flavor-id": "test_id",
1717 "virtual-storages": [
1718 {
1719 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1720 "size-of-storage": "10",
1721 },
1722 ],
1723 },
1724 ],
1725 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1726 },
1727 ],
1728 }
1729 vim_info = {}
1730 target_record_id = ""
1731
1732 epa_params.return_value = {}
1733
1734 result = Ns._process_flavor_params(
1735 target_flavor=target_flavor,
1736 indata=indata,
1737 vim_info=vim_info,
1738 target_record_id=target_record_id,
1739 **kwargs,
1740 )
1741
1742 self.assertTrue(epa_params.called)
1743 self.assertDictEqual(result, expected_result)
1744
1745 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1746 def test__process_flavor_params_with_swap_disk(
1747 self,
1748 epa_params,
1749 ):
1750
1751 expected_result = {
1752 "find_params": {
1753 "flavor_data": {
1754 "disk": 10,
1755 "ram": 1024,
1756 "vcpus": 2,
1757 "swap": 20,
1758 },
1759 },
1760 "params": {
1761 "flavor_data": {
1762 "disk": 10,
1763 "name": "test",
1764 "ram": 1024,
1765 "vcpus": 2,
1766 "swap": 20,
1767 },
1768 },
1769 }
1770 target_flavor = {
1771 "id": "test_id",
1772 "name": "test",
1773 "storage-gb": "10",
1774 "memory-mb": "1024",
1775 "vcpu-count": "2",
1776 }
1777 indata = {
1778 "vnf": [
1779 {
1780 "vdur": [
1781 {
1782 "ns-flavor-id": "test_id",
1783 "virtual-storages": [
1784 {
1785 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
1786 "size-of-storage": "20",
1787 },
1788 ],
1789 },
1790 ],
1791 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1792 },
1793 ],
1794 }
1795 vim_info = {}
1796 target_record_id = ""
1797
1798 epa_params.return_value = {}
1799
1800 result = Ns._process_flavor_params(
1801 target_flavor=target_flavor,
1802 indata=indata,
1803 vim_info=vim_info,
1804 target_record_id=target_record_id,
1805 )
1806
1807 self.assertTrue(epa_params.called)
1808 self.assertDictEqual(result, expected_result)
1809
1810 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1811 def test__process_flavor_params_with_persistent_root_disk(
1812 self,
1813 epa_params,
1814 ):
1815 db = MagicMock(name="database mock")
1816
1817 kwargs = {
1818 "db": db,
1819 }
1820
1821 db.get_one.return_value = {
1822 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1823 "df": [
1824 {
1825 "id": "default-df",
1826 "vdu-profile": [
1827 {"id": "several_volumes-VM", "min-number-of-instances": 1}
1828 ],
1829 }
1830 ],
1831 "id": "several_volumes-vnf",
1832 "product-name": "several_volumes-vnf",
1833 "vdu": [
1834 {
1835 "id": "several_volumes-VM",
1836 "name": "several_volumes-VM",
1837 "sw-image-desc": "ubuntu20.04",
1838 "alternative-sw-image-desc": [
1839 "ubuntu20.04-aws",
1840 "ubuntu20.04-azure",
1841 ],
1842 "virtual-storage-desc": [
1843 "persistent-root-volume",
1844 ],
1845 }
1846 ],
1847 "version": "1.0",
1848 "virtual-storage-desc": [
1849 {
1850 "id": "persistent-root-volume",
1851 "type-of-storage": "persistent-storage:persistent-storage",
1852 "size-of-storage": "10",
1853 },
1854 ],
1855 "_admin": {
1856 "storage": {
1857 "fs": "mongo",
1858 "path": "/app/storage/",
1859 },
1860 "type": "vnfd",
1861 },
1862 }
1863 expected_result = {
1864 "find_params": {
1865 "flavor_data": {
1866 "disk": 0,
1867 "ram": 1024,
1868 "vcpus": 2,
1869 },
1870 },
1871 "params": {
1872 "flavor_data": {
1873 "disk": 0,
1874 "name": "test",
1875 "ram": 1024,
1876 "vcpus": 2,
1877 },
1878 },
1879 }
1880 target_flavor = {
1881 "id": "test_id",
1882 "name": "test",
1883 "storage-gb": "10",
1884 "memory-mb": "1024",
1885 "vcpu-count": "2",
1886 }
1887 indata = {
1888 "vnf": [
1889 {
1890 "vdur": [
1891 {
1892 "vdu-name": "several_volumes-VM",
1893 "ns-flavor-id": "test_id",
1894 "virtual-storages": [
1895 {
1896 "type-of-storage": "persistent-storage:persistent-storage",
1897 "size-of-storage": "10",
1898 },
1899 ],
1900 },
1901 ],
1902 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1903 },
1904 ],
1905 }
1906 vim_info = {}
1907 target_record_id = ""
1908
1909 epa_params.return_value = {}
1910
1911 result = Ns._process_flavor_params(
1912 target_flavor=target_flavor,
1913 indata=indata,
1914 vim_info=vim_info,
1915 target_record_id=target_record_id,
1916 **kwargs,
1917 )
1918
1919 self.assertTrue(epa_params.called)
1920 self.assertDictEqual(result, expected_result)
1921
1922 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1923 def test__process_flavor_params_with_epa_params(
1924 self,
1925 epa_params,
1926 ):
1927
1928 expected_result = {
1929 "find_params": {
1930 "flavor_data": {
1931 "disk": 10,
1932 "ram": 1024,
1933 "vcpus": 2,
1934 "extended": {
1935 "numa": "there-is-numa-here",
1936 },
1937 },
1938 },
1939 "params": {
1940 "flavor_data": {
1941 "disk": 10,
1942 "name": "test",
1943 "ram": 1024,
1944 "vcpus": 2,
1945 "extended": {
1946 "numa": "there-is-numa-here",
1947 },
1948 },
1949 },
1950 }
1951 target_flavor = {
1952 "id": "test_id",
1953 "name": "test",
1954 "storage-gb": "10",
1955 "memory-mb": "1024",
1956 "vcpu-count": "2",
1957 }
1958 indata = {
1959 "vnf": [
1960 {
1961 "vdur": [
1962 {
1963 "ns-flavor-id": "test_id",
1964 },
1965 ],
1966 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1967 },
1968 ],
1969 }
1970 vim_info = {}
1971 target_record_id = ""
1972
1973 epa_params.return_value = {
1974 "numa": "there-is-numa-here",
1975 }
1976
1977 result = Ns._process_flavor_params(
1978 target_flavor=target_flavor,
1979 indata=indata,
1980 vim_info=vim_info,
1981 target_record_id=target_record_id,
1982 )
1983
1984 self.assertTrue(epa_params.called)
1985 self.assertDictEqual(result, expected_result)
1986
1987 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1988 def test__process_flavor_params(
1989 self,
1990 epa_params,
1991 ):
1992 db = MagicMock(name="database mock")
1993
1994 kwargs = {
1995 "db": db,
1996 }
1997
1998 db.get_one.return_value = {
1999 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2000 "df": [
2001 {
2002 "id": "default-df",
2003 "vdu-profile": [
2004 {"id": "without_volumes-VM", "min-number-of-instances": 1}
2005 ],
2006 }
2007 ],
2008 "id": "without_volumes-vnf",
2009 "product-name": "without_volumes-vnf",
2010 "vdu": [
2011 {
2012 "id": "without_volumes-VM",
2013 "name": "without_volumes-VM",
2014 "sw-image-desc": "ubuntu20.04",
2015 "alternative-sw-image-desc": [
2016 "ubuntu20.04-aws",
2017 "ubuntu20.04-azure",
2018 ],
2019 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
2020 }
2021 ],
2022 "version": "1.0",
2023 "virtual-storage-desc": [
2024 {"id": "root-volume", "size-of-storage": "10"},
2025 {
2026 "id": "ephemeral-volume",
2027 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2028 "size-of-storage": "1",
2029 },
2030 ],
2031 "_admin": {
2032 "storage": {
2033 "fs": "mongo",
2034 "path": "/app/storage/",
2035 },
2036 "type": "vnfd",
2037 },
2038 }
2039
2040 expected_result = {
2041 "find_params": {
2042 "flavor_data": {
2043 "disk": 10,
2044 "ram": 1024,
2045 "vcpus": 2,
2046 "ephemeral": 10,
2047 "swap": 20,
2048 "extended": {
2049 "numa": "there-is-numa-here",
2050 },
2051 },
2052 },
2053 "params": {
2054 "flavor_data": {
2055 "disk": 10,
2056 "name": "test",
2057 "ram": 1024,
2058 "vcpus": 2,
2059 "ephemeral": 10,
2060 "swap": 20,
2061 "extended": {
2062 "numa": "there-is-numa-here",
2063 },
2064 },
2065 },
2066 }
2067 target_flavor = {
2068 "id": "test_id",
2069 "name": "test",
2070 "storage-gb": "10",
2071 "memory-mb": "1024",
2072 "vcpu-count": "2",
2073 }
2074 indata = {
2075 "vnf": [
2076 {
2077 "vdur": [
2078 {
2079 "ns-flavor-id": "test_id",
2080 "virtual-storages": [
2081 {
2082 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2083 "size-of-storage": "10",
2084 },
2085 {
2086 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
2087 "size-of-storage": "20",
2088 },
2089 ],
2090 },
2091 ],
2092 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2093 },
2094 ],
2095 }
2096 vim_info = {}
2097 target_record_id = ""
2098
2099 epa_params.return_value = {
2100 "numa": "there-is-numa-here",
2101 }
2102
2103 result = Ns._process_flavor_params(
2104 target_flavor=target_flavor,
2105 indata=indata,
2106 vim_info=vim_info,
2107 target_record_id=target_record_id,
2108 **kwargs,
2109 )
2110
2111 self.assertTrue(epa_params.called)
2112 self.assertDictEqual(result, expected_result)
2113
2114 def test__ip_profile_to_ro_with_none(self):
2115 ip_profile = None
2116
2117 result = Ns._ip_profile_to_ro(
2118 ip_profile=ip_profile,
2119 )
2120
2121 self.assertIsNone(result)
2122
2123 def test__ip_profile_to_ro_with_empty_profile(self):
2124 ip_profile = {}
2125
2126 result = Ns._ip_profile_to_ro(
2127 ip_profile=ip_profile,
2128 )
2129
2130 self.assertIsNone(result)
2131
2132 def test__ip_profile_to_ro_with_wrong_profile(self):
2133 ip_profile = {
2134 "no-profile": "here",
2135 }
2136 expected_result = {
2137 "ip_version": "IPv4",
2138 "subnet_address": None,
2139 "gateway_address": None,
2140 "dhcp_enabled": False,
2141 "dhcp_start_address": None,
2142 "dhcp_count": None,
2143 }
2144
2145 result = Ns._ip_profile_to_ro(
2146 ip_profile=ip_profile,
2147 )
2148
2149 self.assertDictEqual(expected_result, result)
2150
2151 def test__ip_profile_to_ro_with_ipv4_profile(self):
2152 ip_profile = {
2153 "ip-version": "ipv4",
2154 "subnet-address": "192.168.0.0/24",
2155 "gateway-address": "192.168.0.254",
2156 "dhcp-params": {
2157 "enabled": True,
2158 "start-address": "192.168.0.10",
2159 "count": 25,
2160 },
2161 }
2162 expected_result = {
2163 "ip_version": "IPv4",
2164 "subnet_address": "192.168.0.0/24",
2165 "gateway_address": "192.168.0.254",
2166 "dhcp_enabled": True,
2167 "dhcp_start_address": "192.168.0.10",
2168 "dhcp_count": 25,
2169 }
2170
2171 result = Ns._ip_profile_to_ro(
2172 ip_profile=ip_profile,
2173 )
2174
2175 self.assertDictEqual(expected_result, result)
2176
2177 def test__ip_profile_to_ro_with_ipv6_profile(self):
2178 ip_profile = {
2179 "ip-version": "ipv6",
2180 "subnet-address": "2001:0200:0001::/48",
2181 "gateway-address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
2182 "dhcp-params": {
2183 "enabled": True,
2184 "start-address": "2001:0200:0001::0010",
2185 "count": 25,
2186 },
2187 }
2188 expected_result = {
2189 "ip_version": "IPv6",
2190 "subnet_address": "2001:0200:0001::/48",
2191 "gateway_address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
2192 "dhcp_enabled": True,
2193 "dhcp_start_address": "2001:0200:0001::0010",
2194 "dhcp_count": 25,
2195 }
2196
2197 result = Ns._ip_profile_to_ro(
2198 ip_profile=ip_profile,
2199 )
2200
2201 self.assertDictEqual(expected_result, result)
2202
2203 def test__ip_profile_to_ro_with_dns_server(self):
2204 ip_profile = {
2205 "ip-version": "ipv4",
2206 "subnet-address": "192.168.0.0/24",
2207 "gateway-address": "192.168.0.254",
2208 "dhcp-params": {
2209 "enabled": True,
2210 "start-address": "192.168.0.10",
2211 "count": 25,
2212 },
2213 "dns-server": [
2214 {
2215 "address": "8.8.8.8",
2216 },
2217 {
2218 "address": "1.1.1.1",
2219 },
2220 {
2221 "address": "1.0.0.1",
2222 },
2223 ],
2224 }
2225 expected_result = {
2226 "ip_version": "IPv4",
2227 "subnet_address": "192.168.0.0/24",
2228 "gateway_address": "192.168.0.254",
2229 "dhcp_enabled": True,
2230 "dhcp_start_address": "192.168.0.10",
2231 "dhcp_count": 25,
2232 "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
2233 }
2234
2235 result = Ns._ip_profile_to_ro(
2236 ip_profile=ip_profile,
2237 )
2238
2239 self.assertDictEqual(expected_result, result)
2240
2241 def test__ip_profile_to_ro_with_security_group(self):
2242 ip_profile = {
2243 "ip-version": "ipv4",
2244 "subnet-address": "192.168.0.0/24",
2245 "gateway-address": "192.168.0.254",
2246 "dhcp-params": {
2247 "enabled": True,
2248 "start-address": "192.168.0.10",
2249 "count": 25,
2250 },
2251 "security-group": {
2252 "some-security-group": "here",
2253 },
2254 }
2255 expected_result = {
2256 "ip_version": "IPv4",
2257 "subnet_address": "192.168.0.0/24",
2258 "gateway_address": "192.168.0.254",
2259 "dhcp_enabled": True,
2260 "dhcp_start_address": "192.168.0.10",
2261 "dhcp_count": 25,
2262 "security_group": {
2263 "some-security-group": "here",
2264 },
2265 }
2266
2267 result = Ns._ip_profile_to_ro(
2268 ip_profile=ip_profile,
2269 )
2270
2271 self.assertDictEqual(expected_result, result)
2272
2273 def test__ip_profile_to_ro(self):
2274 ip_profile = {
2275 "ip-version": "ipv4",
2276 "subnet-address": "192.168.0.0/24",
2277 "gateway-address": "192.168.0.254",
2278 "dhcp-params": {
2279 "enabled": True,
2280 "start-address": "192.168.0.10",
2281 "count": 25,
2282 },
2283 "dns-server": [
2284 {
2285 "address": "8.8.8.8",
2286 },
2287 {
2288 "address": "1.1.1.1",
2289 },
2290 {
2291 "address": "1.0.0.1",
2292 },
2293 ],
2294 "security-group": {
2295 "some-security-group": "here",
2296 },
2297 }
2298 expected_result = {
2299 "ip_version": "IPv4",
2300 "subnet_address": "192.168.0.0/24",
2301 "gateway_address": "192.168.0.254",
2302 "dhcp_enabled": True,
2303 "dhcp_start_address": "192.168.0.10",
2304 "dhcp_count": 25,
2305 "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
2306 "security_group": {
2307 "some-security-group": "here",
2308 },
2309 }
2310
2311 result = Ns._ip_profile_to_ro(
2312 ip_profile=ip_profile,
2313 )
2314
2315 self.assertDictEqual(expected_result, result)
2316
2317 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2318 def test__process_net_params_with_empty_params(
2319 self,
2320 ip_profile_to_ro,
2321 ):
2322 target_vld = {
2323 "name": "vld-name",
2324 }
2325 indata = {
2326 "name": "ns-name",
2327 }
2328 vim_info = {
2329 "provider_network": "some-profile-here",
2330 }
2331 target_record_id = ""
2332 expected_result = {
2333 "params": {
2334 "net_name": "ns-name-vld-name",
2335 "net_type": "bridge",
2336 "ip_profile": {
2337 "some_ip_profile": "here",
2338 },
2339 "provider_network_profile": "some-profile-here",
2340 }
2341 }
2342
2343 ip_profile_to_ro.return_value = {
2344 "some_ip_profile": "here",
2345 }
2346
2347 result = Ns._process_net_params(
2348 target_vld=target_vld,
2349 indata=indata,
2350 vim_info=vim_info,
2351 target_record_id=target_record_id,
2352 )
2353
2354 self.assertDictEqual(expected_result, result)
2355 self.assertTrue(ip_profile_to_ro.called)
2356
2357 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2358 def test__process_net_params_with_vim_info_sdn(
2359 self,
2360 ip_profile_to_ro,
2361 ):
2362 target_vld = {
2363 "name": "vld-name",
2364 }
2365 indata = {
2366 "name": "ns-name",
2367 }
2368 vim_info = {
2369 "sdn": "some-sdn",
2370 "sdn-ports": ["some", "ports", "here"],
2371 "vlds": ["some", "vlds", "here"],
2372 "type": "sdn-type",
2373 }
2374 target_record_id = "vld.sdn.something"
2375 expected_result = {
2376 "params": {
2377 "sdn-ports": ["some", "ports", "here"],
2378 "vlds": ["some", "vlds", "here"],
2379 "type": "sdn-type",
2380 }
2381 }
2382
2383 result = Ns._process_net_params(
2384 target_vld=target_vld,
2385 indata=indata,
2386 vim_info=vim_info,
2387 target_record_id=target_record_id,
2388 )
2389
2390 self.assertDictEqual(expected_result, result)
2391 self.assertFalse(ip_profile_to_ro.called)
2392
2393 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2394 def test__process_net_params_with_vim_info_sdn_target_vim(
2395 self,
2396 ip_profile_to_ro,
2397 ):
2398 target_vld = {
2399 "name": "vld-name",
2400 }
2401 indata = {
2402 "name": "ns-name",
2403 }
2404 vim_info = {
2405 "sdn": "some-sdn",
2406 "sdn-ports": ["some", "ports", "here"],
2407 "vlds": ["some", "vlds", "here"],
2408 "target_vim": "some-vim",
2409 "type": "sdn-type",
2410 }
2411 target_record_id = "vld.sdn.something"
2412 expected_result = {
2413 "depends_on": ["some-vim vld.sdn"],
2414 "params": {
2415 "sdn-ports": ["some", "ports", "here"],
2416 "vlds": ["some", "vlds", "here"],
2417 "target_vim": "some-vim",
2418 "type": "sdn-type",
2419 },
2420 }
2421
2422 result = Ns._process_net_params(
2423 target_vld=target_vld,
2424 indata=indata,
2425 vim_info=vim_info,
2426 target_record_id=target_record_id,
2427 )
2428
2429 self.assertDictEqual(expected_result, result)
2430 self.assertFalse(ip_profile_to_ro.called)
2431
2432 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2433 def test__process_net_params_with_vim_network_name(
2434 self,
2435 ip_profile_to_ro,
2436 ):
2437 target_vld = {
2438 "name": "vld-name",
2439 }
2440 indata = {
2441 "name": "ns-name",
2442 }
2443 vim_info = {
2444 "vim_network_name": "some-network-name",
2445 }
2446 target_record_id = "vld.sdn.something"
2447 expected_result = {
2448 "find_params": {
2449 "filter_dict": {
2450 "name": "some-network-name",
2451 },
2452 },
2453 }
2454
2455 result = Ns._process_net_params(
2456 target_vld=target_vld,
2457 indata=indata,
2458 vim_info=vim_info,
2459 target_record_id=target_record_id,
2460 )
2461
2462 self.assertDictEqual(expected_result, result)
2463 self.assertFalse(ip_profile_to_ro.called)
2464
2465 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2466 def test__process_net_params_with_vim_network_id(
2467 self,
2468 ip_profile_to_ro,
2469 ):
2470 target_vld = {
2471 "name": "vld-name",
2472 }
2473 indata = {
2474 "name": "ns-name",
2475 }
2476 vim_info = {
2477 "vim_network_id": "some-network-id",
2478 }
2479 target_record_id = "vld.sdn.something"
2480 expected_result = {
2481 "find_params": {
2482 "filter_dict": {
2483 "id": "some-network-id",
2484 },
2485 },
2486 }
2487
2488 result = Ns._process_net_params(
2489 target_vld=target_vld,
2490 indata=indata,
2491 vim_info=vim_info,
2492 target_record_id=target_record_id,
2493 )
2494
2495 self.assertDictEqual(expected_result, result)
2496 self.assertFalse(ip_profile_to_ro.called)
2497
2498 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2499 def test__process_net_params_with_mgmt_network(
2500 self,
2501 ip_profile_to_ro,
2502 ):
2503 target_vld = {
2504 "id": "vld-id",
2505 "name": "vld-name",
2506 "mgmt-network": "some-mgmt-network",
2507 }
2508 indata = {
2509 "name": "ns-name",
2510 }
2511 vim_info = {}
2512 target_record_id = "vld.sdn.something"
2513 expected_result = {
2514 "find_params": {
2515 "mgmt": True,
2516 "name": "vld-id",
2517 },
2518 }
2519
2520 result = Ns._process_net_params(
2521 target_vld=target_vld,
2522 indata=indata,
2523 vim_info=vim_info,
2524 target_record_id=target_record_id,
2525 )
2526
2527 self.assertDictEqual(expected_result, result)
2528 self.assertFalse(ip_profile_to_ro.called)
2529
2530 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2531 def test__process_net_params_with_underlay_eline(
2532 self,
2533 ip_profile_to_ro,
2534 ):
2535 target_vld = {
2536 "name": "vld-name",
2537 "underlay": "some-underlay-here",
2538 "type": "ELINE",
2539 }
2540 indata = {
2541 "name": "ns-name",
2542 }
2543 vim_info = {
2544 "provider_network": "some-profile-here",
2545 }
2546 target_record_id = ""
2547 expected_result = {
2548 "params": {
2549 "ip_profile": {
2550 "some_ip_profile": "here",
2551 },
2552 "net_name": "ns-name-vld-name",
2553 "net_type": "ptp",
2554 "provider_network_profile": "some-profile-here",
2555 }
2556 }
2557
2558 ip_profile_to_ro.return_value = {
2559 "some_ip_profile": "here",
2560 }
2561
2562 result = Ns._process_net_params(
2563 target_vld=target_vld,
2564 indata=indata,
2565 vim_info=vim_info,
2566 target_record_id=target_record_id,
2567 )
2568
2569 self.assertDictEqual(expected_result, result)
2570 self.assertTrue(ip_profile_to_ro.called)
2571
2572 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2573 def test__process_net_params_with_underlay_elan(
2574 self,
2575 ip_profile_to_ro,
2576 ):
2577 target_vld = {
2578 "name": "vld-name",
2579 "underlay": "some-underlay-here",
2580 "type": "ELAN",
2581 }
2582 indata = {
2583 "name": "ns-name",
2584 }
2585 vim_info = {
2586 "provider_network": "some-profile-here",
2587 }
2588 target_record_id = ""
2589 expected_result = {
2590 "params": {
2591 "ip_profile": {
2592 "some_ip_profile": "here",
2593 },
2594 "net_name": "ns-name-vld-name",
2595 "net_type": "data",
2596 "provider_network_profile": "some-profile-here",
2597 }
2598 }
2599
2600 ip_profile_to_ro.return_value = {
2601 "some_ip_profile": "here",
2602 }
2603
2604 result = Ns._process_net_params(
2605 target_vld=target_vld,
2606 indata=indata,
2607 vim_info=vim_info,
2608 target_record_id=target_record_id,
2609 )
2610
2611 self.assertDictEqual(expected_result, result)
2612 self.assertTrue(ip_profile_to_ro.called)
2613
2614 def test__get_cloud_init_exception(self):
2615 db_mock = MagicMock(name="database mock")
2616 fs_mock = None
2617
2618 location = ""
2619
2620 with self.assertRaises(NsException):
2621 Ns._get_cloud_init(db=db_mock, fs=fs_mock, location=location)
2622
2623 def test__get_cloud_init_file_fs_exception(self):
2624 db_mock = MagicMock(name="database mock")
2625 fs_mock = None
2626
2627 location = "vnfr_id_123456:file:test_file"
2628 db_mock.get_one.return_value = {
2629 "_admin": {
2630 "storage": {
2631 "folder": "/home/osm",
2632 "pkg-dir": "vnfr_test_dir",
2633 },
2634 },
2635 }
2636
2637 with self.assertRaises(NsException):
2638 Ns._get_cloud_init(db=db_mock, fs=fs_mock, location=location)
2639
2640 def test__get_cloud_init_file(self):
2641 db_mock = MagicMock(name="database mock")
2642 fs_mock = MagicMock(name="filesystem mock")
2643 file_mock = MagicMock(name="file mock")
2644
2645 location = "vnfr_id_123456:file:test_file"
2646 cloud_init_content = "this is a cloud init file content"
2647
2648 db_mock.get_one.return_value = {
2649 "_admin": {
2650 "storage": {
2651 "folder": "/home/osm",
2652 "pkg-dir": "vnfr_test_dir",
2653 },
2654 },
2655 }
2656 fs_mock.file_open.return_value = file_mock
2657 file_mock.__enter__.return_value.read.return_value = cloud_init_content
2658
2659 result = Ns._get_cloud_init(db=db_mock, fs=fs_mock, location=location)
2660
2661 self.assertEqual(cloud_init_content, result)
2662
2663 def test__get_cloud_init_vdu(self):
2664 db_mock = MagicMock(name="database mock")
2665 fs_mock = None
2666
2667 location = "vnfr_id_123456:vdu:0"
2668 cloud_init_content = "this is a cloud init file content"
2669
2670 db_mock.get_one.return_value = {
2671 "vdu": {
2672 0: {
2673 "cloud-init": cloud_init_content,
2674 },
2675 },
2676 }
2677
2678 result = Ns._get_cloud_init(db=db_mock, fs=fs_mock, location=location)
2679
2680 self.assertEqual(cloud_init_content, result)
2681
2682 @patch("jinja2.Environment.__init__")
2683 def test__parse_jinja2_undefined_error(self, env_mock: Mock):
2684 cloud_init_content = None
2685 params = None
2686 context = None
2687
2688 env_mock.side_effect = UndefinedError("UndefinedError occurred.")
2689
2690 with self.assertRaises(NsException):
2691 Ns._parse_jinja2(
2692 cloud_init_content=cloud_init_content, params=params, context=context
2693 )
2694
2695 @patch("jinja2.Environment.__init__")
2696 def test__parse_jinja2_template_error(self, env_mock: Mock):
2697 cloud_init_content = None
2698 params = None
2699 context = None
2700
2701 env_mock.side_effect = TemplateError("TemplateError occurred.")
2702
2703 with self.assertRaises(NsException):
2704 Ns._parse_jinja2(
2705 cloud_init_content=cloud_init_content, params=params, context=context
2706 )
2707
2708 @patch("jinja2.Environment.__init__")
2709 def test__parse_jinja2_template_not_found(self, env_mock: Mock):
2710 cloud_init_content = None
2711 params = None
2712 context = None
2713
2714 env_mock.side_effect = TemplateNotFound("TemplateNotFound occurred.")
2715
2716 with self.assertRaises(NsException):
2717 Ns._parse_jinja2(
2718 cloud_init_content=cloud_init_content, params=params, context=context
2719 )
2720
2721 def test_rendering_jinja2_temp_without_special_characters(self):
2722 cloud_init_content = """
2723 disk_setup:
2724 ephemeral0:
2725 table_type: {{type}}
2726 layout: True
2727 overwrite: {{is_override}}
2728 runcmd:
2729 - [ ls, -l, / ]
2730 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2731 """
2732 params = {
2733 "type": "mbr",
2734 "is_override": "False",
2735 "command": "; mkdir abc",
2736 }
2737 context = "cloud-init for VM"
2738 expected_result = """
2739 disk_setup:
2740 ephemeral0:
2741 table_type: mbr
2742 layout: True
2743 overwrite: False
2744 runcmd:
2745 - [ ls, -l, / ]
2746 - [ sh, -xc, "echo $(date) '; mkdir abc'" ]
2747 """
2748 result = Ns._parse_jinja2(
2749 cloud_init_content=cloud_init_content, params=params, context=context
2750 )
2751 self.assertEqual(result, expected_result)
2752
2753 def test_rendering_jinja2_temp_with_special_characters(self):
2754 cloud_init_content = """
2755 disk_setup:
2756 ephemeral0:
2757 table_type: {{type}}
2758 layout: True
2759 overwrite: {{is_override}}
2760 runcmd:
2761 - [ ls, -l, / ]
2762 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2763 """
2764 params = {
2765 "type": "mbr",
2766 "is_override": "False",
2767 "command": "& rm -rf",
2768 }
2769 context = "cloud-init for VM"
2770 expected_result = """
2771 disk_setup:
2772 ephemeral0:
2773 table_type: mbr
2774 layout: True
2775 overwrite: False
2776 runcmd:
2777 - [ ls, -l, / ]
2778 - [ sh, -xc, "echo $(date) '& rm -rf /'" ]
2779 """
2780 result = Ns._parse_jinja2(
2781 cloud_init_content=cloud_init_content, params=params, context=context
2782 )
2783 self.assertNotEqual(result, expected_result)
2784
2785 def test_rendering_jinja2_temp_with_special_characters_autoescape_is_false(self):
2786 with patch("osm_ng_ro.ns.Environment") as mock_environment:
2787 mock_environment.return_value = Environment(
2788 undefined=StrictUndefined,
2789 autoescape=select_autoescape(default_for_string=False, default=False),
2790 )
2791 cloud_init_content = """
2792 disk_setup:
2793 ephemeral0:
2794 table_type: {{type}}
2795 layout: True
2796 overwrite: {{is_override}}
2797 runcmd:
2798 - [ ls, -l, / ]
2799 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2800 """
2801 params = {
2802 "type": "mbr",
2803 "is_override": "False",
2804 "command": "& rm -rf /",
2805 }
2806 context = "cloud-init for VM"
2807 expected_result = """
2808 disk_setup:
2809 ephemeral0:
2810 table_type: mbr
2811 layout: True
2812 overwrite: False
2813 runcmd:
2814 - [ ls, -l, / ]
2815 - [ sh, -xc, "echo $(date) '& rm -rf /'" ]
2816 """
2817 result = Ns._parse_jinja2(
2818 cloud_init_content=cloud_init_content,
2819 params=params,
2820 context=context,
2821 )
2822 self.assertEqual(result, expected_result)
2823
2824 def test__process_vdu_params_empty_kargs(self):
2825 pass
2826
2827 def test__process_vdu_params_interface_ns_vld_id(self):
2828 pass
2829
2830 def test__process_vdu_params_interface_vnf_vld_id(self):
2831 pass
2832
2833 def test__process_vdu_params_interface_unknown(self):
2834 pass
2835
2836 def test__process_vdu_params_interface_port_security_enabled(self):
2837 pass
2838
2839 def test__process_vdu_params_interface_port_security_disable_strategy(self):
2840 pass
2841
2842 def test__process_vdu_params_interface_sriov(self):
2843 pass
2844
2845 def test__process_vdu_params_interface_pci_passthrough(self):
2846 pass
2847
2848 def test__process_vdu_params_interface_om_mgmt(self):
2849 pass
2850
2851 def test__process_vdu_params_interface_mgmt_interface(self):
2852 pass
2853
2854 def test__process_vdu_params_interface_mgmt_vnf(self):
2855 pass
2856
2857 def test__process_vdu_params_interface_bridge(self):
2858 pass
2859
2860 def test__process_vdu_params_interface_ip_address(self):
2861 pass
2862
2863 def test__process_vdu_params_interface_mac_address(self):
2864 pass
2865
2866 def test__process_vdu_params_vdu_cloud_init_missing(self):
2867 pass
2868
2869 def test__process_vdu_params_vdu_cloud_init_present(self):
2870 pass
2871
2872 def test__process_vdu_params_vdu_boot_data_drive(self):
2873 pass
2874
2875 def test__process_vdu_params_vdu_ssh_keys(self):
2876 pass
2877
2878 def test__process_vdu_params_vdu_ssh_access_required(self):
2879 pass
2880
2881 @patch("osm_ng_ro.ns.Ns._get_cloud_init")
2882 @patch("osm_ng_ro.ns.Ns._parse_jinja2")
2883 def test__process_vdu_params_vdu_persistent_root_volume(
2884 self, get_cloud_init, parse_jinja2
2885 ):
2886 db = MagicMock(name="database mock")
2887 kwargs = {
2888 "db": db,
2889 "vdu2cloud_init": {},
2890 "vnfr": {
2891 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2892 "member-vnf-index-ref": "vnf-several-volumes",
2893 },
2894 }
2895 get_cloud_init.return_value = {}
2896 parse_jinja2.return_value = {}
2897 db.get_one.return_value = {
2898 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2899 "df": [
2900 {
2901 "id": "default-df",
2902 "vdu-profile": [
2903 {"id": "several_volumes-VM", "min-number-of-instances": 1}
2904 ],
2905 }
2906 ],
2907 "id": "several_volumes-vnf",
2908 "product-name": "several_volumes-vnf",
2909 "vdu": [
2910 {
2911 "id": "several_volumes-VM",
2912 "name": "several_volumes-VM",
2913 "sw-image-desc": "ubuntu20.04",
2914 "alternative-sw-image-desc": [
2915 "ubuntu20.04-aws",
2916 "ubuntu20.04-azure",
2917 ],
2918 "virtual-storage-desc": [
2919 "persistent-root-volume",
2920 "persistent-volume2",
2921 "ephemeral-volume",
2922 ],
2923 }
2924 ],
2925 "version": "1.0",
2926 "virtual-storage-desc": [
2927 {
2928 "id": "persistent-volume2",
2929 "type-of-storage": "persistent-storage:persistent-storage",
2930 "size-of-storage": "10",
2931 },
2932 {
2933 "id": "persistent-root-volume",
2934 "type-of-storage": "persistent-storage:persistent-storage",
2935 "size-of-storage": "10",
2936 },
2937 {
2938 "id": "ephemeral-volume",
2939 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2940 "size-of-storage": "1",
2941 },
2942 ],
2943 "_admin": {
2944 "storage": {
2945 "fs": "mongo",
2946 "path": "/app/storage/",
2947 },
2948 "type": "vnfd",
2949 },
2950 }
2951
2952 target_vdu = {
2953 "_id": "09a0baa7-b7cb-4924-bd63-9f04a1c23960",
2954 "ns-flavor-id": "0",
2955 "ns-image-id": "0",
2956 "vdu-name": "several_volumes-VM",
2957 "interfaces": [
2958 {
2959 "name": "vdu-eth0",
2960 "ns-vld-id": "mgmtnet",
2961 }
2962 ],
2963 "virtual-storages": [
2964 {
2965 "id": "persistent-volume2",
2966 "size-of-storage": "10",
2967 "type-of-storage": "persistent-storage:persistent-storage",
2968 },
2969 {
2970 "id": "persistent-root-volume",
2971 "size-of-storage": "10",
2972 "type-of-storage": "persistent-storage:persistent-storage",
2973 },
2974 {
2975 "id": "ephemeral-volume",
2976 "size-of-storage": "1",
2977 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2978 },
2979 ],
2980 }
2981 indata = {
2982 "name": "sample_name",
2983 }
2984 expected_result = [{"image_id": "ubuntu20.04", "size": "10"}, {"size": "10"}]
2985 result = Ns._process_vdu_params(
2986 target_vdu, indata, vim_info=None, target_record_id=None, **kwargs
2987 )
2988 self.assertEqual(
2989 expected_result, result["params"]["disk_list"], "Wrong Disk List"
2990 )
2991
2992 @patch("osm_ng_ro.ns.Ns._get_cloud_init")
2993 @patch("osm_ng_ro.ns.Ns._parse_jinja2")
2994 def test__process_vdu_params_vdu_without_persistent_storage(
2995 self, get_cloud_init, parse_jinja2
2996 ):
2997 db = MagicMock(name="database mock")
2998 kwargs = {
2999 "db": db,
3000 "vdu2cloud_init": {},
3001 "vnfr": {
3002 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
3003 "member-vnf-index-ref": "vnf-several-volumes",
3004 },
3005 }
3006 get_cloud_init.return_value = {}
3007 parse_jinja2.return_value = {}
3008 db.get_one.return_value = {
3009 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
3010 "df": [
3011 {
3012 "id": "default-df",
3013 "vdu-profile": [
3014 {"id": "without_volumes-VM", "min-number-of-instances": 1}
3015 ],
3016 }
3017 ],
3018 "id": "without_volumes-vnf",
3019 "product-name": "without_volumes-vnf",
3020 "vdu": [
3021 {
3022 "id": "without_volumes-VM",
3023 "name": "without_volumes-VM",
3024 "sw-image-desc": "ubuntu20.04",
3025 "alternative-sw-image-desc": [
3026 "ubuntu20.04-aws",
3027 "ubuntu20.04-azure",
3028 ],
3029 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
3030 }
3031 ],
3032 "version": "1.0",
3033 "virtual-storage-desc": [
3034 {"id": "root-volume", "size-of-storage": "10"},
3035 {
3036 "id": "ephemeral-volume",
3037 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
3038 "size-of-storage": "1",
3039 },
3040 ],
3041 "_admin": {
3042 "storage": {
3043 "fs": "mongo",
3044 "path": "/app/storage/",
3045 },
3046 "type": "vnfd",
3047 },
3048 }
3049
3050 target_vdu = {
3051 "_id": "09a0baa7-b7cb-4924-bd63-9f04a1c23960",
3052 "ns-flavor-id": "0",
3053 "ns-image-id": "0",
3054 "vdu-name": "without_volumes-VM",
3055 "interfaces": [
3056 {
3057 "name": "vdu-eth0",
3058 "ns-vld-id": "mgmtnet",
3059 }
3060 ],
3061 "virtual-storages": [
3062 {
3063 "id": "root-volume",
3064 "size-of-storage": "10",
3065 },
3066 {
3067 "id": "ephemeral-volume",
3068 "size-of-storage": "1",
3069 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
3070 },
3071 ],
3072 }
3073 indata = {
3074 "name": "sample_name",
3075 }
3076 expected_result = []
3077 result = Ns._process_vdu_params(
3078 target_vdu, indata, vim_info=None, target_record_id=None, **kwargs
3079 )
3080 self.assertEqual(
3081 expected_result, result["params"]["disk_list"], "Wrong Disk List"
3082 )
3083
3084 def test__process_vdu_params(self):
3085 pass
3086
3087 @patch("osm_ng_ro.ns.Ns._assign_vim")
3088 def test__rebuild_start_stop_task(self, assign_vim):
3089 self.ns = Ns()
3090 extra_dict = {}
3091 actions = ["start", "stop", "rebuild"]
3092 vdu_id = "bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3093 vnf_id = "665b4165-ce24-4320-bf19-b9a45bade49f"
3094 vdu_index = "0"
3095 action_id = "bb937f49-3870-4169-b758-9732e1ff40f3"
3096 nsr_id = "993166fe-723e-4680-ac4b-b1af2541ae31"
3097 task_index = 0
3098 target_vim = "vim:f9f370ac-0d44-41a7-9000-457f2332bc35"
3099 t = "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3100 for action in actions:
3101 expected_result = {
3102 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3103 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3104 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3105 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:0",
3106 "status": "SCHEDULED",
3107 "action": "EXEC",
3108 "item": "update",
3109 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.0",
3110 "target_record_id": t,
3111 "params": {
3112 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3113 "action": action,
3114 },
3115 }
3116 extra_dict["params"] = {
3117 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3118 "action": action,
3119 }
3120 task = self.ns.rebuild_start_stop_task(
3121 vdu_id,
3122 vnf_id,
3123 vdu_index,
3124 action_id,
3125 nsr_id,
3126 task_index,
3127 target_vim,
3128 extra_dict,
3129 )
3130 self.assertEqual(task.get("action_id"), action_id)
3131 self.assertEqual(task.get("nsr_id"), nsr_id)
3132 self.assertEqual(task.get("target_id"), target_vim)
3133 self.assertDictEqual(task, expected_result)
3134
3135 @patch("osm_ng_ro.ns.Ns._assign_vim")
3136 def test_verticalscale_task(self, assign_vim):
3137 self.ns = Ns()
3138 extra_dict = {}
3139 vdu_index = "1"
3140 action_id = "bb937f49-3870-4169-b758-9732e1ff40f3"
3141 nsr_id = "993166fe-723e-4680-ac4b-b1af2541ae31"
3142 task_index = 1
3143 target_record_id = (
3144 "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
3145 "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3146 )
3147
3148 expected_result = {
3149 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3150 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3151 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3152 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1",
3153 "status": "SCHEDULED",
3154 "action": "EXEC",
3155 "item": "verticalscale",
3156 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1",
3157 "target_record_id": target_record_id,
3158 "params": {
3159 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3160 "flavor_dict": "flavor_dict",
3161 },
3162 }
3163 vdu = {
3164 "id": "bb9c43f9-10a2-4569-a8a8-957c3528b6d1",
3165 "vim_info": {
3166 "vim:f9f370ac-0d44-41a7-9000-457f2332bc35": {"interfaces": []}
3167 },
3168 }
3169 vnf = {"_id": "665b4165-ce24-4320-bf19-b9a45bade49f"}
3170 extra_dict["params"] = {
3171 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3172 "flavor_dict": "flavor_dict",
3173 }
3174 task = self.ns.verticalscale_task(
3175 vdu, vnf, vdu_index, action_id, nsr_id, task_index, extra_dict
3176 )
3177
3178 self.assertDictEqual(task, expected_result)
3179
3180 @patch("osm_ng_ro.ns.Ns._assign_vim")
3181 def test_migrate_task(self, assign_vim):
3182 self.ns = Ns()
3183 extra_dict = {}
3184 vdu_index = "1"
3185 action_id = "bb937f49-3870-4169-b758-9732e1ff40f3"
3186 nsr_id = "993166fe-723e-4680-ac4b-b1af2541ae31"
3187 task_index = 1
3188 target_record_id = (
3189 "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
3190 "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3191 )
3192
3193 expected_result = {
3194 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3195 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3196 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3197 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1",
3198 "status": "SCHEDULED",
3199 "action": "EXEC",
3200 "item": "migrate",
3201 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1",
3202 "target_record_id": target_record_id,
3203 "params": {
3204 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3205 "migrate_host": "migrateToHost",
3206 },
3207 }
3208 vdu = {
3209 "id": "bb9c43f9-10a2-4569-a8a8-957c3528b6d1",
3210 "vim_info": {
3211 "vim:f9f370ac-0d44-41a7-9000-457f2332bc35": {"interfaces": []}
3212 },
3213 }
3214 vnf = {"_id": "665b4165-ce24-4320-bf19-b9a45bade49f"}
3215 extra_dict["params"] = {
3216 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3217 "migrate_host": "migrateToHost",
3218 }
3219 task = self.ns.migrate_task(
3220 vdu, vnf, vdu_index, action_id, nsr_id, task_index, extra_dict
3221 )
3222
3223 self.assertDictEqual(task, expected_result)