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 NsdYang
, VnfdYang
21 from ..config
import ConfigPrimitiveConvertor
24 @pytest.fixture(scope
="function")
26 catalog
= NsdYang
.YangData_Nsd_NsdCatalog()
27 nsd
= catalog
.nsd
.add()
28 nsd
.id = str(uuid
.uuid1())
31 @pytest.fixture(scope
="function")
33 catalog
= VnfdYang
.YangData_Vnfd_VnfdCatalog()
34 vnfd
= catalog
.vnfd
.add()
35 vnfd
.id = str(uuid
.uuid1())
38 @pytest.fixture(scope
="session")
40 return ConfigPrimitiveConvertor()
42 def test_nsd_config(nsd
, convertor
):
43 nsd
.service_primitive
.add().from_dict(
49 "data_type": "INTEGER",
50 "default_value": "3000",
61 "data_type": "INTEGER",
62 "default_value": "3000",
73 "data_type": "INTEGER",
74 "default_value": "10",
79 "name": "Add SP Test Corporation",
80 "user_defined_script": "add_corporation.py"
83 expected_yaml
= """Add SP Test Corporation:
93 assert expected_yaml
== \
94 convertor
.extract_nsd_config(nsd
)
97 def test_nsd_multiple_config(nsd
, convertor
):
98 nsd
.service_primitive
.add().from_dict(
100 "parameter_group": [{
103 "data_type": "INTEGER",
104 "default_value": "3000",
114 "data_type": "INTEGER",
115 "default_value": "10",
116 "name": "Tunnel Key",
120 "name": "Add SP Test Corporation",
121 "user_defined_script": "add_corporation.py"
124 nsd
.service_primitive
.add().from_dict(
126 "parameter_group": [{
129 "data_type": "INTEGER",
130 "default_value": "3000",
140 "data_type": "INTEGER",
141 "default_value": "10",
142 "name": "Tunnel Key",
146 "name": "Add SP Test Corporation 2",
147 "user_defined_script": "add_corporation.py"
150 expected_yaml
= """Add SP Test Corporation:
156 Add SP Test Corporation 2:
164 assert yaml
.load(expected_yaml
) == \
165 yaml
.load(convertor
.extract_nsd_config(nsd
))
168 def test_vnfd_config(vnfd
, convertor
):
169 vnf_config
= vnfd
.vnf_configuration
171 # Set the initital-config
172 vnf_config
.initial_config_primitive
.add().from_dict({
176 {"name": "vpe-router", "value": "<rw_mgmt_ip>"},
177 {"name": "user", "value": "root"},
178 {"name": "pass", "value": "6windos"}
182 vnf_config
.initial_config_primitive
.add().from_dict({
183 "name": "configure-interface",
186 {"value": "10.10.10.2/30", "name": "cidr"}
190 expected_yaml
= """initial_config_primitive:
195 vpe-router: <rw_mgmt_ip>
201 assert expected_yaml
== convertor
.extract_vnfd_config(vnfd
)
203 def test_vnfd_config_prim(vnfd
, convertor
):
204 vnf_config
= vnfd
.vnf_configuration
206 # Set the initital-config
207 vnf_config
.initial_config_primitive
.add().from_dict({
211 {"name": "vpe-router", "value": "<rw_mgmt_ip>"},
212 {"name": "user", "value": "root"},
213 {"name": "pass", "value": "6windos"}
217 vnf_config
.initial_config_primitive
.add().from_dict({
218 "name": "configure-interface",
221 {"value": "10.10.10.2/30", "name": "cidr"}
225 vnf_config
.service_primitive
.add().from_dict({
228 {"name": "Foo", "default_value": "Bar"}
232 expected_yaml
= """service_primitive:
236 initial_config_primitive:
241 vpe-router: <rw_mgmt_ip>
247 assert expected_yaml
== convertor
.extract_vnfd_config(vnfd
)
251 def test_vnfd_merge(vnfd
, convertor
):
252 vnf_config
= vnfd
.vnf_configuration
254 # Set the initital-config
255 vnf_config
.initial_config_primitive
.add().from_dict({
258 "parameter": [{"name": "vpe-router"},
264 vnf_config
.initial_config_primitive
.add().from_dict({
265 "name": "configure-interface",
267 "parameter": [{"name": "cidr"}],
270 vnf_config
.service_primitive
.add().from_dict({
272 "parameter": [{"name": "Foo",}]
275 ip_yaml
= """service_primitive:
279 initial_config_primitive:
284 vpe-router: <rw_mgmt_ip>
290 catalog
= VnfdYang
.YangData_Vnfd_VnfdCatalog()
291 expected_vnfd
= catalog
.vnfd
.add()
292 vnf_config
= expected_vnfd
.vnf_configuration
293 expected_vnfd
.id = vnfd
.id
295 # Set the initital-confi
296 vnf_config
.initial_config_primitive
.add().from_dict({
300 {"name": "vpe-router", "value": "<rw_mgmt_ip>"},
301 {"name": "user", "value": "root"},
302 {"name": "pass", "value": "6windos"}
306 vnf_config
.initial_config_primitive
.add().from_dict({
307 "name": "configure-interface",
310 {"value": "10.10.10.2/30", "name": "cidr"}
314 vnf_config
.service_primitive
.add().from_dict({
317 {"name": "Foo", "default_value": "Bar"}
321 convertor
.merge_vnfd_config(vnfd
, yaml
.load(ip_yaml
))
323 assert vnfd
.as_dict() == expected_vnfd
.as_dict()
326 def test_nsd_merge(nsd
, convertor
):
327 nsd
.service_primitive
.add().from_dict(
333 "data_type": "INTEGER",
334 "default_value": "3000",
345 "data_type": "INTEGER",
346 "default_value": "3000",
357 "data_type": "INTEGER",
358 "default_value": "10",
359 "name": "Tunnel Key",
363 "name": "Add SP Test Corporation",
364 "user_defined_script": "add_corporation.py"
367 ip_yaml
= """Add SP Test Corporation:
377 catalog
= NsdYang
.YangData_Nsd_NsdCatalog()
378 expected_nsd
= catalog
.nsd
.add()
379 expected_nsd
.id = nsd
.id
380 expected_nsd
.service_primitive
.add().from_dict(
386 "data_type": "INTEGER",
387 "default_value": "3000",
398 "data_type": "INTEGER",
399 "default_value": "3000",
410 "data_type": "INTEGER",
411 "default_value": "10",
412 "name": "Tunnel Key",
416 "name": "Add SP Test Corporation",
417 "user_defined_script": "add_corporation.py"
420 convertor
.merge_nsd_config(nsd
, yaml
.load(ip_yaml
))
422 assert nsd
.as_dict() == expected_nsd
.as_dict()