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
,
841 self
.assertEqual(expected_numa_result
, numa_result
)
842 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
844 def test__process_guest_epa_numa_params_with_wrong_numa_params(self
):
845 expected_numa_result
= []
846 expected_epa_vcpu_set_result
= False
847 guest_epa_quota
= {"no_nume": "here"}
849 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
850 guest_epa_quota
=guest_epa_quota
,
853 self
.assertEqual(expected_numa_result
, numa_result
)
854 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
856 def test__process_guest_epa_numa_params_with_numa_node_policy(self
):
857 expected_numa_result
= []
858 expected_epa_vcpu_set_result
= False
859 guest_epa_quota
= {"numa-node-policy": {}}
861 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
862 guest_epa_quota
=guest_epa_quota
,
865 self
.assertEqual(expected_numa_result
, numa_result
)
866 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
868 def test__process_guest_epa_numa_params_with_no_node(self
):
869 expected_numa_result
= []
870 expected_epa_vcpu_set_result
= False
872 "numa-node-policy": {
877 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
878 guest_epa_quota
=guest_epa_quota
,
881 self
.assertEqual(expected_numa_result
, numa_result
)
882 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
884 def test__process_guest_epa_numa_params_with_1_node_num_cores(self
):
885 expected_numa_result
= [{"cores": 3}]
886 expected_epa_vcpu_set_result
= True
888 "numa-node-policy": {
897 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
898 guest_epa_quota
=guest_epa_quota
,
901 self
.assertEqual(expected_numa_result
, numa_result
)
902 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
904 def test__process_guest_epa_numa_params_with_1_node_paired_threads(self
):
905 expected_numa_result
= [{"paired_threads": 3}]
906 expected_epa_vcpu_set_result
= True
908 "numa-node-policy": {
911 "paired-threads": {"num-paired-threads": "3"},
917 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
918 guest_epa_quota
=guest_epa_quota
,
921 self
.assertEqual(expected_numa_result
, numa_result
)
922 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
924 def test__process_guest_epa_numa_params_with_1_node_paired_threads_ids(self
):
925 expected_numa_result
= [
927 "paired-threads-id": [("0", "1"), ("4", "5")],
930 expected_epa_vcpu_set_result
= False
932 "numa-node-policy": {
936 "paired-thread-ids": [
952 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
953 guest_epa_quota
=guest_epa_quota
,
956 self
.assertEqual(expected_numa_result
, numa_result
)
957 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
959 def test__process_guest_epa_numa_params_with_1_node_num_threads(self
):
960 expected_numa_result
= [{"threads": 3}]
961 expected_epa_vcpu_set_result
= True
963 "numa-node-policy": {
972 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
973 guest_epa_quota
=guest_epa_quota
,
976 self
.assertEqual(expected_numa_result
, numa_result
)
977 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
979 def test__process_guest_epa_numa_params_with_1_node_memory_mb(self
):
980 expected_numa_result
= [{"memory": 2}]
981 expected_epa_vcpu_set_result
= False
983 "numa-node-policy": {
992 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
993 guest_epa_quota
=guest_epa_quota
,
996 self
.assertEqual(expected_numa_result
, numa_result
)
997 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
999 def test__process_guest_epa_numa_params_with_1_node_vcpu(self
):
1000 expected_numa_result
= [
1006 expected_epa_vcpu_set_result
= False
1008 "numa-node-policy": {
1009 "node": [{"id": "0", "vcpu": [{"id": "0"}, {"id": "1"}]}],
1013 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
1014 guest_epa_quota
=guest_epa_quota
,
1017 self
.assertEqual(expected_numa_result
, numa_result
)
1018 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1020 def test__process_guest_epa_numa_params_with_2_node_vcpu(self
):
1021 expected_numa_result
= [
1032 expected_epa_vcpu_set_result
= False
1034 "numa-node-policy": {
1036 {"id": "0", "vcpu": [{"id": "0"}, {"id": "1"}]},
1037 {"id": "1", "vcpu": [{"id": "2"}, {"id": "3"}]},
1042 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
1043 guest_epa_quota
=guest_epa_quota
,
1046 self
.assertEqual(expected_numa_result
, numa_result
)
1047 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1049 def test__process_guest_epa_numa_params_with_1_node(self
):
1050 expected_numa_result
= [
1055 "paired_threads": 3,
1056 "paired-threads-id": [("0", "1"), ("4", "5")],
1061 expected_epa_vcpu_set_result
= True
1063 "numa-node-policy": {
1068 "num-paired-threads": "3",
1069 "paired-thread-ids": [
1087 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
1088 guest_epa_quota
=guest_epa_quota
,
1091 self
.assertEqual(expected_numa_result
, numa_result
)
1092 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1094 def test__process_guest_epa_numa_params_with_2_nodes(self
):
1095 expected_numa_result
= [
1098 "paired_threads": 3,
1099 "paired-threads-id": [("0", "1"), ("4", "5")],
1105 "paired_threads": 7,
1106 "paired-threads-id": [("2", "3"), ("5", "6")],
1111 expected_epa_vcpu_set_result
= True
1113 "numa-node-policy": {
1118 "num-paired-threads": "3",
1119 "paired-thread-ids": [
1136 "num-paired-threads": "7",
1137 "paired-thread-ids": [
1155 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_numa
_params
(
1156 guest_epa_quota
=guest_epa_quota
,
1159 self
.assertEqual(expected_numa_result
, numa_result
)
1160 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1162 def test__process_guest_epa_cpu_pinning_params_with_empty_params(self
):
1163 expected_numa_result
= {}
1164 expected_epa_vcpu_set_result
= False
1165 guest_epa_quota
= {}
1167 epa_vcpu_set
= False
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
,
1175 self
.assertDictEqual(expected_numa_result
, numa_result
)
1176 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1178 def test__process_guest_epa_cpu_pinning_params_with_wrong_params(self
):
1179 expected_numa_result
= {}
1180 expected_epa_vcpu_set_result
= False
1182 "no-cpu-pinning-policy": "here",
1185 epa_vcpu_set
= False
1187 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_cpu
_pinning
_params
(
1188 guest_epa_quota
=guest_epa_quota
,
1189 vcpu_count
=vcpu_count
,
1190 epa_vcpu_set
=epa_vcpu_set
,
1193 self
.assertDictEqual(expected_numa_result
, numa_result
)
1194 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1196 def test__process_guest_epa_cpu_pinning_params_with_epa_vcpu_set(self
):
1197 expected_numa_result
= {}
1198 expected_epa_vcpu_set_result
= True
1200 "cpu-pinning-policy": "DEDICATED",
1205 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_cpu
_pinning
_params
(
1206 guest_epa_quota
=guest_epa_quota
,
1207 vcpu_count
=vcpu_count
,
1208 epa_vcpu_set
=epa_vcpu_set
,
1211 self
.assertDictEqual(expected_numa_result
, numa_result
)
1212 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1214 def test__process_guest_epa_cpu_pinning_params_with_threads(self
):
1215 expected_numa_result
= {"threads": 3}
1216 expected_epa_vcpu_set_result
= True
1218 "cpu-pinning-policy": "DEDICATED",
1219 "cpu-thread-pinning-policy": "PREFER",
1222 epa_vcpu_set
= False
1224 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_cpu
_pinning
_params
(
1225 guest_epa_quota
=guest_epa_quota
,
1226 vcpu_count
=vcpu_count
,
1227 epa_vcpu_set
=epa_vcpu_set
,
1230 self
.assertDictEqual(expected_numa_result
, numa_result
)
1231 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1233 def test__process_guest_epa_cpu_pinning_params(self
):
1234 expected_numa_result
= {"cores": 3}
1235 expected_epa_vcpu_set_result
= True
1237 "cpu-pinning-policy": "DEDICATED",
1240 epa_vcpu_set
= False
1242 numa_result
, epa_vcpu_set_result
= Ns
._process
_guest
_epa
_cpu
_pinning
_params
(
1243 guest_epa_quota
=guest_epa_quota
,
1244 vcpu_count
=vcpu_count
,
1245 epa_vcpu_set
=epa_vcpu_set
,
1248 self
.assertDictEqual(expected_numa_result
, numa_result
)
1249 self
.assertEqual(expected_epa_vcpu_set_result
, epa_vcpu_set_result
)
1251 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1252 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1253 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1254 def test__process_guest_epa_params_with_empty_params(
1256 guest_epa_numa_params
,
1257 guest_epa_cpu_pinning_params
,
1258 guest_epa_quota_params
,
1260 expected_result
= {}
1263 result
= Ns
._process
_epa
_params
(
1264 target_flavor
=target_flavor
,
1267 self
.assertDictEqual(expected_result
, result
)
1268 self
.assertFalse(guest_epa_numa_params
.called
)
1269 self
.assertFalse(guest_epa_cpu_pinning_params
.called
)
1270 self
.assertFalse(guest_epa_quota_params
.called
)
1272 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1273 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1274 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1275 def test__process_guest_epa_params_with_wrong_params(
1277 guest_epa_numa_params
,
1278 guest_epa_cpu_pinning_params
,
1279 guest_epa_quota_params
,
1281 expected_result
= {}
1283 "no-guest-epa": "here",
1286 result
= Ns
._process
_epa
_params
(
1287 target_flavor
=target_flavor
,
1290 self
.assertDictEqual(expected_result
, result
)
1291 self
.assertFalse(guest_epa_numa_params
.called
)
1292 self
.assertFalse(guest_epa_cpu_pinning_params
.called
)
1293 self
.assertFalse(guest_epa_quota_params
.called
)
1295 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1296 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1297 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1298 def test__process_guest_epa_params(
1300 guest_epa_numa_params
,
1301 guest_epa_cpu_pinning_params
,
1302 guest_epa_quota_params
,
1305 "mem-policy": "STRICT",
1310 "numa-node-policy": {
1311 "mem-policy": "STRICT",
1316 guest_epa_numa_params
.return_value
= ({}, False)
1317 guest_epa_cpu_pinning_params
.return_value
= ({}, False)
1318 guest_epa_quota_params
.return_value
= {}
1320 result
= Ns
._process
_epa
_params
(
1321 target_flavor
=target_flavor
,
1324 self
.assertDictEqual(expected_result
, result
)
1325 self
.assertTrue(guest_epa_numa_params
.called
)
1326 self
.assertTrue(guest_epa_cpu_pinning_params
.called
)
1327 self
.assertTrue(guest_epa_quota_params
.called
)
1329 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1330 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1331 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1332 def test__process_guest_epa_params_with_mempage_size(
1334 guest_epa_numa_params
,
1335 guest_epa_cpu_pinning_params
,
1336 guest_epa_quota_params
,
1339 "mempage-size": "1G",
1340 "mem-policy": "STRICT",
1345 "mempage-size": "1G",
1346 "numa-node-policy": {
1347 "mem-policy": "STRICT",
1352 guest_epa_numa_params
.return_value
= ({}, False)
1353 guest_epa_cpu_pinning_params
.return_value
= ({}, False)
1354 guest_epa_quota_params
.return_value
= {}
1356 result
= Ns
._process
_epa
_params
(
1357 target_flavor
=target_flavor
,
1360 self
.assertDictEqual(expected_result
, result
)
1361 self
.assertTrue(guest_epa_numa_params
.called
)
1362 self
.assertTrue(guest_epa_cpu_pinning_params
.called
)
1363 self
.assertTrue(guest_epa_quota_params
.called
)
1365 @patch("osm_ng_ro.ns.Ns._process_guest_epa_quota_params")
1366 @patch("osm_ng_ro.ns.Ns._process_guest_epa_cpu_pinning_params")
1367 @patch("osm_ng_ro.ns.Ns._process_guest_epa_numa_params")
1368 def test__process_guest_epa_params_with_numa(
1370 guest_epa_numa_params
,
1371 guest_epa_cpu_pinning_params
,
1372 guest_epa_quota_params
,
1375 "mempage-size": "1G",
1376 "cpu-pinning-policy": "DEDICATED",
1377 "cpu-thread-pinning-policy": "PREFER",
1382 "paired-threads": 3,
1383 "paired-threads-id": [("0", "1"), ("4", "5")],
1387 "cpu-quota": {"limit": 10, "reserve": 20, "shares": 30},
1388 "disk-io-quota": {"limit": 10, "reserve": 20, "shares": 30},
1389 "mem-quota": {"limit": 10, "reserve": 20, "shares": 30},
1390 "vif-quota": {"limit": 10, "reserve": 20, "shares": 30},
1395 "mempage-size": "1G",
1396 "cpu-pinning-policy": "DEDICATED",
1397 "cpu-thread-pinning-policy": "PREFER",
1398 "numa-node-policy": {
1403 "num-paired-threads": "3",
1404 "paired-thread-ids": [
1443 guest_epa_numa_params
.return_value
= (
1447 "paired-threads": 3,
1448 "paired-threads-id": [("0", "1"), ("4", "5")],
1455 guest_epa_cpu_pinning_params
.return_value
= (
1461 guest_epa_quota_params
.return_value
= {
1484 result
= Ns
._process
_epa
_params
(
1485 target_flavor
=target_flavor
,
1487 self
.assertEqual(expected_result
, result
)
1488 self
.assertTrue(guest_epa_numa_params
.called
)
1489 self
.assertTrue(guest_epa_cpu_pinning_params
.called
)
1490 self
.assertTrue(guest_epa_quota_params
.called
)
1492 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1493 def test__process_flavor_params_with_empty_target_flavor(
1501 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1506 target_record_id
= ""
1508 with self
.assertRaises(KeyError):
1509 Ns
._process
_flavor
_params
(
1510 target_flavor
=target_flavor
,
1513 target_record_id
=target_record_id
,
1516 self
.assertFalse(epa_params
.called
)
1518 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1519 def test__process_flavor_params_with_wrong_target_flavor(
1524 "no-target-flavor": "here",
1528 target_record_id
= ""
1530 with self
.assertRaises(KeyError):
1531 Ns
._process
_flavor
_params
(
1532 target_flavor
=target_flavor
,
1535 target_record_id
=target_record_id
,
1538 self
.assertFalse(epa_params
.called
)
1540 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1541 def test__process_flavor_params_with_empty_indata(
1565 "memory-mb": "1024",
1570 target_record_id
= ""
1572 epa_params
.return_value
= {}
1574 result
= Ns
._process
_flavor
_params
(
1575 target_flavor
=target_flavor
,
1578 target_record_id
=target_record_id
,
1581 self
.assertTrue(epa_params
.called
)
1582 self
.assertDictEqual(result
, expected_result
)
1584 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1585 def test__process_flavor_params_with_wrong_indata(
1609 "memory-mb": "1024",
1616 target_record_id
= ""
1618 epa_params
.return_value
= {}
1620 result
= Ns
._process
_flavor
_params
(
1621 target_flavor
=target_flavor
,
1624 target_record_id
=target_record_id
,
1627 self
.assertTrue(epa_params
.called
)
1628 self
.assertDictEqual(result
, expected_result
)
1630 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1631 def test__process_flavor_params_with_ephemeral_disk(
1635 db
= MagicMock(name
="database mock")
1640 db
.get_one
.return_value
= {
1641 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1646 {"id": "without_volumes-VM", "min-number-of-instances": 1}
1650 "id": "without_volumes-vnf",
1651 "product-name": "without_volumes-vnf",
1654 "id": "without_volumes-VM",
1655 "name": "without_volumes-VM",
1656 "sw-image-desc": "ubuntu20.04",
1657 "alternative-sw-image-desc": [
1659 "ubuntu20.04-azure",
1661 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
1665 "virtual-storage-desc": [
1666 {"id": "root-volume", "size-of-storage": "10"},
1668 "id": "ephemeral-volume",
1669 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1670 "size-of-storage": "1",
1676 "path": "/app/storage/",
1704 "memory-mb": "1024",
1712 "ns-flavor-id": "test_id",
1713 "virtual-storages": [
1715 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
1716 "size-of-storage": "10",
1721 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1726 target_record_id
= ""
1728 epa_params
.return_value
= {}
1730 result
= Ns
._process
_flavor
_params
(
1731 target_flavor
=target_flavor
,
1734 target_record_id
=target_record_id
,
1738 self
.assertTrue(epa_params
.called
)
1739 self
.assertDictEqual(result
, expected_result
)
1741 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1742 def test__process_flavor_params_with_swap_disk(
1769 "memory-mb": "1024",
1777 "ns-flavor-id": "test_id",
1778 "virtual-storages": [
1780 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
1781 "size-of-storage": "20",
1786 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1791 target_record_id
= ""
1793 epa_params
.return_value
= {}
1795 result
= Ns
._process
_flavor
_params
(
1796 target_flavor
=target_flavor
,
1799 target_record_id
=target_record_id
,
1802 self
.assertTrue(epa_params
.called
)
1803 self
.assertDictEqual(result
, expected_result
)
1805 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1806 def test__process_flavor_params_with_persistent_root_disk(
1810 db
= MagicMock(name
="database mock")
1816 db
.get_one
.return_value
= {
1817 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1822 {"id": "several_volumes-VM", "min-number-of-instances": 1}
1826 "id": "several_volumes-vnf",
1827 "product-name": "several_volumes-vnf",
1830 "id": "several_volumes-VM",
1831 "name": "several_volumes-VM",
1832 "sw-image-desc": "ubuntu20.04",
1833 "alternative-sw-image-desc": [
1835 "ubuntu20.04-azure",
1837 "virtual-storage-desc": [
1838 "persistent-root-volume",
1843 "virtual-storage-desc": [
1845 "id": "persistent-root-volume",
1846 "type-of-storage": "persistent-storage:persistent-storage",
1847 "size-of-storage": "10",
1853 "path": "/app/storage/",
1879 "memory-mb": "1024",
1887 "vdu-name": "several_volumes-VM",
1888 "ns-flavor-id": "test_id",
1889 "virtual-storages": [
1891 "type-of-storage": "persistent-storage:persistent-storage",
1892 "size-of-storage": "10",
1897 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1902 target_record_id
= ""
1904 epa_params
.return_value
= {}
1906 result
= Ns
._process
_flavor
_params
(
1907 target_flavor
=target_flavor
,
1910 target_record_id
=target_record_id
,
1914 self
.assertTrue(epa_params
.called
)
1915 self
.assertDictEqual(result
, expected_result
)
1917 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1918 def test__process_flavor_params_with_epa_params(
1929 "numa": "there-is-numa-here",
1940 "numa": "there-is-numa-here",
1949 "memory-mb": "1024",
1957 "ns-flavor-id": "test_id",
1960 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1965 target_record_id
= ""
1967 epa_params
.return_value
= {
1968 "numa": "there-is-numa-here",
1971 result
= Ns
._process
_flavor
_params
(
1972 target_flavor
=target_flavor
,
1975 target_record_id
=target_record_id
,
1978 self
.assertTrue(epa_params
.called
)
1979 self
.assertDictEqual(result
, expected_result
)
1981 @patch("osm_ng_ro.ns.Ns._process_epa_params")
1982 def test__process_flavor_params(
1986 db
= MagicMock(name
="database mock")
1992 db
.get_one
.return_value
= {
1993 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
1998 {"id": "without_volumes-VM", "min-number-of-instances": 1}
2002 "id": "without_volumes-vnf",
2003 "product-name": "without_volumes-vnf",
2006 "id": "without_volumes-VM",
2007 "name": "without_volumes-VM",
2008 "sw-image-desc": "ubuntu20.04",
2009 "alternative-sw-image-desc": [
2011 "ubuntu20.04-azure",
2013 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
2017 "virtual-storage-desc": [
2018 {"id": "root-volume", "size-of-storage": "10"},
2020 "id": "ephemeral-volume",
2021 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2022 "size-of-storage": "1",
2028 "path": "/app/storage/",
2043 "numa": "there-is-numa-here",
2056 "numa": "there-is-numa-here",
2065 "memory-mb": "1024",
2073 "ns-flavor-id": "test_id",
2074 "virtual-storages": [
2076 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2077 "size-of-storage": "10",
2080 "type-of-storage": "etsi-nfv-descriptors:swap-storage",
2081 "size-of-storage": "20",
2086 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2091 target_record_id
= ""
2093 epa_params
.return_value
= {
2094 "numa": "there-is-numa-here",
2097 result
= Ns
._process
_flavor
_params
(
2098 target_flavor
=target_flavor
,
2101 target_record_id
=target_record_id
,
2105 self
.assertTrue(epa_params
.called
)
2106 self
.assertDictEqual(result
, expected_result
)
2108 def test__ip_profile_to_ro_with_none(self
):
2111 result
= Ns
._ip
_profile
_to
_ro
(
2112 ip_profile
=ip_profile
,
2115 self
.assertIsNone(result
)
2117 def test__ip_profile_to_ro_with_empty_profile(self
):
2120 result
= Ns
._ip
_profile
_to
_ro
(
2121 ip_profile
=ip_profile
,
2124 self
.assertIsNone(result
)
2126 def test__ip_profile_to_ro_with_wrong_profile(self
):
2128 "no-profile": "here",
2131 "ip_version": "IPv4",
2132 "subnet_address": None,
2133 "gateway_address": None,
2134 "dhcp_enabled": False,
2135 "dhcp_start_address": None,
2139 result
= Ns
._ip
_profile
_to
_ro
(
2140 ip_profile
=ip_profile
,
2143 self
.assertDictEqual(expected_result
, result
)
2145 def test__ip_profile_to_ro_with_ipv4_profile(self
):
2147 "ip-version": "ipv4",
2148 "subnet-address": "192.168.0.0/24",
2149 "gateway-address": "192.168.0.254",
2152 "start-address": "192.168.0.10",
2157 "ip_version": "IPv4",
2158 "subnet_address": "192.168.0.0/24",
2159 "gateway_address": "192.168.0.254",
2160 "dhcp_enabled": True,
2161 "dhcp_start_address": "192.168.0.10",
2165 result
= Ns
._ip
_profile
_to
_ro
(
2166 ip_profile
=ip_profile
,
2169 self
.assertDictEqual(expected_result
, result
)
2171 def test__ip_profile_to_ro_with_ipv6_profile(self
):
2173 "ip-version": "ipv6",
2174 "subnet-address": "2001:0200:0001::/48",
2175 "gateway-address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
2178 "start-address": "2001:0200:0001::0010",
2183 "ip_version": "IPv6",
2184 "subnet_address": "2001:0200:0001::/48",
2185 "gateway_address": "2001:0200:0001:ffff:ffff:ffff:ffff:fffe",
2186 "dhcp_enabled": True,
2187 "dhcp_start_address": "2001:0200:0001::0010",
2191 result
= Ns
._ip
_profile
_to
_ro
(
2192 ip_profile
=ip_profile
,
2195 self
.assertDictEqual(expected_result
, result
)
2197 def test__ip_profile_to_ro_with_dns_server(self
):
2199 "ip-version": "ipv4",
2200 "subnet-address": "192.168.0.0/24",
2201 "gateway-address": "192.168.0.254",
2204 "start-address": "192.168.0.10",
2209 "address": "8.8.8.8",
2212 "address": "1.1.1.1",
2215 "address": "1.0.0.1",
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",
2229 result
= Ns
._ip
_profile
_to
_ro
(
2230 ip_profile
=ip_profile
,
2233 self
.assertDictEqual(expected_result
, result
)
2235 def test__ip_profile_to_ro_with_security_group(self
):
2237 "ip-version": "ipv4",
2238 "subnet-address": "192.168.0.0/24",
2239 "gateway-address": "192.168.0.254",
2242 "start-address": "192.168.0.10",
2246 "some-security-group": "here",
2250 "ip_version": "IPv4",
2251 "subnet_address": "192.168.0.0/24",
2252 "gateway_address": "192.168.0.254",
2253 "dhcp_enabled": True,
2254 "dhcp_start_address": "192.168.0.10",
2257 "some-security-group": "here",
2261 result
= Ns
._ip
_profile
_to
_ro
(
2262 ip_profile
=ip_profile
,
2265 self
.assertDictEqual(expected_result
, result
)
2267 def test__ip_profile_to_ro(self
):
2269 "ip-version": "ipv4",
2270 "subnet-address": "192.168.0.0/24",
2271 "gateway-address": "192.168.0.254",
2274 "start-address": "192.168.0.10",
2279 "address": "8.8.8.8",
2282 "address": "1.1.1.1",
2285 "address": "1.0.0.1",
2289 "some-security-group": "here",
2293 "ip_version": "IPv4",
2294 "subnet_address": "192.168.0.0/24",
2295 "gateway_address": "192.168.0.254",
2296 "dhcp_enabled": True,
2297 "dhcp_start_address": "192.168.0.10",
2299 "dns_address": "8.8.8.8;1.1.1.1;1.0.0.1",
2301 "some-security-group": "here",
2305 result
= Ns
._ip
_profile
_to
_ro
(
2306 ip_profile
=ip_profile
,
2309 self
.assertDictEqual(expected_result
, result
)
2311 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2312 def test__process_net_params_with_empty_params(
2323 "provider_network": "some-profile-here",
2325 target_record_id
= ""
2328 "net_name": "ns-name-vld-name",
2329 "net_type": "bridge",
2331 "some_ip_profile": "here",
2333 "provider_network_profile": "some-profile-here",
2337 ip_profile_to_ro
.return_value
= {
2338 "some_ip_profile": "here",
2341 result
= Ns
._process
_net
_params
(
2342 target_vld
=target_vld
,
2345 target_record_id
=target_record_id
,
2348 self
.assertDictEqual(expected_result
, result
)
2349 self
.assertTrue(ip_profile_to_ro
.called
)
2351 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2352 def test__process_net_params_with_vim_info_sdn(
2364 "sdn-ports": ["some", "ports", "here"],
2365 "vlds": ["some", "vlds", "here"],
2368 target_record_id
= "vld.sdn.something"
2371 "sdn-ports": ["some", "ports", "here"],
2372 "vlds": ["some", "vlds", "here"],
2377 result
= Ns
._process
_net
_params
(
2378 target_vld
=target_vld
,
2381 target_record_id
=target_record_id
,
2384 self
.assertDictEqual(expected_result
, result
)
2385 self
.assertFalse(ip_profile_to_ro
.called
)
2387 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2388 def test__process_net_params_with_vim_info_sdn_target_vim(
2400 "sdn-ports": ["some", "ports", "here"],
2401 "vlds": ["some", "vlds", "here"],
2402 "target_vim": "some-vim",
2405 target_record_id
= "vld.sdn.something"
2407 "depends_on": ["some-vim vld.sdn"],
2409 "sdn-ports": ["some", "ports", "here"],
2410 "vlds": ["some", "vlds", "here"],
2411 "target_vim": "some-vim",
2416 result
= Ns
._process
_net
_params
(
2417 target_vld
=target_vld
,
2420 target_record_id
=target_record_id
,
2423 self
.assertDictEqual(expected_result
, result
)
2424 self
.assertFalse(ip_profile_to_ro
.called
)
2426 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2427 def test__process_net_params_with_vim_network_name(
2438 "vim_network_name": "some-network-name",
2440 target_record_id
= "vld.sdn.something"
2444 "name": "some-network-name",
2449 result
= Ns
._process
_net
_params
(
2450 target_vld
=target_vld
,
2453 target_record_id
=target_record_id
,
2456 self
.assertDictEqual(expected_result
, result
)
2457 self
.assertFalse(ip_profile_to_ro
.called
)
2459 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2460 def test__process_net_params_with_vim_network_id(
2471 "vim_network_id": "some-network-id",
2473 target_record_id
= "vld.sdn.something"
2477 "id": "some-network-id",
2482 result
= Ns
._process
_net
_params
(
2483 target_vld
=target_vld
,
2486 target_record_id
=target_record_id
,
2489 self
.assertDictEqual(expected_result
, result
)
2490 self
.assertFalse(ip_profile_to_ro
.called
)
2492 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2493 def test__process_net_params_with_mgmt_network(
2500 "mgmt-network": "some-mgmt-network",
2506 target_record_id
= "vld.sdn.something"
2514 result
= Ns
._process
_net
_params
(
2515 target_vld
=target_vld
,
2518 target_record_id
=target_record_id
,
2521 self
.assertDictEqual(expected_result
, result
)
2522 self
.assertFalse(ip_profile_to_ro
.called
)
2524 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2525 def test__process_net_params_with_underlay_eline(
2531 "underlay": "some-underlay-here",
2538 "provider_network": "some-profile-here",
2540 target_record_id
= ""
2544 "some_ip_profile": "here",
2546 "net_name": "ns-name-vld-name",
2548 "provider_network_profile": "some-profile-here",
2552 ip_profile_to_ro
.return_value
= {
2553 "some_ip_profile": "here",
2556 result
= Ns
._process
_net
_params
(
2557 target_vld
=target_vld
,
2560 target_record_id
=target_record_id
,
2563 self
.assertDictEqual(expected_result
, result
)
2564 self
.assertTrue(ip_profile_to_ro
.called
)
2566 @patch("osm_ng_ro.ns.Ns._ip_profile_to_ro")
2567 def test__process_net_params_with_underlay_elan(
2573 "underlay": "some-underlay-here",
2580 "provider_network": "some-profile-here",
2582 target_record_id
= ""
2586 "some_ip_profile": "here",
2588 "net_name": "ns-name-vld-name",
2590 "provider_network_profile": "some-profile-here",
2594 ip_profile_to_ro
.return_value
= {
2595 "some_ip_profile": "here",
2598 result
= Ns
._process
_net
_params
(
2599 target_vld
=target_vld
,
2602 target_record_id
=target_record_id
,
2605 self
.assertDictEqual(expected_result
, result
)
2606 self
.assertTrue(ip_profile_to_ro
.called
)
2608 def test__get_cloud_init_exception(self
):
2609 db_mock
= MagicMock(name
="database mock")
2614 with self
.assertRaises(NsException
):
2615 Ns
._get
_cloud
_init
(db
=db_mock
, fs
=fs_mock
, location
=location
)
2617 def test__get_cloud_init_file_fs_exception(self
):
2618 db_mock
= MagicMock(name
="database mock")
2621 location
= "vnfr_id_123456:file:test_file"
2622 db_mock
.get_one
.return_value
= {
2625 "folder": "/home/osm",
2626 "pkg-dir": "vnfr_test_dir",
2631 with self
.assertRaises(NsException
):
2632 Ns
._get
_cloud
_init
(db
=db_mock
, fs
=fs_mock
, location
=location
)
2634 def test__get_cloud_init_file(self
):
2635 db_mock
= MagicMock(name
="database mock")
2636 fs_mock
= MagicMock(name
="filesystem mock")
2637 file_mock
= MagicMock(name
="file mock")
2639 location
= "vnfr_id_123456:file:test_file"
2640 cloud_init_content
= "this is a cloud init file content"
2642 db_mock
.get_one
.return_value
= {
2645 "folder": "/home/osm",
2646 "pkg-dir": "vnfr_test_dir",
2650 fs_mock
.file_open
.return_value
= file_mock
2651 file_mock
.__enter
__.return_value
.read
.return_value
= cloud_init_content
2653 result
= Ns
._get
_cloud
_init
(db
=db_mock
, fs
=fs_mock
, location
=location
)
2655 self
.assertEqual(cloud_init_content
, result
)
2657 def test__get_cloud_init_vdu(self
):
2658 db_mock
= MagicMock(name
="database mock")
2661 location
= "vnfr_id_123456:vdu:0"
2662 cloud_init_content
= "this is a cloud init file content"
2664 db_mock
.get_one
.return_value
= {
2667 "cloud-init": cloud_init_content
,
2672 result
= Ns
._get
_cloud
_init
(db
=db_mock
, fs
=fs_mock
, location
=location
)
2674 self
.assertEqual(cloud_init_content
, result
)
2676 @patch("jinja2.Environment.__init__")
2677 def test__parse_jinja2_undefined_error(self
, env_mock
: Mock
):
2678 cloud_init_content
= None
2682 env_mock
.side_effect
= UndefinedError("UndefinedError occurred.")
2684 with self
.assertRaises(NsException
):
2686 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2689 @patch("jinja2.Environment.__init__")
2690 def test__parse_jinja2_template_error(self
, env_mock
: Mock
):
2691 cloud_init_content
= None
2695 env_mock
.side_effect
= TemplateError("TemplateError occurred.")
2697 with self
.assertRaises(NsException
):
2699 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2702 @patch("jinja2.Environment.__init__")
2703 def test__parse_jinja2_template_not_found(self
, env_mock
: Mock
):
2704 cloud_init_content
= None
2708 env_mock
.side_effect
= TemplateNotFound("TemplateNotFound occurred.")
2710 with self
.assertRaises(NsException
):
2712 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2715 def test_rendering_jinja2_temp_without_special_characters(self
):
2716 cloud_init_content
= """
2719 table_type: {{type}}
2721 overwrite: {{is_override}}
2724 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2728 "is_override": "False",
2729 "command": "; mkdir abc",
2731 context
= "cloud-init for VM"
2732 expected_result
= """
2740 - [ sh, -xc, "echo $(date) '; mkdir abc'" ]
2742 result
= Ns
._parse
_jinja
2(
2743 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2745 self
.assertEqual(result
, expected_result
)
2747 def test_rendering_jinja2_temp_with_special_characters(self
):
2748 cloud_init_content
= """
2751 table_type: {{type}}
2753 overwrite: {{is_override}}
2756 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2760 "is_override": "False",
2761 "command": "& rm -rf",
2763 context
= "cloud-init for VM"
2764 expected_result
= """
2772 - [ sh, -xc, "echo $(date) '& rm -rf /'" ]
2774 result
= Ns
._parse
_jinja
2(
2775 cloud_init_content
=cloud_init_content
, params
=params
, context
=context
2777 self
.assertNotEqual(result
, expected_result
)
2779 def test_rendering_jinja2_temp_with_special_characters_autoescape_is_false(self
):
2780 with
patch("osm_ng_ro.ns.Environment") as mock_environment
:
2781 mock_environment
.return_value
= Environment(
2782 undefined
=StrictUndefined
,
2783 autoescape
=select_autoescape(default_for_string
=False, default
=False),
2785 cloud_init_content
= """
2788 table_type: {{type}}
2790 overwrite: {{is_override}}
2793 - [ sh, -xc, "echo $(date) '{{command}}'" ]
2797 "is_override": "False",
2798 "command": "& rm -rf /",
2800 context
= "cloud-init for VM"
2801 expected_result
= """
2809 - [ sh, -xc, "echo $(date) '& rm -rf /'" ]
2811 result
= Ns
._parse
_jinja
2(
2812 cloud_init_content
=cloud_init_content
,
2816 self
.assertEqual(result
, expected_result
)
2818 def test__process_vdu_params_empty_kargs(self
):
2821 def test__process_vdu_params_interface_ns_vld_id(self
):
2824 def test__process_vdu_params_interface_vnf_vld_id(self
):
2827 def test__process_vdu_params_interface_unknown(self
):
2830 def test__process_vdu_params_interface_port_security_enabled(self
):
2833 def test__process_vdu_params_interface_port_security_disable_strategy(self
):
2836 def test__process_vdu_params_interface_sriov(self
):
2839 def test__process_vdu_params_interface_pci_passthrough(self
):
2842 def test__process_vdu_params_interface_om_mgmt(self
):
2845 def test__process_vdu_params_interface_mgmt_interface(self
):
2848 def test__process_vdu_params_interface_mgmt_vnf(self
):
2851 def test__process_vdu_params_interface_bridge(self
):
2854 def test__process_vdu_params_interface_ip_address(self
):
2857 def test__process_vdu_params_interface_mac_address(self
):
2860 def test__process_vdu_params_vdu_cloud_init_missing(self
):
2863 def test__process_vdu_params_vdu_cloud_init_present(self
):
2866 def test__process_vdu_params_vdu_boot_data_drive(self
):
2869 def test__process_vdu_params_vdu_ssh_keys(self
):
2872 def test__process_vdu_params_vdu_ssh_access_required(self
):
2875 @patch("osm_ng_ro.ns.Ns._get_cloud_init")
2876 @patch("osm_ng_ro.ns.Ns._parse_jinja2")
2877 def test__process_vdu_params_vdu_persistent_root_volume(
2878 self
, get_cloud_init
, parse_jinja2
2880 db
= MagicMock(name
="database mock")
2883 "vdu2cloud_init": {},
2885 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2886 "member-vnf-index-ref": "vnf-several-volumes",
2889 get_cloud_init
.return_value
= {}
2890 parse_jinja2
.return_value
= {}
2891 db
.get_one
.return_value
= {
2892 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2897 {"id": "several_volumes-VM", "min-number-of-instances": 1}
2901 "id": "several_volumes-vnf",
2902 "product-name": "several_volumes-vnf",
2905 "id": "several_volumes-VM",
2906 "name": "several_volumes-VM",
2907 "sw-image-desc": "ubuntu20.04",
2908 "alternative-sw-image-desc": [
2910 "ubuntu20.04-azure",
2912 "virtual-storage-desc": [
2913 "persistent-root-volume",
2914 "persistent-volume2",
2920 "virtual-storage-desc": [
2922 "id": "persistent-volume2",
2923 "type-of-storage": "persistent-storage:persistent-storage",
2924 "size-of-storage": "10",
2927 "id": "persistent-root-volume",
2928 "type-of-storage": "persistent-storage:persistent-storage",
2929 "size-of-storage": "10",
2932 "id": "ephemeral-volume",
2933 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2934 "size-of-storage": "1",
2940 "path": "/app/storage/",
2947 "_id": "09a0baa7-b7cb-4924-bd63-9f04a1c23960",
2948 "ns-flavor-id": "0",
2950 "vdu-name": "several_volumes-VM",
2954 "ns-vld-id": "mgmtnet",
2957 "virtual-storages": [
2959 "id": "persistent-volume2",
2960 "size-of-storage": "10",
2961 "type-of-storage": "persistent-storage:persistent-storage",
2964 "id": "persistent-root-volume",
2965 "size-of-storage": "10",
2966 "type-of-storage": "persistent-storage:persistent-storage",
2969 "id": "ephemeral-volume",
2970 "size-of-storage": "1",
2971 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
2976 "name": "sample_name",
2978 expected_result
= [{"image_id": "ubuntu20.04", "size": "10"}, {"size": "10"}]
2979 result
= Ns
._process
_vdu
_params
(
2980 target_vdu
, indata
, vim_info
=None, target_record_id
=None, **kwargs
2983 expected_result
, result
["params"]["disk_list"], "Wrong Disk List"
2986 @patch("osm_ng_ro.ns.Ns._get_cloud_init")
2987 @patch("osm_ng_ro.ns.Ns._parse_jinja2")
2988 def test__process_vdu_params_vdu_without_persistent_storage(
2989 self
, get_cloud_init
, parse_jinja2
2991 db
= MagicMock(name
="database mock")
2994 "vdu2cloud_init": {},
2996 "vnfd-id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
2997 "member-vnf-index-ref": "vnf-several-volumes",
3000 get_cloud_init
.return_value
= {}
3001 parse_jinja2
.return_value
= {}
3002 db
.get_one
.return_value
= {
3003 "_id": "ad6356e3-698c-43bf-9901-3aae9e9b9d18",
3008 {"id": "without_volumes-VM", "min-number-of-instances": 1}
3012 "id": "without_volumes-vnf",
3013 "product-name": "without_volumes-vnf",
3016 "id": "without_volumes-VM",
3017 "name": "without_volumes-VM",
3018 "sw-image-desc": "ubuntu20.04",
3019 "alternative-sw-image-desc": [
3021 "ubuntu20.04-azure",
3023 "virtual-storage-desc": ["root-volume", "ephemeral-volume"],
3027 "virtual-storage-desc": [
3028 {"id": "root-volume", "size-of-storage": "10"},
3030 "id": "ephemeral-volume",
3031 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
3032 "size-of-storage": "1",
3038 "path": "/app/storage/",
3045 "_id": "09a0baa7-b7cb-4924-bd63-9f04a1c23960",
3046 "ns-flavor-id": "0",
3048 "vdu-name": "without_volumes-VM",
3052 "ns-vld-id": "mgmtnet",
3055 "virtual-storages": [
3057 "id": "root-volume",
3058 "size-of-storage": "10",
3061 "id": "ephemeral-volume",
3062 "size-of-storage": "1",
3063 "type-of-storage": "etsi-nfv-descriptors:ephemeral-storage",
3068 "name": "sample_name",
3070 expected_result
= []
3071 result
= Ns
._process
_vdu
_params
(
3072 target_vdu
, indata
, vim_info
=None, target_record_id
=None, **kwargs
3075 expected_result
, result
["params"]["disk_list"], "Wrong Disk List"
3078 def test__process_vdu_params(self
):
3081 @patch("osm_ng_ro.ns.Ns._assign_vim")
3082 def test__rebuild_start_stop_task(self
, assign_vim
):
3085 actions
= ["start", "stop", "rebuild"]
3086 vdu_id
= "bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3087 vnf_id
= "665b4165-ce24-4320-bf19-b9a45bade49f"
3089 action_id
= "bb937f49-3870-4169-b758-9732e1ff40f3"
3090 nsr_id
= "993166fe-723e-4680-ac4b-b1af2541ae31"
3092 target_vim
= "vim:f9f370ac-0d44-41a7-9000-457f2332bc35"
3093 t
= "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3094 for action
in actions
:
3096 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3097 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3098 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3099 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:0",
3100 "status": "SCHEDULED",
3103 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.0",
3104 "target_record_id": t
,
3106 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3110 extra_dict
["params"] = {
3111 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3114 task
= self
.ns
.rebuild_start_stop_task(
3124 self
.assertEqual(task
.get("action_id"), action_id
)
3125 self
.assertEqual(task
.get("nsr_id"), nsr_id
)
3126 self
.assertEqual(task
.get("target_id"), target_vim
)
3127 self
.assertDictEqual(task
, expected_result
)
3129 @patch("osm_ng_ro.ns.Ns._assign_vim")
3130 def test_verticalscale_task(self
, assign_vim
):
3134 action_id
= "bb937f49-3870-4169-b758-9732e1ff40f3"
3135 nsr_id
= "993166fe-723e-4680-ac4b-b1af2541ae31"
3137 target_record_id
= (
3138 "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
3139 "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3143 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3144 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3145 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3146 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1",
3147 "status": "SCHEDULED",
3149 "item": "verticalscale",
3150 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1",
3151 "target_record_id": target_record_id
,
3153 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3154 "flavor_dict": "flavor_dict",
3158 "id": "bb9c43f9-10a2-4569-a8a8-957c3528b6d1",
3160 "vim:f9f370ac-0d44-41a7-9000-457f2332bc35": {"interfaces": []}
3163 vnf
= {"_id": "665b4165-ce24-4320-bf19-b9a45bade49f"}
3164 extra_dict
["params"] = {
3165 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3166 "flavor_dict": "flavor_dict",
3168 task
= self
.ns
.verticalscale_task(
3169 vdu
, vnf
, vdu_index
, action_id
, nsr_id
, task_index
, extra_dict
3172 self
.assertDictEqual(task
, expected_result
)
3174 @patch("osm_ng_ro.ns.Ns._assign_vim")
3175 def test_migrate_task(self
, assign_vim
):
3179 action_id
= "bb937f49-3870-4169-b758-9732e1ff40f3"
3180 nsr_id
= "993166fe-723e-4680-ac4b-b1af2541ae31"
3182 target_record_id
= (
3183 "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
3184 "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
3188 "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
3189 "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
3190 "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
3191 "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1",
3192 "status": "SCHEDULED",
3195 "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1",
3196 "target_record_id": target_record_id
,
3198 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3199 "migrate_host": "migrateToHost",
3203 "id": "bb9c43f9-10a2-4569-a8a8-957c3528b6d1",
3205 "vim:f9f370ac-0d44-41a7-9000-457f2332bc35": {"interfaces": []}
3208 vnf
= {"_id": "665b4165-ce24-4320-bf19-b9a45bade49f"}
3209 extra_dict
["params"] = {
3210 "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
3211 "migrate_host": "migrateToHost",
3213 task
= self
.ns
.migrate_task(
3214 vdu
, vnf
, vdu_index
, action_id
, nsr_id
, task_index
, extra_dict
3217 self
.assertDictEqual(task
, expected_result
)