2 # -*- coding: utf-8 -*-
6 # This file is part of openmano
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
25 if os
.getenv('OSMRO_PDB_DEBUG'):
33 Module for testing openmano functionality. It uses openmanoclient.py for invoking openmano
49 from argparse
import ArgumentParser
51 __author__
= "Pablo Montes, Alfonso Tierno"
52 __date__
= "$16-Feb-2017 17:08:16$"
54 version_date
= "Oct 2017"
56 test_config
= {} # used for global variables with the test configuration
59 class test_base(unittest
.TestCase
):
65 logger
.info("{}. {}".format(test_config
["test_number"], cls
.__name
__))
68 def tearDownClass(cls
):
69 test_config
["test_number"] += 1
72 exec_info
= sys
.exc_info()
73 if exec_info
== (None, None, None):
74 logger
.info(self
.__class
__.test_text
+" -> TEST OK")
76 logger
.warning(self
.__class
__.test_text
+" -> TEST NOK")
77 logger
.critical("Traceback error",exc_info
=True)
80 def check_instance_scenario_active(uuid
):
81 instance
= test_config
["client"].get_instance(uuid
=uuid
)
83 for net
in instance
['nets']:
84 status
= net
['status']
85 if status
!= 'ACTIVE':
86 return (False, status
)
88 for vnf
in instance
['vnfs']:
91 if status
!= 'ACTIVE':
92 return (False, status
)
99 All unittest classes for code based tests must have prefix 'test_' in order to be taken into account for tests
101 class test_VIM_datacenter_tenant_operations(test_base
):
104 def test_000_create_RO_tenant(self
):
105 self
.__class
__.tenant_name
= _get_random_string(20)
106 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
107 inspect
.currentframe().f_code
.co_name
)
108 self
.__class
__.test_index
+= 1
109 tenant
= test_config
["client"].create_tenant(name
=self
.__class
__.tenant_name
,
110 description
=self
.__class
__.tenant_name
)
111 logger
.debug("{}".format(tenant
))
112 self
.assertEqual(tenant
.get('tenant', {}).get('name', ''), self
.__class
__.tenant_name
)
114 def test_010_list_RO_tenant(self
):
115 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
116 inspect
.currentframe().f_code
.co_name
)
117 self
.__class
__.test_index
+= 1
118 tenant
= test_config
["client"].get_tenant(name
=self
.__class
__.tenant_name
)
119 logger
.debug("{}".format(tenant
))
120 self
.assertEqual(tenant
.get('tenant', {}).get('name', ''), self
.__class
__.tenant_name
)
122 def test_020_delete_RO_tenant(self
):
123 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
124 inspect
.currentframe().f_code
.co_name
)
125 self
.__class
__.test_index
+= 1
126 tenant
= test_config
["client"].delete_tenant(name
=self
.__class
__.tenant_name
)
127 logger
.debug("{}".format(tenant
))
128 assert('deleted' in tenant
.get('result',""))
131 class test_VIM_datacenter_operations(test_base
):
132 datacenter_name
= None
134 def test_000_create_datacenter(self
):
135 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
136 inspect
.currentframe().f_code
.co_name
)
137 self
.__class
__.datacenter_name
= _get_random_string(20)
138 self
.__class
__.test_index
+= 1
139 self
.datacenter
= test_config
["client"].create_datacenter(name
=self
.__class
__.datacenter_name
,
140 vim_url
="http://fakeurl/fake")
141 logger
.debug("{}".format(self
.datacenter
))
142 self
.assertEqual (self
.datacenter
.get('datacenter', {}).get('name',''), self
.__class
__.datacenter_name
)
144 def test_010_list_datacenter(self
):
145 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
146 inspect
.currentframe().f_code
.co_name
)
148 self
.__class
__.test_index
+= 1
149 self
.datacenter
= test_config
["client"].get_datacenter(all_tenants
=True, name
=self
.__class
__.datacenter_name
)
150 logger
.debug("{}".format(self
.datacenter
))
151 self
.assertEqual (self
.datacenter
.get('datacenter', {}).get('name', ''), self
.__class
__.datacenter_name
)
153 def test_020_attach_datacenter(self
):
154 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
155 inspect
.currentframe().f_code
.co_name
)
157 self
.__class
__.test_index
+= 1
158 self
.datacenter
= test_config
["client"].attach_datacenter(name
=self
.__class
__.datacenter_name
,
159 vim_tenant_name
='fake')
160 logger
.debug("{}".format(self
.datacenter
))
161 assert ('uuid' in self
.datacenter
.get('datacenter', {}))
163 def test_030_list_attached_datacenter(self
):
164 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
165 inspect
.currentframe().f_code
.co_name
)
167 self
.__class
__.test_index
+= 1
168 self
.datacenter
= test_config
["client"].get_datacenter(all_tenants
=False, name
=self
.__class
__.datacenter_name
)
169 logger
.debug("{}".format(self
.datacenter
))
170 self
.assertEqual (self
.datacenter
.get('datacenter', {}).get('name', ''), self
.__class
__.datacenter_name
)
172 def test_040_detach_datacenter(self
):
173 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
174 inspect
.currentframe().f_code
.co_name
)
176 self
.__class
__.test_index
+= 1
177 self
.datacenter
= test_config
["client"].detach_datacenter(name
=self
.__class
__.datacenter_name
)
178 logger
.debug("{}".format(self
.datacenter
))
179 assert ('detached' in self
.datacenter
.get('result', ""))
181 def test_050_delete_datacenter(self
):
182 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
183 inspect
.currentframe().f_code
.co_name
)
185 self
.__class
__.test_index
+= 1
186 self
.datacenter
= test_config
["client"].delete_datacenter(name
=self
.__class
__.datacenter_name
)
187 logger
.debug("{}".format(self
.datacenter
))
188 assert('deleted' in self
.datacenter
.get('result',""))
191 class test_VIM_network_operations(test_base
):
192 vim_network_name
= None
193 vim_network_uuid
= None
195 def test_000_create_VIM_network(self
):
196 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
197 inspect
.currentframe().f_code
.co_name
)
198 self
.__class
__.vim_network_name
= _get_random_string(20)
199 self
.__class
__.test_index
+= 1
200 network
= test_config
["client"].vim_action("create", "networks", name
=self
.__class
__.vim_network_name
)
201 logger
.debug("{}".format(network
))
202 self
.__class
__.vim_network_uuid
= network
["network"]["id"]
203 self
.assertEqual(network
.get('network', {}).get('name', ''), self
.__class
__.vim_network_name
)
205 def test_010_list_VIM_networks(self
):
206 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
207 inspect
.currentframe().f_code
.co_name
)
208 self
.__class
__.test_index
+= 1
209 networks
= test_config
["client"].vim_action("list", "networks")
210 logger
.debug("{}".format(networks
))
212 def test_020_get_VIM_network_by_uuid(self
):
213 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
214 inspect
.currentframe().f_code
.co_name
)
216 self
.__class
__.test_index
+= 1
217 network
= test_config
["client"].vim_action("show", "networks", uuid
=self
.__class
__.vim_network_uuid
)
218 logger
.debug("{}".format(network
))
219 self
.assertEqual(network
.get('network', {}).get('name', ''), self
.__class
__.vim_network_name
)
221 def test_030_delete_VIM_network_by_uuid(self
):
222 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
223 inspect
.currentframe().f_code
.co_name
)
225 self
.__class
__.test_index
+= 1
226 network
= test_config
["client"].vim_action("delete", "networks", uuid
=self
.__class
__.vim_network_uuid
)
227 logger
.debug("{}".format(network
))
228 assert ('deleted' in network
.get('result', ""))
231 class test_VIM_image_operations(test_base
):
233 def test_000_list_VIM_images(self
):
234 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
235 inspect
.currentframe().f_code
.co_name
)
236 self
.__class
__.test_index
+= 1
237 images
= test_config
["client"].vim_action("list", "images")
238 logger
.debug("{}".format(images
))
241 The following is a non critical test that will fail most of the times.
242 In case of OpenStack datacenter these tests will only success if RO has access to the admin endpoint
243 This test will only be executed in case it is specifically requested by the user
245 class test_VIM_tenant_operations(test_base
):
246 vim_tenant_name
= None
247 vim_tenant_uuid
= None
251 test_base
.setUpClass(cls
)
252 logger
.warning("In case of OpenStack datacenter these tests will only success "
253 "if RO has access to the admin endpoint")
255 def test_000_create_VIM_tenant(self
):
256 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
257 inspect
.currentframe().f_code
.co_name
)
258 self
.__class
__.vim_tenant_name
= _get_random_string(20)
259 self
.__class
__.test_index
+= 1
260 tenant
= test_config
["client"].vim_action("create", "tenants", name
=self
.__class
__.vim_tenant_name
)
261 logger
.debug("{}".format(tenant
))
262 self
.__class
__.vim_tenant_uuid
= tenant
["tenant"]["id"]
263 self
.assertEqual(tenant
.get('tenant', {}).get('name', ''), self
.__class
__.vim_tenant_name
)
265 def test_010_list_VIM_tenants(self
):
266 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
267 inspect
.currentframe().f_code
.co_name
)
268 self
.__class
__.test_index
+= 1
269 tenants
= test_config
["client"].vim_action("list", "tenants")
270 logger
.debug("{}".format(tenants
))
272 def test_020_get_VIM_tenant_by_uuid(self
):
273 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
274 inspect
.currentframe().f_code
.co_name
)
276 self
.__class
__.test_index
+= 1
277 tenant
= test_config
["client"].vim_action("show", "tenants", uuid
=self
.__class
__.vim_tenant_uuid
)
278 logger
.debug("{}".format(tenant
))
279 self
.assertEqual(tenant
.get('tenant', {}).get('name', ''), self
.__class
__.vim_tenant_name
)
281 def test_030_delete_VIM_tenant_by_uuid(self
):
282 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"], self
.__class
__.test_index
,
283 inspect
.currentframe().f_code
.co_name
)
285 self
.__class
__.test_index
+= 1
286 tenant
= test_config
["client"].vim_action("delete", "tenants", uuid
=self
.__class
__.vim_tenant_uuid
)
287 logger
.debug("{}".format(tenant
))
288 assert ('deleted' in tenant
.get('result', ""))
291 class test_vimconn_connect(test_base
):
293 def test_000_connect(self
):
294 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
295 self
.__class
__.test_index
,
296 inspect
.currentframe().f_code
.co_name
)
298 self
.__class
__.test_index
+= 1
299 if test_config
['vimtype'] == 'vmware':
300 vca_object
= test_config
["vim_conn"].connect()
301 logger
.debug("{}".format(vca_object
))
302 self
.assertIsNotNone(vca_object
)
303 elif test_config
['vimtype'] in ('openstack', 'azure'):
304 test_config
["vim_conn"]._reload
_connection
()
305 network_list
= test_config
["vim_conn"].get_network_list()
306 logger
.debug("{}".format(network_list
))
307 self
.assertIsNotNone(network_list
)
309 class test_vimconn_new_network(test_base
):
312 def test_000_new_network(self
):
313 self
.__class
__.network_name
= _get_random_string(20)
314 network_type
= 'bridge'
316 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
317 self
.__class
__.test_index
, inspect
.currentframe().f_code
.co_name
)
318 self
.__class
__.test_index
+= 1
320 network
, _
= test_config
["vim_conn"].new_network(net_name
=self
.__class
__.network_name
,
321 net_type
=network_type
)
322 self
.__class
__.network_id
= network
323 logger
.debug("{}".format(network
))
325 network_list
= test_config
["vim_conn"].get_network_list()
326 for net
in network_list
:
327 if self
.__class
__.network_name
in net
.get('name'):
328 self
.assertIn(self
.__class
__.network_name
, net
.get('name'))
329 self
.assertEqual(net
.get('type'), network_type
)
331 # Deleting created network
332 result
= test_config
["vim_conn"].delete_network(self
.__class
__.network_id
)
334 logger
.info("Network id {} sucessfully deleted".format(self
.__class
__.network_id
))
336 logger
.info("Failed to delete network id {}".format(self
.__class
__.network_id
))
338 def test_010_new_network_by_types(self
):
340 network_types
= ['data','bridge','mgmt']
341 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
342 self
.__class
__.test_index
,
343 inspect
.currentframe().f_code
.co_name
)
344 self
.__class
__.test_index
+= 1
345 for net_type
in network_types
:
346 self
.__class
__.network_name
= _get_random_string(20)
347 network_id
, _
= test_config
["vim_conn"].new_network(net_name
=self
.__class
__.network_name
,
350 delete_net_ids
.append(network_id
)
351 logger
.debug("{}".format(network_id
))
353 network_list
= test_config
["vim_conn"].get_network_list()
354 for net
in network_list
:
355 if self
.__class
__.network_name
in net
.get('name'):
356 self
.assertIn(self
.__class
__.network_name
, net
.get('name'))
357 if net_type
in net
.get('type'):
358 self
.assertEqual(net
.get('type'), net_type
)
360 self
.assertNotEqual(net
.get('type'), net_type
)
362 # Deleting created network
363 for net_id
in delete_net_ids
:
364 result
= test_config
["vim_conn"].delete_network(net_id
)
366 logger
.info("Network id {} sucessfully deleted".format(net_id
))
368 logger
.info("Failed to delete network id {}".format(net_id
))
370 def test_020_new_network_by_ipprofile(self
):
371 test_directory_content
= os
.listdir(test_config
["test_directory"])
373 for dir_name
in test_directory_content
:
374 if dir_name
== 'simple_multi_vnfc':
375 self
.__class
__.scenario_test_path
= test_config
["test_directory"] + '/'+ dir_name
376 vnfd_files
= glob
.glob(self
.__class
__.scenario_test_path
+'/vnfd_*.yaml')
379 for vnfd
in vnfd_files
:
380 with
open(vnfd
, 'r') as stream
:
381 vnf_descriptor
= yaml
.load(stream
)
383 internal_connections_list
= vnf_descriptor
['vnf']['internal-connections']
384 for item
in internal_connections_list
:
385 if 'ip-profile' in item
:
386 version
= item
['ip-profile']['ip-version']
387 dhcp_count
= item
['ip-profile']['dhcp']['count']
388 dhcp_enabled
= item
['ip-profile']['dhcp']['enabled']
389 dhcp_start_address
= item
['ip-profile']['dhcp']['start-address']
390 subnet_address
= item
['ip-profile']['subnet-address']
393 self
.__class
__.network_name
= _get_random_string(20)
394 ip_profile
= {'dhcp_count': dhcp_count
,
395 'dhcp_enabled': dhcp_enabled
,
396 'dhcp_start_address': dhcp_start_address
,
397 'ip_version': version
,
398 'subnet_address': subnet_address
400 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
401 self
.__class
__.test_index
,
402 inspect
.currentframe().f_code
.co_name
)
403 self
.__class
__.test_index
+= 1
404 network
, _
= test_config
["vim_conn"].new_network(net_name
=self
.__class
__.network_name
,
406 ip_profile
=ip_profile
)
407 self
.__class
__.network_id
= network
408 logger
.debug("{}".format(network
))
410 network_list
= test_config
["vim_conn"].get_network_list()
411 for net
in network_list
:
412 if self
.__class
__.network_name
in net
.get('name'):
413 self
.assertIn(self
.__class
__.network_name
, net
.get('name'))
415 # Deleting created network
416 result
= test_config
["vim_conn"].delete_network(self
.__class
__.network_id
)
418 logger
.info("Network id {} sucessfully deleted".format(self
.__class
__.network_id
))
420 logger
.info("Failed to delete network id {}".format(self
.__class
__.network_id
))
422 def test_030_new_network_by_isshared(self
):
423 self
.__class
__.network_name
= _get_random_string(20)
425 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
426 self
.__class
__.test_index
,
427 inspect
.currentframe().f_code
.co_name
)
428 self
.__class
__.test_index
+= 1
429 network
, _
= test_config
["vim_conn"].new_network(net_name
=self
.__class
__.network_name
,
432 self
.__class
__.network_id
= network
433 logger
.debug("{}".format(network
))
435 network_list
= test_config
["vim_conn"].get_network_list()
436 for net
in network_list
:
437 if self
.__class
__.network_name
in net
.get('name'):
438 self
.assertIn(self
.__class
__.network_name
, net
.get('name'))
439 self
.assertEqual(net
.get('shared'), shared
)
441 # Deleting created network
442 result
= test_config
["vim_conn"].delete_network(self
.__class
__.network_id
)
444 logger
.info("Network id {} sucessfully deleted".format(self
.__class
__.network_id
))
446 logger
.info("Failed to delete network id {}".format(self
.__class
__.network_id
))
448 def test_040_new_network_by_negative(self
):
449 self
.__class
__.network_name
= _get_random_string(20)
450 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
451 self
.__class
__.test_index
,
452 inspect
.currentframe().f_code
.co_name
)
453 self
.__class
__.test_index
+= 1
454 network
, _
= test_config
["vim_conn"].new_network(net_name
=self
.__class
__.network_name
,
455 net_type
='unknowntype')
456 self
.__class
__.network_id
= network
457 logger
.debug("{}".format(network
))
458 network_list
= test_config
["vim_conn"].get_network_list()
459 for net
in network_list
:
460 if self
.__class
__.network_name
in net
.get('name'):
461 self
.assertIn(self
.__class
__.network_name
, net
.get('name'))
463 # Deleting created network
464 result
= test_config
["vim_conn"].delete_network(self
.__class
__.network_id
)
466 logger
.info("Network id {} sucessfully deleted".format(self
.__class
__.network_id
))
468 logger
.info("Failed to delete network id {}".format(self
.__class
__.network_id
))
470 def test_050_refresh_nets_status(self
):
471 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
472 self
.__class
__.test_index
,
473 inspect
.currentframe().f_code
.co_name
)
474 self
.__class
__.test_index
+= 1
475 # creating new network
476 network_name
= _get_random_string(20)
478 network_id
, _
= test_config
["vim_conn"].new_network(net_name
=network_name
,
481 net_dict
= test_config
["vim_conn"].refresh_nets_status([network_id
])
482 for attr
in net_dict
[network_id
]:
484 self
.assertEqual(net_dict
[network_id
][attr
], 'ACTIVE')
486 # Deleting created network
487 result
= test_config
["vim_conn"].delete_network(network_id
)
489 logger
.info("Network id {} sucessfully deleted".format(network_id
))
491 logger
.info("Failed to delete network id {}".format(network_id
))
493 def test_060_refresh_nets_status_negative(self
):
494 unknown_net_id
= str(uuid
.uuid4())
495 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
496 self
.__class
__.test_index
,
497 inspect
.currentframe().f_code
.co_name
)
498 self
.__class
__.test_index
+= 1
501 net_dict
= test_config
["vim_conn"].refresh_nets_status([unknown_net_id
])
502 if test_config
['vimtype'] in ('openstack', 'azure'):
503 self
.assertEqual(net_dict
[unknown_net_id
]['status'], 'DELETED')
505 # TODO : Fix vmware connector to return status DELETED as per vimconn.py
506 self
.assertEqual(net_dict
, {})
508 class test_vimconn_get_network_list(test_base
):
512 # creating new network
513 self
.__class
__.network_name
= _get_random_string(20)
514 self
.__class
__.net_type
= 'bridge'
515 network
, _
= test_config
["vim_conn"].new_network(net_name
=self
.__class
__.network_name
,
516 net_type
=self
.__class
__.net_type
)
517 self
.__class
__.network_id
= network
518 logger
.debug("{}".format(network
))
521 test_base
.tearDown(self
)
523 # Deleting created network
524 result
= test_config
["vim_conn"].delete_network(self
.__class
__.network_id
)
526 logger
.info("Network id {} sucessfully deleted".format(self
.__class
__.network_id
))
528 logger
.info("Failed to delete network id {}".format(self
.__class
__.network_id
))
530 def test_000_get_network_list(self
):
531 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
532 self
.__class
__.test_index
,
533 inspect
.currentframe().f_code
.co_name
)
534 self
.__class
__.test_index
+= 1
536 network_list
= test_config
["vim_conn"].get_network_list()
537 for net
in network_list
:
538 if self
.__class
__.network_name
in net
.get('name'):
539 self
.assertIn(self
.__class
__.network_name
, net
.get('name'))
540 self
.assertEqual(net
.get('type'), self
.__class
__.net_type
)
541 self
.assertEqual(net
.get('status'), 'ACTIVE')
542 if test_config
['vimtype'] != 'azure':
543 self
.assertEqual(net
.get('shared'), False)
545 def test_010_get_network_list_by_name(self
):
546 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
547 self
.__class
__.test_index
,
548 inspect
.currentframe().f_code
.co_name
)
549 self
.__class
__.test_index
+= 1
551 if test_config
['vimtype'] in ('openstack', 'azure'):
552 network_name
= test_config
['vim_conn'].get_network(self
.__class
__.network_id
)['name']
554 network_name
= test_config
['vim_conn'].get_network_name_by_id(self
.__class
__.network_id
)
556 # find network from list by it's name
557 new_network_list
= test_config
["vim_conn"].get_network_list({'name': network_name
})
558 for list_item
in new_network_list
:
559 if self
.__class
__.network_name
in list_item
.get('name'):
560 self
.assertEqual(network_name
, list_item
.get('name'))
561 self
.assertEqual(list_item
.get('type'), self
.__class
__.net_type
)
562 self
.assertEqual(list_item
.get('status'), 'ACTIVE')
564 def test_020_get_network_list_by_id(self
):
565 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
566 self
.__class
__.test_index
,
567 inspect
.currentframe().f_code
.co_name
)
568 self
.__class
__.test_index
+= 1
570 # find network from list by it's id
571 new_network_list
= test_config
["vim_conn"].get_network_list({'id':self
.__class
__.network_id
})
572 for list_item
in new_network_list
:
573 if self
.__class
__.network_id
in list_item
.get('id'):
574 self
.assertEqual(self
.__class
__.network_id
, list_item
.get('id'))
575 self
.assertEqual(list_item
.get('type'), self
.__class
__.net_type
)
576 self
.assertEqual(list_item
.get('status'), 'ACTIVE')
578 def test_030_get_network_list_by_shared(self
):
580 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
581 self
.__class
__.test_index
,
582 inspect
.currentframe().f_code
.co_name
)
583 self
.__class
__.test_index
+= 1
585 if test_config
['vimtype'] in ('openstack', 'azure'):
586 network_name
= test_config
['vim_conn'].get_network(self
.__class
__.network_id
)['name']
588 network_name
= test_config
['vim_conn'].get_network_name_by_id(self
.__class
__.network_id
)
589 # find network from list by it's shared value
590 new_network_list
= test_config
["vim_conn"].get_network_list({'shared':Shared
,
591 'name':network_name
})
592 for list_item
in new_network_list
:
593 if list_item
.get('shared') == Shared
:
594 self
.assertEqual(list_item
.get('shared'), Shared
)
595 self
.assertEqual(list_item
.get('type'), self
.__class
__.net_type
)
596 self
.assertEqual(network_name
, list_item
.get('name'))
598 def test_040_get_network_list_by_tenant_id(self
):
599 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
600 self
.__class
__.test_index
,
601 inspect
.currentframe().f_code
.co_name
)
602 self
.__class
__.test_index
+= 1
604 tenant_list
= test_config
["vim_conn"].get_tenant_list()
605 if test_config
['vimtype'] in ('openstack', 'azure'):
606 network_name
= test_config
['vim_conn'].get_network(self
.__class
__.network_id
)['name']
608 network_name
= test_config
['vim_conn'].get_network_name_by_id(self
.__class
__.network_id
)
610 for tenant_item
in tenant_list
:
611 if test_config
['tenant'] == tenant_item
.get('name'):
612 # find network from list by it's tenant id
613 tenant_id
= tenant_item
.get('id')
614 new_network_list
= test_config
["vim_conn"].get_network_list({'tenant_id':tenant_id
,
615 'name':network_name
})
616 for list_item
in new_network_list
:
617 self
.assertEqual(tenant_id
, list_item
.get('tenant_id'))
618 self
.assertEqual(network_name
, list_item
.get('name'))
619 self
.assertEqual(list_item
.get('type'), self
.__class
__.net_type
)
620 self
.assertEqual(list_item
.get('status'), 'ACTIVE')
622 def test_050_get_network_list_by_status(self
):
623 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
624 self
.__class
__.test_index
,
625 inspect
.currentframe().f_code
.co_name
)
626 self
.__class
__.test_index
+= 1
629 if test_config
['vimtype'] in ('openstack', 'azure'):
630 network_name
= test_config
['vim_conn'].get_network(self
.__class
__.network_id
)['name']
632 network_name
= test_config
['vim_conn'].get_network_name_by_id(self
.__class
__.network_id
)
634 # find network from list by it's status
635 new_network_list
= test_config
["vim_conn"].get_network_list({'status':status
,
636 'name': network_name
})
637 for list_item
in new_network_list
:
638 self
.assertIn(self
.__class
__.network_name
, list_item
.get('name'))
639 self
.assertEqual(list_item
.get('type'), self
.__class
__.net_type
)
640 self
.assertEqual(list_item
.get('status'), status
)
642 def test_060_get_network_list_by_negative(self
):
643 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
644 self
.__class
__.test_index
,
645 inspect
.currentframe().f_code
.co_name
)
646 self
.__class
__.test_index
+= 1
648 network_list
= test_config
["vim_conn"].get_network_list({'name': 'unknown_name'})
649 self
.assertEqual(network_list
, [])
651 class test_vimconn_get_network(test_base
):
655 # creating new network
656 self
.__class
__.network_name
= _get_random_string(20)
657 self
.__class
__.net_type
= 'bridge'
658 network
, _
= test_config
["vim_conn"].new_network(net_name
=self
.__class
__.network_name
,
659 net_type
=self
.__class
__.net_type
)
660 self
.__class
__.network_id
= network
661 logger
.debug("{}".format(network
))
664 test_base
.tearDown(self
)
666 # Deleting created network
667 result
= test_config
["vim_conn"].delete_network(self
.__class
__.network_id
)
669 logger
.info("Network id {} sucessfully deleted".format(self
.__class
__.network_id
))
671 logger
.info("Failed to delete network id {}".format(self
.__class
__.network_id
))
673 def test_000_get_network(self
):
674 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
675 self
.__class
__.test_index
,
676 inspect
.currentframe().f_code
.co_name
)
677 self
.__class
__.test_index
+= 1
679 network_info
= test_config
["vim_conn"].get_network(self
.__class
__.network_id
)
680 self
.assertEqual(network_info
.get('status'), 'ACTIVE')
681 self
.assertIn(self
.__class
__.network_name
, network_info
.get('name'))
682 self
.assertEqual(network_info
.get('type'), self
.__class
__.net_type
)
683 self
.assertEqual(network_info
.get('id'), self
.__class
__.network_id
)
685 def test_010_get_network_negative(self
):
686 Non_exist_id
= str(uuid
.uuid4())
687 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
688 self
.__class
__.test_index
,
689 inspect
.currentframe().f_code
.co_name
)
690 self
.__class
__.test_index
+= 1
691 with self
.assertRaises(Exception) as context
:
692 test_config
["vim_conn"].get_network(Non_exist_id
)
694 self
.assertEqual((context
.exception
).http_code
, 404)
696 class test_vimconn_delete_network(test_base
):
699 def test_000_delete_network(self
):
701 self
.__class
__.network_name
= _get_random_string(20)
702 self
.__class
__.net_type
= 'bridge'
703 network
, _
= test_config
["vim_conn"].new_network(net_name
=self
.__class
__.network_name
,
704 net_type
=self
.__class
__.net_type
)
705 self
.__class
__.network_id
= network
706 logger
.debug("{}".format(network
))
708 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
709 self
.__class
__.test_index
,
710 inspect
.currentframe().f_code
.co_name
)
711 self
.__class
__.test_index
+= 1
713 result
= test_config
["vim_conn"].delete_network(self
.__class
__.network_id
)
715 logger
.info("Network id {} sucessfully deleted".format(self
.__class
__.network_id
))
717 logger
.info("Failed to delete network id {}".format(self
.__class
__.network_id
))
719 # after deleting network we check in network list
720 network_list
= test_config
["vim_conn"].get_network_list({ 'id':self
.__class
__.network_id
})
721 self
.assertEqual(network_list
, [])
723 def test_010_delete_network_negative(self
):
724 Non_exist_id
= str(uuid
.uuid4())
726 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
727 self
.__class
__.test_index
,
728 inspect
.currentframe().f_code
.co_name
)
729 self
.__class
__.test_index
+= 1
731 with self
.assertRaises(Exception) as context
:
732 test_config
["vim_conn"].delete_network(Non_exist_id
)
734 self
.assertEqual((context
.exception
).http_code
, 404)
736 class test_vimconn_get_flavor(test_base
):
738 def test_000_get_flavor(self
):
739 test_directory_content
= os
.listdir(test_config
["test_directory"])
741 for dir_name
in test_directory_content
:
742 if dir_name
== 'simple_linux':
743 self
.__class
__.scenario_test_path
= test_config
["test_directory"] + '/'+ dir_name
744 vnfd_files
= glob
.glob(self
.__class
__.scenario_test_path
+'/vnfd_*.yaml')
747 for vnfd
in vnfd_files
:
748 with
open(vnfd
, 'r') as stream
:
749 vnf_descriptor
= yaml
.load(stream
)
751 vnfc_list
= vnf_descriptor
['vnf']['VNFC']
752 for item
in vnfc_list
:
753 if 'ram' in item
and 'vcpus' in item
and 'disk' in item
:
755 vcpus
= item
['vcpus']
759 'name' : _get_random_string(20),
765 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
766 self
.__class
__.test_index
,
767 inspect
.currentframe().f_code
.co_name
)
768 self
.__class
__.test_index
+= 1
770 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
772 result
= test_config
["vim_conn"].get_flavor(flavor_id
)
774 if test_config
['vimtype'] != 'azure':
775 self
.assertEqual(ram
, result
['ram'])
776 self
.assertEqual(vcpus
, result
['vcpus'])
777 self
.assertEqual(disk
, result
['disk'])
779 self
.assertTrue(ram
<= result
['ram'])
780 self
.assertTrue(vcpus
<= result
['vcpus'])
781 self
.assertTrue(disk
<= result
['disk'])
784 if test_config
['vimtype'] != 'azure':
785 result
= test_config
["vim_conn"].delete_flavor(flavor_id
)
787 logger
.info("Flavor id {} sucessfully deleted".format(result
))
789 logger
.info("Failed to delete flavor id {}".format(result
))
791 def test_010_get_flavor_negative(self
):
792 Non_exist_flavor_id
= str(uuid
.uuid4())
794 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
795 self
.__class
__.test_index
,
796 inspect
.currentframe().f_code
.co_name
)
797 self
.__class
__.test_index
+= 1
799 with self
.assertRaises(Exception) as context
:
800 test_config
["vim_conn"].get_flavor(Non_exist_flavor_id
)
802 self
.assertEqual((context
.exception
).http_code
, 404)
804 class test_vimconn_new_flavor(test_base
):
807 def test_000_new_flavor(self
):
808 flavor_data
= {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
810 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
811 self
.__class
__.test_index
,
812 inspect
.currentframe().f_code
.co_name
)
813 self
.__class
__.test_index
+= 1
816 self
.__class
__.flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
817 self
.assertIsInstance(self
.__class
__.flavor_id
, (str, unicode))
818 self
.assertIsInstance(uuid
.UUID(self
.__class
__.flavor_id
), uuid
.UUID
)
820 def test_010_delete_flavor(self
):
821 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
822 self
.__class
__.test_index
,
823 inspect
.currentframe().f_code
.co_name
)
824 self
.__class
__.test_index
+= 1
827 if test_config
['vimtype'] == 'azure':
828 with self
.assertRaises(Exception) as context
:
829 test_config
["vim_conn"].delete_flavor(self
.__class
__.flavor_id
)
831 self
.assertEqual((context
.exception
).http_code
, 401)
833 result
= test_config
["vim_conn"].delete_flavor(self
.__class
__.flavor_id
)
835 logger
.info("Flavor id {} sucessfully deleted".format(result
))
837 logger
.error("Failed to delete flavor id {}".format(result
))
838 raise Exception ("Failed to delete created flavor")
840 def test_020_new_flavor_negative(self
):
841 Invalid_flavor_data
= {'ram': '1024', 'vcpus': 2.0, 'disk': 2.0}
843 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
844 self
.__class
__.test_index
,
845 inspect
.currentframe().f_code
.co_name
)
846 self
.__class
__.test_index
+= 1
848 with self
.assertRaises(Exception) as context
:
849 test_config
["vim_conn"].new_flavor(Invalid_flavor_data
)
851 if test_config
['vimtype'] == 'azure':
852 self
.assertEqual((context
.exception
).http_code
, 404)
854 self
.assertEqual((context
.exception
).http_code
, 400)
856 def test_030_delete_flavor_negative(self
):
857 Non_exist_flavor_id
= str(uuid
.uuid4())
859 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
860 self
.__class
__.test_index
,
861 inspect
.currentframe().f_code
.co_name
)
862 self
.__class
__.test_index
+= 1
864 with self
.assertRaises(Exception) as context
:
865 test_config
["vim_conn"].delete_flavor(Non_exist_flavor_id
)
867 if test_config
['vimtype'] == 'azure':
868 self
.assertEqual((context
.exception
).http_code
, 401)
870 self
.assertEqual((context
.exception
).http_code
, 404)
872 class test_vimconn_new_image(test_base
):
874 def test_000_new_image(self
):
875 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
876 self
.__class
__.test_index
,
877 inspect
.currentframe().f_code
.co_name
)
878 self
.__class
__.test_index
+= 1
880 image_path
= test_config
['image_path']
882 self
.__class
__.image_id
= test_config
["vim_conn"].new_image({ 'name': 'TestImage', 'location' : image_path
,
883 'metadata': {'upload_location':None} })
886 self
.assertIsInstance(self
.__class
__.image_id
, (str, unicode))
887 self
.assertIsInstance(uuid
.UUID(self
.__class
__.image_id
), uuid
.UUID
)
889 self
.skipTest("Skipping test as image file not present at RO container")
891 def test_010_new_image_negative(self
):
892 Non_exist_image_path
= '/temp1/cirros.ovf'
894 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
895 self
.__class
__.test_index
,
896 inspect
.currentframe().f_code
.co_name
)
897 self
.__class
__.test_index
+= 1
899 with self
.assertRaises(Exception) as context
:
900 test_config
["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path
})
902 self
.assertEqual((context
.exception
).http_code
, 400)
904 def test_020_delete_image(self
):
905 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
906 self
.__class
__.test_index
,
907 inspect
.currentframe().f_code
.co_name
)
908 self
.__class
__.test_index
+= 1
910 image_id
= test_config
["vim_conn"].delete_image(self
.__class
__.image_id
)
912 self
.assertIsInstance(image_id
, (str, unicode))
914 def test_030_delete_image_negative(self
):
915 Non_exist_image_id
= str(uuid
.uuid4())
917 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
918 self
.__class
__.test_index
,
919 inspect
.currentframe().f_code
.co_name
)
920 self
.__class
__.test_index
+= 1
922 with self
.assertRaises(Exception) as context
:
923 test_config
["vim_conn"].delete_image(Non_exist_image_id
)
925 self
.assertEqual((context
.exception
).http_code
, 404)
927 class test_vimconn_get_image_id_from_path(test_base
):
929 def test_000_get_image_id_from_path(self
):
930 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
931 self
.__class
__.test_index
,
932 inspect
.currentframe().f_code
.co_name
)
933 self
.__class
__.test_index
+= 1
935 image_path
= test_config
['image_path']
937 image_id
= test_config
["vim_conn"].get_image_id_from_path( image_path
)
938 self
.assertEqual(type(image_id
),str)
940 self
.skipTest("Skipping test as image file not present at RO container")
942 def test_010_get_image_id_from_path_negative(self
):
943 Non_exist_image_path
= '/temp1/cirros.ovf'
945 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
946 self
.__class
__.test_index
,
947 inspect
.currentframe().f_code
.co_name
)
948 self
.__class
__.test_index
+= 1
950 with self
.assertRaises(Exception) as context
:
951 test_config
["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path
})
953 self
.assertEqual((context
.exception
).http_code
, 400)
955 class test_vimconn_get_image_list(test_base
):
959 def test_000_get_image_list(self
):
960 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
961 self
.__class
__.test_index
,
962 inspect
.currentframe().f_code
.co_name
)
963 self
.__class
__.test_index
+= 1
965 if test_config
['image_name']:
966 image_list
= test_config
['vim_conn'].get_image_list({'name': test_config
['image_name']})
968 image_list
= test_config
["vim_conn"].get_image_list()
970 for item
in image_list
:
972 self
.__class
__.image_name
= item
['name']
973 self
.__class
__.image_id
= item
['id']
974 self
.assertIsInstance(self
.__class
__.image_name
, (str, unicode))
975 self
.assertIsInstance(self
.__class
__.image_id
, (str, unicode))
977 def test_010_get_image_list_by_name(self
):
978 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
979 self
.__class
__.test_index
,
980 inspect
.currentframe().f_code
.co_name
)
981 self
.__class
__.test_index
+= 1
983 image_list
= test_config
["vim_conn"].get_image_list({'name': self
.__class
__.image_name
})
985 for item
in image_list
:
986 self
.assertIsInstance(item
['id'], (str, unicode))
987 self
.assertIsInstance(item
['name'], (str, unicode))
988 self
.assertEqual(item
['id'], self
.__class
__.image_id
)
989 self
.assertEqual(item
['name'], self
.__class
__.image_name
)
991 def test_020_get_image_list_by_id(self
):
992 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
993 self
.__class
__.test_index
,
994 inspect
.currentframe().f_code
.co_name
)
995 self
.__class
__.test_index
+= 1
997 filter_image_list
= test_config
["vim_conn"].get_image_list({'id': self
.__class
__.image_id
})
999 for item1
in filter_image_list
:
1000 self
.assertIsInstance(item1
['id'], (str, unicode))
1001 self
.assertIsInstance(item1
['name'], (str, unicode))
1002 self
.assertEqual(item1
['id'], self
.__class
__.image_id
)
1003 self
.assertEqual(item1
['name'], self
.__class
__.image_name
)
1005 def test_030_get_image_list_negative(self
):
1006 Non_exist_image_id
= uuid
.uuid4()
1007 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1008 self
.__class
__.test_index
,
1009 inspect
.currentframe().f_code
.co_name
)
1010 self
.__class
__.test_index
+= 1
1011 image_list
= test_config
["vim_conn"].get_image_list({'name': 'Unknown_name', 'id': Non_exist_image_id
})
1013 self
.assertIsNotNone(image_list
, None)
1014 self
.assertEqual(image_list
, [])
1016 class test_vimconn_new_vminstance(test_base
):
1025 self
.__class
__.network_name
= _get_random_string(20)
1026 self
.__class
__.net_type
= 'bridge'
1028 self
.__class
__.network_id
, _
= test_config
["vim_conn"].new_network(net_name
=self
.__class
__.network_name
,
1029 net_type
=self
.__class
__.net_type
)
1030 # find image name and image id
1031 if test_config
['image_name']:
1032 image_list
= test_config
['vim_conn'].get_image_list({'name': test_config
['image_name']})
1033 if len(image_list
) == 0:
1034 raise Exception("Image {} is not found at VIM".format(test_config
['image_name']))
1036 self
.__class
__.image_id
= image_list
[0]['id']
1038 image_list
= test_config
['vim_conn'].get_image_list()
1039 if len(image_list
) == 0:
1040 raise Exception("Not found any image at VIM")
1042 self
.__class
__.image_id
= image_list
[0]['id']
1045 test_base
.tearDown(self
)
1046 # Deleting created network
1047 result
= test_config
["vim_conn"].delete_network(self
.__class
__.network_id
)
1049 logger
.info("Network id {} sucessfully deleted".format(self
.__class
__.network_id
))
1051 logger
.info("Failed to delete network id {}".format(self
.__class
__.network_id
))
1053 def test_000_new_vminstance(self
):
1054 vpci
= "0000:00:11.0"
1057 flavor_data
= {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
1060 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1063 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1064 self
.__class
__.test_index
,
1065 inspect
.currentframe().f_code
.co_name
)
1066 self
.__class
__.test_index
+= 1
1068 net_list
= [{'use': self
.__class
__.net_type
, 'name': name
, 'floating_ip': False, 'vpci': vpci
,
1069 'port_security': True, 'type': 'virtual', 'net_id': self
.__class
__.network_id
}]
1071 self
.__class
__.instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='',
1073 image_id
=self
.__class
__.image_id
,
1074 flavor_id
=flavor_id
, net_list
=net_list
)
1076 self
.assertIsInstance(self
.__class
__.instance_id
, (str, unicode))
1078 def test_010_new_vminstance_by_model(self
):
1079 flavor_data
= {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
1080 model_name
= 'e1000'
1084 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1086 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1087 self
.__class
__.test_index
,
1088 inspect
.currentframe().f_code
.co_name
)
1089 self
.__class
__.test_index
+= 1
1091 net_list
= [{'use': self
.__class
__.net_type
, 'name': name
, 'floating_ip': False, 'port_security': True,
1092 'model': model_name
, 'type': 'virtual', 'net_id': self
.__class
__.network_id
}]
1094 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1095 image_id
=self
.__class
__.image_id
,
1096 flavor_id
=flavor_id
,net_list
=net_list
)
1098 self
.assertIsInstance(instance_id
, (str, unicode))
1100 # Deleting created vm instance
1101 logger
.info("Deleting created vm intance")
1102 test_config
["vim_conn"].delete_vminstance(instance_id
)
1105 def test_020_new_vminstance_by_net_use(self
):
1106 flavor_data
= {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
1111 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1113 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1114 self
.__class
__.test_index
,
1115 inspect
.currentframe().f_code
.co_name
)
1116 self
.__class
__.test_index
+= 1
1118 net_list
= [{'use': net_use
, 'name': name
, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
1119 'net_id': self
.__class
__.network_id
}]
1121 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1122 image_id
=self
.__class
__.image_id
,disk_list
=None,
1123 flavor_id
=flavor_id
, net_list
=net_list
)
1124 self
.assertIsInstance(instance_id
, (str, unicode))
1126 # Deleting created vm instance
1127 logger
.info("Deleting created vm intance")
1128 test_config
["vim_conn"].delete_vminstance(instance_id
)
1131 def test_030_new_vminstance_by_net_type(self
):
1132 flavor_data
= {'name':_get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
1137 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1139 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1140 self
.__class
__.test_index
,
1141 inspect
.currentframe().f_code
.co_name
)
1142 self
.__class
__.test_index
+= 1
1144 if test_config
['vimtype'] == 'vmware':
1145 net_list
= [{'use': self
.__class
__.net_type
, 'name': name
, 'floating_ip': False, 'port_security': True,
1146 'type': _type
, 'net_id': self
.__class
__.network_id
}]
1148 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', image_id
=self
.__class
__.image_id
,
1149 flavor_id
=flavor_id
,
1151 self
.assertEqual(type(instance_id
),str)
1153 if test_config
['vimtype'] in ('openstack', 'azure'):
1154 # create network of type data
1155 network_name
= _get_random_string(20)
1158 network_id
, _
= test_config
["vim_conn"].new_network(net_name
=network_name
,
1160 net_list
= [{'use': net_type
, 'name': name
, 'floating_ip': False, 'port_security': True,
1161 'type': _type
, 'net_id': network_id
}]
1163 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1164 image_id
=self
.__class
__.image_id
, disk_list
=None,
1165 flavor_id
=flavor_id
,
1168 self
.assertEqual(type(instance_id
), unicode)
1170 # delete created network
1171 result
= test_config
["vim_conn"].delete_network(network_id
)
1173 logger
.info("Network id {} sucessfully deleted".format(network_id
))
1175 logger
.info("Failed to delete network id {}".format(network_id
))
1177 # Deleting created vm instance
1178 logger
.info("Deleting created vm intance")
1179 test_config
["vim_conn"].delete_vminstance(instance_id
)
1182 def test_040_new_vminstance_by_cloud_config(self
):
1183 flavor_data
= {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
1185 user_name
= 'test_user'
1187 key_pairs
= ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtAjl5R+GSKP3gFrdFxgizKEUzhXKQbyjaxJH9thsK 0/fDiYlaNEjvijgPgiVZkfwvqgWeLprPcpzL2j4jvmmSJ3+7C8ihCwObWP0VUiuewmbIINBPAR0RqusjMRyPsa+q0asFBPOoZLx3Cv3vzmC1AA3mKuCNeT EuA0rlWhDIOVwMcU5sP1grnmuexQB8HcR7BdKcA9y08pTwnCQR8vmtW77SRkaxEGXm4Gnw5qw8Z27mHdk2wWS2SnbVH7aFwWvDXc6jjf5TpEWypdr/EAPC +eJipeS2Oa4FsntEqAu3Fz6gp/9ub8uNqgCgHfMzs6FhYpZpipwS0hXYyF6eVsSx osm@osm']
1189 users_data
= [{'key-pairs': ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtAjl5R+GSKP3gFrdFxgizKEUzhXKQbyjaxJH9thsK0/fDiYlaNEjvijgPgiVZkfwvqgWeLprPcpzL2j4jvmmSJ3+7C8ihCwObWP0VUiuewmbIINBPAR0RqusjMRyPsa+q0asFBPOoZLx3Cv3vzmC1AA3mKuCNeTEuA0rlWhDIOVwMcU5sP1grnmuexQB8HcR7BdKcA9y08pTwnCQR8vmtW77SRkaxEGXm4Gnw5qw8Z27mHdk2wWS2SnbVH7aFwWvDXc6jjf5TpEWypdr/EAPC+eJipeS2Oa4FsntEqAu3Fz6gp/9ub8uNqgCgHfMzs6FhYpZpipwS0hXYyF6eVsSx osm@osm'], 'name': 'cloudinit'}]
1191 cloud_data
= {'config-files': [{'content': 'auto enp0s3\niface enp0s3 inet dhcp\n', 'dest': '/etc/network/interfaces.d/enp0s3.cfg', 'owner': 'root:root', 'permissions': '0644'}, {'content': '#! /bin/bash\nls -al >> /var/log/osm.log\n', 'dest': '/etc/rc.local', 'permissions': '0755'}, {'content': 'file content', 'dest': '/etc/test_delete'}], 'boot-data-drive': True, 'key-pairs': key_pairs
, 'users': users_data
}
1192 #cloud_data = {'users': users_data }
1195 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1197 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1198 self
.__class
__.test_index
,
1199 inspect
.currentframe().f_code
.co_name
)
1200 self
.__class
__.test_index
+= 1
1202 net_list
= [{'use': self
.__class
__.net_type
, 'name': name
, 'floating_ip': False, 'port_security': True,
1203 'type': 'virtual', 'net_id': self
.__class
__.network_id
}]
1205 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Cloud_vm', description
='', start
=False,
1206 image_id
=self
.__class
__.image_id
,
1207 flavor_id
=flavor_id
,net_list
=net_list
,
1208 cloud_config
=cloud_data
)
1210 self
.assertIsInstance(instance_id
, (str, unicode))
1212 # Deleting created vm instance
1213 logger
.info("Deleting created vm intance")
1214 test_config
["vim_conn"].delete_vminstance(instance_id
)
1217 def test_050_new_vminstance_by_disk_list(self
):
1218 flavor_data
= {'name':_get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
1221 device_data
= [{'image_id': self
.__class
__.image_id
, 'size': '10'}]
1224 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1226 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1227 self
.__class
__.test_index
,
1228 inspect
.currentframe().f_code
.co_name
)
1229 self
.__class
__.test_index
+= 1
1231 net_list
= [{'use': self
.__class
__.net_type
, 'name': name
, 'floating_ip': False, 'port_security': True,
1232 'type': 'virtual', 'net_id': self
.__class
__.network_id
}]
1234 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='VM_test1', description
='', start
=False,
1235 image_id
=self
.__class
__.image_id
,
1236 flavor_id
=flavor_id
, net_list
=net_list
,
1237 disk_list
=device_data
)
1239 self
.assertIsInstance(instance_id
, (str, unicode))
1240 # Deleting created vm instance
1241 logger
.info("Deleting created vm intance")
1242 test_config
["vim_conn"].delete_vminstance(instance_id
)
1245 def test_060_new_vminstance_negative(self
):
1246 unknown_flavor_id
= str(uuid
.uuid4())
1247 unknown_image_id
= str(uuid
.uuid4())
1250 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1251 self
.__class
__.test_index
,
1252 inspect
.currentframe().f_code
.co_name
)
1253 self
.__class
__.test_index
+= 1
1255 net_list
= [{'use': self
.__class
__.net_type
, 'name': name
, 'floating_ip': False, 'port_security': True,
1256 'type': 'virtual', 'net_id': self
.__class
__.network_id
}]
1258 with self
.assertRaises(Exception) as context
:
1259 test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1260 image_id
=unknown_image_id
,
1261 flavor_id
=unknown_flavor_id
,
1264 self
.assertIn((context
.exception
).http_code
, (400, 404))
1267 def test_070_get_vminstance(self
):
1268 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1269 self
.__class
__.test_index
,
1270 inspect
.currentframe().f_code
.co_name
)
1271 self
.__class
__.test_index
+= 1
1273 # Get instance by its id
1274 vm_info
= test_config
["vim_conn"].get_vminstance(self
.__class
__.instance_id
)
1276 if test_config
['vimtype'] == 'vmware':
1277 for attr
in vm_info
:
1278 if attr
== 'status':
1279 self
.assertEqual(vm_info
[attr
], 'ACTIVE')
1280 if attr
== 'hostId':
1281 self
.assertEqual(type(vm_info
[attr
]), str)
1282 if attr
== 'interfaces':
1283 self
.assertEqual(type(vm_info
[attr
]), list)
1284 self
.assertEqual(vm_info
[attr
][0]['IsConnected'], 'true')
1285 if attr
== 'IsEnabled':
1286 self
.assertEqual(vm_info
[attr
], 'true')
1288 def test_080_get_vminstance_negative(self
):
1289 unknown_instance_id
= str(uuid
.uuid4())
1291 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1292 self
.__class
__.test_index
,
1293 inspect
.currentframe().f_code
.co_name
)
1294 self
.__class
__.test_index
+= 1
1296 with self
.assertRaises(Exception) as context
:
1297 test_config
["vim_conn"].get_vminstance(unknown_instance_id
)
1299 self
.assertEqual((context
.exception
).http_code
, 404)
1301 def test_090_refresh_vms_status(self
):
1302 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1303 self
.__class
__.test_index
,
1304 inspect
.currentframe().f_code
.co_name
)
1305 self
.__class
__.test_index
+= 1
1307 if test_config
['vimtype'] == 'vmware':
1309 vm_list
.append(self
.__class
__.instance_id
)
1312 vm_info
= test_config
["vim_conn"].refresh_vms_status(vm_list
)
1313 for attr
in vm_info
[self
.__class
__.instance_id
]:
1314 if attr
== 'status':
1315 self
.assertEqual(vm_info
[self
.__class
__.instance_id
][attr
], 'ACTIVE')
1316 if attr
== 'interfaces':
1317 self
.assertEqual(type(vm_info
[self
.__class
__.instance_id
][attr
]), list)
1319 if test_config
['vimtype'] in ('openstack', 'azure'):
1320 vpci
= "0000:00:11.0"
1323 flavor_data
= {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
1326 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1327 # create new vm instance
1328 net_list
= [{'use': self
.__class
__.net_type
, 'name': name
, 'floating_ip': False, 'vpci': vpci
,
1329 'port_security': True, 'type': 'virtual', 'net_id': self
.__class
__.network_id
}]
1331 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1332 image_id
=self
.__class
__.image_id
,
1333 flavor_id
=flavor_id
, net_list
=net_list
)
1337 vm_list
.append(instance_id
)
1340 vm_info
= test_config
["vim_conn"].refresh_vms_status(vm_list
)
1341 for attr
in vm_info
[instance_id
]:
1342 if attr
== 'status':
1343 self
.assertEqual(vm_info
[instance_id
][attr
], 'ACTIVE')
1344 if attr
== 'interfaces':
1345 self
.assertEqual(type(vm_info
[instance_id
][attr
]), list)
1347 #Deleting created vm instance
1348 logger
.info("Deleting created vm intance")
1349 test_config
["vim_conn"].delete_vminstance(instance_id
)
1353 def test_100_refresh_vms_status_negative(self
):
1354 unknown_id
= str(uuid
.uuid4())
1356 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1357 self
.__class
__.test_index
,
1358 inspect
.currentframe().f_code
.co_name
)
1359 self
.__class
__.test_index
+= 1
1361 vm_dict
= test_config
["vim_conn"].refresh_vms_status([unknown_id
])
1363 if test_config
['vimtype'] == 'vmware':
1364 self
.assertEqual(vm_dict
,{})
1366 if test_config
['vimtype'] in ('openstack', 'azure'):
1367 self
.assertEqual(vm_dict
[unknown_id
]['status'], 'DELETED')
1369 def test_110_action_vminstance(self
):
1370 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1371 self
.__class
__.test_index
,
1372 inspect
.currentframe().f_code
.co_name
)
1373 self
.__class
__.test_index
+= 1
1375 if test_config
['vimtype'] == 'vmware':
1376 action_list
= ['shutdown', 'start', 'shutoff', 'rebuild', 'pause', 'resume']
1377 # various action on vminstace
1378 for action
in action_list
:
1379 instance_id
= test_config
["vim_conn"].action_vminstance(self
.__class
__.instance_id
,
1381 self
.assertEqual(instance_id
, self
.__class
__.instance_id
)
1383 if test_config
['vimtype'] in ('openstack', 'azure'):
1384 # create new vm instance
1385 vpci
= "0000:00:11.0"
1388 flavor_data
= {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
1391 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1393 net_list
= [{'use': self
.__class
__.net_type
, 'name': name
, 'floating_ip': False, 'vpci': vpci
,
1394 'port_security': True, 'type': 'virtual', 'net_id': self
.__class
__.network_id
}]
1396 new_instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='',
1397 start
=False, image_id
=self
.__class
__.image_id
,
1398 flavor_id
=flavor_id
, net_list
=net_list
)
1400 if test_config
['vimtype'] == 'openstack':
1401 action_list
= ['shutdown','start','shutoff','rebuild','start','pause','start']
1403 action_list
= ['shutdown','start','stop','start','shutoff','start','reboot']
1405 # various action on vminstace
1406 for action
in action_list
:
1407 # sleep for sometime till status is changed
1409 instance_id
= test_config
["vim_conn"].action_vminstance(new_instance_id
, {action
: None})
1411 self
.assertTrue(instance_id
is None)
1413 #Deleting created vm instance
1414 logger
.info("Deleting created vm intance")
1415 test_config
["vim_conn"].delete_vminstance(new_instance_id
)
1418 def test_120_action_vminstance_negative(self
):
1419 non_exist_id
= str(uuid
.uuid4())
1420 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1421 self
.__class
__.test_index
,
1422 inspect
.currentframe().f_code
.co_name
)
1423 self
.__class
__.test_index
+= 1
1426 with self
.assertRaises(Exception) as context
:
1427 test_config
["vim_conn"].action_vminstance(non_exist_id
, { action
: None})
1429 self
.assertEqual((context
.exception
).http_code
, 404)
1432 def test_130_delete_vminstance(self
):
1433 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1434 self
.__class
__.test_index
,
1435 inspect
.currentframe().f_code
.co_name
)
1436 self
.__class
__.test_index
+= 1
1438 # Deleting created vm instance
1439 logger
.info("Deleting created vm instance")
1440 test_config
["vim_conn"].delete_vminstance(self
.__class
__.instance_id
)
1443 def test_140_new_vminstance_sriov(self
):
1444 logger
.info("Testing creation of sriov vm instance using {}".format(test_config
['sriov_net_name']))
1445 flavor_data
= {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
1449 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1451 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1452 self
.__class
__.test_index
,
1453 inspect
.currentframe().f_code
.co_name
)
1454 self
.__class
__.test_index
+= 1
1456 sriov_net_name
= test_config
['sriov_net_name']
1457 new_network_list
= test_config
["vim_conn"].get_network_list({'name': sriov_net_name
})
1458 for list_item
in new_network_list
:
1459 self
.assertEqual(sriov_net_name
, list_item
.get('name'))
1460 self
.__class
__.sriov_network_id
= list_item
.get('id')
1462 net_list
= [{'use': 'data', 'name': name
, 'floating_ip': False, 'port_security': True, 'type': 'VF',
1463 'net_id': self
.__class
__.sriov_network_id
}]
1465 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_sriov_vm', description
='', start
=False,
1466 image_id
=self
.__class
__.image_id
, flavor_id
=flavor_id
,
1469 self
.assertIsInstance(instance_id
, (str, unicode))
1471 logger
.info("Waiting for created sriov-vm intance")
1473 # Deleting created vm instance
1474 logger
.info("Deleting created sriov-vm intance")
1475 test_config
["vim_conn"].delete_vminstance(instance_id
)
1478 class test_vimconn_get_tenant_list(test_base
):
1481 def test_000_get_tenant_list(self
):
1482 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1483 self
.__class
__.test_index
,
1484 inspect
.currentframe().f_code
.co_name
)
1485 self
.__class
__.test_index
+= 1
1487 # Getting tenant list
1488 tenant_list
= test_config
["vim_conn"].get_tenant_list()
1490 for item
in tenant_list
:
1491 if test_config
['tenant'] == item
['name']:
1492 self
.__class
__.tenant_id
= item
['id']
1493 self
.assertIsInstance(item
['name'], (str, unicode))
1494 self
.assertIsInstance(item
['id'], (str, unicode))
1496 def test_010_get_tenant_list_by_id(self
):
1497 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1498 self
.__class
__.test_index
,
1499 inspect
.currentframe().f_code
.co_name
)
1500 self
.__class
__.test_index
+= 1
1502 # Getting filter tenant list by its id
1503 filter_tenant_list
= test_config
["vim_conn"].get_tenant_list({'id': self
.__class
__.tenant_id
})
1505 for item
in filter_tenant_list
:
1506 self
.assertIsInstance(item
['id'], (str, unicode))
1507 self
.assertEqual(item
['id'], self
.__class
__.tenant_id
)
1509 def test_020_get_tenant_list_by_name(self
):
1510 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1511 self
.__class
__.test_index
,
1512 inspect
.currentframe().f_code
.co_name
)
1513 self
.__class
__.test_index
+= 1
1515 # Getting filter tenant list by its name
1516 filter_tenant_list
= test_config
["vim_conn"].get_tenant_list({'name': test_config
['tenant']})
1518 for item
in filter_tenant_list
:
1519 self
.assertIsInstance(item
['name'], (str, unicode))
1520 self
.assertEqual(item
['name'], test_config
['tenant'])
1522 def test_030_get_tenant_list_by_name_and_id(self
):
1523 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1524 self
.__class
__.test_index
,
1525 inspect
.currentframe().f_code
.co_name
)
1526 self
.__class
__.test_index
+= 1
1528 # Getting filter tenant list by its name and id
1529 filter_tenant_list
= test_config
["vim_conn"].get_tenant_list({'name': test_config
['tenant'],
1530 'id': self
.__class
__.tenant_id
})
1532 for item
in filter_tenant_list
:
1533 self
.assertIsInstance(item
['name'], (str, unicode))
1534 self
.assertIsInstance(item
['id'], (str, unicode))
1535 self
.assertEqual(item
['name'], test_config
['tenant'])
1536 self
.assertEqual(item
['id'], self
.__class
__.tenant_id
)
1538 def test_040_get_tenant_list_negative(self
):
1539 non_exist_tenant_name
= "Tenant_123"
1540 non_exist_tenant_id
= "kjhgrt456-45345kjhdfgnbdk-34dsfjdfg"
1541 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1542 self
.__class
__.test_index
,
1543 inspect
.currentframe().f_code
.co_name
)
1544 self
.__class
__.test_index
+= 1
1546 filter_tenant_list
= test_config
["vim_conn"].get_tenant_list({'name': non_exist_tenant_name
,
1547 'id': non_exist_tenant_id
})
1549 self
.assertEqual(filter_tenant_list
, [])
1552 class test_vimconn_new_tenant(test_base
):
1555 def test_000_new_tenant(self
):
1556 tenant_name
= _get_random_string(20)
1557 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1558 self
.__class
__.test_index
,
1559 inspect
.currentframe().f_code
.co_name
)
1560 self
.__class
__.test_index
+= 1
1562 if test_config
['vimtype'] != 'azure':
1563 self
.__class
__.tenant_id
= test_config
["vim_conn"].new_tenant(tenant_name
, "")
1566 self
.assertIsInstance(self
.__class
__.tenant_id
, (str, unicode))
1568 with self
.assertRaises(Exception) as context
:
1569 test_config
["vim_conn"].new_tenant(self
.__class
__.tenant_id
)
1570 self
.assertEqual((context
.exception
).http_code
, 401)
1573 def test_010_new_tenant_negative(self
):
1574 Invalid_tenant_name
= 10121
1575 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1576 self
.__class
__.test_index
,
1577 inspect
.currentframe().f_code
.co_name
)
1578 self
.__class
__.test_index
+= 1
1580 with self
.assertRaises(Exception) as context
:
1581 test_config
["vim_conn"].new_tenant(Invalid_tenant_name
, "")
1583 if test_config
['vimtype'] != 'azure':
1584 self
.assertEqual((context
.exception
).http_code
, 400)
1586 self
.assertEqual((context
.exception
).http_code
, 401)
1589 def test_020_delete_tenant(self
):
1590 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1591 self
.__class
__.test_index
,
1592 inspect
.currentframe().f_code
.co_name
)
1593 self
.__class
__.test_index
+= 1
1595 if test_config
['vimtype'] != 'azure':
1596 tenant_id
= test_config
["vim_conn"].delete_tenant(self
.__class
__.tenant_id
)
1597 self
.assertIsInstance(tenant_id
, (str, unicode))
1599 with self
.assertRaises(Exception) as context
:
1600 test_config
["vim_conn"].delete_tenant(self
.__class
__.tenant_id
)
1601 self
.assertEqual((context
.exception
).http_code
, 401)
1603 def test_030_delete_tenant_negative(self
):
1604 Non_exist_tenant_name
= 'Test_30_tenant'
1605 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1606 self
.__class
__.test_index
,
1607 inspect
.currentframe().f_code
.co_name
)
1608 self
.__class
__.test_index
+= 1
1610 with self
.assertRaises(Exception) as context
:
1611 test_config
["vim_conn"].delete_tenant(Non_exist_tenant_name
)
1613 if test_config
['vimtype'] != 'azure':
1614 self
.assertEqual((context
.exception
).http_code
, 404)
1616 self
.assertEqual((context
.exception
).http_code
, 401)
1620 if test_config
['image_name']:
1621 image_list
= test_config
['vim_conn'].get_image_list({'name': test_config
['image_name']})
1622 if len(image_list
) == 0:
1623 raise Exception("Image {} is not found at VIM".format(test_config
['image_name']))
1625 image_id
= image_list
[0]['id']
1627 image_list
= test_config
['vim_conn'].get_image_list()
1628 if len(image_list
) == 0:
1629 raise Exception("Not found any image at VIM")
1631 image_id
= image_list
[0]['id']
1635 class test_vimconn_vminstance_by_ip_address(test_base
):
1641 self
.network_name
= _get_random_string(20)
1643 self
.network_id
, _
= test_config
["vim_conn"].new_network(net_name
=self
.network_name
,
1647 test_base
.tearDown(self
)
1648 # Deleting created network
1649 result
= test_config
["vim_conn"].delete_network(self
.network_id
)
1651 logger
.info("Network id {} sucessfully deleted".format(self
.network_id
))
1653 logger
.info("Failed to delete network id {}".format(self
.network_id
))
1656 def test_000_vminstance_by_ip_address(self
):
1658 This test case will deploy VM with provided IP address
1659 Pre-requesite: provided IP address should be from IP pool range which has used for network creation
1662 # provide ip address
1665 flavor_data
= {'ram': 1024, 'vcpus': 1, 'disk': 10}
1668 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1671 image_id
= get_image_id()
1673 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1674 self
.__class
__.test_index
,
1675 inspect
.currentframe().f_code
.co_name
)
1676 self
.__class
__.test_index
+= 1
1678 net_list
= [{'use': 'bridge', 'name': name
, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
1679 'net_id': self
.network_id
, 'ip_address': ip_address
}]
1681 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', image_id
=image_id
,
1682 flavor_id
=flavor_id
, net_list
=net_list
)
1684 self
.assertEqual(type(instance_id
),str)
1685 logger
.info("Deleting created vm instance")
1686 test_config
["vim_conn"].delete_vminstance(instance_id
)
1689 def test_010_vminstance_by_ip_address_negative(self
):
1691 # IP address not from subnet range
1692 invalid_ip_address
= '10.10.12.1'
1694 flavor_data
= {'ram': 1024, 'vcpus': 1, 'disk': 10}
1697 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1699 # find image name and image id
1700 image_id
= get_image_id()
1702 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1703 self
.__class
__.test_index
,
1704 inspect
.currentframe().f_code
.co_name
)
1705 self
.__class
__.test_index
+= 1
1707 net_list
= [{'use': 'bridge', 'name': name
, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
1708 'net_id': self
.network_id
, 'ip_address': invalid_ip_address
}]
1710 with self
.assertRaises(Exception) as context
:
1711 test_config
["vim_conn"].new_vminstance(name
='Test1_vm', image_id
=image_id
,
1712 flavor_id
=flavor_id
,
1714 self
.assertEqual((context
.exception
).http_code
, 400)
1716 def test_020_vminstance_by_floating_ip(self
):
1718 flavor_data
= {'ram': 1024, 'vcpus': 1, 'disk': 10}
1721 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1723 # find image name and image id
1724 image_id
= get_image_id()
1726 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1727 self
.__class
__.test_index
,
1728 inspect
.currentframe().f_code
.co_name
)
1729 self
.__class
__.test_index
+= 1
1731 net_list
= [{'use': 'bridge', 'name': name
, 'floating_ip': True, 'port_security': True, 'type': 'virtual',
1732 'net_id': self
.network_id
}]
1734 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', image_id
=image_id
,
1735 flavor_id
=flavor_id
, net_list
=net_list
)
1737 self
.assertEqual(type(instance_id
),str)
1738 logger
.info("Deleting created vm instance")
1739 test_config
["vim_conn"].delete_vminstance(instance_id
)
1742 def test_030_vminstance_by_mac_address(self
):
1744 mac_address
= "74:54:2f:21:da:8c"
1745 flavor_data
= {'ram': 1024, 'vcpus': 1, 'disk': 10}
1748 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1750 # find image name and image id
1751 image_id
= get_image_id()
1753 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1754 self
.__class
__.test_index
,
1755 inspect
.currentframe().f_code
.co_name
)
1756 self
.__class
__.test_index
+= 1
1758 net_list
= [{'use': 'bridge', 'name': name
, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
1759 'net_id': self
.network_id
,'mac_address': mac_address
}]
1761 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', image_id
=image_id
,
1762 flavor_id
=flavor_id
, net_list
=net_list
)
1764 self
.assertEqual(type(instance_id
),str)
1765 logger
.info("Deleting created vm instance")
1766 test_config
["vim_conn"].delete_vminstance(instance_id
)
1769 class test_vimconn_vminstance_by_adding_10_nics(test_base
):
1777 self
.network_name
= _get_random_string(20)
1778 network_id
, _
= test_config
["vim_conn"].new_network(net_name
=self
.network_name
,
1780 self
.net_ids
.append(network_id
)
1783 test_base
.tearDown(self
)
1784 # Deleting created network
1785 for net_id
in self
.net_ids
:
1786 result
= test_config
["vim_conn"].delete_network(net_id
)
1788 logger
.info("Network id {} sucessfully deleted".format(net_id
))
1790 logger
.info("Failed to delete network id {}".format(net_id
))
1792 def test_000_vminstance_by_adding_10_nics(self
):
1793 flavor_data
= {'ram': 1024, 'vcpus': 1, 'disk': 10}
1796 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1798 # find image name and image id
1799 image_id
= get_image_id()
1801 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1802 self
.__class
__.test_index
,
1803 inspect
.currentframe().f_code
.co_name
)
1804 self
.__class
__.test_index
+= 1
1808 for net_id
in self
.net_ids
:
1809 name
= "eth{}".format(c
)
1810 net_list
.append({'use': 'bridge', 'name': name
, 'floating_ip': False,
1811 'port_security': True, 'type': 'virtual', 'net_id': net_id
})
1814 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1815 image_id
=image_id
, flavor_id
=flavor_id
, net_list
=net_list
)
1817 self
.assertEqual(type(instance_id
),str)
1818 logger
.info("Deleting created vm instance")
1819 test_config
["vim_conn"].delete_vminstance(instance_id
)
1823 class test_vimconn_vminstance_by_existing_disk(test_base
):
1829 self
.network_name
= _get_random_string(20)
1830 self
.network_id
, _
= test_config
["vim_conn"].new_network(net_name
=self
.network_name
,
1834 test_base
.tearDown(self
)
1835 # Deleting created network
1836 result
= test_config
["vim_conn"].delete_network(self
.network_id
)
1838 logger
.info("Network id {} sucessfully deleted".format(self
.network_id
))
1840 logger
.info("Failed to delete network id {}".format(self
.network_id
))
1843 def test_000_vminstance_by_existing_disk(self
):
1844 """ This testcase will add existing disk only if given catalog/image is free
1845 means not used by any other VM
1848 flavor_data
= {'ram': 1024, 'vcpus': 1, 'disk': 10}
1852 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1854 # find image name and image id
1855 image_id
= get_image_id()
1856 cirros_image
= test_config
["vim_conn"].get_image_list({'name': 'cirros'})
1857 disk_list
= [{'image_id': cirros_image
[0]['id'],'size': 5}]
1859 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1860 self
.__class
__.test_index
,
1861 inspect
.currentframe().f_code
.co_name
)
1862 self
.__class
__.test_index
+= 1
1864 net_list
= [{'use': 'bridge', 'name': name
, 'floating_ip': False, 'port_security': True,
1865 'type': 'virtual', 'net_id': self
.network_id
}]
1867 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1869 flavor_id
=flavor_id
, net_list
=net_list
,disk_list
=disk_list
)
1871 self
.assertEqual(type(instance_id
),str)
1872 logger
.info("Deleting created vm instance")
1873 test_config
["vim_conn"].delete_vminstance(instance_id
)
1876 def test_010_vminstance_by_new_disk(self
):
1877 flavor_data
= {'ram': 1024, 'vcpus': 1, 'disk': 10}
1881 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1883 # find image name and image id
1884 image_id
= get_image_id()
1885 disk_list
= [{'size': '5'}]
1887 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1888 self
.__class
__.test_index
,
1889 inspect
.currentframe().f_code
.co_name
)
1890 self
.__class
__.test_index
+= 1
1892 net_list
= [{'use': 'bridge', 'name': name
, 'floating_ip': False, 'port_security': True,
1893 'type': 'virtual', 'net_id': self
.network_id
}]
1895 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1897 flavor_id
=flavor_id
, net_list
=net_list
,disk_list
=disk_list
)
1899 self
.assertEqual(type(instance_id
),str)
1900 logger
.info("Deleting created vm instance")
1901 test_config
["vim_conn"].delete_vminstance(instance_id
)
1904 def test_020_vminstance_by_CDROM(self
):
1905 """ This testcase will insert media file only if provided catalog
1906 has pre-created ISO media file into vCD
1908 flavor_data
={'ram': 1024, 'vcpus': 1, 'disk': 10}
1910 image_list
= test_config
["vim_conn"].get_image_list({'name':'Ubuntu'})
1911 disk_list
= [{'image_id':image_list
[0]['id'],'device_type':'cdrom'}]
1914 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1916 # find image name and image id
1917 image_id
= get_image_id()
1919 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1920 self
.__class
__.test_index
,
1921 inspect
.currentframe().f_code
.co_name
)
1922 self
.__class
__.test_index
+= 1
1924 net_list
= [{'use': 'bridge', 'name': name
, 'floating_ip': False, 'port_security': True,
1925 'type': 'virtual', 'net_id': self
.network_id
}]
1927 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1929 flavor_id
=flavor_id
, net_list
=net_list
,disk_list
=disk_list
)
1931 self
.assertEqual(type(instance_id
),str)
1932 logger
.info("Deleting created vm instance")
1933 test_config
["vim_conn"].delete_vminstance(instance_id
)
1937 class test_vimconn_vminstance_by_affinity_anti_affinity(test_base
):
1943 self
.network_name
= _get_random_string(20)
1944 self
.network_id
, _
= test_config
["vim_conn"].new_network(net_name
=self
.network_name
,
1948 test_base
.tearDown(self
)
1949 # Deleting created network
1950 result
= test_config
["vim_conn"].delete_network(self
.network_id
)
1952 logger
.info("Network id {} sucessfully deleted".format(self
.network_id
))
1954 logger
.info("Failed to delete network id {}".format(self
.network_id
))
1956 def test_000_vminstance_by_affinity_anti_affinity(self
):
1957 """ This testcase will deploy VM into provided HOSTGROUP in VIM config
1958 Pre-requisites: User has created Hosh Groups in vCenter with respective Hosts to be used
1959 While creating VIM account user has to pass the Host Group names in availability_zone list
1961 flavor_data
= {'ram': 1024, 'vcpus': 1, 'disk': 10}
1965 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
1967 # find image name and image id
1968 image_id
= get_image_id()
1970 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
1971 self
.__class
__.test_index
,
1972 inspect
.currentframe().f_code
.co_name
)
1973 self
.__class
__.test_index
+= 1
1975 net_list
= [{'use': 'bridge', 'name': name
, 'floating_ip': False, 'port_security': True,
1976 'type': 'virtual', 'net_id': self
.network_id
}]
1978 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
1980 flavor_id
=flavor_id
, net_list
=net_list
,availability_zone_index
=1,
1981 availability_zone_list
=['HG_174','HG_175'])
1983 self
.assertEqual(type(instance_id
),str)
1985 logger
.info("Deleting created vm instance")
1986 test_config
["vim_conn"].delete_vminstance(instance_id
)
1988 class test_vimconn_vminstance_by_numa_affinity(test_base
):
1994 self
.network_name
= _get_random_string(20)
1995 self
.network_id
, _
= test_config
["vim_conn"].new_network(net_name
=self
.network_name
,
1999 test_base
.tearDown(self
)
2000 # Deleting created network
2001 result
= test_config
["vim_conn"].delete_network(self
.network_id
)
2003 logger
.info("Network id {} sucessfully deleted".format(self
.network_id
))
2005 logger
.info("Failed to delete network id {}".format(self
.network_id
))
2007 def test_000_vminstance_by_numa_affinity(self
):
2008 flavor_data
= {'extended': {'numas': [{'paired-threads-id': [['1', '3'], ['2', '4']],
2009 ' paired-threads': 2, 'memory': 1}]},
2010 'ram': 1024, 'vcpus': 1, 'disk': 10}
2014 flavor_id
= test_config
["vim_conn"].new_flavor(flavor_data
)
2016 # find image name and image id
2017 image_id
= get_image_id()
2019 self
.__class
__.test_text
= "{}.{}. TEST {}".format(test_config
["test_number"],
2020 self
.__class
__.test_index
,
2021 inspect
.currentframe().f_code
.co_name
)
2022 self
.__class
__.test_index
+= 1
2024 net_list
= [{'use': 'bridge', 'name': name
, 'floating_ip': False, 'port_security': True,
2025 'type': 'virtual', 'net_id': self
.network_id
}]
2027 instance_id
, _
= test_config
["vim_conn"].new_vminstance(name
='Test1_vm', description
='', start
=False,
2029 flavor_id
=flavor_id
, net_list
=net_list
)
2031 self
.assertEqual(type(instance_id
),str)
2032 logger
.info("Deleting created vm instance")
2033 test_config
["vim_conn"].delete_vminstance(instance_id
)
2039 The following unittest class does not have the 'test_' on purpose. This test is the one used for the
2040 scenario based tests.
2042 class descriptor_based_scenario_test(test_base
):
2044 scenario_test_path
= None
2047 def setUpClass(cls
):
2049 cls
.to_delete_list
= []
2050 cls
.scenario_uuids
= []
2051 cls
.instance_scenario_uuids
= []
2052 cls
.scenario_test_path
= test_config
["test_directory"] + '/' + test_config
["test_folder"]
2053 logger
.info("{}. {} {}".format(test_config
["test_number"], cls
.__name
__, test_config
["test_folder"]))
2056 def tearDownClass(cls
):
2057 test_config
["test_number"] += 1
2059 def test_000_load_scenario(self
):
2060 self
.__class
__.test_text
= "{}.{}. TEST {} {}".format(test_config
["test_number"], self
.__class
__.test_index
,
2061 inspect
.currentframe().f_code
.co_name
,
2062 test_config
["test_folder"])
2063 self
.__class
__.test_index
+= 1
2065 descriptor_files
= glob
.glob(self
.__class
__.scenario_test_path
+'/*.yaml')
2066 vnf_descriptors
= []
2067 scenario_descriptors
= []
2068 for descriptor_file
in descriptor_files
:
2069 with
open(descriptor_file
, 'r') as stream
:
2070 descriptor
= yaml
.load(stream
)
2071 if "vnf" in descriptor
or "vnfd:vnfd-catalog" in descriptor
or "vnfd-catalog" in descriptor
:
2072 vnf_descriptors
.append(descriptor
)
2074 scenario_descriptors
.append(descriptor
)
2076 scenario_file
= glob
.glob(self
.__class
__.scenario_test_path
+ '/scenario_*.yaml')
2077 if not vnf_descriptors
or not scenario_descriptors
or len(scenario_descriptors
) > 1:
2078 raise Exception("Test '{}' not valid. It must contain an scenario file and at least one vnfd file'".format(
2079 test_config
["test_folder"]))
2082 for vnf_descriptor
in vnf_descriptors
:
2083 logger
.debug("VNF descriptor: {}".format(vnf_descriptor
))
2084 vnf
= test_config
["client"].create_vnf(descriptor
=vnf_descriptor
, image_name
=test_config
["image_name"])
2087 vnf_uuid
= vnf
['vnf']['uuid']
2089 vnf_uuid
= vnf
['vnfd'][0]['uuid']
2090 self
.__class
__.to_delete_list
.insert(0, {"item": "vnf", "function": test_config
["client"].delete_vnf
,
2091 "params": {"uuid": vnf_uuid
}})
2093 # load the scenario definition
2094 for scenario_descriptor
in scenario_descriptors
:
2095 # networks = scenario_descriptor['scenario']['networks']
2096 # networks[test_config["mgmt_net"]] = networks.pop('mgmt')
2097 logger
.debug("Scenario descriptor: {}".format(scenario_descriptor
))
2098 scenario
= test_config
["client"].create_scenario(descriptor
=scenario_descriptor
)
2099 logger
.debug(scenario
)
2100 if 'scenario' in scenario
:
2101 scenario_uuid
= scenario
['scenario']['uuid']
2103 scenario_uuid
= scenario
['nsd'][0]['uuid']
2104 self
.__class
__.to_delete_list
.insert(0, {"item": "scenario",
2105 "function": test_config
["client"].delete_scenario
,
2106 "params": {"uuid": scenario_uuid
}})
2107 self
.__class
__.scenario_uuids
.append(scenario_uuid
)
2109 def test_010_instantiate_scenario(self
):
2110 self
.__class
__.test_text
= "{}.{}. TEST {} {}".format(test_config
["test_number"], self
.__class
__.test_index
,
2111 inspect
.currentframe().f_code
.co_name
,
2112 test_config
["test_folder"])
2113 self
.__class
__.test_index
+= 1
2114 for scenario_uuid
in self
.__class
__.scenario_uuids
:
2115 instance_descriptor
= {
2117 "name": self
.__class
__.test_text
,
2118 "scenario": scenario_uuid
,
2120 "mgmt": {"sites": [ { "netmap-use": test_config
["mgmt_net"]} ]}
2124 instance
= test_config
["client"].create_instance(instance_descriptor
)
2125 self
.__class
__.instance_scenario_uuids
.append(instance
['uuid'])
2126 logger
.debug(instance
)
2127 self
.__class
__.to_delete_list
.insert(0, {"item": "instance",
2128 "function": test_config
["client"].delete_instance
,
2129 "params": {"uuid": instance
['uuid']}})
2131 def test_020_check_deployent(self
):
2132 self
.__class
__.test_text
= "{}.{}. TEST {} {}".format(test_config
["test_number"], self
.__class
__.test_index
,
2133 inspect
.currentframe().f_code
.co_name
,
2134 test_config
["test_folder"])
2135 self
.__class
__.test_index
+= 1
2137 if test_config
["manual"]:
2138 raw_input('Scenario has been deployed. Perform manual check and press any key to resume')
2141 keep_waiting
= test_config
["timeout"]
2142 pending_instance_scenario_uuids
= list(self
.__class
__.instance_scenario_uuids
) # make a copy
2143 while pending_instance_scenario_uuids
:
2145 while index
< len(pending_instance_scenario_uuids
):
2146 result
= check_instance_scenario_active(pending_instance_scenario_uuids
[index
])
2148 del pending_instance_scenario_uuids
[index
]
2150 elif 'ERROR' in result
[1]:
2151 msg
= 'Got error while waiting for the instance to get active: '+result
[1]
2153 raise Exception(msg
)
2156 if keep_waiting
>= 5:
2159 elif keep_waiting
> 0:
2160 time
.sleep(keep_waiting
)
2163 msg
= 'Timeout reached while waiting instance scenario to get active'
2165 raise Exception(msg
)
2167 def test_030_clean_deployment(self
):
2168 self
.__class
__.test_text
= "{}.{}. TEST {} {}".format(test_config
["test_number"], self
.__class
__.test_index
,
2169 inspect
.currentframe().f_code
.co_name
,
2170 test_config
["test_folder"])
2171 self
.__class
__.test_index
+= 1
2172 #At the moment if you delete an scenario right after creating it, in openstack datacenters
2173 #sometimes scenario ports get orphaned. This sleep is just a dirty workaround
2175 for item
in self
.__class
__.to_delete_list
:
2176 response
= item
["function"](**item
["params"])
2177 logger
.debug(response
)
2180 def _get_random_string(maxLength
):
2181 '''generates a string with random characters string.letters and string.digits
2182 with a random length up to maxLength characters. If maxLength is <15 it will be changed automatically to 15
2186 minLength
= min_string
- len(prefix
)
2187 if maxLength
< min_string
: maxLength
= min_string
2188 maxLength
-= len(prefix
)
2189 length
= random
.randint(minLength
,maxLength
)
2190 return 'testing_'+"".join([random
.choice(string
.letters
+string
.digits
) for i
in xrange(length
)])
2193 def test_vimconnector(args
):
2195 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))) + "/osm_ro")
2196 test_config
['vimtype'] = args
.vimtype
2197 if args
.vimtype
== "vmware":
2198 import vimconn_vmware
as vim
2200 test_config
["test_directory"] = os
.path
.dirname(__file__
) + "/RO_tests"
2202 tenant_name
= args
.tenant_name
2203 test_config
['tenant'] = tenant_name
2204 config_params
= yaml
.load(args
.config_param
)
2205 org_name
= config_params
.get('orgname')
2206 org_user
= config_params
.get('user')
2207 org_passwd
= config_params
.get('passwd')
2208 vim_url
= args
.endpoint_url
2209 test_config
['image_path'] = args
.image_path
2210 test_config
['image_name'] = args
.image_name
2211 test_config
['sriov_net_name'] = args
.sriov_net_name
2213 # vmware connector obj
2214 test_config
['vim_conn'] = vim
.vimconnector(name
=org_name
, tenant_name
=tenant_name
, user
=org_user
,
2215 passwd
=org_passwd
, url
=vim_url
, config
=config_params
)
2217 elif args
.vimtype
== "aws":
2218 import vimconn_aws
as vim
2219 elif args
.vimtype
== "openstack":
2220 import vimconn_openstack
as vim
2222 test_config
["test_directory"] = os
.path
.dirname(__file__
) + "/RO_tests"
2224 tenant_name
= args
.tenant_name
2225 test_config
['tenant'] = tenant_name
2226 config_params
= yaml
.load(args
.config_param
)
2227 os_user
= config_params
.get('user')
2228 os_passwd
= config_params
.get('passwd')
2229 vim_url
= args
.endpoint_url
2230 test_config
['image_path'] = args
.image_path
2231 test_config
['image_name'] = args
.image_name
2232 test_config
['sriov_net_name'] = args
.sriov_net_name
2234 # openstack connector obj
2235 vim_persistent_info
= {}
2236 test_config
['vim_conn'] = vim
.vimconnector(
2237 uuid
="test-uuid-1", name
="VIO-openstack",
2238 tenant_id
=None, tenant_name
=tenant_name
,
2239 url
=vim_url
, url_admin
=None,
2240 user
=os_user
, passwd
=os_passwd
,
2241 config
=config_params
, persistent_info
=vim_persistent_info
2243 test_config
['vim_conn'].debug
= "true"
2245 elif args
.vimtype
== "openvim":
2246 import vimconn_openvim
as vim
2247 elif args
.vimtype
== "azure":
2248 import vimconn_azure
as vim
2250 test_config
["test_directory"] = os
.path
.dirname(__file__
) + "/RO_tests"
2252 tenant_name
= args
.tenant_name
2253 test_config
['tenant'] = tenant_name
2254 config_params
= yaml
.load(args
.config_param
)
2255 os_user
= config_params
.get('user')
2256 os_passwd
= config_params
.get('passwd')
2257 vim_url
= args
.endpoint_url
2258 test_config
['image_path'] = args
.image_path
2259 test_config
['image_name'] = args
.image_name
2260 #test_config['sriov_net_name'] = args.sriov_net_name
2262 # azure connector obj
2263 vim_persistent_info
= {}
2264 test_config
['vim_conn'] = vim
.vimconnector(
2265 uuid
="test-uuid-1", name
="VIO-azure",
2266 tenant_id
=None, tenant_name
=tenant_name
,
2267 url
=vim_url
, url_admin
=None,
2268 user
=os_user
, passwd
=os_passwd
,
2269 config
=config_params
, persistent_info
=vim_persistent_info
2271 test_config
['vim_conn'].debug
= "true"
2274 logger
.critical("vimtype '{}' not supported".format(args
.vimtype
))
2278 clsmembers
= inspect
.getmembers(sys
.modules
[__name__
], inspect
.isclass
)
2279 # If only want to obtain a tests list print it and exit
2282 for cls
in clsmembers
:
2283 if cls
[0].startswith('test_vimconn'):
2284 tests_names
.append(cls
[0])
2286 msg
= "The 'vim' set tests are:\n\t" + ', '.join(sorted(tests_names
))
2291 # Create the list of tests to be run
2292 code_based_tests
= []
2294 for test
in args
.tests
:
2295 for t
in test
.split(','):
2296 matches_code_based_tests
= [item
for item
in clsmembers
if item
[0] == t
]
2297 if len(matches_code_based_tests
) > 0:
2298 code_based_tests
.append(matches_code_based_tests
[0][1])
2300 logger
.critical("Test '{}' is not among the possible ones".format(t
))
2302 if not code_based_tests
:
2304 for cls
in clsmembers
:
2305 # We exclude 'test_VIM_tenant_operations' unless it is specifically requested by the user
2306 if cls
[0].startswith('test_vimconn'):
2307 code_based_tests
.append(cls
[1])
2309 logger
.debug("tests to be executed: {}".format(code_based_tests
))
2311 # TextTestRunner stream is set to /dev/null in order to avoid the method to directly print the result of tests.
2312 # This is handled in the tests using logging.
2313 stream
= open('/dev/null', 'w')
2315 # Run code based tests
2316 basic_tests_suite
= unittest
.TestSuite()
2317 for test
in code_based_tests
:
2318 basic_tests_suite
.addTest(unittest
.makeSuite(test
))
2319 result
= unittest
.TextTestRunner(stream
=stream
, failfast
=failfast
).run(basic_tests_suite
)
2320 executed
+= result
.testsRun
2321 failed
+= len(result
.failures
) + len(result
.errors
)
2322 if failfast
and failed
:
2324 if len(result
.failures
) > 0:
2325 logger
.debug("failures : {}".format(result
.failures
))
2326 if len(result
.errors
) > 0:
2327 logger
.debug("errors : {}".format(result
.errors
))
2328 return executed
, failed
2333 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))) + "/osm_ro")
2334 import openmanoclient
2337 test_config
["client"] = openmanoclient
.openmanoclient(
2338 endpoint_url
=args
.endpoint_url
,
2339 tenant_name
=args
.tenant_name
,
2340 datacenter_name
=args
.datacenter
,
2341 debug
=args
.debug
, logger
=test_config
["logger_name"])
2342 clsmembers
= inspect
.getmembers(sys
.modules
[__name__
], inspect
.isclass
)
2343 # If only want to obtain a tests list print it and exit
2346 for cls
in clsmembers
:
2347 if cls
[0].startswith('test_VIM'):
2348 tests_names
.append(cls
[0])
2350 msg
= "The 'vim' set tests are:\n\t" + ', '.join(sorted(tests_names
)) +\
2351 "\nNOTE: The test test_VIM_tenant_operations will fail in case the used datacenter is type OpenStack " \
2352 "unless RO has access to the admin endpoint. Therefore this test is excluded by default"
2357 # Create the list of tests to be run
2358 code_based_tests
= []
2360 for test
in args
.tests
:
2361 for t
in test
.split(','):
2362 matches_code_based_tests
= [item
for item
in clsmembers
if item
[0] == t
]
2363 if len(matches_code_based_tests
) > 0:
2364 code_based_tests
.append(matches_code_based_tests
[0][1])
2366 logger
.critical("Test '{}' is not among the possible ones".format(t
))
2368 if not code_based_tests
:
2370 for cls
in clsmembers
:
2371 # We exclude 'test_VIM_tenant_operations' unless it is specifically requested by the user
2372 if cls
[0].startswith('test_VIM') and cls
[0] != 'test_VIM_tenant_operations':
2373 code_based_tests
.append(cls
[1])
2375 logger
.debug("tests to be executed: {}".format(code_based_tests
))
2377 # TextTestRunner stream is set to /dev/null in order to avoid the method to directly print the result of tests.
2378 # This is handled in the tests using logging.
2379 stream
= open('/dev/null', 'w')
2381 # Run code based tests
2382 basic_tests_suite
= unittest
.TestSuite()
2383 for test
in code_based_tests
:
2384 basic_tests_suite
.addTest(unittest
.makeSuite(test
))
2385 result
= unittest
.TextTestRunner(stream
=stream
, failfast
=failfast
).run(basic_tests_suite
)
2386 executed
+= result
.testsRun
2387 failed
+= len(result
.failures
) + len(result
.errors
)
2388 if failfast
and failed
:
2390 if len(result
.failures
) > 0:
2391 logger
.debug("failures : {}".format(result
.failures
))
2392 if len(result
.errors
) > 0:
2393 logger
.debug("errors : {}".format(result
.errors
))
2394 return executed
, failed
2399 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))) + "/osm_ro")
2400 import openmanoclient
2403 test_config
["client"] = openmanoclient
.openmanoclient(
2404 endpoint_url
=args
.endpoint_url
,
2405 tenant_name
=args
.tenant_name
,
2406 datacenter_name
=args
.datacenter
,
2407 debug
=args
.debug
, logger
=test_config
["logger_name"])
2408 clsmembers
= inspect
.getmembers(sys
.modules
[__name__
], inspect
.isclass
)
2409 # If only want to obtain a tests list print it and exit
2412 for cls
in clsmembers
:
2413 if cls
[0].startswith('test_WIM'):
2414 tests_names
.append(cls
[0])
2416 msg
= "The 'wim' set tests are:\n\t" + ', '.join(sorted(tests_names
)) +\
2417 "\nNOTE: The test test_VIM_tenant_operations will fail in case the used datacenter is type OpenStack " \
2418 "unless RO has access to the admin endpoint. Therefore this test is excluded by default"
2423 # Create the list of tests to be run
2424 code_based_tests
= []
2426 for test
in args
.tests
:
2427 for t
in test
.split(','):
2428 matches_code_based_tests
= [item
for item
in clsmembers
if item
[0] == t
]
2429 if len(matches_code_based_tests
) > 0:
2430 code_based_tests
.append(matches_code_based_tests
[0][1])
2432 logger
.critical("Test '{}' is not among the possible ones".format(t
))
2434 if not code_based_tests
:
2436 for cls
in clsmembers
:
2437 # We exclude 'test_VIM_tenant_operations' unless it is specifically requested by the user
2438 if cls
[0].startswith('test_VIM') and cls
[0] != 'test_VIM_tenant_operations':
2439 code_based_tests
.append(cls
[1])
2441 logger
.debug("tests to be executed: {}".format(code_based_tests
))
2443 # TextTestRunner stream is set to /dev/null in order to avoid the method to directly print the result of tests.
2444 # This is handled in the tests using logging.
2445 stream
= open('/dev/null', 'w')
2447 # Run code based tests
2448 basic_tests_suite
= unittest
.TestSuite()
2449 for test
in code_based_tests
:
2450 basic_tests_suite
.addTest(unittest
.makeSuite(test
))
2451 result
= unittest
.TextTestRunner(stream
=stream
, failfast
=failfast
).run(basic_tests_suite
)
2452 executed
+= result
.testsRun
2453 failed
+= len(result
.failures
) + len(result
.errors
)
2454 if failfast
and failed
:
2456 if len(result
.failures
) > 0:
2457 logger
.debug("failures : {}".format(result
.failures
))
2458 if len(result
.errors
) > 0:
2459 logger
.debug("errors : {}".format(result
.errors
))
2460 return executed
, failed
2463 def test_deploy(args
):
2465 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))) + "/osm_ro")
2466 import openmanoclient
2469 test_config
["test_directory"] = os
.path
.dirname(__file__
) + "/RO_tests"
2470 test_config
["image_name"] = args
.image_name
2471 test_config
["mgmt_net"] = args
.mgmt_net
2472 test_config
["manual"] = args
.manual
2473 test_directory_content
= os
.listdir(test_config
["test_directory"])
2474 # If only want to obtain a tests list print it and exit
2476 msg
= "the 'deploy' set tests are:\n\t" + ', '.join(sorted(test_directory_content
))
2481 descriptor_based_tests
= []
2482 # Create the list of tests to be run
2483 code_based_tests
= []
2485 for test
in args
.tests
:
2486 for t
in test
.split(','):
2487 if t
in test_directory_content
:
2488 descriptor_based_tests
.append(t
)
2490 logger
.critical("Test '{}' is not among the possible ones".format(t
))
2492 if not descriptor_based_tests
:
2494 descriptor_based_tests
= test_directory_content
2496 logger
.debug("tests to be executed: {}".format(code_based_tests
))
2498 # import openmanoclient from relative path
2499 test_config
["client"] = openmanoclient
.openmanoclient(
2500 endpoint_url
=args
.endpoint_url
,
2501 tenant_name
=args
.tenant_name
,
2502 datacenter_name
=args
.datacenter
,
2503 debug
=args
.debug
, logger
=test_config
["logger_name"])
2505 # TextTestRunner stream is set to /dev/null in order to avoid the method to directly print the result of tests.
2506 # This is handled in the tests using logging.
2507 stream
= open('/dev/null', 'w')
2508 # This scenario based tests are defined as directories inside the directory defined in 'test_directory'
2509 for test
in descriptor_based_tests
:
2510 test_config
["test_folder"] = test
2511 test_suite
= unittest
.TestSuite()
2512 test_suite
.addTest(unittest
.makeSuite(descriptor_based_scenario_test
))
2513 result
= unittest
.TextTestRunner(stream
=stream
, failfast
=False).run(test_suite
)
2514 executed
+= result
.testsRun
2515 failed
+= len(result
.failures
) + len(result
.errors
)
2516 if failfast
and failed
:
2518 if len(result
.failures
) > 0:
2519 logger
.debug("failures : {}".format(result
.failures
))
2520 if len(result
.errors
) > 0:
2521 logger
.debug("errors : {}".format(result
.errors
))
2523 return executed
, failed
2525 if __name__
=="__main__":
2527 parser
= ArgumentParser(description
='Test RO module')
2528 parser
.add_argument('-v','--version', action
='version', help="Show current version",
2529 version
='%(prog)s version ' + __version__
+ ' ' + version_date
)
2532 parent_parser
= ArgumentParser(add_help
=False)
2533 parent_parser
.add_argument('--failfast', help='Stop when a test fails rather than execute all tests',
2534 dest
='failfast', action
="store_true", default
=False)
2535 parent_parser
.add_argument('--failed', help='Set logs to show only failed tests. --debug disables this option',
2536 dest
='failed', action
="store_true", default
=False)
2537 default_logger_file
= os
.path
.dirname(__file__
)+'/'+os
.path
.splitext(os
.path
.basename(__file__
))[0]+'.log'
2538 parent_parser
.add_argument('--list-tests', help='List all available tests', dest
='list_tests', action
="store_true",
2540 parent_parser
.add_argument('--logger_file', dest
='logger_file', default
=default_logger_file
,
2541 help='Set the logger file. By default '+default_logger_file
)
2542 parent_parser
.add_argument("-t", '--tenant', dest
='tenant_name', default
="osm",
2543 help="Set the openmano tenant to use for the test. By default 'osm'")
2544 parent_parser
.add_argument('--debug', help='Set logs to debug level', dest
='debug', action
="store_true")
2545 parent_parser
.add_argument('--timeout', help='Specify the instantiation timeout in seconds. By default 300',
2546 dest
='timeout', type=int, default
=300)
2547 parent_parser
.add_argument('--test', '--tests', help='Specify the tests to run', dest
='tests', action
="append")
2549 subparsers
= parser
.add_subparsers(help='test sets')
2551 # Deployment test set
2552 # -------------------
2553 deploy_parser
= subparsers
.add_parser('deploy', parents
=[parent_parser
],
2554 help="test deployment using descriptors at RO_test folder ")
2555 deploy_parser
.set_defaults(func
=test_deploy
)
2557 # Mandatory arguments
2558 mandatory_arguments
= deploy_parser
.add_argument_group('mandatory arguments')
2559 mandatory_arguments
.add_argument('-d', '--datacenter', required
=True, help='Set the datacenter to test')
2560 mandatory_arguments
.add_argument("-i", '--image-name', required
=True, dest
="image_name",
2561 help='Image name available at datacenter used for the tests')
2562 mandatory_arguments
.add_argument("-n", '--mgmt-net-name', required
=True, dest
='mgmt_net',
2563 help='Set the vim management network to use for tests')
2565 # Optional arguments
2566 deploy_parser
.add_argument('-m', '--manual-check', dest
='manual', action
="store_true", default
=False,
2567 help='Pause execution once deployed to allow manual checking of the '
2568 'deployed instance scenario')
2569 deploy_parser
.add_argument('-u', '--url', dest
='endpoint_url', default
='http://localhost:9090/openmano',
2570 help="Set the openmano server url. By default 'http://localhost:9090/openmano'")
2573 # -------------------
2574 vimconn_parser
= subparsers
.add_parser('vimconn', parents
=[parent_parser
], help="test vimconnector plugin")
2575 vimconn_parser
.set_defaults(func
=test_vimconnector
)
2576 # Mandatory arguments
2577 mandatory_arguments
= vimconn_parser
.add_argument_group('mandatory arguments')
2578 mandatory_arguments
.add_argument('--vimtype', choices
=['vmware', 'aws', 'openstack', 'openvim','azure'], required
=True,
2579 help='Set the vimconnector type to test')
2580 mandatory_arguments
.add_argument('-c', '--config', dest
='config_param', required
=True,
2581 help='Set the vimconnector specific config parameters in dictionary format')
2582 mandatory_arguments
.add_argument('-u', '--url', dest
='endpoint_url',required
=True, help="Set the vim connector url or Host IP")
2583 # Optional arguments
2584 vimconn_parser
.add_argument('-i', '--image-path', dest
='image_path', help="Provide image path present at RO container")
2585 vimconn_parser
.add_argument('-n', '--image-name', dest
='image_name', help="Provide image name for test")
2586 # TODO add optional arguments for vimconn tests
2587 # vimconn_parser.add_argument("-i", '--image-name', dest='image_name', help='<HELP>'))
2588 vimconn_parser
.add_argument('-s', '--sriov-net-name', dest
='sriov_net_name', help="Provide SRIOV network name for test")
2590 # Datacenter test set
2591 # -------------------
2592 vimconn_parser
= subparsers
.add_parser('vim', parents
=[parent_parser
], help="test vim")
2593 vimconn_parser
.set_defaults(func
=test_vim
)
2595 # Mandatory arguments
2596 mandatory_arguments
= vimconn_parser
.add_argument_group('mandatory arguments')
2597 mandatory_arguments
.add_argument('-d', '--datacenter', required
=True, help='Set the datacenter to test')
2599 # Optional arguments
2600 vimconn_parser
.add_argument('-u', '--url', dest
='endpoint_url', default
='http://localhost:9090/openmano',
2601 help="Set the openmano server url. By default 'http://localhost:9090/openmano'")
2604 # -------------------
2605 vimconn_parser
= subparsers
.add_parser('wim', parents
=[parent_parser
], help="test wim")
2606 vimconn_parser
.set_defaults(func
=test_wim
)
2608 # Mandatory arguments
2609 mandatory_arguments
= vimconn_parser
.add_argument_group('mandatory arguments')
2610 mandatory_arguments
.add_argument('-d', '--datacenter', required
=True, help='Set the datacenter to test')
2612 # Optional arguments
2613 vimconn_parser
.add_argument('-u', '--url', dest
='endpoint_url', default
='http://localhost:9090/openmano',
2614 help="Set the openmano server url. By default 'http://localhost:9090/openmano'")
2616 argcomplete
.autocomplete(parser
)
2617 args
= parser
.parse_args()
2621 # default logger level is INFO. Options --debug and --failed override this, being --debug prioritary
2622 logger_level
= 'INFO'
2624 logger_level
= 'DEBUG'
2626 logger_level
= 'WARNING'
2627 logger_name
= os
.path
.basename(__file__
)
2628 test_config
["logger_name"] = logger_name
2629 logger
= logging
.getLogger(logger_name
)
2630 logger
.setLevel(logger_level
)
2631 failfast
= args
.failfast
2633 # Configure a logging handler to store in a logging file
2634 if args
.logger_file
:
2635 fileHandler
= logging
.FileHandler(args
.logger_file
)
2636 formatter_fileHandler
= logging
.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s')
2637 fileHandler
.setFormatter(formatter_fileHandler
)
2638 logger
.addHandler(fileHandler
)
2640 # Configure a handler to print to stdout
2641 consoleHandler
= logging
.StreamHandler(sys
.stdout
)
2642 formatter_consoleHandler
= logging
.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s')
2643 consoleHandler
.setFormatter(formatter_consoleHandler
)
2644 logger
.addHandler(consoleHandler
)
2646 logger
.debug('Program started with the following arguments: ' + str(args
))
2648 # set test config parameters
2649 test_config
["timeout"] = args
.timeout
2650 test_config
["test_number"] = 1
2652 executed
, failed
= args
.func(args
)
2655 logger
.warning("Total number of tests: {}; Total number of failures/errors: {}".format(executed
, failed
))
2656 sys
.exit(1 if failed
else 0)