4 # Copyright 2016-2017 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
19 @file lp_3vnfs_test.py
20 @author Austin Cormier (Austin.Cormier@riftio.com)
22 @brief Launchpad Module Test ExtVNF
36 gi
.require_version('RwIwpYang', '1.0')
37 gi
.require_version('RwNsrYang', '1.0')
38 gi
.require_version('RwProjectVnfdYang', '1.0')
39 gi
.require_version('RwCloudYang', '1.0')
40 gi
.require_version('RwBaseYang', '1.0')
41 gi
.require_version('RwResourceMgrYang', '1.0')
42 gi
.require_version('RwConmanYang', '1.0')
43 gi
.require_version('RwNsmYang', '1.0')
47 from gi
.repository
import (
49 ProjectNsdYang
as NsdYang
,
53 RwProjectVnfdYang
as RwVnfdYang
,
61 logging
.basicConfig(level
=logging
.DEBUG
)
64 RW_VROUTER_PKG_INSTALL_DIR
= os
.path
.join(
65 os
.environ
["RIFT_INSTALL"],
66 "usr/rift/mano/vnfds/vrouter"
68 RW_TRAFGEN_PKG_INSTALL_DIR
= os
.path
.join(
69 os
.environ
["RIFT_INSTALL"],
70 "usr/rift/mano/vnfds/trafgen"
72 RW_TRAFSINK_PKG_INSTALL_DIR
= os
.path
.join(
73 os
.environ
["RIFT_INSTALL"],
74 "usr/rift/mano/vnfds/trafsink"
76 RW_TG_2VROUTER_TS_NSD_PKG_INSTALL_DIR
= os
.path
.join(
77 os
.environ
["RIFT_INSTALL"],
78 "usr/rift/mano/nsds/tg_2vrouter_ts"
82 class PackageError(Exception):
86 def raise_package_error():
87 raise PackageError("Could not find ns packages")
90 @pytest.fixture(scope
='module')
91 def iwp_proxy(request
, mgmt_session
):
92 return mgmt_session
.proxy(RwIwpYang
)
94 @pytest.fixture(scope
='module')
95 def resource_mgr_proxy(request
, mgmt_session
):
96 return mgmt_session
.proxy(RwResourceMgrYang
)
99 @pytest.fixture(scope
='module')
100 def cloud_proxy(request
, mgmt_session
):
101 return mgmt_session
.proxy(RwCloudYang
)
104 @pytest.fixture(scope
='module')
105 def vnfd_proxy(request
, mgmt_session
):
106 return mgmt_session
.proxy(RwVnfdYang
)
109 @pytest.fixture(scope
='module')
110 def vld_proxy(request
, mgmt_session
):
111 return mgmt_session
.proxy(VldYang
)
114 @pytest.fixture(scope
='module')
115 def nsd_proxy(request
, mgmt_session
):
116 return mgmt_session
.proxy(NsdYang
)
119 @pytest.fixture(scope
='module')
120 def nsr_proxy(request
, mgmt_session
):
121 return mgmt_session
.proxy(NsrYang
)
124 @pytest.fixture(scope
='module')
125 def rwnsr_proxy(request
, mgmt_session
):
126 return mgmt_session
.proxy(RwNsrYang
)
129 @pytest.fixture(scope
='module')
130 def base_proxy(request
, mgmt_session
):
131 return mgmt_session
.proxy(RwBaseYang
)
133 @pytest.fixture(scope
='module')
134 def so_proxy(request
, mgmt_session
):
135 return mgmt_session
.proxy(RwConmanYang
)
137 @pytest.fixture(scope
='module')
138 def nsm_proxy(request
, mgmt_session
):
139 return mgmt_session
.proxy(RwNsmYang
)
141 @pytest.fixture(scope
='session')
142 def vrouter_vnfd_package_file():
143 vrouter_pkg_file
= os
.path
.join(
144 RW_VROUTER_PKG_INSTALL_DIR
,
145 "vrouter_vnfd_with_epa.tar.gz",
147 if not os
.path
.exists(vrouter_pkg_file
):
148 raise_package_error()
150 return vrouter_pkg_file
152 @pytest.fixture(scope
='session')
153 def tg_vnfd_package_file():
154 tg_pkg_file
= os
.path
.join(
155 RW_TRAFGEN_PKG_INSTALL_DIR
,
156 "trafgen_vnfd_with_epa.tar.gz",
158 if not os
.path
.exists(tg_pkg_file
):
159 raise_package_error()
163 @pytest.fixture(scope
='session')
164 def ts_vnfd_package_file():
165 ts_pkg_file
= os
.path
.join(
166 RW_TRAFSINK_PKG_INSTALL_DIR
,
167 "trafsink_vnfd_with_epa.tar.gz",
169 if not os
.path
.exists(ts_pkg_file
):
170 raise_package_error()
174 @pytest.fixture(scope
='session')
175 def tg_2vrouter_ts_nsd_package_file():
176 tg_2vrouter_ts_nsd_pkg_file
= os
.path
.join(
177 RW_TG_2VROUTER_TS_NSD_PKG_INSTALL_DIR
,
178 "tg_2vrouter_ts_nsd_with_epa.tar.gz",
180 if not os
.path
.exists(tg_2vrouter_ts_nsd_pkg_file
):
181 raise_package_error()
183 return tg_2vrouter_ts_nsd_pkg_file
186 def create_nsr_from_nsd_id(nsd_id
):
187 nsr
= NsrYang
.YangData_RwProject_Project_NsInstanceConfig_Nsr()
188 nsr
.id = str(uuid
.uuid4())
189 nsr
.name
= "TG-2Vrouter-TS EPA"
190 nsr
.short_name
= "TG-2Vrouter-TS EPA"
191 nsr
.description
= "4 VNFs with Trafgen, 2 Vrouters and Trafsink EPA"
193 nsr
.admin_status
= "ENABLED"
198 def upload_descriptor(logger
, descriptor_file
, host
="127.0.0.1"):
199 curl_cmd
= 'curl -F "descriptor=@{file}" http://{host}:4567/api/upload'.format(
200 file=descriptor_file
,
203 logger
.debug("Uploading descriptor %s using cmd: %s", descriptor_file
, curl_cmd
)
204 stdout
= subprocess
.check_output(shlex
.split(curl_cmd
), universal_newlines
=True)
206 json_out
= json
.loads(stdout
)
207 transaction_id
= json_out
["transaction_id"]
209 return transaction_id
212 class DescriptorOnboardError(Exception):
216 def wait_unboard_transaction_finished(logger
, transaction_id
, timeout_secs
=600, host
="127.0.0.1"):
217 logger
.info("Waiting for onboard trans_id %s to complete",
219 start_time
= time
.time()
220 while (time
.time() - start_time
) < timeout_secs
:
222 'http://{host}:4567/api/upload/{t_id}/state'.format(
223 host
=host
, t_id
=transaction_id
227 if state
["status"] == "pending":
231 elif state
["status"] == "success":
232 logger
.info("Descriptor onboard was successful")
236 raise DescriptorOnboardError(state
)
238 if state
["status"] != "success":
239 raise DescriptorOnboardError(state
)
241 @pytest.mark
.incremental
242 class TestLaunchpadStartStop(object):
243 def test_configure_cloud_account(self
, cloud_proxy
, logger
):
244 cloud_account
= RwCloudYang
.CloudAccountConfig()
245 #cloud_account.name = "cloudsim_proxy"
246 #cloud_account.account_type = "cloudsim_proxy"
247 cloud_account
.name
= "riftuser1"
248 cloud_account
.account_type
= "openstack"
249 cloud_account
.openstack
.key
= 'pluto'
250 cloud_account
.openstack
.secret
= 'mypasswd'
251 cloud_account
.openstack
.auth_url
= 'http://10.66.4.xx:5000/v3/'
252 cloud_account
.openstack
.tenant
= 'demo'
253 cloud_account
.openstack
.mgmt_network
= 'private'
255 cloud_proxy
.merge_config("/rw-project:project/rw-cloud:cloud-account", cloud_account
)
257 def test_configure_pools(self
, resource_mgr_proxy
):
258 pools
= RwResourceMgrYang
.ResourcePools
.from_dict({
259 "pools": [{ "name": "vm_pool_a",
260 "resource_type": "compute",
261 "pool_type" : "dynamic"},
262 {"name": "network_pool_a",
263 "resource_type": "network",
264 "pool_type" : "dynamic",}]})
266 resource_mgr_proxy
.merge_config('/rw-project:project/rw-resource-mgr:resource-mgr-config/rw-resource-mgr:resource-pools', pools
)
268 def test_configure_resource_orchestrator(self
, so_proxy
):
269 cfg
= RwConmanYang
.RoEndpoint
.from_dict({'ro_ip_address': '127.0.0.1',
271 'ro_username' : 'admin',
272 'ro_password' : 'admin'})
273 so_proxy
.merge_config('/rw-project:project/rw-conman:cm-config', cfg
)
275 def test_configure_service_orchestrator(self
, nsm_proxy
):
276 cfg
= RwNsmYang
.SoEndpoint
.from_dict({'cm_ip_address': '127.0.0.1',
278 'cm_username' : 'admin',
279 'cm_password' : 'admin'})
280 nsm_proxy
.merge_config('/rw-nsm:ro-config/rw-nsm:cm-endpoint', cfg
)
283 def test_onboard_tg_vnfd(self
, logger
, vnfd_proxy
, tg_vnfd_package_file
):
284 logger
.info("Onboarding trafgen_vnfd package: %s", tg_vnfd_package_file
)
285 trans_id
= upload_descriptor(logger
, tg_vnfd_package_file
)
286 wait_unboard_transaction_finished(logger
, trans_id
)
288 catalog
= vnfd_proxy
.get_config('/vnfd-catalog')
290 assert len(vnfds
) == 1, "There should be one vnfds"
291 assert "trafgen_vnfd" in [vnfds
[0].name
]
293 def test_onboard_vrouter_vnfd(self
, logger
, vnfd_proxy
, vrouter_vnfd_package_file
):
294 logger
.info("Onboarding vrouter_vnfd package: %s", vrouter_vnfd_package_file
)
295 trans_id
= upload_descriptor(logger
, vrouter_vnfd_package_file
)
296 wait_unboard_transaction_finished(logger
, trans_id
)
298 catalog
= vnfd_proxy
.get_config('/vnfd-catalog')
300 assert len(vnfds
) == 2, "There should be two vnfds"
301 assert "vrouter_vnfd" in [vnfds
[0].name
, vnfds
[1].name
]
303 def test_onboard_ts_vnfd(self
, logger
, vnfd_proxy
, ts_vnfd_package_file
):
304 logger
.info("Onboarding trafsink_vnfd package: %s", ts_vnfd_package_file
)
305 trans_id
= upload_descriptor(logger
, ts_vnfd_package_file
)
306 wait_unboard_transaction_finished(logger
, trans_id
)
308 catalog
= vnfd_proxy
.get_config('/vnfd-catalog')
310 assert len(vnfds
) == 3, "There should be three vnfds"
311 assert "trafsink_vnfd" in [vnfds
[0].name
, vnfds
[1].name
, vnfds
[2].name
]
313 def test_onboard_tg_2vrouter_ts_nsd(self
, logger
, nsd_proxy
, tg_2vrouter_ts_nsd_package_file
):
314 logger
.info("Onboarding tg_2vrouter_ts nsd package: %s", tg_2vrouter_ts_nsd_package_file
)
315 trans_id
= upload_descriptor(logger
, tg_2vrouter_ts_nsd_package_file
)
316 wait_unboard_transaction_finished(logger
, trans_id
)
318 catalog
= nsd_proxy
.get_config('/nsd-catalog')
320 assert len(nsds
) == 1, "There should only be a single nsd"
322 assert nsd
.name
== "tg_vrouter_ts_nsd"
323 assert nsd
.short_name
== "tg_2vrouter_ts_nsd"
325 def test_instantiate_tg_2vrouter_ts_nsr(self
, logger
, nsd_proxy
, nsr_proxy
, rwnsr_proxy
, base_proxy
):
326 catalog
= nsd_proxy
.get_config('/nsd-catalog')
329 nsr
= create_nsr_from_nsd_id(nsd
.id)
330 nsr_proxy
.merge_config('/ns-instance-config', nsr
)
332 nsr_opdata
= rwnsr_proxy
.get('/ns-instance-opdata')
333 nsrs
= nsr_opdata
.nsr
334 assert len(nsrs
) == 1
335 assert nsrs
[0].ns_instance_config_ref
== nsr
.id