+ def test_080_get_vminstance_negative(self):
+ unknown_instance_id = str(uuid.uuid4())
+
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ with self.assertRaises(Exception) as context:
+ test_config["vim_conn"].get_vminstance(unknown_instance_id)
+
+ self.assertEqual((context.exception).http_code, 404)
+
+ def test_090_refresh_vms_status(self):
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ if test_config['vimtype'] == 'vmware':
+ vm_list = []
+ vm_list.append(self.__class__.instance_id)
+
+ # refresh vm status
+ vm_info = test_config["vim_conn"].refresh_vms_status(vm_list)
+ for attr in vm_info[self.__class__.instance_id]:
+ if attr == 'status':
+ self.assertEqual(vm_info[self.__class__.instance_id][attr], 'ACTIVE')
+ if attr == 'interfaces':
+ self.assertEqual(type(vm_info[self.__class__.instance_id][attr]), list)
+
+ if test_config['vimtype'] == 'openstack':
+ vpci = "0000:00:11.0"
+ name = "eth0"
+
+ flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+ # create new vm instance
+ net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'vpci': vpci, 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}]
+
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, image_id=self.__class__.image_id, flavor_id=flavor_id, net_list=net_list)
+
+ time.sleep(30)
+ vm_list = []
+ vm_list.append(instance_id)
+
+ # refresh vm status
+ vm_info = test_config["vim_conn"].refresh_vms_status(vm_list)
+ for attr in vm_info[instance_id]:
+ if attr == 'status':
+ self.assertEqual(vm_info[instance_id][attr], 'ACTIVE')
+ if attr == 'interfaces':
+ self.assertEqual(type(vm_info[instance_id][attr]), list)
+
+ #Deleting created vm instance
+ logger.info("Deleting created vm intance")
+ test_config["vim_conn"].delete_vminstance(instance_id)
+ time.sleep(10)
+
+
+ def test_100_refresh_vms_status_negative(self):
+ unknown_id = str(uuid.uuid4())
+
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ vm_dict = test_config["vim_conn"].refresh_vms_status([unknown_id])
+
+ if test_config['vimtype'] == 'vmware':
+ self.assertEqual(vm_dict,{})
+
+ if test_config['vimtype'] == 'openstack':
+ self.assertEqual(vm_dict[unknown_id]['status'], 'DELETED')
+
+ def test_110_action_vminstance(self):
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ if test_config['vimtype'] == 'vmware':
+ action_list = ['shutdown', 'start', 'shutoff', 'rebuild', 'pause', 'resume']
+ # various action on vminstace
+ for action in action_list:
+ instance_id = test_config["vim_conn"].action_vminstance(self.__class__.instance_id,
+ {action: None})
+ self.assertEqual(instance_id, self.__class__.instance_id)
+
+ if test_config['vimtype'] == 'openstack':
+ # create new vm instance
+ vpci = "0000:00:11.0"
+ name = "eth0"
+
+ flavor_data = {'name': _get_random_string(20), 'ram': 1024, 'vcpus': 1, 'disk': 10}
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+
+ net_list = [{'use': self.__class__.net_type, 'name': name, 'floating_ip': False, 'vpci': vpci, 'port_security': True, 'type': 'virtual', 'net_id': self.__class__.network_id}]
+
+ new_instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False, image_id=self.__class__.image_id, flavor_id=flavor_id, net_list=net_list)
+
+ action_list = ['shutdown','start','shutoff','rebuild','start','pause','start']
+
+ # various action on vminstace
+ for action in action_list:
+ # sleep for sometime till status is changed
+ time.sleep(25)
+ instance_id = test_config["vim_conn"].action_vminstance(new_instance_id,
+ { action: None})
+
+ self.assertTrue(instance_id is None)
+
+ # Deleting created vm instance
+ logger.info("Deleting created vm intance")
+ test_config["vim_conn"].delete_vminstance(new_instance_id)
+ time.sleep(10)
+
+ def test_120_action_vminstance_negative(self):
+ non_exist_id = str(uuid.uuid4())
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ action = 'start'
+ with self.assertRaises(Exception) as context:
+ test_config["vim_conn"].action_vminstance(non_exist_id, { action: None})
+
+ self.assertEqual((context.exception).http_code, 404)
+
+
+ def test_130_delete_vminstance(self):
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ # Deleting created vm instance
+ logger.info("Deleting created vm instance")
+ test_config["vim_conn"].delete_vminstance(self.__class__.instance_id)
+ time.sleep(10)
+
+ def test_140_new_vminstance_sriov(self):
+ logger.info("Testing creation of sriov vm instance using {}".format(test_config['sriov_net_name']))
+ flavor_data = {'name': _get_random_string(20),'ram': 1024, 'vcpus': 2, 'disk': 10}
+ name = 'eth0'
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ sriov_net_name = test_config['sriov_net_name']
+ new_network_list = test_config["vim_conn"].get_network_list({'name': sriov_net_name})
+ for list_item in new_network_list:
+ self.assertEqual(sriov_net_name, list_item.get('name'))
+ self.__class__.sriov_network_id = list_item.get('id')
+
+ net_list = [{'use': 'data', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'VF', 'net_id': self.__class__.sriov_network_id}]
+
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_sriov_vm', description='', start=False, image_id=self.__class__.image_id, flavor_id=flavor_id, net_list=net_list)
+
+ self.assertIsInstance(instance_id, (str, unicode))
+
+ logger.info("Waiting for created sriov-vm intance")
+ time.sleep(10)
+ # Deleting created vm instance
+ logger.info("Deleting created sriov-vm intance")
+ test_config["vim_conn"].delete_vminstance(instance_id)
+ time.sleep(10)
+
+class test_vimconn_get_tenant_list(test_base):
+ tenant_id = None
+
+ def test_000_get_tenant_list(self):
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ # Getting tenant list
+ tenant_list = test_config["vim_conn"].get_tenant_list()
+
+ for item in tenant_list:
+ if test_config['tenant'] == item['name']:
+ self.__class__.tenant_id = item['id']
+ self.assertIsInstance(item['name'], (str, unicode))
+ self.assertIsInstance(item['id'], (str, unicode))
+
+ def test_010_get_tenant_list_by_id(self):
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ # Getting filter tenant list by its id
+ filter_tenant_list = test_config["vim_conn"].get_tenant_list({'id': self.__class__.tenant_id})
+
+ for item in filter_tenant_list:
+ self.assertIsInstance(item['id'], (str, unicode))
+ self.assertEqual(item['id'], self.__class__.tenant_id)
+
+ def test_020_get_tenant_list_by_name(self):
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ # Getting filter tenant list by its name
+ filter_tenant_list = test_config["vim_conn"].get_tenant_list({'name': test_config['tenant']})
+
+ for item in filter_tenant_list:
+ self.assertIsInstance(item['name'], (str, unicode))
+ self.assertEqual(item['name'], test_config['tenant'])
+
+ def test_030_get_tenant_list_by_name_and_id(self):
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ # Getting filter tenant list by its name and id
+ filter_tenant_list = test_config["vim_conn"].get_tenant_list({'name': test_config['tenant'],
+ 'id': self.__class__.tenant_id})
+
+ for item in filter_tenant_list:
+ self.assertIsInstance(item['name'], (str, unicode))
+ self.assertIsInstance(item['id'], (str, unicode))
+ self.assertEqual(item['name'], test_config['tenant'])
+ self.assertEqual(item['id'], self.__class__.tenant_id)
+
+ def test_040_get_tenant_list_negative(self):
+ non_exist_tenant_name = "Tenant_123"
+ non_exist_tenant_id = "kjhgrt456-45345kjhdfgnbdk-34dsfjdfg"
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ filter_tenant_list = test_config["vim_conn"].get_tenant_list({'name': non_exist_tenant_name,
+ 'id': non_exist_tenant_id})
+
+ self.assertEqual(filter_tenant_list, [])
+
+
+class test_vimconn_new_tenant(test_base):
+ tenant_id = None
+
+ def test_000_new_tenant(self):
+ tenant_name = _get_random_string(20)
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ self.__class__.tenant_id = test_config["vim_conn"].new_tenant(tenant_name, "")
+ time.sleep(15)
+
+ self.assertIsInstance(self.__class__.tenant_id, (str, unicode))
+
+
+ def test_010_new_tenant_negative(self):
+ Invalid_tenant_name = 10121
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ with self.assertRaises(Exception) as context:
+ test_config["vim_conn"].new_tenant(Invalid_tenant_name, "")
+
+ self.assertEqual((context.exception).http_code, 400)
+
+
+ def test_020_delete_tenant(self):
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ tenant_id = test_config["vim_conn"].delete_tenant(self.__class__.tenant_id)
+
+ self.assertIsInstance(tenant_id, (str, unicode))
+
+ def test_030_delete_tenant_negative(self):
+ Non_exist_tenant_name = 'Test_30_tenant'
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ with self.assertRaises(Exception) as context:
+ test_config["vim_conn"].delete_tenant(Non_exist_tenant_name)
+
+ self.assertEqual((context.exception).http_code, 404)
+
+
+def get_image_id():
+ if test_config['image_name']:
+ image_list = test_config['vim_conn'].get_image_list({'name': test_config['image_name']})
+ if len(image_list) == 0:
+ raise Exception("Image {} is not found at VIM".format(test_config['image_name']))
+ else:
+ image_id = image_list[0]['id']
+ else:
+ image_list = test_config['vim_conn'].get_image_list()
+ if len(image_list) == 0:
+ raise Exception("Not found any image at VIM")
+ else:
+ image_id = image_list[0]['id']
+ return image_id
+
+
+class test_vimconn_vminstance_by_ip_address(test_base):
+ network_name = None
+ network_id = None
+
+ def setUp(self):
+ # create network
+ self.network_name = _get_random_string(20)
+
+ self.network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name,
+ net_type='bridge')
+
+ def tearDown(self):
+ test_base.tearDown(self)
+ # Deleting created network
+ result = test_config["vim_conn"].delete_network(self.network_id)
+ if result:
+ logger.info("Network id {} sucessfully deleted".format(self.network_id))
+ else:
+ logger.info("Failed to delete network id {}".format(self.network_id))
+
+
+ def test_000_vminstance_by_ip_address(self):
+ """
+ This test case will deploy VM with provided IP address
+ Pre-requesite: provided IP address should be from IP pool range which has used for network creation
+ """
+ name = "eth0"
+ # provide ip address
+ ip_address = ''
+
+ flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+
+ # find image id
+ image_id = get_image_id()
+
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
+ 'net_id': self.network_id, 'ip_address': ip_address}]
+
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
+ flavor_id=flavor_id, net_list=net_list)
+
+ self.assertEqual(type(instance_id),str)
+ logger.info("Deleting created vm instance")
+ test_config["vim_conn"].delete_vminstance(instance_id)
+ time.sleep(10)
+
+ def test_010_vminstance_by_ip_address_negative(self):
+ name = "eth1"
+ # IP address not from subnet range
+ invalid_ip_address = '10.10.12.1'
+
+ flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+
+ # find image name and image id
+ image_id = get_image_id()
+
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
+ 'net_id': self.network_id, 'ip_address': invalid_ip_address}]
+
+ with self.assertRaises(Exception) as context:
+ test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
+ flavor_id=flavor_id,
+ net_list=net_list)
+ self.assertEqual((context.exception).http_code, 400)
+
+ def test_020_vminstance_by_floating_ip(self):
+ name = "eth1"
+ flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+
+ # find image name and image id
+ image_id = get_image_id()
+
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ net_list = [{'use': 'bridge', 'name': name, 'floating_ip': True, 'port_security': True, 'type': 'virtual',
+ 'net_id': self.network_id}]
+
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
+ flavor_id=flavor_id, net_list=net_list)
+
+ self.assertEqual(type(instance_id),str)
+ logger.info("Deleting created vm instance")
+ test_config["vim_conn"].delete_vminstance(instance_id)
+ time.sleep(10)
+
+ def test_030_vminstance_by_mac_address(self):
+ name = "eth1"
+ mac_address = "74:54:2f:21:da:8c"
+ flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+
+ # find image name and image id
+ image_id = get_image_id()
+
+ self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+ self.__class__.test_index,
+ inspect.currentframe().f_code.co_name)
+ self.__class__.test_index += 1
+
+ net_list = [{'use': 'bridge', 'name': name, 'floating_ip': False, 'port_security': True, 'type': 'virtual',
+ 'net_id': self.network_id,'mac_address': mac_address}]
+
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
+ flavor_id=flavor_id, net_list=net_list)
+
+ self.assertEqual(type(instance_id),str)
+ logger.info("Deleting created vm instance")
+ test_config["vim_conn"].delete_vminstance(instance_id)
+ time.sleep(10)
+
+class test_vimconn_vminstance_by_adding_10_nics(test_base):
+ network_name = None
+ net_ids = []
+
+ def setUp(self):
+ # create network
+ i = 0
+ for i in range(10):
+ self.network_name = _get_random_string(20)
+ network_id, _ = test_config["vim_conn"].new_network(net_name=self.network_name,
+ net_type='bridge')
+ self.net_ids.append(network_id)
+
+ def tearDown(self):
+ test_base.tearDown(self)
+ # Deleting created network
+ for net_id in self.net_ids:
+ result = test_config["vim_conn"].delete_network(net_id)
+ if result:
+ logger.info("Network id {} sucessfully deleted".format(net_id))
+ else:
+ logger.info("Failed to delete network id {}".format(net_id))
+
+ def test_000_vminstance_by_adding_10_nics(self):
+ flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+
+ # find image name and image id
+ image_id = get_image_id()