6cc5f778c65bb0a76c1b980903c4c77cf8226298
[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 patch, Mock
20
21 from osm_ng_ro.ns import Ns
22
23
24 __author__ = "Eduardo Sousa"
25 __date__ = "$19-NOV-2021 00:00:00$"
26
27
28 class TestNs(unittest.TestCase):
29 def setUp(self):
30 pass
31
32 def test__create_task_without_extra_dict(self):
33 expected_result = {
34 "target_id": "vim_openstack_1",
35 "action_id": "123456",
36 "nsr_id": "654321",
37 "task_id": "123456:1",
38 "status": "SCHEDULED",
39 "action": "CREATE",
40 "item": "test_item",
41 "target_record": "test_target_record",
42 "target_record_id": "test_target_record_id",
43 }
44 deployment_info = {
45 "action_id": "123456",
46 "nsr_id": "654321",
47 "task_index": 1,
48 }
49
50 task = Ns._create_task(
51 deployment_info=deployment_info,
52 target_id="vim_openstack_1",
53 item="test_item",
54 action="CREATE",
55 target_record="test_target_record",
56 target_record_id="test_target_record_id",
57 )
58
59 self.assertEqual(deployment_info.get("task_index"), 2)
60 self.assertDictEqual(task, expected_result)
61
62 def test__create_task(self):
63 expected_result = {
64 "target_id": "vim_openstack_1",
65 "action_id": "123456",
66 "nsr_id": "654321",
67 "task_id": "123456:1",
68 "status": "SCHEDULED",
69 "action": "CREATE",
70 "item": "test_item",
71 "target_record": "test_target_record",
72 "target_record_id": "test_target_record_id",
73 # values coming from extra_dict
74 "params": "test_params",
75 "find_params": "test_find_params",
76 "depends_on": "test_depends_on",
77 }
78 deployment_info = {
79 "action_id": "123456",
80 "nsr_id": "654321",
81 "task_index": 1,
82 }
83
84 task = Ns._create_task(
85 deployment_info=deployment_info,
86 target_id="vim_openstack_1",
87 item="test_item",
88 action="CREATE",
89 target_record="test_target_record",
90 target_record_id="test_target_record_id",
91 extra_dict={
92 "params": "test_params",
93 "find_params": "test_find_params",
94 "depends_on": "test_depends_on",
95 },
96 )
97
98 self.assertEqual(deployment_info.get("task_index"), 2)
99 self.assertDictEqual(task, expected_result)
100
101 @patch("osm_ng_ro.ns.time")
102 def test__create_ro_task(self, mock_time: Mock):
103 now = 1637324838.994551
104 mock_time.return_value = now
105 task = {
106 "target_id": "vim_openstack_1",
107 "action_id": "123456",
108 "nsr_id": "654321",
109 "task_id": "123456:1",
110 "status": "SCHEDULED",
111 "action": "CREATE",
112 "item": "test_item",
113 "target_record": "test_target_record",
114 "target_record_id": "test_target_record_id",
115 # values coming from extra_dict
116 "params": "test_params",
117 "find_params": "test_find_params",
118 "depends_on": "test_depends_on",
119 }
120 expected_result = {
121 "_id": "123456:1",
122 "locked_by": None,
123 "locked_at": 0.0,
124 "target_id": "vim_openstack_1",
125 "vim_info": {
126 "created": False,
127 "created_items": None,
128 "vim_id": None,
129 "vim_name": None,
130 "vim_status": None,
131 "vim_details": None,
132 "refresh_at": None,
133 },
134 "modified_at": now,
135 "created_at": now,
136 "to_check_at": now,
137 "tasks": [task],
138 }
139
140 ro_task = Ns._create_ro_task(
141 target_id="vim_openstack_1",
142 task=task,
143 )
144
145 self.assertDictEqual(ro_task, expected_result)
146
147 def test__process_image_params_with_empty_target_image(self):
148 expected_result = {
149 "find_params": {},
150 }
151 target_image = {}
152
153 result = Ns._process_image_params(
154 target_image=target_image,
155 indata=None,
156 vim_info=None,
157 target_record_id=None,
158 )
159
160 self.assertDictEqual(expected_result, result)
161
162 def test__process_image_params_with_wrong_target_image(self):
163 expected_result = {
164 "find_params": {},
165 }
166 target_image = {
167 "no_image": "to_see_here",
168 }
169
170 result = Ns._process_image_params(
171 target_image=target_image,
172 indata=None,
173 vim_info=None,
174 target_record_id=None,
175 )
176
177 self.assertDictEqual(expected_result, result)
178
179 def test__process_image_params_with_image(self):
180 expected_result = {
181 "find_params": {
182 "filter_dict": {
183 "name": "cirros",
184 },
185 },
186 }
187 target_image = {
188 "image": "cirros",
189 }
190
191 result = Ns._process_image_params(
192 target_image=target_image,
193 indata=None,
194 vim_info=None,
195 target_record_id=None,
196 )
197
198 self.assertDictEqual(expected_result, result)
199
200 def test__process_image_params_with_vim_image_id(self):
201 expected_result = {
202 "find_params": {
203 "filter_dict": {
204 "id": "123456",
205 },
206 },
207 }
208 target_image = {
209 "vim_image_id": "123456",
210 }
211
212 result = Ns._process_image_params(
213 target_image=target_image,
214 indata=None,
215 vim_info=None,
216 target_record_id=None,
217 )
218
219 self.assertDictEqual(expected_result, result)
220
221 def test__process_image_params_with_image_checksum(self):
222 expected_result = {
223 "find_params": {
224 "filter_dict": {
225 "checksum": "e3fc50a88d0a364313df4b21ef20c29e",
226 },
227 },
228 }
229 target_image = {
230 "image_checksum": "e3fc50a88d0a364313df4b21ef20c29e",
231 }
232
233 result = Ns._process_image_params(
234 target_image=target_image,
235 indata=None,
236 vim_info=None,
237 target_record_id=None,
238 )
239
240 self.assertDictEqual(expected_result, result)
241
242 def test__get_resource_allocation_params_with_empty_target_image(self):
243 expected_result = {}
244 quota_descriptor = {}
245
246 result = Ns._get_resource_allocation_params(
247 quota_descriptor=quota_descriptor,
248 )
249
250 self.assertDictEqual(expected_result, result)
251
252 def test__get_resource_allocation_params_with_wrong_target_image(self):
253 expected_result = {}
254 quota_descriptor = {
255 "no_quota": "present_here",
256 }
257
258 result = Ns._get_resource_allocation_params(
259 quota_descriptor=quota_descriptor,
260 )
261
262 self.assertDictEqual(expected_result, result)
263
264 def test__get_resource_allocation_params_with_limit(self):
265 expected_result = {
266 "limit": 10,
267 }
268 quota_descriptor = {
269 "limit": "10",
270 }
271
272 result = Ns._get_resource_allocation_params(
273 quota_descriptor=quota_descriptor,
274 )
275
276 self.assertDictEqual(expected_result, result)
277
278 def test__get_resource_allocation_params_with_reserve(self):
279 expected_result = {
280 "reserve": 20,
281 }
282 quota_descriptor = {
283 "reserve": "20",
284 }
285
286 result = Ns._get_resource_allocation_params(
287 quota_descriptor=quota_descriptor,
288 )
289
290 self.assertDictEqual(expected_result, result)
291
292 def test__get_resource_allocation_params_with_shares(self):
293 expected_result = {
294 "shares": 30,
295 }
296 quota_descriptor = {
297 "shares": "30",
298 }
299
300 result = Ns._get_resource_allocation_params(
301 quota_descriptor=quota_descriptor,
302 )
303
304 self.assertDictEqual(expected_result, result)
305
306 def test__get_resource_allocation_params(self):
307 expected_result = {
308 "limit": 10,
309 "reserve": 20,
310 "shares": 30,
311 }
312 quota_descriptor = {
313 "limit": "10",
314 "reserve": "20",
315 "shares": "30",
316 }
317
318 result = Ns._get_resource_allocation_params(
319 quota_descriptor=quota_descriptor,
320 )
321
322 self.assertDictEqual(expected_result, result)
323
324 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
325 def test__process_guest_epa_quota_params_with_empty_quota_epa_cpu(
326 self,
327 resource_allocation,
328 ):
329 expected_result = {}
330 guest_epa_quota = {}
331 epa_vcpu_set = True
332
333 result = Ns._process_guest_epa_quota_params(
334 guest_epa_quota=guest_epa_quota,
335 epa_vcpu_set=epa_vcpu_set,
336 )
337
338 self.assertDictEqual(expected_result, result)
339 self.assertFalse(resource_allocation.called)
340
341 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
342 def test__process_guest_epa_quota_params_with_empty_quota_false_epa_cpu(
343 self,
344 resource_allocation,
345 ):
346 expected_result = {}
347 guest_epa_quota = {}
348 epa_vcpu_set = False
349
350 result = Ns._process_guest_epa_quota_params(
351 guest_epa_quota=guest_epa_quota,
352 epa_vcpu_set=epa_vcpu_set,
353 )
354
355 self.assertDictEqual(expected_result, result)
356 self.assertFalse(resource_allocation.called)
357
358 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
359 def test__process_guest_epa_quota_params_with_wrong_quota_epa_cpu(
360 self,
361 resource_allocation,
362 ):
363 expected_result = {}
364 guest_epa_quota = {
365 "no-quota": "nothing",
366 }
367 epa_vcpu_set = True
368
369 result = Ns._process_guest_epa_quota_params(
370 guest_epa_quota=guest_epa_quota,
371 epa_vcpu_set=epa_vcpu_set,
372 )
373
374 self.assertDictEqual(expected_result, result)
375 self.assertFalse(resource_allocation.called)
376
377 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
378 def test__process_guest_epa_quota_params_with_wrong_quota_false_epa_cpu(
379 self,
380 resource_allocation,
381 ):
382 expected_result = {}
383 guest_epa_quota = {
384 "no-quota": "nothing",
385 }
386 epa_vcpu_set = False
387
388 result = Ns._process_guest_epa_quota_params(
389 guest_epa_quota=guest_epa_quota,
390 epa_vcpu_set=epa_vcpu_set,
391 )
392
393 self.assertDictEqual(expected_result, result)
394 self.assertFalse(resource_allocation.called)
395
396 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
397 def test__process_guest_epa_quota_params_with_cpu_quota_epa_cpu(
398 self,
399 resource_allocation,
400 ):
401 expected_result = {}
402 guest_epa_quota = {
403 "cpu-quota": {
404 "limit": "10",
405 "reserve": "20",
406 "shares": "30",
407 },
408 }
409 epa_vcpu_set = True
410
411 result = Ns._process_guest_epa_quota_params(
412 guest_epa_quota=guest_epa_quota,
413 epa_vcpu_set=epa_vcpu_set,
414 )
415
416 self.assertDictEqual(expected_result, result)
417 self.assertFalse(resource_allocation.called)
418
419 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
420 def test__process_guest_epa_quota_params_with_cpu_quota_false_epa_cpu(
421 self,
422 resource_allocation,
423 ):
424 expected_result = {
425 "cpu-quota": {
426 "limit": 10,
427 "reserve": 20,
428 "shares": 30,
429 },
430 }
431 guest_epa_quota = {
432 "cpu-quota": {
433 "limit": "10",
434 "reserve": "20",
435 "shares": "30",
436 },
437 }
438 epa_vcpu_set = False
439
440 resource_allocation_param = {
441 "limit": "10",
442 "reserve": "20",
443 "shares": "30",
444 }
445 resource_allocation.return_value = {
446 "limit": 10,
447 "reserve": 20,
448 "shares": 30,
449 }
450
451 result = Ns._process_guest_epa_quota_params(
452 guest_epa_quota=guest_epa_quota,
453 epa_vcpu_set=epa_vcpu_set,
454 )
455
456 resource_allocation.assert_called_once_with(resource_allocation_param)
457 self.assertDictEqual(expected_result, result)
458
459 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
460 def test__process_guest_epa_quota_params_with_mem_quota_epa_cpu(
461 self,
462 resource_allocation,
463 ):
464 expected_result = {
465 "mem-quota": {
466 "limit": 10,
467 "reserve": 20,
468 "shares": 30,
469 },
470 }
471 guest_epa_quota = {
472 "mem-quota": {
473 "limit": "10",
474 "reserve": "20",
475 "shares": "30",
476 },
477 }
478 epa_vcpu_set = True
479
480 resource_allocation_param = {
481 "limit": "10",
482 "reserve": "20",
483 "shares": "30",
484 }
485 resource_allocation.return_value = {
486 "limit": 10,
487 "reserve": 20,
488 "shares": 30,
489 }
490
491 result = Ns._process_guest_epa_quota_params(
492 guest_epa_quota=guest_epa_quota,
493 epa_vcpu_set=epa_vcpu_set,
494 )
495
496 resource_allocation.assert_called_once_with(resource_allocation_param)
497 self.assertDictEqual(expected_result, result)
498
499 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
500 def test__process_guest_epa_quota_params_with_mem_quota_false_epa_cpu(
501 self,
502 resource_allocation,
503 ):
504 expected_result = {
505 "mem-quota": {
506 "limit": 10,
507 "reserve": 20,
508 "shares": 30,
509 },
510 }
511 guest_epa_quota = {
512 "mem-quota": {
513 "limit": "10",
514 "reserve": "20",
515 "shares": "30",
516 },
517 }
518 epa_vcpu_set = False
519
520 resource_allocation_param = {
521 "limit": "10",
522 "reserve": "20",
523 "shares": "30",
524 }
525 resource_allocation.return_value = {
526 "limit": 10,
527 "reserve": 20,
528 "shares": 30,
529 }
530
531 result = Ns._process_guest_epa_quota_params(
532 guest_epa_quota=guest_epa_quota,
533 epa_vcpu_set=epa_vcpu_set,
534 )
535
536 resource_allocation.assert_called_once_with(resource_allocation_param)
537 self.assertDictEqual(expected_result, result)
538
539 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
540 def test__process_guest_epa_quota_params_with_disk_io_quota_epa_cpu(
541 self,
542 resource_allocation,
543 ):
544 expected_result = {
545 "disk-io-quota": {
546 "limit": 10,
547 "reserve": 20,
548 "shares": 30,
549 },
550 }
551 guest_epa_quota = {
552 "disk-io-quota": {
553 "limit": "10",
554 "reserve": "20",
555 "shares": "30",
556 },
557 }
558 epa_vcpu_set = True
559
560 resource_allocation_param = {
561 "limit": "10",
562 "reserve": "20",
563 "shares": "30",
564 }
565 resource_allocation.return_value = {
566 "limit": 10,
567 "reserve": 20,
568 "shares": 30,
569 }
570
571 result = Ns._process_guest_epa_quota_params(
572 guest_epa_quota=guest_epa_quota,
573 epa_vcpu_set=epa_vcpu_set,
574 )
575
576 resource_allocation.assert_called_once_with(resource_allocation_param)
577 self.assertDictEqual(expected_result, result)
578
579 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
580 def test__process_guest_epa_quota_params_with_disk_io_quota_false_epa_cpu(
581 self,
582 resource_allocation,
583 ):
584 expected_result = {
585 "disk-io-quota": {
586 "limit": 10,
587 "reserve": 20,
588 "shares": 30,
589 },
590 }
591 guest_epa_quota = {
592 "disk-io-quota": {
593 "limit": "10",
594 "reserve": "20",
595 "shares": "30",
596 },
597 }
598 epa_vcpu_set = False
599
600 resource_allocation_param = {
601 "limit": "10",
602 "reserve": "20",
603 "shares": "30",
604 }
605 resource_allocation.return_value = {
606 "limit": 10,
607 "reserve": 20,
608 "shares": 30,
609 }
610
611 result = Ns._process_guest_epa_quota_params(
612 guest_epa_quota=guest_epa_quota,
613 epa_vcpu_set=epa_vcpu_set,
614 )
615
616 resource_allocation.assert_called_once_with(resource_allocation_param)
617 self.assertDictEqual(expected_result, result)
618
619 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
620 def test__process_guest_epa_quota_params_with_vif_quota_epa_cpu(
621 self,
622 resource_allocation,
623 ):
624 expected_result = {
625 "vif-quota": {
626 "limit": 10,
627 "reserve": 20,
628 "shares": 30,
629 },
630 }
631 guest_epa_quota = {
632 "vif-quota": {
633 "limit": "10",
634 "reserve": "20",
635 "shares": "30",
636 },
637 }
638 epa_vcpu_set = True
639
640 resource_allocation_param = {
641 "limit": "10",
642 "reserve": "20",
643 "shares": "30",
644 }
645 resource_allocation.return_value = {
646 "limit": 10,
647 "reserve": 20,
648 "shares": 30,
649 }
650
651 result = Ns._process_guest_epa_quota_params(
652 guest_epa_quota=guest_epa_quota,
653 epa_vcpu_set=epa_vcpu_set,
654 )
655
656 resource_allocation.assert_called_once_with(resource_allocation_param)
657 self.assertDictEqual(expected_result, result)
658
659 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
660 def test__process_guest_epa_quota_params_with_vif_quota_false_epa_cpu(
661 self,
662 resource_allocation,
663 ):
664 expected_result = {
665 "vif-quota": {
666 "limit": 10,
667 "reserve": 20,
668 "shares": 30,
669 },
670 }
671 guest_epa_quota = {
672 "vif-quota": {
673 "limit": "10",
674 "reserve": "20",
675 "shares": "30",
676 },
677 }
678 epa_vcpu_set = False
679
680 resource_allocation_param = {
681 "limit": "10",
682 "reserve": "20",
683 "shares": "30",
684 }
685 resource_allocation.return_value = {
686 "limit": 10,
687 "reserve": 20,
688 "shares": 30,
689 }
690
691 result = Ns._process_guest_epa_quota_params(
692 guest_epa_quota=guest_epa_quota,
693 epa_vcpu_set=epa_vcpu_set,
694 )
695
696 resource_allocation.assert_called_once_with(resource_allocation_param)
697 self.assertDictEqual(expected_result, result)
698
699 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
700 def test__process_guest_epa_quota_params_with_quota_epa_cpu(
701 self,
702 resource_allocation,
703 ):
704 expected_result = {
705 "mem-quota": {
706 "limit": 10,
707 "reserve": 20,
708 "shares": 30,
709 },
710 "disk-io-quota": {
711 "limit": 10,
712 "reserve": 20,
713 "shares": 30,
714 },
715 "vif-quota": {
716 "limit": 10,
717 "reserve": 20,
718 "shares": 30,
719 },
720 }
721 guest_epa_quota = {
722 "cpu-quota": {
723 "limit": "10",
724 "reserve": "20",
725 "shares": "30",
726 },
727 "mem-quota": {
728 "limit": "10",
729 "reserve": "20",
730 "shares": "30",
731 },
732 "disk-io-quota": {
733 "limit": "10",
734 "reserve": "20",
735 "shares": "30",
736 },
737 "vif-quota": {
738 "limit": "10",
739 "reserve": "20",
740 "shares": "30",
741 },
742 }
743 epa_vcpu_set = True
744
745 resource_allocation.return_value = {
746 "limit": 10,
747 "reserve": 20,
748 "shares": 30,
749 }
750
751 result = Ns._process_guest_epa_quota_params(
752 guest_epa_quota=guest_epa_quota,
753 epa_vcpu_set=epa_vcpu_set,
754 )
755
756 self.assertTrue(resource_allocation.called)
757 self.assertDictEqual(expected_result, result)
758
759 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
760 def test__process_guest_epa_quota_params_with_quota_epa_cpu_no_set(
761 self,
762 resource_allocation,
763 ):
764 expected_result = {
765 "cpu-quota": {
766 "limit": 10,
767 "reserve": 20,
768 "shares": 30,
769 },
770 "mem-quota": {
771 "limit": 10,
772 "reserve": 20,
773 "shares": 30,
774 },
775 "disk-io-quota": {
776 "limit": 10,
777 "reserve": 20,
778 "shares": 30,
779 },
780 "vif-quota": {
781 "limit": 10,
782 "reserve": 20,
783 "shares": 30,
784 },
785 }
786 guest_epa_quota = {
787 "cpu-quota": {
788 "limit": "10",
789 "reserve": "20",
790 "shares": "30",
791 },
792 "mem-quota": {
793 "limit": "10",
794 "reserve": "20",
795 "shares": "30",
796 },
797 "disk-io-quota": {
798 "limit": "10",
799 "reserve": "20",
800 "shares": "30",
801 },
802 "vif-quota": {
803 "limit": "10",
804 "reserve": "20",
805 "shares": "30",
806 },
807 }
808 epa_vcpu_set = False
809
810 resource_allocation.return_value = {
811 "limit": 10,
812 "reserve": 20,
813 "shares": 30,
814 }
815
816 result = Ns._process_guest_epa_quota_params(
817 guest_epa_quota=guest_epa_quota,
818 epa_vcpu_set=epa_vcpu_set,
819 )
820
821 self.assertTrue(resource_allocation.called)
822 self.assertDictEqual(expected_result, result)
823
824 def test__process_guest_epa_numa_params_with_empty_numa_params(self):
825 expected_numa_result = {}
826 expected_epa_vcpu_set_result = False
827 guest_epa_quota = {}
828
829 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
830 guest_epa_quota=guest_epa_quota,
831 )
832
833 self.assertDictEqual(expected_numa_result, numa_result)
834 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
835
836 def test__process_guest_epa_numa_params_with_wrong_numa_params(self):
837 expected_numa_result = {}
838 expected_epa_vcpu_set_result = False
839 guest_epa_quota = {"no_nume": "here"}
840
841 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
842 guest_epa_quota=guest_epa_quota,
843 )
844
845 self.assertDictEqual(expected_numa_result, numa_result)
846 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
847
848 def test__process_guest_epa_numa_params_with_numa_node_policy(self):
849 expected_numa_result = {}
850 expected_epa_vcpu_set_result = False
851 guest_epa_quota = {"numa-node-policy": {}}
852
853 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
854 guest_epa_quota=guest_epa_quota,
855 )
856
857 self.assertDictEqual(expected_numa_result, numa_result)
858 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
859
860 def test__process_guest_epa_numa_params_with_no_node(self):
861 expected_numa_result = {}
862 expected_epa_vcpu_set_result = False
863 guest_epa_quota = {
864 "numa-node-policy": {
865 "node": [],
866 },
867 }
868
869 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
870 guest_epa_quota=guest_epa_quota,
871 )
872
873 self.assertDictEqual(expected_numa_result, numa_result)
874 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
875
876 def test__process_guest_epa_numa_params_with_1_node_num_cores(self):
877 expected_numa_result = {"cores": 3}
878 expected_epa_vcpu_set_result = True
879 guest_epa_quota = {
880 "numa-node-policy": {
881 "node": [
882 {
883 "num-cores": 3,
884 },
885 ],
886 },
887 }
888
889 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
890 guest_epa_quota=guest_epa_quota,
891 )
892
893 self.assertDictEqual(expected_numa_result, numa_result)
894 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
895
896 def test__process_guest_epa_numa_params_with_1_node_paired_threads(self):
897 expected_numa_result = {"paired-threads": 3}
898 expected_epa_vcpu_set_result = True
899 guest_epa_quota = {
900 "numa-node-policy": {
901 "node": [
902 {
903 "paired-threads": {"num-paired-threads": "3"},
904 },
905 ],
906 },
907 }
908
909 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
910 guest_epa_quota=guest_epa_quota,
911 )
912
913 self.assertDictEqual(expected_numa_result, numa_result)
914 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
915
916 def test__process_guest_epa_numa_params_with_1_node_paired_threads_ids(self):
917 expected_numa_result = {
918 "paired-threads-id": [("0", "1"), ("4", "5")],
919 }
920 expected_epa_vcpu_set_result = False
921 guest_epa_quota = {
922 "numa-node-policy": {
923 "node": [
924 {
925 "paired-threads": {
926 "paired-thread-ids": [
927 {
928 "thread-a": 0,
929 "thread-b": 1,
930 },
931 {
932 "thread-a": 4,
933 "thread-b": 5,
934 },
935 ],
936 },
937 },
938 ],
939 },
940 }
941
942 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
943 guest_epa_quota=guest_epa_quota,
944 )
945
946 self.assertDictEqual(expected_numa_result, numa_result)
947 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
948
949 def test__process_guest_epa_numa_params_with_1_node_num_threads(self):
950 expected_numa_result = {"threads": 3}
951 expected_epa_vcpu_set_result = True
952 guest_epa_quota = {
953 "numa-node-policy": {
954 "node": [
955 {
956 "num-threads": "3",
957 },
958 ],
959 },
960 }
961
962 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
963 guest_epa_quota=guest_epa_quota,
964 )
965
966 self.assertDictEqual(expected_numa_result, numa_result)
967 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
968
969 def test__process_guest_epa_numa_params_with_1_node_memory_mb(self):
970 expected_numa_result = {"memory": 2}
971 expected_epa_vcpu_set_result = False
972 guest_epa_quota = {
973 "numa-node-policy": {
974 "node": [
975 {
976 "memory-mb": 2048,
977 },
978 ],
979 },
980 }
981
982 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
983 guest_epa_quota=guest_epa_quota,
984 )
985
986 self.assertDictEqual(expected_numa_result, numa_result)
987 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
988
989 def test__process_guest_epa_numa_params_with_1_node(self):
990 expected_numa_result = {
991 "cores": 3,
992 "paired-threads": 3,
993 "paired-threads-id": [("0", "1"), ("4", "5")],
994 "threads": 3,
995 "memory": 2,
996 }
997 expected_epa_vcpu_set_result = True
998 guest_epa_quota = {
999 "numa-node-policy": {
1000 "node": [
1001 {
1002 "num-cores": 3,
1003 "paired-threads": {
1004 "num-paired-threads": "3",
1005 "paired-thread-ids": [
1006 {
1007 "thread-a": 0,
1008 "thread-b": 1,
1009 },
1010 {
1011 "thread-a": 4,
1012 "thread-b": 5,
1013 },
1014 ],
1015 },
1016 "num-threads": "3",
1017 "memory-mb": 2048,
1018 },
1019 ],
1020 },
1021 }
1022
1023 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
1024 guest_epa_quota=guest_epa_quota,
1025 )
1026
1027 self.assertDictEqual(expected_numa_result, numa_result)
1028 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1029
1030 def test__process_guest_epa_numa_params_with_2_nodes(self):
1031 expected_numa_result = {
1032 "cores": 3,
1033 "paired-threads": 3,
1034 "paired-threads-id": [("0", "1"), ("4", "5")],
1035 "threads": 3,
1036 "memory": 2,
1037 }
1038 expected_epa_vcpu_set_result = True
1039 guest_epa_quota = {
1040 "numa-node-policy": {
1041 "node": [
1042 {
1043 "num-cores": 3,
1044 "paired-threads": {
1045 "num-paired-threads": "3",
1046 "paired-thread-ids": [
1047 {
1048 "thread-a": 0,
1049 "thread-b": 1,
1050 },
1051 {
1052 "thread-a": 4,
1053 "thread-b": 5,
1054 },
1055 ],
1056 },
1057 "num-threads": "3",
1058 "memory-mb": 2048,
1059 },
1060 {
1061 "num-cores": 7,
1062 "paired-threads": {
1063 "num-paired-threads": "7",
1064 "paired-thread-ids": [
1065 {
1066 "thread-a": 2,
1067 "thread-b": 3,
1068 },
1069 {
1070 "thread-a": 5,
1071 "thread-b": 6,
1072 },
1073 ],
1074 },
1075 "num-threads": "4",
1076 "memory-mb": 4096,
1077 },
1078 ],
1079 },
1080 }
1081
1082 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
1083 guest_epa_quota=guest_epa_quota,
1084 )
1085
1086 self.assertDictEqual(expected_numa_result, numa_result)
1087 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1088
1089 def test__process_guest_epa_cpu_pinning_params_with_empty_params(self):
1090 expected_numa_result = {}
1091 expected_epa_vcpu_set_result = False
1092 guest_epa_quota = {}
1093 vcpu_count = 0
1094 epa_vcpu_set = False
1095
1096 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params(
1097 guest_epa_quota=guest_epa_quota,
1098 vcpu_count=vcpu_count,
1099 epa_vcpu_set=epa_vcpu_set,
1100 )
1101
1102 self.assertDictEqual(expected_numa_result, numa_result)
1103 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1104
1105 def test__process_guest_epa_cpu_pinning_params_with_wrong_params(self):
1106 expected_numa_result = {}
1107 expected_epa_vcpu_set_result = False
1108 guest_epa_quota = {
1109 "no-cpu-pinning-policy": "here",
1110 }
1111 vcpu_count = 0
1112 epa_vcpu_set = False
1113
1114 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params(
1115 guest_epa_quota=guest_epa_quota,
1116 vcpu_count=vcpu_count,
1117 epa_vcpu_set=epa_vcpu_set,
1118 )
1119
1120 self.assertDictEqual(expected_numa_result, numa_result)
1121 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1122
1123 def test__process_guest_epa_cpu_pinning_params_with_epa_vcpu_set(self):
1124 expected_numa_result = {}
1125 expected_epa_vcpu_set_result = True
1126 guest_epa_quota = {
1127 "cpu-pinning-policy": "DEDICATED",
1128 }
1129 vcpu_count = 0
1130 epa_vcpu_set = True
1131
1132 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params(
1133 guest_epa_quota=guest_epa_quota,
1134 vcpu_count=vcpu_count,
1135 epa_vcpu_set=epa_vcpu_set,
1136 )
1137
1138 self.assertDictEqual(expected_numa_result, numa_result)
1139 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1140
1141 def test__process_guest_epa_cpu_pinning_params_with_threads(self):
1142 expected_numa_result = {"threads": 3}
1143 expected_epa_vcpu_set_result = True
1144 guest_epa_quota = {
1145 "cpu-pinning-policy": "DEDICATED",
1146 "cpu-thread-pinning-policy": "PREFER",
1147 }
1148 vcpu_count = 3
1149 epa_vcpu_set = False
1150
1151 numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params(
1152 guest_epa_quota=guest_epa_quota,
1153 vcpu_count=vcpu_count,
1154 epa_vcpu_set=epa_vcpu_set,
1155 )
1156
1157 self.assertDictEqual(expected_numa_result, numa_result)
1158 self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
1159
1160 def test__process_guest_epa_cpu_pinning_params(self):
1161 expected_numa_result = {"cores": 3}
1162 expected_epa_vcpu_set_result = True
1163 guest_epa_quota = {
1164 "cpu-pinning-policy": "DEDICATED",
1165 }
1166 vcpu_count = 3
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 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1179 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1180 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1181 def test__process_guest_epa_params_with_empty_params(
1182 self,
1183 guest_epa_numa_params,
1184 guest_epa_cpu_pinning_params,
1185 guest_epa_quota_params,
1186 ):
1187 expected_result = {}
1188 target_flavor = {}
1189
1190 result = Ns._process_epa_params(
1191 target_flavor=target_flavor,
1192 )
1193
1194 self.assertDictEqual(expected_result, result)
1195 self.assertFalse(guest_epa_numa_params.called)
1196 self.assertFalse(guest_epa_cpu_pinning_params.called)
1197 self.assertFalse(guest_epa_quota_params.called)
1198
1199 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1200 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1201 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1202 def test__process_guest_epa_params_with_wrong_params(
1203 self,
1204 guest_epa_numa_params,
1205 guest_epa_cpu_pinning_params,
1206 guest_epa_quota_params,
1207 ):
1208 expected_result = {}
1209 target_flavor = {
1210 "no-guest-epa": "here",
1211 }
1212
1213 result = Ns._process_epa_params(
1214 target_flavor=target_flavor,
1215 )
1216
1217 self.assertDictEqual(expected_result, result)
1218 self.assertFalse(guest_epa_numa_params.called)
1219 self.assertFalse(guest_epa_cpu_pinning_params.called)
1220 self.assertFalse(guest_epa_quota_params.called)
1221
1222 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1223 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1224 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1225 def test__process_guest_epa_params(
1226 self,
1227 guest_epa_numa_params,
1228 guest_epa_cpu_pinning_params,
1229 guest_epa_quota_params,
1230 ):
1231 expected_result = {}
1232 target_flavor = {
1233 "guest-epa": {
1234 "vcpu-count": 1,
1235 },
1236 }
1237
1238 guest_epa_numa_params.return_value = ({}, False)
1239 guest_epa_cpu_pinning_params.return_value = ({}, False)
1240 guest_epa_quota_params.return_value = {}
1241
1242 result = Ns._process_epa_params(
1243 target_flavor=target_flavor,
1244 )
1245
1246 self.assertDictEqual(expected_result, result)
1247 self.assertTrue(guest_epa_numa_params.called)
1248 self.assertTrue(guest_epa_cpu_pinning_params.called)
1249 self.assertTrue(guest_epa_quota_params.called)
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_mempage_size(
1255 self,
1256 guest_epa_numa_params,
1257 guest_epa_cpu_pinning_params,
1258 guest_epa_quota_params,
1259 ):
1260 expected_result = {
1261 "mempage-size": "1G",
1262 }
1263 target_flavor = {
1264 "guest-epa": {"vcpu-count": 1, "mempage-size": "1G"},
1265 }
1266
1267 guest_epa_numa_params.return_value = ({}, False)
1268 guest_epa_cpu_pinning_params.return_value = ({}, False)
1269 guest_epa_quota_params.return_value = {}
1270
1271 result = Ns._process_epa_params(
1272 target_flavor=target_flavor,
1273 )
1274
1275 self.assertDictEqual(expected_result, result)
1276 self.assertTrue(guest_epa_numa_params.called)
1277 self.assertTrue(guest_epa_cpu_pinning_params.called)
1278 self.assertTrue(guest_epa_quota_params.called)
1279
1280 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1281 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1282 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1283 def test__process_guest_epa_params_with_numa(
1284 self,
1285 guest_epa_numa_params,
1286 guest_epa_cpu_pinning_params,
1287 guest_epa_quota_params,
1288 ):
1289 expected_result = {
1290 "mempage-size": "1G",
1291 "numas": [
1292 {
1293 "cores": 3,
1294 "memory": 2,
1295 "paired-threads": 3,
1296 "paired-threads-id": [("0", "1"), ("4", "5")],
1297 "threads": 3,
1298 }
1299 ],
1300 "cpu-quota": {"limit": 10, "reserve": 20, "shares": 30},
1301 "disk-io-quota": {"limit": 10, "reserve": 20, "shares": 30},
1302 "mem-quota": {"limit": 10, "reserve": 20, "shares": 30},
1303 "vif-quota": {"limit": 10, "reserve": 20, "shares": 30},
1304 }
1305 target_flavor = {
1306 "guest-epa": {
1307 "vcpu-count": 1,
1308 "mempage-size": "1G",
1309 "cpu-pinning-policy": "DEDICATED",
1310 "cpu-thread-pinning-policy": "PREFER",
1311 "numa-node-policy": {
1312 "node": [
1313 {
1314 "num-cores": 3,
1315 "paired-threads": {
1316 "num-paired-threads": "3",
1317 "paired-thread-ids": [
1318 {
1319 "thread-a": 0,
1320 "thread-b": 1,
1321 },
1322 {
1323 "thread-a": 4,
1324 "thread-b": 5,
1325 },
1326 ],
1327 },
1328 "num-threads": "3",
1329 "memory-mb": 2048,
1330 },
1331 ],
1332 },
1333 "cpu-quota": {
1334 "limit": "10",
1335 "reserve": "20",
1336 "shares": "30",
1337 },
1338 "mem-quota": {
1339 "limit": "10",
1340 "reserve": "20",
1341 "shares": "30",
1342 },
1343 "disk-io-quota": {
1344 "limit": "10",
1345 "reserve": "20",
1346 "shares": "30",
1347 },
1348 "vif-quota": {
1349 "limit": "10",
1350 "reserve": "20",
1351 "shares": "30",
1352 },
1353 },
1354 }
1355
1356 guest_epa_numa_params.return_value = (
1357 {
1358 "cores": 3,
1359 "paired-threads": 3,
1360 "paired-threads-id": [("0", "1"), ("4", "5")],
1361 "threads": 3,
1362 "memory": 2,
1363 },
1364 True,
1365 )
1366 guest_epa_cpu_pinning_params.return_value = (
1367 {
1368 "threads": 3,
1369 },
1370 True,
1371 )
1372 guest_epa_quota_params.return_value = {
1373 "cpu-quota": {
1374 "limit": 10,
1375 "reserve": 20,
1376 "shares": 30,
1377 },
1378 "mem-quota": {
1379 "limit": 10,
1380 "reserve": 20,
1381 "shares": 30,
1382 },
1383 "disk-io-quota": {
1384 "limit": 10,
1385 "reserve": 20,
1386 "shares": 30,
1387 },
1388 "vif-quota": {
1389 "limit": 10,
1390 "reserve": 20,
1391 "shares": 30,
1392 },
1393 }
1394
1395 result = Ns._process_epa_params(
1396 target_flavor=target_flavor,
1397 )
1398
1399 self.assertDictEqual(expected_result, result)
1400 self.assertTrue(guest_epa_numa_params.called)
1401 self.assertTrue(guest_epa_cpu_pinning_params.called)
1402 self.assertTrue(guest_epa_quota_params.called)
1403
1404 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1405 def test__process_flavor_params_with_empty_target_flavor(
1406 self,
1407 epa_params,
1408 ):
1409 target_flavor = {}
1410 indata = {}
1411 vim_info = {}
1412 target_record_id = ""
1413
1414 with self.assertRaises(KeyError):
1415 Ns._process_flavor_params(
1416 target_flavor=target_flavor,
1417 indata=indata,
1418 vim_info=vim_info,
1419 target_record_id=target_record_id,
1420 )
1421
1422 self.assertFalse(epa_params.called)
1423
1424 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1425 def test__process_flavor_params_with_wrong_target_flavor(
1426 self,
1427 epa_params,
1428 ):
1429 target_flavor = {
1430 "no-target-flavor": "here",
1431 }
1432 indata = {}
1433 vim_info = {}
1434 target_record_id = ""
1435
1436 with self.assertRaises(KeyError):
1437 Ns._process_flavor_params(
1438 target_flavor=target_flavor,
1439 indata=indata,
1440 vim_info=vim_info,
1441 target_record_id=target_record_id,
1442 )
1443
1444 self.assertFalse(epa_params.called)
1445
1446 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1447 def test__process_flavor_params_with_empty_indata(
1448 self,
1449 epa_params,
1450 ):
1451 expected_result = {
1452 "find_params": {
1453 "flavor_data": {
1454 "disk": 10,
1455 "ram": 1024,
1456 "vcpus": 2,
1457 },
1458 },
1459 "params": {
1460 "flavor_data": {
1461 "disk": 10,
1462 "name": "test",
1463 "ram": 1024,
1464 "vcpus": 2,
1465 },
1466 },
1467 }
1468 target_flavor = {
1469 "name": "test",
1470 "storage-gb": "10",
1471 "memory-mb": "1024",
1472 "vcpu-count": "2",
1473 }
1474 indata = {}
1475 vim_info = {}
1476 target_record_id = ""
1477
1478 epa_params.return_value = {}
1479
1480 result = Ns._process_flavor_params(
1481 target_flavor=target_flavor,
1482 indata=indata,
1483 vim_info=vim_info,
1484 target_record_id=target_record_id,
1485 )
1486
1487 self.assertTrue(epa_params.called)
1488 self.assertDictEqual(result, expected_result)
1489
1490 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1491 def test__process_flavor_params_with_wrong_indata(
1492 self,
1493 epa_params,
1494 ):
1495 expected_result = {
1496 "find_params": {
1497 "flavor_data": {
1498 "disk": 10,
1499 "ram": 1024,
1500 "vcpus": 2,
1501 },
1502 },
1503 "params": {
1504 "flavor_data": {
1505 "disk": 10,
1506 "name": "test",
1507 "ram": 1024,
1508 "vcpus": 2,
1509 },
1510 },
1511 }
1512 target_flavor = {
1513 "name": "test",
1514 "storage-gb": "10",
1515 "memory-mb": "1024",
1516 "vcpu-count": "2",
1517 }
1518 indata = {
1519 "no-vnf": "here",
1520 }
1521 vim_info = {}
1522 target_record_id = ""
1523
1524 epa_params.return_value = {}
1525
1526 result = Ns._process_flavor_params(
1527 target_flavor=target_flavor,
1528 indata=indata,
1529 vim_info=vim_info,
1530 target_record_id=target_record_id,
1531 )
1532
1533 self.assertTrue(epa_params.called)
1534 self.assertDictEqual(result, expected_result)
1535
1536 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1537 def test__process_flavor_params_with_ephemeral_disk(
1538 self,
1539 epa_params,
1540 ):
1541 expected_result = {
1542 "find_params": {
1543 "flavor_data": {
1544 "disk": 10,
1545 "ram": 1024,
1546 "vcpus": 2,
1547 "ephemeral": 10,
1548 },
1549 },
1550 "params": {
1551 "flavor_data": {
1552 "disk": 10,
1553 "name": "test",
1554 "ram": 1024,
1555 "vcpus": 2,
1556 "ephemeral": 10,
1557 },
1558 },
1559 }
1560 target_flavor = {
1561 "id": "test_id",
1562 "name": "test",
1563 "storage-gb": "10",
1564 "memory-mb": "1024",
1565 "vcpu-count": "2",
1566 }
1567 indata = {
1568 "vnf": [
1569 {
1570 "vdur": [
1571 {
1572 "ns-flavor-id": "test_id",
1573 "virtual-storages": [
1574 {
1575 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1576 "size-of-storage": "10",
1577 },
1578 ],
1579 },
1580 ],
1581 },
1582 ],
1583 }
1584 vim_info = {}
1585 target_record_id = ""
1586
1587 epa_params.return_value = {}
1588
1589 result = Ns._process_flavor_params(
1590 target_flavor=target_flavor,
1591 indata=indata,
1592 vim_info=vim_info,
1593 target_record_id=target_record_id,
1594 )
1595
1596 self.assertTrue(epa_params.called)
1597 self.assertDictEqual(result, expected_result)
1598
1599 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1600 def test__process_flavor_params_with_swap_disk(
1601 self,
1602 epa_params,
1603 ):
1604 expected_result = {
1605 "find_params": {
1606 "flavor_data": {
1607 "disk": 10,
1608 "ram": 1024,
1609 "vcpus": 2,
1610 "swap": 20,
1611 },
1612 },
1613 "params": {
1614 "flavor_data": {
1615 "disk": 10,
1616 "name": "test",
1617 "ram": 1024,
1618 "vcpus": 2,
1619 "swap": 20,
1620 },
1621 },
1622 }
1623 target_flavor = {
1624 "id": "test_id",
1625 "name": "test",
1626 "storage-gb": "10",
1627 "memory-mb": "1024",
1628 "vcpu-count": "2",
1629 }
1630 indata = {
1631 "vnf": [
1632 {
1633 "vdur": [
1634 {
1635 "ns-flavor-id": "test_id",
1636 "virtual-storages": [
1637 {
1638 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
1639 "size-of-storage": "20",
1640 },
1641 ],
1642 },
1643 ],
1644 },
1645 ],
1646 }
1647 vim_info = {}
1648 target_record_id = ""
1649
1650 epa_params.return_value = {}
1651
1652 result = Ns._process_flavor_params(
1653 target_flavor=target_flavor,
1654 indata=indata,
1655 vim_info=vim_info,
1656 target_record_id=target_record_id,
1657 )
1658
1659 self.assertTrue(epa_params.called)
1660 self.assertDictEqual(result, expected_result)
1661
1662 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1663 def test__process_flavor_params_with_epa_params(
1664 self,
1665 epa_params,
1666 ):
1667 expected_result = {
1668 "find_params": {
1669 "flavor_data": {
1670 "disk": 10,
1671 "ram": 1024,
1672 "vcpus": 2,
1673 "extended": {
1674 "numa": "there-is-numa-here",
1675 },
1676 },
1677 },
1678 "params": {
1679 "flavor_data": {
1680 "disk": 10,
1681 "name": "test",
1682 "ram": 1024,
1683 "vcpus": 2,
1684 "extended": {
1685 "numa": "there-is-numa-here",
1686 },
1687 },
1688 },
1689 }
1690 target_flavor = {
1691 "id": "test_id",
1692 "name": "test",
1693 "storage-gb": "10",
1694 "memory-mb": "1024",
1695 "vcpu-count": "2",
1696 }
1697 indata = {}
1698 vim_info = {}
1699 target_record_id = ""
1700
1701 epa_params.return_value = {
1702 "numa": "there-is-numa-here",
1703 }
1704
1705 result = Ns._process_flavor_params(
1706 target_flavor=target_flavor,
1707 indata=indata,
1708 vim_info=vim_info,
1709 target_record_id=target_record_id,
1710 )
1711
1712 self.assertTrue(epa_params.called)
1713 self.assertDictEqual(result, expected_result)
1714
1715 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1716 def test__process_flavor_params(
1717 self,
1718 epa_params,
1719 ):
1720 expected_result = {
1721 "find_params": {
1722 "flavor_data": {
1723 "disk": 10,
1724 "ram": 1024,
1725 "vcpus": 2,
1726 "ephemeral": 10,
1727 "swap": 20,
1728 "extended": {
1729 "numa": "there-is-numa-here",
1730 },
1731 },
1732 },
1733 "params": {
1734 "flavor_data": {
1735 "disk": 10,
1736 "name": "test",
1737 "ram": 1024,
1738 "vcpus": 2,
1739 "ephemeral": 10,
1740 "swap": 20,
1741 "extended": {
1742 "numa": "there-is-numa-here",
1743 },
1744 },
1745 },
1746 }
1747 target_flavor = {
1748 "id": "test_id",
1749 "name": "test",
1750 "storage-gb": "10",
1751 "memory-mb": "1024",
1752 "vcpu-count": "2",
1753 }
1754 indata = {
1755 "vnf": [
1756 {
1757 "vdur": [
1758 {
1759 "ns-flavor-id": "test_id",
1760 "virtual-storages": [
1761 {
1762 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1763 "size-of-storage": "10",
1764 },
1765 {
1766 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
1767 "size-of-storage": "20",
1768 },
1769 ],
1770 },
1771 ],
1772 },
1773 ],
1774 }
1775 vim_info = {}
1776 target_record_id = ""
1777
1778 epa_params.return_value = {
1779 "numa": "there-is-numa-here",
1780 }
1781
1782 result = Ns._process_flavor_params(
1783 target_flavor=target_flavor,
1784 indata=indata,
1785 vim_info=vim_info,
1786 target_record_id=target_record_id,
1787 )
1788
1789 self.assertTrue(epa_params.called)
1790 self.assertDictEqual(result, expected_result)
1791
1792 def test__ip_profile_to_ro_with_none(self):
1793 ip_profile = None
1794
1795 result = Ns._ip_profile_to_ro(
1796 ip_profile=ip_profile,
1797 )
1798
1799 self.assertIsNone(result)
1800
1801 def test__ip_profile_to_ro_with_empty_profile(self):
1802 ip_profile = {}
1803
1804 result = Ns._ip_profile_to_ro(
1805 ip_profile=ip_profile,
1806 )
1807
1808 self.assertIsNone(result)
1809
1810 def test__ip_profile_to_ro_with_wrong_profile(self):
1811 ip_profile = {
1812 "no-profile": "here",
1813 }
1814 expected_result = {
1815 "ip_version": "IPv4",
1816 "subnet_address": None,
1817 "gateway_address": None,
1818 "dhcp_enabled": False,
1819 "dhcp_start_address": None,
1820 "dhcp_count": None,
1821 }
1822
1823 result = Ns._ip_profile_to_ro(
1824 ip_profile=ip_profile,
1825 )
1826
1827 self.assertDictEqual(expected_result, result)
1828
1829 def test__ip_profile_to_ro_with_ipv4_profile(self):
1830 ip_profile = {
1831 "ip-version": "ipv4",
1832 "subnet-address": "192.168.0.0/24",
1833 "gateway-address": "192.168.0.254",
1834 "dhcp-params": {
1835 "enabled": True,
1836 "start-address": "192.168.0.10",
1837 "count": 25,
1838 },
1839 }
1840 expected_result = {
1841 "ip_version": "IPv4",
1842 "subnet_address": "192.168.0.0/24",
1843 "gateway_address": "192.168.0.254",
1844 "dhcp_enabled": True,
1845 "dhcp_start_address": "192.168.0.10",
1846 "dhcp_count": 25,
1847 }
1848
1849 result = Ns._ip_profile_to_ro(
1850 ip_profile=ip_profile,
1851 )
1852
1853 self.assertDictEqual(expected_result, result)
1854
1855 def test__ip_profile_to_ro_with_ipv6_profile(self):
1856 ip_profile = {
1857 "ip-version": "ipv6",
1858 "subnet-address": "2001:0200:0001::/48",
1859 "gateway-address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
1860 "dhcp-params": {
1861 "enabled": True,
1862 "start-address": "2001:0200:0001::0010",
1863 "count": 25,
1864 },
1865 }
1866 expected_result = {
1867 "ip_version": "IPv6",
1868 "subnet_address": "2001:0200:0001::/48",
1869 "gateway_address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
1870 "dhcp_enabled": True,
1871 "dhcp_start_address": "2001:0200:0001::0010",
1872 "dhcp_count": 25,
1873 }
1874
1875 result = Ns._ip_profile_to_ro(
1876 ip_profile=ip_profile,
1877 )
1878
1879 self.assertDictEqual(expected_result, result)
1880
1881 def test__ip_profile_to_ro_with_dns_server(self):
1882 ip_profile = {
1883 "ip-version": "ipv4",
1884 "subnet-address": "192.168.0.0/24",
1885 "gateway-address": "192.168.0.254",
1886 "dhcp-params": {
1887 "enabled": True,
1888 "start-address": "192.168.0.10",
1889 "count": 25,
1890 },
1891 "dns-server": [
1892 {
1893 "address": "8.8.8.8",
1894 },
1895 {
1896 "address": "1.1.1.1",
1897 },
1898 {
1899 "address": "1.0.0.1",
1900 },
1901 ],
1902 }
1903 expected_result = {
1904 "ip_version": "IPv4",
1905 "subnet_address": "192.168.0.0/24",
1906 "gateway_address": "192.168.0.254",
1907 "dhcp_enabled": True,
1908 "dhcp_start_address": "192.168.0.10",
1909 "dhcp_count": 25,
1910 "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
1911 }
1912
1913 result = Ns._ip_profile_to_ro(
1914 ip_profile=ip_profile,
1915 )
1916
1917 self.assertDictEqual(expected_result, result)
1918
1919 def test__ip_profile_to_ro_with_security_group(self):
1920 ip_profile = {
1921 "ip-version": "ipv4",
1922 "subnet-address": "192.168.0.0/24",
1923 "gateway-address": "192.168.0.254",
1924 "dhcp-params": {
1925 "enabled": True,
1926 "start-address": "192.168.0.10",
1927 "count": 25,
1928 },
1929 "security-group": {
1930 "some-security-group": "here",
1931 },
1932 }
1933 expected_result = {
1934 "ip_version": "IPv4",
1935 "subnet_address": "192.168.0.0/24",
1936 "gateway_address": "192.168.0.254",
1937 "dhcp_enabled": True,
1938 "dhcp_start_address": "192.168.0.10",
1939 "dhcp_count": 25,
1940 "security_group": {
1941 "some-security-group": "here",
1942 },
1943 }
1944
1945 result = Ns._ip_profile_to_ro(
1946 ip_profile=ip_profile,
1947 )
1948
1949 self.assertDictEqual(expected_result, result)
1950
1951 def test__ip_profile_to_ro(self):
1952 ip_profile = {
1953 "ip-version": "ipv4",
1954 "subnet-address": "192.168.0.0/24",
1955 "gateway-address": "192.168.0.254",
1956 "dhcp-params": {
1957 "enabled": True,
1958 "start-address": "192.168.0.10",
1959 "count": 25,
1960 },
1961 "dns-server": [
1962 {
1963 "address": "8.8.8.8",
1964 },
1965 {
1966 "address": "1.1.1.1",
1967 },
1968 {
1969 "address": "1.0.0.1",
1970 },
1971 ],
1972 "security-group": {
1973 "some-security-group": "here",
1974 },
1975 }
1976 expected_result = {
1977 "ip_version": "IPv4",
1978 "subnet_address": "192.168.0.0/24",
1979 "gateway_address": "192.168.0.254",
1980 "dhcp_enabled": True,
1981 "dhcp_start_address": "192.168.0.10",
1982 "dhcp_count": 25,
1983 "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
1984 "security_group": {
1985 "some-security-group": "here",
1986 },
1987 }
1988
1989 result = Ns._ip_profile_to_ro(
1990 ip_profile=ip_profile,
1991 )
1992
1993 self.assertDictEqual(expected_result, result)
1994
1995 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
1996 def test__process_net_params_with_empty_params(
1997 self,
1998 ip_profile_to_ro,
1999 ):
2000 target_vld = {
2001 "name": "vld-name",
2002 }
2003 indata = {
2004 "name": "ns-name",
2005 }
2006 vim_info = {
2007 "provider_network": "some-profile-here",
2008 }
2009 target_record_id = ""
2010 expected_result = {
2011 "params": {
2012 "net_name": "ns-name-vld-name",
2013 "net_type": "bridge",
2014 "ip_profile": {
2015 "some_ip_profile": "here",
2016 },
2017 "provider_network_profile": "some-profile-here",
2018 }
2019 }
2020
2021 ip_profile_to_ro.return_value = {
2022 "some_ip_profile": "here",
2023 }
2024
2025 result = Ns._process_net_params(
2026 target_vld=target_vld,
2027 indata=indata,
2028 vim_info=vim_info,
2029 target_record_id=target_record_id,
2030 )
2031
2032 self.assertDictEqual(expected_result, result)
2033 self.assertTrue(ip_profile_to_ro.called)
2034
2035 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2036 def test__process_net_params_with_vim_info_sdn(
2037 self,
2038 ip_profile_to_ro,
2039 ):
2040 target_vld = {
2041 "name": "vld-name",
2042 }
2043 indata = {
2044 "name": "ns-name",
2045 }
2046 vim_info = {
2047 "sdn": "some-sdn",
2048 "sdn-ports": ["some", "ports", "here"],
2049 "vlds": ["some", "vlds", "here"],
2050 "type": "sdn-type",
2051 }
2052 target_record_id = "vld.sdn.something"
2053 expected_result = {
2054 "params": {
2055 "sdn-ports": ["some", "ports", "here"],
2056 "vlds": ["some", "vlds", "here"],
2057 "type": "sdn-type",
2058 }
2059 }
2060
2061 result = Ns._process_net_params(
2062 target_vld=target_vld,
2063 indata=indata,
2064 vim_info=vim_info,
2065 target_record_id=target_record_id,
2066 )
2067
2068 self.assertDictEqual(expected_result, result)
2069 self.assertFalse(ip_profile_to_ro.called)
2070
2071 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2072 def test__process_net_params_with_vim_info_sdn_target_vim(
2073 self,
2074 ip_profile_to_ro,
2075 ):
2076 target_vld = {
2077 "name": "vld-name",
2078 }
2079 indata = {
2080 "name": "ns-name",
2081 }
2082 vim_info = {
2083 "sdn": "some-sdn",
2084 "sdn-ports": ["some", "ports", "here"],
2085 "vlds": ["some", "vlds", "here"],
2086 "target_vim": "some-vim",
2087 "type": "sdn-type",
2088 }
2089 target_record_id = "vld.sdn.something"
2090 expected_result = {
2091 "depends_on": ["some-vim vld.sdn"],
2092 "params": {
2093 "sdn-ports": ["some", "ports", "here"],
2094 "vlds": ["some", "vlds", "here"],
2095 "target_vim": "some-vim",
2096 "type": "sdn-type",
2097 },
2098 }
2099
2100 result = Ns._process_net_params(
2101 target_vld=target_vld,
2102 indata=indata,
2103 vim_info=vim_info,
2104 target_record_id=target_record_id,
2105 )
2106
2107 self.assertDictEqual(expected_result, result)
2108 self.assertFalse(ip_profile_to_ro.called)
2109
2110 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2111 def test__process_net_params_with_vim_network_name(
2112 self,
2113 ip_profile_to_ro,
2114 ):
2115 target_vld = {
2116 "name": "vld-name",
2117 }
2118 indata = {
2119 "name": "ns-name",
2120 }
2121 vim_info = {
2122 "vim_network_name": "some-network-name",
2123 }
2124 target_record_id = "vld.sdn.something"
2125 expected_result = {
2126 "find_params": {
2127 "filter_dict": {
2128 "name": "some-network-name",
2129 },
2130 },
2131 }
2132
2133 result = Ns._process_net_params(
2134 target_vld=target_vld,
2135 indata=indata,
2136 vim_info=vim_info,
2137 target_record_id=target_record_id,
2138 )
2139
2140 self.assertDictEqual(expected_result, result)
2141 self.assertFalse(ip_profile_to_ro.called)
2142
2143 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2144 def test__process_net_params_with_vim_network_id(
2145 self,
2146 ip_profile_to_ro,
2147 ):
2148 target_vld = {
2149 "name": "vld-name",
2150 }
2151 indata = {
2152 "name": "ns-name",
2153 }
2154 vim_info = {
2155 "vim_network_id": "some-network-id",
2156 }
2157 target_record_id = "vld.sdn.something"
2158 expected_result = {
2159 "find_params": {
2160 "filter_dict": {
2161 "id": "some-network-id",
2162 },
2163 },
2164 }
2165
2166 result = Ns._process_net_params(
2167 target_vld=target_vld,
2168 indata=indata,
2169 vim_info=vim_info,
2170 target_record_id=target_record_id,
2171 )
2172
2173 self.assertDictEqual(expected_result, result)
2174 self.assertFalse(ip_profile_to_ro.called)
2175
2176 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2177 def test__process_net_params_with_mgmt_network(
2178 self,
2179 ip_profile_to_ro,
2180 ):
2181 target_vld = {
2182 "id": "vld-id",
2183 "name": "vld-name",
2184 "mgmt-network": "some-mgmt-network",
2185 }
2186 indata = {
2187 "name": "ns-name",
2188 }
2189 vim_info = {}
2190 target_record_id = "vld.sdn.something"
2191 expected_result = {
2192 "find_params": {
2193 "mgmt": True,
2194 "name": "vld-id",
2195 },
2196 }
2197
2198 result = Ns._process_net_params(
2199 target_vld=target_vld,
2200 indata=indata,
2201 vim_info=vim_info,
2202 target_record_id=target_record_id,
2203 )
2204
2205 self.assertDictEqual(expected_result, result)
2206 self.assertFalse(ip_profile_to_ro.called)
2207
2208 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2209 def test__process_net_params_with_underlay_eline(
2210 self,
2211 ip_profile_to_ro,
2212 ):
2213 target_vld = {
2214 "name": "vld-name",
2215 "underlay": "some-underlay-here",
2216 "type": "ELINE",
2217 }
2218 indata = {
2219 "name": "ns-name",
2220 }
2221 vim_info = {
2222 "provider_network": "some-profile-here",
2223 }
2224 target_record_id = ""
2225 expected_result = {
2226 "params": {
2227 "ip_profile": {
2228 "some_ip_profile": "here",
2229 },
2230 "net_name": "ns-name-vld-name",
2231 "net_type": "ptp",
2232 "provider_network_profile": "some-profile-here",
2233 }
2234 }
2235
2236 ip_profile_to_ro.return_value = {
2237 "some_ip_profile": "here",
2238 }
2239
2240 result = Ns._process_net_params(
2241 target_vld=target_vld,
2242 indata=indata,
2243 vim_info=vim_info,
2244 target_record_id=target_record_id,
2245 )
2246
2247 self.assertDictEqual(expected_result, result)
2248 self.assertTrue(ip_profile_to_ro.called)
2249
2250 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2251 def test__process_net_params_with_underlay_elan(
2252 self,
2253 ip_profile_to_ro,
2254 ):
2255 target_vld = {
2256 "name": "vld-name",
2257 "underlay": "some-underlay-here",
2258 "type": "ELAN",
2259 }
2260 indata = {
2261 "name": "ns-name",
2262 }
2263 vim_info = {
2264 "provider_network": "some-profile-here",
2265 }
2266 target_record_id = ""
2267 expected_result = {
2268 "params": {
2269 "ip_profile": {
2270 "some_ip_profile": "here",
2271 },
2272 "net_name": "ns-name-vld-name",
2273 "net_type": "data",
2274 "provider_network_profile": "some-profile-here",
2275 }
2276 }
2277
2278 ip_profile_to_ro.return_value = {
2279 "some_ip_profile": "here",
2280 }
2281
2282 result = Ns._process_net_params(
2283 target_vld=target_vld,
2284 indata=indata,
2285 vim_info=vim_info,
2286 target_record_id=target_record_id,
2287 )
2288
2289 self.assertDictEqual(expected_result, result)
2290 self.assertTrue(ip_profile_to_ro.called)