3 # Copyright 2016 RIFT.IO Inc
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
20 from gi
.repository
import (
21 ProjectNsdYang
as NsdYang
,
22 ProjectVnfdYang
as VnfdYang
,
24 from ..config
import ConfigPrimitiveConvertor
27 @pytest.fixture(scope
="function")
29 catalog
= NsdYang
.YangData_RwProject_Project_NsdCatalog()
30 nsd
= catalog
.nsd
.add()
31 nsd
.id = str(uuid
.uuid1())
34 @pytest.fixture(scope
="function")
36 catalog
= VnfdYang
.YangData_RwProject_Project_VnfdCatalog()
37 vnfd
= catalog
.vnfd
.add()
38 vnfd
.id = str(uuid
.uuid1())
41 @pytest.fixture(scope
="session")
43 return ConfigPrimitiveConvertor()
45 def test_nsd_config(nsd
, convertor
):
46 nsd
.service_primitive
.add().from_dict(
52 "data_type": "INTEGER",
53 "default_value": "3000",
64 "data_type": "INTEGER",
65 "default_value": "3000",
76 "data_type": "INTEGER",
77 "default_value": "10",
82 "name": "Add SP Test Corporation",
83 "user_defined_script": "add_corporation.py"
86 expected_yaml
= """Add SP Test Corporation:
96 assert expected_yaml
== \
97 convertor
.extract_nsd_config(nsd
)
100 def test_nsd_multiple_config(nsd
, convertor
):
101 nsd
.service_primitive
.add().from_dict(
103 "parameter_group": [{
106 "data_type": "INTEGER",
107 "default_value": "3000",
117 "data_type": "INTEGER",
118 "default_value": "10",
119 "name": "Tunnel Key",
123 "name": "Add SP Test Corporation",
124 "user_defined_script": "add_corporation.py"
127 nsd
.service_primitive
.add().from_dict(
129 "parameter_group": [{
132 "data_type": "INTEGER",
133 "default_value": "3000",
143 "data_type": "INTEGER",
144 "default_value": "10",
145 "name": "Tunnel Key",
149 "name": "Add SP Test Corporation 2",
150 "user_defined_script": "add_corporation.py"
153 expected_yaml
= """Add SP Test Corporation:
159 Add SP Test Corporation 2:
167 assert yaml
.load(expected_yaml
) == \
168 yaml
.load(convertor
.extract_nsd_config(nsd
))
171 def test_vnfd_config(vnfd
, convertor
):
172 vnf_config
= vnfd
.vnf_configuration
174 # Set the initital-config
175 vnf_config
.initial_config_primitive
.add().from_dict({
179 {"name": "vpe-router", "value": "<rw_mgmt_ip>"},
180 {"name": "user", "value": "root"},
181 {"name": "pass", "value": "6windos"}
185 vnf_config
.initial_config_primitive
.add().from_dict({
186 "name": "configure-interface",
189 {"value": "10.10.10.2/30", "name": "cidr"}
193 expected_yaml
= """initial_config_primitive:
198 vpe-router: <rw_mgmt_ip>
204 assert expected_yaml
== convertor
.extract_vnfd_config(vnfd
)
206 def test_vnfd_config_prim(vnfd
, convertor
):
207 vnf_config
= vnfd
.vnf_configuration
209 # Set the initital-config
210 vnf_config
.initial_config_primitive
.add().from_dict({
214 {"name": "vpe-router", "value": "<rw_mgmt_ip>"},
215 {"name": "user", "value": "root"},
216 {"name": "pass", "value": "6windos"}
220 vnf_config
.initial_config_primitive
.add().from_dict({
221 "name": "configure-interface",
224 {"value": "10.10.10.2/30", "name": "cidr"}
228 vnf_config
.config_primitive
.add().from_dict({
231 {"name": "Foo", "default_value": "Bar"}
235 expected_yaml
= """config_primitive:
239 initial_config_primitive:
244 vpe-router: <rw_mgmt_ip>
250 assert expected_yaml
== convertor
.extract_vnfd_config(vnfd
)
254 def test_vnfd_merge(vnfd
, convertor
):
255 vnf_config
= vnfd
.vnf_configuration
257 # Set the initital-config
258 vnf_config
.initial_config_primitive
.add().from_dict({
261 "parameter": [{"name": "vpe-router"},
267 vnf_config
.initial_config_primitive
.add().from_dict({
268 "name": "configure-interface",
270 "parameter": [{"name": "cidr"}],
273 vnf_config
.config_primitive
.add().from_dict({
275 "parameter": [{"name": "Foo",}]
278 ip_yaml
= """config_primitive:
282 initial_config_primitive:
287 vpe-router: <rw_mgmt_ip>
293 catalog
= VnfdYang
.YangData_RwProject_Project_VnfdCatalog()
294 expected_vnfd
= catalog
.vnfd
.add()
295 vnf_config
= expected_vnfd
.vnf_configuration
296 expected_vnfd
.id = vnfd
.id
298 # Set the initital-confi
299 vnf_config
.initial_config_primitive
.add().from_dict({
303 {"name": "vpe-router", "value": "<rw_mgmt_ip>"},
304 {"name": "user", "value": "root"},
305 {"name": "pass", "value": "6windos"}
309 vnf_config
.initial_config_primitive
.add().from_dict({
310 "name": "configure-interface",
313 {"value": "10.10.10.2/30", "name": "cidr"}
317 vnf_config
.config_primitive
.add().from_dict({
320 {"name": "Foo", "default_value": "Bar"}
324 convertor
.merge_vnfd_config(vnfd
, yaml
.load(ip_yaml
))
326 assert vnfd
.as_dict() == expected_vnfd
.as_dict()
329 def test_nsd_merge(nsd
, convertor
):
330 nsd
.service_primitive
.add().from_dict(
336 "data_type": "INTEGER",
337 "default_value": "3000",
348 "data_type": "INTEGER",
349 "default_value": "3000",
360 "data_type": "INTEGER",
361 "default_value": "10",
362 "name": "Tunnel Key",
366 "name": "Add SP Test Corporation",
367 "user_defined_script": "add_corporation.py"
370 ip_yaml
= """Add SP Test Corporation:
380 catalog
= NsdYang
.YangData_RwProject_Project_NsdCatalog()
381 expected_nsd
= catalog
.nsd
.add()
382 expected_nsd
.id = nsd
.id
383 expected_nsd
.service_primitive
.add().from_dict(
389 "data_type": "INTEGER",
390 "default_value": "3000",
401 "data_type": "INTEGER",
402 "default_value": "3000",
413 "data_type": "INTEGER",
414 "default_value": "10",
415 "name": "Tunnel Key",
419 "name": "Add SP Test Corporation",
420 "user_defined_script": "add_corporation.py"
423 convertor
.merge_nsd_config(nsd
, yaml
.load(ip_yaml
))
425 assert nsd
.as_dict() == expected_nsd
.as_dict()