1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
19 from unittest
.mock
import MagicMock
, Mock
, patch
29 from osm_ng_ro
.ns
import Ns
, NsException
32 __author__
= "Eduardo Sousa"
33 __date__
= "$19-NOV-2021 00:00:00$"
36 class TestNs(unittest
.TestCase
):
40 def test__create_task_without_extra_dict(self
):
42 "target_id": "vim_openstack_1",
43 "action_id": "123456",
45 "task_id": "123456:1",
46 "status": "SCHEDULED",
49 "target_record": "test_target_record",
50 "target_record_id": "test_target_record_id",
53 "action_id": "123456",
58 task
= Ns
._create
_task
(
59 deployment_info
=deployment_info
,
60 target_id
="vim_openstack_1",
63 target_record
="test_target_record",
64 target_record_id
="test_target_record_id",
67 self
.assertEqual(deployment_info
.get("task_index"), 2)
68 self
.assertDictEqual(task
, expected_result
)
70 def test__create_task(self
):
72 "target_id": "vim_openstack_1",
73 "action_id": "123456",
75 "task_id": "123456:1",
76 "status": "SCHEDULED",
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",
87 "action_id": "123456",
92 task
= Ns
._create
_task
(
93 deployment_info
=deployment_info
,
94 target_id
="vim_openstack_1",
97 target_record
="test_target_record",
98 target_record_id
="test_target_record_id",
100 "params": "test_params",
101 "find_params": "test_find_params",
102 "depends_on": "test_depends_on",
106 self
.assertEqual(deployment_info
.get("task_index"), 2)
107 self
.assertDictEqual(task
, expected_result
)
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
114 "target_id": "vim_openstack_1",
115 "action_id": "123456",
117 "task_id": "123456:1",
118 "status": "SCHEDULED",
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",
132 "target_id": "vim_openstack_1",
135 "created_items": None,
149 ro_task
= Ns
._create
_ro
_task
(
150 target_id
="vim_openstack_1",
154 self
.assertDictEqual(ro_task
, expected_result
)
156 def test__process_image_params_with_empty_target_image(self
):
162 result
= Ns
._process
_image
_params
(
163 target_image
=target_image
,
166 target_record_id
=None,
169 self
.assertDictEqual(expected_result
, result
)
171 def test__process_image_params_with_wrong_target_image(self
):
176 "no_image": "to_see_here",
179 result
= Ns
._process
_image
_params
(
180 target_image
=target_image
,
183 target_record_id
=None,
186 self
.assertDictEqual(expected_result
, result
)
188 def test__process_image_params_with_image(self
):
200 result
= Ns
._process
_image
_params
(
201 target_image
=target_image
,
204 target_record_id
=None,
207 self
.assertDictEqual(expected_result
, result
)
209 def test__process_image_params_with_vim_image_id(self
):
218 "vim_image_id": "123456",
221 result
= Ns
._process
_image
_params
(
222 target_image
=target_image
,
225 target_record_id
=None,
228 self
.assertDictEqual(expected_result
, result
)
230 def test__process_image_params_with_image_checksum(self
):
234 "checksum": "e3fc50a88d0a364313df4b21ef20c29e",
239 "image_checksum": "e3fc50a88d0a364313df4b21ef20c29e",
242 result
= Ns
._process
_image
_params
(
243 target_image
=target_image
,
246 target_record_id
=None,
249 self
.assertDictEqual(expected_result
, result
)
251 def test__get_resource_allocation_params_with_empty_target_image(self
):
253 quota_descriptor
= {}
255 result
= Ns
._get
_resource
_allocation
_params
(
256 quota_descriptor
=quota_descriptor
,
259 self
.assertDictEqual(expected_result
, result
)
261 def test__get_resource_allocation_params_with_wrong_target_image(self
):
264 "no_quota": "present_here",
267 result
= Ns
._get
_resource
_allocation
_params
(
268 quota_descriptor
=quota_descriptor
,
271 self
.assertDictEqual(expected_result
, result
)
273 def test__get_resource_allocation_params_with_limit(self
):
281 result
= Ns
._get
_resource
_allocation
_params
(
282 quota_descriptor
=quota_descriptor
,
285 self
.assertDictEqual(expected_result
, result
)
287 def test__get_resource_allocation_params_with_reserve(self
):
295 result
= Ns
._get
_resource
_allocation
_params
(
296 quota_descriptor
=quota_descriptor
,
299 self
.assertDictEqual(expected_result
, result
)
301 def test__get_resource_allocation_params_with_shares(self
):
309 result
= Ns
._get
_resource
_allocation
_params
(
310 quota_descriptor
=quota_descriptor
,
313 self
.assertDictEqual(expected_result
, result
)
315 def test__get_resource_allocation_params(self
):
327 result
= Ns
._get
_resource
_allocation
_params
(
328 quota_descriptor
=quota_descriptor
,
331 self
.assertDictEqual(expected_result
, result
)
333 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
334 def test__process_guest_epa_quota_params_with_empty_quota_epa_cpu(
342 result
= Ns
._process
_guest
_epa
_quota
_params
(
343 guest_epa_quota
=guest_epa_quota
,
344 epa_vcpu_set
=epa_vcpu_set
,
347 self
.assertDictEqual(expected_result
, result
)
348 self
.assertFalse(resource_allocation
.called
)
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(
359 result
= Ns
._process
_guest
_epa
_quota
_params
(
360 guest_epa_quota
=guest_epa_quota
,
361 epa_vcpu_set
=epa_vcpu_set
,
364 self
.assertDictEqual(expected_result
, result
)
365 self
.assertFalse(resource_allocation
.called
)
367 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
368 def test__process_guest_epa_quota_params_with_wrong_quota_epa_cpu(
374 "no-quota": "nothing",
378 result
= Ns
._process
_guest
_epa
_quota
_params
(
379 guest_epa_quota
=guest_epa_quota
,
380 epa_vcpu_set
=epa_vcpu_set
,
383 self
.assertDictEqual(expected_result
, result
)
384 self
.assertFalse(resource_allocation
.called
)
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(
393 "no-quota": "nothing",
397 result
= Ns
._process
_guest
_epa
_quota
_params
(
398 guest_epa_quota
=guest_epa_quota
,
399 epa_vcpu_set
=epa_vcpu_set
,
402 self
.assertDictEqual(expected_result
, result
)
403 self
.assertFalse(resource_allocation
.called
)
405 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
406 def test__process_guest_epa_quota_params_with_cpu_quota_epa_cpu(
420 result
= Ns
._process
_guest
_epa
_quota
_params
(
421 guest_epa_quota
=guest_epa_quota
,
422 epa_vcpu_set
=epa_vcpu_set
,
425 self
.assertDictEqual(expected_result
, result
)
426 self
.assertFalse(resource_allocation
.called
)
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(
449 resource_allocation_param
= {
454 resource_allocation
.return_value
= {
460 result
= Ns
._process
_guest
_epa
_quota
_params
(
461 guest_epa_quota
=guest_epa_quota
,
462 epa_vcpu_set
=epa_vcpu_set
,
465 resource_allocation
.assert_called_once_with(resource_allocation_param
)
466 self
.assertDictEqual(expected_result
, result
)
468 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
469 def test__process_guest_epa_quota_params_with_mem_quota_epa_cpu(
489 resource_allocation_param
= {
494 resource_allocation
.return_value
= {
500 result
= Ns
._process
_guest
_epa
_quota
_params
(
501 guest_epa_quota
=guest_epa_quota
,
502 epa_vcpu_set
=epa_vcpu_set
,
505 resource_allocation
.assert_called_once_with(resource_allocation_param
)
506 self
.assertDictEqual(expected_result
, result
)
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(
529 resource_allocation_param
= {
534 resource_allocation
.return_value
= {
540 result
= Ns
._process
_guest
_epa
_quota
_params
(
541 guest_epa_quota
=guest_epa_quota
,
542 epa_vcpu_set
=epa_vcpu_set
,
545 resource_allocation
.assert_called_once_with(resource_allocation_param
)
546 self
.assertDictEqual(expected_result
, result
)
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(
569 resource_allocation_param
= {
574 resource_allocation
.return_value
= {
580 result
= Ns
._process
_guest
_epa
_quota
_params
(
581 guest_epa_quota
=guest_epa_quota
,
582 epa_vcpu_set
=epa_vcpu_set
,
585 resource_allocation
.assert_called_once_with(resource_allocation_param
)
586 self
.assertDictEqual(expected_result
, result
)
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(
609 resource_allocation_param
= {
614 resource_allocation
.return_value
= {
620 result
= Ns
._process
_guest
_epa
_quota
_params
(
621 guest_epa_quota
=guest_epa_quota
,
622 epa_vcpu_set
=epa_vcpu_set
,
625 resource_allocation
.assert_called_once_with(resource_allocation_param
)
626 self
.assertDictEqual(expected_result
, result
)
628 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
629 def test__process_guest_epa_quota_params_with_vif_quota_epa_cpu(
649 resource_allocation_param
= {
654 resource_allocation
.return_value
= {
660 result
= Ns
._process
_guest
_epa
_quota
_params
(
661 guest_epa_quota
=guest_epa_quota
,
662 epa_vcpu_set
=epa_vcpu_set
,
665 resource_allocation
.assert_called_once_with(resource_allocation_param
)
666 self
.assertDictEqual(expected_result
, result
)
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(
689 resource_allocation_param
= {
694 resource_allocation
.return_value
= {
700 result
= Ns
._process
_guest
_epa
_quota
_params
(
701 guest_epa_quota
=guest_epa_quota
,
702 epa_vcpu_set
=epa_vcpu_set
,
705 resource_allocation
.assert_called_once_with(resource_allocation_param
)
706 self
.assertDictEqual(expected_result
, result
)
708 @patch("osm_ng_ro.ns.Ns._get_resource_allocation_params")
709 def test__process_guest_epa_quota_params_with_quota_epa_cpu(
754 resource_allocation
.return_value
= {
760 result
= Ns
._process
_guest
_epa
_quota
_params
(
761 guest_epa_quota
=guest_epa_quota
,
762 epa_vcpu_set
=epa_vcpu_set
,
765 self
.assertTrue(resource_allocation
.called
)
766 self
.assertDictEqual(expected_result
, result
)
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(
819 resource_allocation
.return_value
= {
825 result
= Ns
._process
_guest
_epa
_quota
_params
(
826 guest_epa_quota
=guest_epa_quota
,
827 epa_vcpu_set
=epa_vcpu_set
,
830 self
.assertTrue(resource_allocation
.called
)
831 self
.assertDictEqual(expected_result
, result
)
833 def test__process_guest_epa_numa_params_with_empty_numa_params(self
):
834 expected_numa_result
= {}
835 expected_epa_vcpu_set_result
= False
838 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
839 guest_epa_quota
=guest_epa_quota
,
842 self
.assertDictEqual(expected_numa_result
, numa_result
)
843 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
845 def test__process_guest_epa_numa_params_with_wrong_numa_params(self
):
846 expected_numa_result
= {}
847 expected_epa_vcpu_set_result
= False
848 guest_epa_quota
= {"no_nume": "here"}
850 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
851 guest_epa_quota
=guest_epa_quota
,
854 self
.assertDictEqual(expected_numa_result
, numa_result
)
855 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
857 def test__process_guest_epa_numa_params_with_numa_node_policy(self
):
858 expected_numa_result
= {}
859 expected_epa_vcpu_set_result
= False
860 guest_epa_quota
= {"numa-node-policy": {}}
862 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
863 guest_epa_quota
=guest_epa_quota
,
866 self
.assertDictEqual(expected_numa_result
, numa_result
)
867 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
869 def test__process_guest_epa_numa_params_with_no_node(self
):
870 expected_numa_result
= {}
871 expected_epa_vcpu_set_result
= False
873 "numa-node-policy": {
878 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
879 guest_epa_quota
=guest_epa_quota
,
882 self
.assertDictEqual(expected_numa_result
, numa_result
)
883 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
885 def test__process_guest_epa_numa_params_with_1_node_num_cores(self
):
886 expected_numa_result
= {"cores": 3}
887 expected_epa_vcpu_set_result
= True
889 "numa-node-policy": {
898 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
899 guest_epa_quota
=guest_epa_quota
,
902 self
.assertDictEqual(expected_numa_result
, numa_result
)
903 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
905 def test__process_guest_epa_numa_params_with_1_node_paired_threads(self
):
906 expected_numa_result
= {"paired-threads": 3}
907 expected_epa_vcpu_set_result
= True
909 "numa-node-policy": {
912 "paired-threads": {"num-paired-threads": "3"},
918 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
919 guest_epa_quota
=guest_epa_quota
,
922 self
.assertDictEqual(expected_numa_result
, numa_result
)
923 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
925 def test__process_guest_epa_numa_params_with_1_node_paired_threads_ids(self
):
926 expected_numa_result
= {
927 "paired-threads-id": [("0", "1"), ("4", "5")],
929 expected_epa_vcpu_set_result
= False
931 "numa-node-policy": {
935 "paired-thread-ids": [
951 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
952 guest_epa_quota
=guest_epa_quota
,
955 self
.assertDictEqual(expected_numa_result
, numa_result
)
956 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
958 def test__process_guest_epa_numa_params_with_1_node_num_threads(self
):
959 expected_numa_result
= {"threads": 3}
960 expected_epa_vcpu_set_result
= True
962 "numa-node-policy": {
971 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
972 guest_epa_quota
=guest_epa_quota
,
975 self
.assertDictEqual(expected_numa_result
, numa_result
)
976 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
978 def test__process_guest_epa_numa_params_with_1_node_memory_mb(self
):
979 expected_numa_result
= {"memory": 2}
980 expected_epa_vcpu_set_result
= False
982 "numa-node-policy": {
991 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
992 guest_epa_quota
=guest_epa_quota
,
995 self
.assertDictEqual(expected_numa_result
, numa_result
)
996 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
998 def test__process_guest_epa_numa_params_with_1_node(self
):
999 expected_numa_result
= {
1001 "paired-threads": 3,
1002 "paired-threads-id": [("0", "1"), ("4", "5")],
1006 expected_epa_vcpu_set_result
= True
1008 "numa-node-policy": {
1013 "num-paired-threads": "3",
1014 "paired-thread-ids": [
1032 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
1033 guest_epa_quota
=guest_epa_quota
,
1036 self
.assertDictEqual(expected_numa_result
, numa_result
)
1037 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1039 def test__process_guest_epa_numa_params_with_2_nodes(self
):
1040 expected_numa_result
= {
1042 "paired-threads": 3,
1043 "paired-threads-id": [("0", "1"), ("4", "5")],
1047 expected_epa_vcpu_set_result
= True
1049 "numa-node-policy": {
1054 "num-paired-threads": "3",
1055 "paired-thread-ids": [
1072 "num-paired-threads": "7",
1073 "paired-thread-ids": [
1091 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
1092 guest_epa_quota
=guest_epa_quota
,
1095 self
.assertDictEqual(expected_numa_result
, numa_result
)
1096 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1098 def test__process_guest_epa_cpu_pinning_params_with_empty_params(self
):
1099 expected_numa_result
= {}
1100 expected_epa_vcpu_set_result
= False
1101 guest_epa_quota
= {}
1103 epa_vcpu_set
= False
1105 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_cpu
_pinning
_params
(
1106 guest_epa_quota
=guest_epa_quota
,
1107 vcpu_count
=vcpu_count
,
1108 epa_vcpu_set
=epa_vcpu_set
,
1111 self
.assertDictEqual(expected_numa_result
, numa_result
)
1112 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1114 def test__process_guest_epa_cpu_pinning_params_with_wrong_params(self
):
1115 expected_numa_result
= {}
1116 expected_epa_vcpu_set_result
= False
1118 "no-cpu-pinning-policy": "here",
1121 epa_vcpu_set
= False
1123 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_cpu
_pinning
_params
(
1124 guest_epa_quota
=guest_epa_quota
,
1125 vcpu_count
=vcpu_count
,
1126 epa_vcpu_set
=epa_vcpu_set
,
1129 self
.assertDictEqual(expected_numa_result
, numa_result
)
1130 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1132 def test__process_guest_epa_cpu_pinning_params_with_epa_vcpu_set(self
):
1133 expected_numa_result
= {}
1134 expected_epa_vcpu_set_result
= True
1136 "cpu-pinning-policy": "DEDICATED",
1141 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_cpu
_pinning
_params
(
1142 guest_epa_quota
=guest_epa_quota
,
1143 vcpu_count
=vcpu_count
,
1144 epa_vcpu_set
=epa_vcpu_set
,
1147 self
.assertDictEqual(expected_numa_result
, numa_result
)
1148 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1150 def test__process_guest_epa_cpu_pinning_params_with_threads(self
):
1151 expected_numa_result
= {"threads": 3}
1152 expected_epa_vcpu_set_result
= True
1154 "cpu-pinning-policy": "DEDICATED",
1155 "cpu-thread-pinning-policy": "PREFER",
1158 epa_vcpu_set
= False
1160 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_cpu
_pinning
_params
(
1161 guest_epa_quota
=guest_epa_quota
,
1162 vcpu_count
=vcpu_count
,
1163 epa_vcpu_set
=epa_vcpu_set
,
1166 self
.assertDictEqual(expected_numa_result
, numa_result
)
1167 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1169 def test__process_guest_epa_cpu_pinning_params(self
):
1170 expected_numa_result
= {"cores": 3}
1171 expected_epa_vcpu_set_result
= True
1173 "cpu-pinning-policy": "DEDICATED",
1176 epa_vcpu_set
= False
1178 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_cpu
_pinning
_params
(
1179 guest_epa_quota
=guest_epa_quota
,
1180 vcpu_count
=vcpu_count
,
1181 epa_vcpu_set
=epa_vcpu_set
,
1184 self
.assertDictEqual(expected_numa_result
, numa_result
)
1185 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1187 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1188 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1189 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1190 def test__process_guest_epa_params_with_empty_params(
1192 guest_epa_numa_params
,
1193 guest_epa_cpu_pinning_params
,
1194 guest_epa_quota_params
,
1196 expected_result
= {}
1199 result
= Ns
._process
_epa
_params
(
1200 target_flavor
=target_flavor
,
1203 self
.assertDictEqual(expected_result
, result
)
1204 self
.assertFalse(guest_epa_numa_params
.called
)
1205 self
.assertFalse(guest_epa_cpu_pinning_params
.called
)
1206 self
.assertFalse(guest_epa_quota_params
.called
)
1208 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1209 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1210 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1211 def test__process_guest_epa_params_with_wrong_params(
1213 guest_epa_numa_params
,
1214 guest_epa_cpu_pinning_params
,
1215 guest_epa_quota_params
,
1217 expected_result
= {}
1219 "no-guest-epa": "here",
1222 result
= Ns
._process
_epa
_params
(
1223 target_flavor
=target_flavor
,
1226 self
.assertDictEqual(expected_result
, result
)
1227 self
.assertFalse(guest_epa_numa_params
.called
)
1228 self
.assertFalse(guest_epa_cpu_pinning_params
.called
)
1229 self
.assertFalse(guest_epa_quota_params
.called
)
1231 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1232 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1233 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1234 def test__process_guest_epa_params(
1236 guest_epa_numa_params
,
1237 guest_epa_cpu_pinning_params
,
1238 guest_epa_quota_params
,
1240 expected_result
= {}
1247 guest_epa_numa_params
.return_value
= ({}, False)
1248 guest_epa_cpu_pinning_params
.return_value
= ({}, False)
1249 guest_epa_quota_params
.return_value
= {}
1251 result
= Ns
._process
_epa
_params
(
1252 target_flavor
=target_flavor
,
1255 self
.assertDictEqual(expected_result
, result
)
1256 self
.assertTrue(guest_epa_numa_params
.called
)
1257 self
.assertTrue(guest_epa_cpu_pinning_params
.called
)
1258 self
.assertTrue(guest_epa_quota_params
.called
)
1260 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1261 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1262 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1263 def test__process_guest_epa_params_with_mempage_size(
1265 guest_epa_numa_params
,
1266 guest_epa_cpu_pinning_params
,
1267 guest_epa_quota_params
,
1270 "mempage-size": "1G",
1273 "guest-epa": {"vcpu-count": 1, "mempage-size": "1G"},
1276 guest_epa_numa_params
.return_value
= ({}, False)
1277 guest_epa_cpu_pinning_params
.return_value
= ({}, False)
1278 guest_epa_quota_params
.return_value
= {}
1280 result
= Ns
._process
_epa
_params
(
1281 target_flavor
=target_flavor
,
1284 self
.assertDictEqual(expected_result
, result
)
1285 self
.assertTrue(guest_epa_numa_params
.called
)
1286 self
.assertTrue(guest_epa_cpu_pinning_params
.called
)
1287 self
.assertTrue(guest_epa_quota_params
.called
)
1289 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1290 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1291 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1292 def test__process_guest_epa_params_with_numa(
1294 guest_epa_numa_params
,
1295 guest_epa_cpu_pinning_params
,
1296 guest_epa_quota_params
,
1299 "mempage-size": "1G",
1304 "paired-threads": 3,
1305 "paired-threads-id": [("0", "1"), ("4", "5")],
1309 "cpu-quota": {"limit": 10, "reserve": 20, "shares": 30},
1310 "disk-io-quota": {"limit": 10, "reserve": 20, "shares": 30},
1311 "mem-quota": {"limit": 10, "reserve": 20, "shares": 30},
1312 "vif-quota": {"limit": 10, "reserve": 20, "shares": 30},
1317 "mempage-size": "1G",
1318 "cpu-pinning-policy": "DEDICATED",
1319 "cpu-thread-pinning-policy": "PREFER",
1320 "numa-node-policy": {
1325 "num-paired-threads": "3",
1326 "paired-thread-ids": [
1365 guest_epa_numa_params
.return_value
= (
1368 "paired-threads": 3,
1369 "paired-threads-id": [("0", "1"), ("4", "5")],
1375 guest_epa_cpu_pinning_params
.return_value
= (
1381 guest_epa_quota_params
.return_value
= {
1404 result
= Ns
._process
_epa
_params
(
1405 target_flavor
=target_flavor
,
1408 self
.assertDictEqual(expected_result
, result
)
1409 self
.assertTrue(guest_epa_numa_params
.called
)
1410 self
.assertTrue(guest_epa_cpu_pinning_params
.called
)
1411 self
.assertTrue(guest_epa_quota_params
.called
)
1413 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1414 def test__process_flavor_params_with_empty_target_flavor(
1423 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1428 target_record_id
= ""
1430 with self
.assertRaises(KeyError):
1431 Ns
._process
_flavor
_params
(
1432 target_flavor
=target_flavor
,
1435 target_record_id
=target_record_id
,
1438 self
.assertFalse(epa_params
.called
)
1440 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1441 def test__process_flavor_params_with_wrong_target_flavor(
1447 "no-target-flavor": "here",
1451 target_record_id
= ""
1453 with self
.assertRaises(KeyError):
1454 Ns
._process
_flavor
_params
(
1455 target_flavor
=target_flavor
,
1458 target_record_id
=target_record_id
,
1461 self
.assertFalse(epa_params
.called
)
1463 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1464 def test__process_flavor_params_with_empty_indata(
1489 "memory-mb": "1024",
1494 target_record_id
= ""
1496 epa_params
.return_value
= {}
1498 result
= Ns
._process
_flavor
_params
(
1499 target_flavor
=target_flavor
,
1502 target_record_id
=target_record_id
,
1505 self
.assertTrue(epa_params
.called
)
1506 self
.assertDictEqual(result
, expected_result
)
1508 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1509 def test__process_flavor_params_with_wrong_indata(
1534 "memory-mb": "1024",
1541 target_record_id
= ""
1543 epa_params
.return_value
= {}
1545 result
= Ns
._process
_flavor
_params
(
1546 target_flavor
=target_flavor
,
1549 target_record_id
=target_record_id
,
1552 self
.assertTrue(epa_params
.called
)
1553 self
.assertDictEqual(result
, expected_result
)
1555 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1556 def test__process_flavor_params_with_ephemeral_disk(
1560 db
= MagicMock(name
="database mock")
1565 db
.get_one
.return_value
= {
1566 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1571 {"id": "without_volumes-VM", "min-number-of-instances": 1}
1575 "id": "without_volumes-vnf",
1576 "product-name": "without_volumes-vnf",
1579 "id": "without_volumes-VM",
1580 "name": "without_volumes-VM",
1581 "sw-image-desc": "ubuntu20.04",
1582 "alternative-sw-image-desc": [
1584 "ubuntu20.04-azure",
1586 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
1590 "virtual-storage-desc": [
1591 {"id": "root-volume", "size-of-storage": "10"},
1593 "id": "ephemeral-volume",
1594 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1595 "size-of-storage": "1",
1601 "path": "/app/storage/",
1629 "memory-mb": "1024",
1637 "ns-flavor-id": "test_id",
1638 "virtual-storages": [
1640 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1641 "size-of-storage": "10",
1646 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1651 target_record_id
= ""
1653 epa_params
.return_value
= {}
1655 result
= Ns
._process
_flavor
_params
(
1656 target_flavor
=target_flavor
,
1659 target_record_id
=target_record_id
,
1663 self
.assertTrue(epa_params
.called
)
1664 self
.assertDictEqual(result
, expected_result
)
1666 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1667 def test__process_flavor_params_with_swap_disk(
1695 "memory-mb": "1024",
1703 "ns-flavor-id": "test_id",
1704 "virtual-storages": [
1706 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
1707 "size-of-storage": "20",
1712 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1717 target_record_id
= ""
1719 epa_params
.return_value
= {}
1721 result
= Ns
._process
_flavor
_params
(
1722 target_flavor
=target_flavor
,
1725 target_record_id
=target_record_id
,
1728 self
.assertTrue(epa_params
.called
)
1729 self
.assertDictEqual(result
, expected_result
)
1731 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1732 def test__process_flavor_params_with_persistent_root_disk(
1736 db
= MagicMock(name
="database mock")
1742 db
.get_one
.return_value
= {
1743 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1748 {"id": "several_volumes-VM", "min-number-of-instances": 1}
1752 "id": "several_volumes-vnf",
1753 "product-name": "several_volumes-vnf",
1756 "id": "several_volumes-VM",
1757 "name": "several_volumes-VM",
1758 "sw-image-desc": "ubuntu20.04",
1759 "alternative-sw-image-desc": [
1761 "ubuntu20.04-azure",
1763 "virtual-storage-desc": [
1764 "persistent-root-volume",
1769 "virtual-storage-desc": [
1771 "id": "persistent-root-volume",
1772 "type-of-storage": "persistent-storage:persistent-storage",
1773 "size-of-storage": "10",
1779 "path": "/app/storage/",
1805 "memory-mb": "1024",
1813 "vdu-name": "several_volumes-VM",
1814 "ns-flavor-id": "test_id",
1815 "virtual-storages": [
1817 "type-of-storage": "persistent-storage:persistent-storage",
1818 "size-of-storage": "10",
1823 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1828 target_record_id
= ""
1830 epa_params
.return_value
= {}
1832 result
= Ns
._process
_flavor
_params
(
1833 target_flavor
=target_flavor
,
1836 target_record_id
=target_record_id
,
1840 self
.assertTrue(epa_params
.called
)
1841 self
.assertDictEqual(result
, expected_result
)
1843 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1844 def test__process_flavor_params_with_epa_params(
1856 "numa": "there-is-numa-here",
1867 "numa": "there-is-numa-here",
1876 "memory-mb": "1024",
1884 "ns-flavor-id": "test_id",
1887 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1892 target_record_id
= ""
1894 epa_params
.return_value
= {
1895 "numa": "there-is-numa-here",
1898 result
= Ns
._process
_flavor
_params
(
1899 target_flavor
=target_flavor
,
1902 target_record_id
=target_record_id
,
1905 self
.assertTrue(epa_params
.called
)
1906 self
.assertDictEqual(result
, expected_result
)
1908 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1909 def test__process_flavor_params(
1913 db
= MagicMock(name
="database mock")
1919 db
.get_one
.return_value
= {
1920 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1925 {"id": "without_volumes-VM", "min-number-of-instances": 1}
1929 "id": "without_volumes-vnf",
1930 "product-name": "without_volumes-vnf",
1933 "id": "without_volumes-VM",
1934 "name": "without_volumes-VM",
1935 "sw-image-desc": "ubuntu20.04",
1936 "alternative-sw-image-desc": [
1938 "ubuntu20.04-azure",
1940 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
1944 "virtual-storage-desc": [
1945 {"id": "root-volume", "size-of-storage": "10"},
1947 "id": "ephemeral-volume",
1948 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1949 "size-of-storage": "1",
1955 "path": "/app/storage/",
1970 "numa": "there-is-numa-here",
1983 "numa": "there-is-numa-here",
1992 "memory-mb": "1024",
2000 "ns-flavor-id": "test_id",
2001 "virtual-storages": [
2003 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2004 "size-of-storage": "10",
2007 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
2008 "size-of-storage": "20",
2013 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2018 target_record_id
= ""
2020 epa_params
.return_value
= {
2021 "numa": "there-is-numa-here",
2024 result
= Ns
._process
_flavor
_params
(
2025 target_flavor
=target_flavor
,
2028 target_record_id
=target_record_id
,
2032 self
.assertTrue(epa_params
.called
)
2033 self
.assertDictEqual(result
, expected_result
)
2035 def test__ip_profile_to_ro_with_none(self
):
2038 result
= Ns
._ip
_profile
_to
_ro
(
2039 ip_profile
=ip_profile
,
2042 self
.assertIsNone(result
)
2044 def test__ip_profile_to_ro_with_empty_profile(self
):
2047 result
= Ns
._ip
_profile
_to
_ro
(
2048 ip_profile
=ip_profile
,
2051 self
.assertIsNone(result
)
2053 def test__ip_profile_to_ro_with_wrong_profile(self
):
2055 "no-profile": "here",
2058 "ip_version": "IPv4",
2059 "subnet_address": None,
2060 "gateway_address": None,
2061 "dhcp_enabled": False,
2062 "dhcp_start_address": None,
2066 result
= Ns
._ip
_profile
_to
_ro
(
2067 ip_profile
=ip_profile
,
2070 self
.assertDictEqual(expected_result
, result
)
2072 def test__ip_profile_to_ro_with_ipv4_profile(self
):
2074 "ip-version": "ipv4",
2075 "subnet-address": "192.168.0.0/24",
2076 "gateway-address": "192.168.0.254",
2079 "start-address": "192.168.0.10",
2084 "ip_version": "IPv4",
2085 "subnet_address": "192.168.0.0/24",
2086 "gateway_address": "192.168.0.254",
2087 "dhcp_enabled": True,
2088 "dhcp_start_address": "192.168.0.10",
2092 result
= Ns
._ip
_profile
_to
_ro
(
2093 ip_profile
=ip_profile
,
2096 self
.assertDictEqual(expected_result
, result
)
2098 def test__ip_profile_to_ro_with_ipv6_profile(self
):
2100 "ip-version": "ipv6",
2101 "subnet-address": "2001:0200:0001::/48",
2102 "gateway-address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
2105 "start-address": "2001:0200:0001::0010",
2110 "ip_version": "IPv6",
2111 "subnet_address": "2001:0200:0001::/48",
2112 "gateway_address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
2113 "dhcp_enabled": True,
2114 "dhcp_start_address": "2001:0200:0001::0010",
2118 result
= Ns
._ip
_profile
_to
_ro
(
2119 ip_profile
=ip_profile
,
2122 self
.assertDictEqual(expected_result
, result
)
2124 def test__ip_profile_to_ro_with_dns_server(self
):
2126 "ip-version": "ipv4",
2127 "subnet-address": "192.168.0.0/24",
2128 "gateway-address": "192.168.0.254",
2131 "start-address": "192.168.0.10",
2136 "address": "8.8.8.8",
2139 "address": "1.1.1.1",
2142 "address": "1.0.0.1",
2147 "ip_version": "IPv4",
2148 "subnet_address": "192.168.0.0/24",
2149 "gateway_address": "192.168.0.254",
2150 "dhcp_enabled": True,
2151 "dhcp_start_address": "192.168.0.10",
2153 "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
2156 result
= Ns
._ip
_profile
_to
_ro
(
2157 ip_profile
=ip_profile
,
2160 self
.assertDictEqual(expected_result
, result
)
2162 def test__ip_profile_to_ro_with_security_group(self
):
2164 "ip-version": "ipv4",
2165 "subnet-address": "192.168.0.0/24",
2166 "gateway-address": "192.168.0.254",
2169 "start-address": "192.168.0.10",
2173 "some-security-group": "here",
2177 "ip_version": "IPv4",
2178 "subnet_address": "192.168.0.0/24",
2179 "gateway_address": "192.168.0.254",
2180 "dhcp_enabled": True,
2181 "dhcp_start_address": "192.168.0.10",
2184 "some-security-group": "here",
2188 result
= Ns
._ip
_profile
_to
_ro
(
2189 ip_profile
=ip_profile
,
2192 self
.assertDictEqual(expected_result
, result
)
2194 def test__ip_profile_to_ro(self
):
2196 "ip-version": "ipv4",
2197 "subnet-address": "192.168.0.0/24",
2198 "gateway-address": "192.168.0.254",
2201 "start-address": "192.168.0.10",
2206 "address": "8.8.8.8",
2209 "address": "1.1.1.1",
2212 "address": "1.0.0.1",
2216 "some-security-group": "here",
2220 "ip_version": "IPv4",
2221 "subnet_address": "192.168.0.0/24",
2222 "gateway_address": "192.168.0.254",
2223 "dhcp_enabled": True,
2224 "dhcp_start_address": "192.168.0.10",
2226 "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
2228 "some-security-group": "here",
2232 result
= Ns
._ip
_profile
_to
_ro
(
2233 ip_profile
=ip_profile
,
2236 self
.assertDictEqual(expected_result
, result
)
2238 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2239 def test__process_net_params_with_empty_params(
2250 "provider_network": "some-profile-here",
2252 target_record_id
= ""
2255 "net_name": "ns-name-vld-name",
2256 "net_type": "bridge",
2258 "some_ip_profile": "here",
2260 "provider_network_profile": "some-profile-here",
2264 ip_profile_to_ro
.return_value
= {
2265 "some_ip_profile": "here",
2268 result
= Ns
._process
_net
_params
(
2269 target_vld
=target_vld
,
2272 target_record_id
=target_record_id
,
2275 self
.assertDictEqual(expected_result
, result
)
2276 self
.assertTrue(ip_profile_to_ro
.called
)
2278 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2279 def test__process_net_params_with_vim_info_sdn(
2291 "sdn-ports": ["some", "ports", "here"],
2292 "vlds": ["some", "vlds", "here"],
2295 target_record_id
= "vld.sdn.something"
2298 "sdn-ports": ["some", "ports", "here"],
2299 "vlds": ["some", "vlds", "here"],
2304 result
= Ns
._process
_net
_params
(
2305 target_vld
=target_vld
,
2308 target_record_id
=target_record_id
,
2311 self
.assertDictEqual(expected_result
, result
)
2312 self
.assertFalse(ip_profile_to_ro
.called
)
2314 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2315 def test__process_net_params_with_vim_info_sdn_target_vim(
2327 "sdn-ports": ["some", "ports", "here"],
2328 "vlds": ["some", "vlds", "here"],
2329 "target_vim": "some-vim",
2332 target_record_id
= "vld.sdn.something"
2334 "depends_on": ["some-vim vld.sdn"],
2336 "sdn-ports": ["some", "ports", "here"],
2337 "vlds": ["some", "vlds", "here"],
2338 "target_vim": "some-vim",
2343 result
= Ns
._process
_net
_params
(
2344 target_vld
=target_vld
,
2347 target_record_id
=target_record_id
,
2350 self
.assertDictEqual(expected_result
, result
)
2351 self
.assertFalse(ip_profile_to_ro
.called
)
2353 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2354 def test__process_net_params_with_vim_network_name(
2365 "vim_network_name": "some-network-name",
2367 target_record_id
= "vld.sdn.something"
2371 "name": "some-network-name",
2376 result
= Ns
._process
_net
_params
(
2377 target_vld
=target_vld
,
2380 target_record_id
=target_record_id
,
2383 self
.assertDictEqual(expected_result
, result
)
2384 self
.assertFalse(ip_profile_to_ro
.called
)
2386 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2387 def test__process_net_params_with_vim_network_id(
2398 "vim_network_id": "some-network-id",
2400 target_record_id
= "vld.sdn.something"
2404 "id": "some-network-id",
2409 result
= Ns
._process
_net
_params
(
2410 target_vld
=target_vld
,
2413 target_record_id
=target_record_id
,
2416 self
.assertDictEqual(expected_result
, result
)
2417 self
.assertFalse(ip_profile_to_ro
.called
)
2419 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2420 def test__process_net_params_with_mgmt_network(
2427 "mgmt-network": "some-mgmt-network",
2433 target_record_id
= "vld.sdn.something"
2441 result
= Ns
._process
_net
_params
(
2442 target_vld
=target_vld
,
2445 target_record_id
=target_record_id
,
2448 self
.assertDictEqual(expected_result
, result
)
2449 self
.assertFalse(ip_profile_to_ro
.called
)
2451 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2452 def test__process_net_params_with_underlay_eline(
2458 "underlay": "some-underlay-here",
2465 "provider_network": "some-profile-here",
2467 target_record_id
= ""
2471 "some_ip_profile": "here",
2473 "net_name": "ns-name-vld-name",
2475 "provider_network_profile": "some-profile-here",
2479 ip_profile_to_ro
.return_value
= {
2480 "some_ip_profile": "here",
2483 result
= Ns
._process
_net
_params
(
2484 target_vld
=target_vld
,
2487 target_record_id
=target_record_id
,
2490 self
.assertDictEqual(expected_result
, result
)
2491 self
.assertTrue(ip_profile_to_ro
.called
)
2493 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2494 def test__process_net_params_with_underlay_elan(
2500 "underlay": "some-underlay-here",
2507 "provider_network": "some-profile-here",
2509 target_record_id
= ""
2513 "some_ip_profile": "here",
2515 "net_name": "ns-name-vld-name",
2517 "provider_network_profile": "some-profile-here",
2521 ip_profile_to_ro
.return_value
= {
2522 "some_ip_profile": "here",
2525 result
= Ns
._process
_net
_params
(
2526 target_vld
=target_vld
,
2529 target_record_id
=target_record_id
,
2532 self
.assertDictEqual(expected_result
, result
)
2533 self
.assertTrue(ip_profile_to_ro
.called
)
2535 def test__get_cloud_init_exception(self
):
2536 db_mock
= MagicMock(name
="database mock")
2541 with self
.assertRaises(NsException
):
2542 Ns
._get
_cloud
_init
(db
=db_mock
, fs
=fs_mock
, location
=location
)
2544 def test__get_cloud_init_file_fs_exception(self
):
2545 db_mock
= MagicMock(name
="database mock")
2548 location
= "vnfr_id_123456:file:test_file"
2549 db_mock
.get_one
.return_value
= {
2552 "folder": "/home/osm",
2553 "pkg-dir": "vnfr_test_dir",
2558 with self
.assertRaises(NsException
):
2559 Ns
._get
_cloud
_init
(db
=db_mock
, fs
=fs_mock
, location
=location
)
2561 def test__get_cloud_init_file(self
):
2562 db_mock
= MagicMock(name
="database mock")
2563 fs_mock
= MagicMock(name
="filesystem mock")
2564 file_mock
= MagicMock(name
="file mock")
2566 location
= "vnfr_id_123456:file:test_file"
2567 cloud_init_content
= "this is a cloud init file content"
2569 db_mock
.get_one
.return_value
= {
2572 "folder": "/home/osm",
2573 "pkg-dir": "vnfr_test_dir",
2577 fs_mock
.file_open
.return_value
= file_mock
2578 file_mock
.__enter
__.return_value
.read
.return_value
= cloud_init_content
2580 result
= Ns
._get
_cloud
_init
(db
=db_mock
, fs
=fs_mock
, location
=location
)
2582 self
.assertEqual(cloud_init_content
, result
)
2584 def test__get_cloud_init_vdu(self
):
2585 db_mock
= MagicMock(name
="database mock")
2588 location
= "vnfr_id_123456:vdu:0"
2589 cloud_init_content
= "this is a cloud init file content"
2591 db_mock
.get_one
.return_value
= {
2594 "cloud-init": cloud_init_content
,
2599 result
= Ns
._get
_cloud
_init
(db
=db_mock
, fs
=fs_mock
, location
=location
)
2601 self
.assertEqual(cloud_init_content
, result
)
2603 @patch("jinja2.Environment.__init__")
2604 def test__parse_jinja2_undefined_error(self
, env_mock
: Mock
):
2605 cloud_init_content
= None
2609 env_mock
.side_effect
= UndefinedError("UndefinedError occurred.")
2611 with self
.assertRaises(NsException
):
2613 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2616 @patch("jinja2.Environment.__init__")
2617 def test__parse_jinja2_template_error(self
, env_mock
: Mock
):
2618 cloud_init_content
= None
2622 env_mock
.side_effect
= TemplateError("TemplateError occurred.")
2624 with self
.assertRaises(NsException
):
2626 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2629 @patch("jinja2.Environment.__init__")
2630 def test__parse_jinja2_template_not_found(self
, env_mock
: Mock
):
2631 cloud_init_content
= None
2635 env_mock
.side_effect
= TemplateNotFound("TemplateNotFound occurred.")
2637 with self
.assertRaises(NsException
):
2639 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2642 def test_rendering_jinja2_temp_without_special_characters(self
):
2643 cloud_init_content
= """
2646 table_type: {{type}}
2648 overwrite: {{is_override}}
2651 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2655 "is_override": "False",
2656 "command": "; mkdir abc",
2658 context
= "cloud-init for VM"
2659 expected_result
= """
2667 - [ sh, -xc, "echo $(date) '; mkdir abc'" ]
2669 result
= Ns
._parse
_jinja
2(
2670 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2672 self
.assertEqual(result
, expected_result
)
2674 def test_rendering_jinja2_temp_with_special_characters(self
):
2675 cloud_init_content
= """
2678 table_type: {{type}}
2680 overwrite: {{is_override}}
2683 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2687 "is_override": "False",
2688 "command": "& rm -rf",
2690 context
= "cloud-init for VM"
2691 expected_result
= """
2699 - [ sh, -xc, "echo $(date) '& rm -rf /'" ]
2701 result
= Ns
._parse
_jinja
2(
2702 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2704 self
.assertNotEqual(result
, expected_result
)
2706 def test_rendering_jinja2_temp_with_special_characters_autoescape_is_false(self
):
2707 with
patch("osm_ng_ro.ns.Environment") as mock_environment
:
2708 mock_environment
.return_value
= Environment(
2709 undefined
=StrictUndefined
,
2710 autoescape
=select_autoescape(default_for_string
=False, default
=False),
2712 cloud_init_content
= """
2715 table_type: {{type}}
2717 overwrite: {{is_override}}
2720 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2724 "is_override": "False",
2725 "command": "& rm -rf /",
2727 context
= "cloud-init for VM"
2728 expected_result
= """
2736 - [ sh, -xc, "echo $(date) '& rm -rf /'" ]
2738 result
= Ns
._parse
_jinja
2(
2739 cloud_init_content
=cloud_init_content
,
2743 self
.assertEqual(result
, expected_result
)
2745 def test__process_vdu_params_empty_kargs(self
):
2748 def test__process_vdu_params_interface_ns_vld_id(self
):
2751 def test__process_vdu_params_interface_vnf_vld_id(self
):
2754 def test__process_vdu_params_interface_unknown(self
):
2757 def test__process_vdu_params_interface_port_security_enabled(self
):
2760 def test__process_vdu_params_interface_port_security_disable_strategy(self
):
2763 def test__process_vdu_params_interface_sriov(self
):
2766 def test__process_vdu_params_interface_pci_passthrough(self
):
2769 def test__process_vdu_params_interface_om_mgmt(self
):
2772 def test__process_vdu_params_interface_mgmt_interface(self
):
2775 def test__process_vdu_params_interface_mgmt_vnf(self
):
2778 def test__process_vdu_params_interface_bridge(self
):
2781 def test__process_vdu_params_interface_ip_address(self
):
2784 def test__process_vdu_params_interface_mac_address(self
):
2787 def test__process_vdu_params_vdu_cloud_init_missing(self
):
2790 def test__process_vdu_params_vdu_cloud_init_present(self
):
2793 def test__process_vdu_params_vdu_boot_data_drive(self
):
2796 def test__process_vdu_params_vdu_ssh_keys(self
):
2799 def test__process_vdu_params_vdu_ssh_access_required(self
):
2802 @patch("osm_ng_ro.ns.Ns._get_cloud_init")
2803 @patch("osm_ng_ro.ns.Ns._parse_jinja2")
2804 def test__process_vdu_params_vdu_persistent_root_volume(
2805 self
, get_cloud_init
, parse_jinja2
2807 db
= MagicMock(name
="database mock")
2810 "vdu2cloud_init": {},
2812 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2813 "member-vnf-index-ref": "vnf-several-volumes",
2816 get_cloud_init
.return_value
= {}
2817 parse_jinja2
.return_value
= {}
2818 db
.get_one
.return_value
= {
2819 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2824 {"id": "several_volumes-VM", "min-number-of-instances": 1}
2828 "id": "several_volumes-vnf",
2829 "product-name": "several_volumes-vnf",
2832 "id": "several_volumes-VM",
2833 "name": "several_volumes-VM",
2834 "sw-image-desc": "ubuntu20.04",
2835 "alternative-sw-image-desc": [
2837 "ubuntu20.04-azure",
2839 "virtual-storage-desc": [
2840 "persistent-root-volume",
2841 "persistent-volume2",
2847 "virtual-storage-desc": [
2849 "id": "persistent-volume2",
2850 "type-of-storage": "persistent-storage:persistent-storage",
2851 "size-of-storage": "10",
2854 "id": "persistent-root-volume",
2855 "type-of-storage": "persistent-storage:persistent-storage",
2856 "size-of-storage": "10",
2859 "id": "ephemeral-volume",
2860 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2861 "size-of-storage": "1",
2867 "path": "/app/storage/",
2874 "_id": "09a0baa7-b7cb-4924-bd63-9f04a1c23960",
2875 "ns-flavor-id": "0",
2877 "vdu-name": "several_volumes-VM",
2881 "ns-vld-id": "mgmtnet",
2884 "virtual-storages": [
2886 "id": "persistent-volume2",
2887 "size-of-storage": "10",
2888 "type-of-storage": "persistent-storage:persistent-storage",
2891 "id": "persistent-root-volume",
2892 "size-of-storage": "10",
2893 "type-of-storage": "persistent-storage:persistent-storage",
2896 "id": "ephemeral-volume",
2897 "size-of-storage": "1",
2898 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2903 "name": "sample_name",
2905 expected_result
= [{"image_id": "ubuntu20.04", "size": "10"}, {"size": "10"}]
2906 result
= Ns
._process
_vdu
_params
(
2907 target_vdu
, indata
, vim_info
=None, target_record_id
=None, **kwargs
2910 expected_result
, result
["params"]["disk_list"], "Wrong Disk List"
2913 @patch("osm_ng_ro.ns.Ns._get_cloud_init")
2914 @patch("osm_ng_ro.ns.Ns._parse_jinja2")
2915 def test__process_vdu_params_vdu_without_persistent_storage(
2916 self
, get_cloud_init
, parse_jinja2
2918 db
= MagicMock(name
="database mock")
2921 "vdu2cloud_init": {},
2923 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2924 "member-vnf-index-ref": "vnf-several-volumes",
2927 get_cloud_init
.return_value
= {}
2928 parse_jinja2
.return_value
= {}
2929 db
.get_one
.return_value
= {
2930 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2935 {"id": "without_volumes-VM", "min-number-of-instances": 1}
2939 "id": "without_volumes-vnf",
2940 "product-name": "without_volumes-vnf",
2943 "id": "without_volumes-VM",
2944 "name": "without_volumes-VM",
2945 "sw-image-desc": "ubuntu20.04",
2946 "alternative-sw-image-desc": [
2948 "ubuntu20.04-azure",
2950 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
2954 "virtual-storage-desc": [
2955 {"id": "root-volume", "size-of-storage": "10"},
2957 "id": "ephemeral-volume",
2958 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2959 "size-of-storage": "1",
2965 "path": "/app/storage/",
2972 "_id": "09a0baa7-b7cb-4924-bd63-9f04a1c23960",
2973 "ns-flavor-id": "0",
2975 "vdu-name": "without_volumes-VM",
2979 "ns-vld-id": "mgmtnet",
2982 "virtual-storages": [
2984 "id": "root-volume",
2985 "size-of-storage": "10",
2988 "id": "ephemeral-volume",
2989 "size-of-storage": "1",
2990 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2995 "name": "sample_name",
2997 expected_result
= []
2998 result
= Ns
._process
_vdu
_params
(
2999 target_vdu
, indata
, vim_info
=None, target_record_id
=None, **kwargs
3002 expected_result
, result
["params"]["disk_list"], "Wrong Disk List"
3005 def test__process_vdu_params(self
):
3008 @patch("osm_ng_ro.ns.Ns._assign_vim")
3009 def test__rebuild_start_stop_task(self
, assign_vim
):
3012 actions
= ["start", "stop", "rebuild"]
3013 vdu_id
= "bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3014 vnf_id
= "665b4165-ce24-4320-bf19-b9a45bade49f"
3016 action_id
= "bb937f49-3870-4169-b758-9732e1ff40f3"
3017 nsr_id
= "993166fe-723e-4680-ac4b-b1af2541ae31"
3019 target_vim
= "vim:f9f370ac-0d44-41a7-9000-457f2332bc35"
3020 t
= "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3021 for action
in actions
:
3023 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3024 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3025 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3026 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:0",
3027 "status": "SCHEDULED",
3030 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.0",
3031 "target_record_id": t
,
3033 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3037 extra_dict
["params"] = {
3038 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3041 task
= self
.ns
.rebuild_start_stop_task(
3051 self
.assertEqual(task
.get("action_id"), action_id
)
3052 self
.assertEqual(task
.get("nsr_id"), nsr_id
)
3053 self
.assertEqual(task
.get("target_id"), target_vim
)
3054 self
.assertDictEqual(task
, expected_result
)
3056 @patch("osm_ng_ro.ns.Ns._assign_vim")
3057 def test_verticalscale_task(self
, assign_vim
):
3061 action_id
= "bb937f49-3870-4169-b758-9732e1ff40f3"
3062 nsr_id
= "993166fe-723e-4680-ac4b-b1af2541ae31"
3064 target_record_id
= (
3065 "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
3066 "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3070 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3071 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3072 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3073 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1",
3074 "status": "SCHEDULED",
3076 "item": "verticalscale",
3077 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1",
3078 "target_record_id": target_record_id
,
3080 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3081 "flavor_dict": "flavor_dict",
3085 "id": "bb9c43f9-10a2-4569-a8a8-957c3528b6d1",
3087 "vim:f9f370ac-0d44-41a7-9000-457f2332bc35": {"interfaces": []}
3090 vnf
= {"_id": "665b4165-ce24-4320-bf19-b9a45bade49f"}
3091 extra_dict
["params"] = {
3092 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3093 "flavor_dict": "flavor_dict",
3095 task
= self
.ns
.verticalscale_task(
3096 vdu
, vnf
, vdu_index
, action_id
, nsr_id
, task_index
, extra_dict
3099 self
.assertDictEqual(task
, expected_result
)
3101 @patch("osm_ng_ro.ns.Ns._assign_vim")
3102 def test_migrate_task(self
, assign_vim
):
3106 action_id
= "bb937f49-3870-4169-b758-9732e1ff40f3"
3107 nsr_id
= "993166fe-723e-4680-ac4b-b1af2541ae31"
3109 target_record_id
= (
3110 "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
3111 "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3115 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3116 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3117 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3118 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1",
3119 "status": "SCHEDULED",
3122 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1",
3123 "target_record_id": target_record_id
,
3125 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3126 "migrate_host": "migrateToHost",
3130 "id": "bb9c43f9-10a2-4569-a8a8-957c3528b6d1",
3132 "vim:f9f370ac-0d44-41a7-9000-457f2332bc35": {"interfaces": []}
3135 vnf
= {"_id": "665b4165-ce24-4320-bf19-b9a45bade49f"}
3136 extra_dict
["params"] = {
3137 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3138 "migrate_host": "migrateToHost",
3140 task
= self
.ns
.migrate_task(
3141 vdu
, vnf
, vdu_index
, action_id
, nsr_id
, task_index
, extra_dict
3144 self
.assertDictEqual(task
, expected_result
)