4 # Copyright 2016 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.
20 @author Austin Cormier (Austin.Cormier@riftio.com)
22 @brief Launchpad Module Test
37 gi
.require_version('RwBaseYang', '1.0')
38 gi
.require_version('RwCloudYang', '1.0')
39 gi
.require_version('RwIwpYang', '1.0')
40 gi
.require_version('RwlogMgmtYang', '1.0')
41 gi
.require_version('RwNsmYang', '1.0')
42 gi
.require_version('RwNsmYang', '1.0')
43 gi
.require_version('RwResourceMgrYang', '1.0')
44 gi
.require_version('RwConmanYang', '1.0')
45 gi
.require_version('RwVnfdYang', '1.0')
47 from gi
.repository
import (
62 logging
.basicConfig(level
=logging
.DEBUG
)
65 RW_PING_PONG_PKG_INSTALL_DIR
= os
.path
.join(
66 os
.environ
["RIFT_ROOT"],
70 class PackageError(Exception):
74 def raise_package_error():
75 raise PackageError("Could not find ns packages")
78 @pytest.fixture(scope
='module')
79 def iwp_proxy(request
, mgmt_session
):
80 return mgmt_session
.proxy(RwIwpYang
)
83 @pytest.fixture(scope
='module')
84 def rwlog_mgmt_proxy(request
, mgmt_session
):
85 return mgmt_session
.proxy(RwlogMgmtYang
)
88 @pytest.fixture(scope
='module')
89 def resource_mgr_proxy(request
, mgmt_session
):
90 return mgmt_session
.proxy(RwResourceMgrYang
)
93 @pytest.fixture(scope
='module')
94 def cloud_proxy(request
, mgmt_session
):
95 return mgmt_session
.proxy(RwCloudYang
)
98 @pytest.fixture(scope
='module')
99 def vnfd_proxy(request
, mgmt_session
):
100 return mgmt_session
.proxy(RwVnfdYang
)
103 @pytest.fixture(scope
='module')
104 def vld_proxy(request
, mgmt_session
):
105 return mgmt_session
.proxy(VldYang
)
108 @pytest.fixture(scope
='module')
109 def nsd_proxy(request
, mgmt_session
):
110 return mgmt_session
.proxy(NsdYang
)
113 @pytest.fixture(scope
='module')
114 def nsr_proxy(request
, mgmt_session
):
115 return mgmt_session
.proxy(NsrYang
)
118 @pytest.fixture(scope
='module')
119 def rwnsr_proxy(request
, mgmt_session
):
120 return mgmt_session
.proxy(RwNsrYang
)
123 @pytest.fixture(scope
='module')
124 def base_proxy(request
, mgmt_session
):
125 return mgmt_session
.proxy(RwBaseYang
)
128 @pytest.fixture(scope
='module')
129 def so_proxy(request
, mgmt_session
):
130 return mgmt_session
.proxy(RwConmanYang
)
133 @pytest.fixture(scope
='module')
134 def nsm_proxy(request
, mgmt_session
):
135 return mgmt_session
.proxy(RwNsmYang
)
138 @pytest.fixture(scope
='session')
139 def ping_vnfd_package_file():
140 ping_pkg_file
= os
.path
.join(
141 RW_PING_PONG_PKG_INSTALL_DIR
,
142 "ping_vnfd_with_image.tar.gz",
144 if not os
.path
.exists(ping_pkg_file
):
145 raise_package_error()
150 @pytest.fixture(scope
='session')
151 def pong_vnfd_package_file():
152 pong_pkg_file
= os
.path
.join(
153 RW_PING_PONG_PKG_INSTALL_DIR
,
154 "pong_vnfd_with_image.tar.gz",
156 if not os
.path
.exists(pong_pkg_file
):
157 raise_package_error()
162 @pytest.fixture(scope
='session')
163 def ping_pong_nsd_package_file():
164 ping_pong_pkg_file
= os
.path
.join(
165 RW_PING_PONG_PKG_INSTALL_DIR
,
166 "ping_pong_nsd.tar.gz",
168 if not os
.path
.exists(ping_pong_pkg_file
):
169 raise_package_error()
171 return ping_pong_pkg_file
174 def create_nsr_from_nsd_id(nsd_id
):
175 nsr
= RwNsrYang
.YangData_Nsr_NsInstanceConfig_Nsr()
176 nsr
.id = str(uuid
.uuid4())
177 nsr
.name
= "pingpong_{}".format(datetime
.datetime
.now().strftime("%Y%m%d_%H%M%S"))
178 nsr
.short_name
= "nsr_short_name"
179 nsr
.description
= "This is a description"
181 nsr
.admin_status
= "ENABLED"
182 nsr
.cloud_account
= "openstack"
184 param
= NsrYang
.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter()
185 param
.xpath
= '/nsd:nsd-catalog/nsd:nsd/nsd:vendor'
186 param
.value
= "rift-o-matic"
188 nsr
.input_parameter
.append(param
)
193 def upload_descriptor(logger
, descriptor_file
, host
="127.0.0.1"):
194 curl_cmd
= 'curl -F "descriptor=@{file}" http://{host}:4567/api/upload'.format(
195 file=descriptor_file
,
198 logger
.debug("Uploading descriptor %s using cmd: %s", descriptor_file
, curl_cmd
)
199 stdout
= subprocess
.check_output(shlex
.split(curl_cmd
), universal_newlines
=True)
201 json_out
= json
.loads(stdout
)
202 transaction_id
= json_out
["transaction_id"]
204 return transaction_id
207 class DescriptorOnboardError(Exception):
211 def wait_unboard_transaction_finished(logger
, transaction_id
, timeout_secs
=600, host
="127.0.0.1"):
212 logger
.info("Waiting for onboard trans_id %s to complete",
214 start_time
= time
.time()
215 while (time
.time() - start_time
) < timeout_secs
:
217 'http://{host}:4567/api/upload/{t_id}/state'.format(
218 host
=host
, t_id
=transaction_id
222 if state
["status"] == "pending":
226 elif state
["status"] == "success":
227 logger
.info("Descriptor onboard was successful")
231 raise DescriptorOnboardError(state
)
233 if state
["status"] != "success":
234 raise DescriptorOnboardError(state
)
237 @pytest.mark
.incremental
238 class TestLaunchpadStartStop(object):
239 def test_configure_logging(self
, rwlog_mgmt_proxy
):
240 logging
= RwlogMgmtYang
.Logging
.from_dict({
245 "name": "rw-generic",
251 rwlog_mgmt_proxy
.merge_config("/rwlog-mgmt:logging", logging
)
253 def test_configure_cloud_account(self
, cloud_proxy
, logger
):
254 cloud_account
= RwCloudYang
.CloudAccount()
255 # cloud_account.name = "cloudsim_proxy"
256 # cloud_account.account_type = "cloudsim_proxy"
257 cloud_account
.name
= "openstack"
258 cloud_account
.account_type
= "openstack"
259 cloud_account
.openstack
.key
= 'pluto'
260 cloud_account
.openstack
.secret
= 'mypasswd'
261 cloud_account
.openstack
.auth_url
= 'http://10.96.4.2:5000/v3/'
262 cloud_account
.openstack
.tenant
= 'mano1'
263 cloud_account
.openstack
.mgmt_network
= 'private1'
265 cloud_proxy
.merge_config("/rw-cloud:cloud/account", cloud_account
)
267 def test_onboard_ping_vnfd(self
, logger
, vnfd_proxy
, ping_vnfd_package_file
):
268 logger
.info("Onboarding ping_vnfd package: %s", ping_vnfd_package_file
)
269 trans_id
= upload_descriptor(logger
, ping_vnfd_package_file
)
270 wait_unboard_transaction_finished(logger
, trans_id
)
272 catalog
= vnfd_proxy
.get_config('/vnfd-catalog')
274 assert len(vnfds
) == 1, "There should only be a single vnfd"
276 assert vnfd
.name
== "ping_vnfd"
278 def test_onboard_pong_vnfd(self
, logger
, vnfd_proxy
, pong_vnfd_package_file
):
279 logger
.info("Onboarding pong_vnfd package: %s", pong_vnfd_package_file
)
280 trans_id
= upload_descriptor(logger
, pong_vnfd_package_file
)
281 wait_unboard_transaction_finished(logger
, trans_id
)
283 catalog
= vnfd_proxy
.get_config('/vnfd-catalog')
285 assert len(vnfds
) == 2, "There should be two vnfds"
286 assert "pong_vnfd" in [vnfds
[0].name
, vnfds
[1].name
]
288 def test_onboard_ping_pong_nsd(self
, logger
, nsd_proxy
, ping_pong_nsd_package_file
):
289 logger
.info("Onboarding ping_pong_nsd package: %s", ping_pong_nsd_package_file
)
290 trans_id
= upload_descriptor(logger
, ping_pong_nsd_package_file
)
291 wait_unboard_transaction_finished(logger
, trans_id
)
293 catalog
= nsd_proxy
.get_config('/nsd-catalog')
295 assert len(nsds
) == 1, "There should only be a single nsd"
297 assert nsd
.name
== "ping_pong_nsd"
299 def test_instantiate_ping_pong_nsr(self
, logger
, nsd_proxy
, nsr_proxy
, rwnsr_proxy
, base_proxy
):
300 catalog
= nsd_proxy
.get_config('/nsd-catalog')
303 nsr
= create_nsr_from_nsd_id(nsd
.id)
304 rwnsr_proxy
.merge_config('/ns-instance-config', nsr
)
306 nsr_opdata
= rwnsr_proxy
.get('/ns-instance-opdata')
307 nsrs
= nsr_opdata
.nsr
308 assert len(nsrs
) == 1
309 assert nsrs
[0].ns_instance_config_ref
== nsr
.id
311 # logger.info("Waiting up to 30 seconds for ping and pong components to show "
312 # "up in show tasklet info")
314 # start_time = time.time()
315 # while (time.time() - start_time) < 30:
316 # vcs_info = base_proxy.get('/vcs/info')
317 # components = vcs_info.components.component_info
319 # def find_component_by_name(name):
320 # for component in components:
321 # if name in component.component_name:
324 # logger.warning("Did not find %s component name in show tasklet info",
330 # ping_cluster_component = find_component_by_name(
331 # "rw_ping_vnfd:rwping_cluster"
333 # if ping_cluster_component is None:
336 # pong_cluster_component = find_component_by_name(
337 # "rw_pong_vnfd:rwpong_cluster"
339 # if pong_cluster_component is None:
343 # ping_vm_component = find_component_by_name(
344 # "rw_ping_vnfd:rwping_vm"
346 # if ping_vm_component is None:
349 # pong_vm_component = find_component_by_name(
350 # "rw_pong_vnfd:rwpong_vm"
352 # if pong_vm_component is None:
355 # ping_proc_component = find_component_by_name(
356 # "rw_ping_vnfd:rwping_proc"
358 # if ping_proc_component is None:
361 # pong_proc_component = find_component_by_name(
362 # "rw_pong_vnfd:rwpong_proc"
364 # if pong_proc_component is None:
367 # ping_tasklet_component = find_component_by_name(
368 # "rw_ping_vnfd:rwping_tasklet"
370 # if ping_tasklet_component is None:
373 # pong_tasklet_component = find_component_by_name(
374 # "rw_pong_vnfd:rwpong_tasklet"
376 # if pong_tasklet_component is None:
379 # logger.info("TEST SUCCESSFUL: All ping and pong components were found in show tasklet info")
383 # assert False, "Did not find all ping and pong component in time"
385 #def test_terminate_ping_pong_ns(self, logger, nsd_proxy, nsr_proxy, rwnsr_proxy, base_proxy):
386 # nsr_configs = nsr_proxy.get_config('/ns-instance-config')
387 # nsr = nsr_configs.nsr[0]
390 # nsr_configs = nsr_proxy.delete_config("/ns-instance-config/nsr[id='{}']".format(nsr_id))