+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()
+
+ 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 = []
+ c = 1
+ for net_id in self.net_ids:
+ name = "eth{}".format(c)
+ net_list.append({'use': 'bridge', 'name': name, 'floating_ip': False,
+ 'port_security': True, 'type': 'virtual', 'net_id': net_id})
+ c = c+1
+
+ 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_existing_disk(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_existing_disk(self):
+ """ This testcase will add existing disk only if given catalog/image is free
+ means not used by any other VM
+ """
+
+ flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
+ name = "eth10"
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+
+ # find image name and image id
+ image_id = get_image_id()
+ cirros_image = test_config["vim_conn"].get_image_list({'name': 'cirros'})
+ disk_list = [{'image_id': cirros_image[0]['id'],'size': 5}]
+
+ 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}]
+
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
+ flavor_id=flavor_id, net_list=net_list,disk_list=disk_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_new_disk(self):
+ flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
+ name = "eth10"
+
+ # create new flavor
+ flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
+
+ # find image name and image id
+ image_id = get_image_id()
+ disk_list = [{'size': '5'}]
+
+ 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}]
+
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
+ flavor_id=flavor_id, net_list=net_list,disk_list=disk_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_020_vminstance_by_CDROM(self):
+ """ This testcase will insert media file only if provided catalog
+ has pre-created ISO media file into vCD
+ """
+ flavor_data ={'ram': 1024, 'vcpus': 1, 'disk': 10}
+ name = "eth10"
+ image_list = test_config["vim_conn"].get_image_list({'name':'Ubuntu'})
+ disk_list = [{'image_id':image_list[0]['id'],'device_type':'cdrom'}]
+
+ # 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}]
+
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
+ flavor_id=flavor_id, net_list=net_list,disk_list=disk_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_affinity_anti_affinity(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_affinity_anti_affinity(self):
+ """ This testcase will deploy VM into provided HOSTGROUP in VIM config
+ Pre-requisites: User has created Hosh Groups in vCenter with respective Hosts to be used
+ While creating VIM account user has to pass the Host Group names in availability_zone list
+ """
+ flavor_data = {'ram': 1024, 'vcpus': 1, 'disk': 10}
+ name = "eth10"
+
+ # 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}]
+
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
+ flavor_id=flavor_id, net_list=net_list,availability_zone_index=1,
+ availability_zone_list=['HG_174','HG_175'])
+
+ self.assertEqual(type(instance_id),str)
+ time.sleep(10)
+ logger.info("Deleting created vm instance")
+ test_config["vim_conn"].delete_vminstance(instance_id)
+
+class test_vimconn_vminstance_by_numa_affinity(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_numa_affinity(self):
+ flavor_data = {'extended': {'numas': [{'paired-threads-id': [['1', '3'], ['2', '4']],
+ ' paired-threads': 2, 'memory': 1}]},
+ 'ram': 1024, 'vcpus': 1, 'disk': 10}
+ name = "eth10"
+
+ # 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}]
+
+ 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)
+
+
+'''
+IMPORTANT NOTE
+The following unittest class does not have the 'test_' on purpose. This test is the one used for the
+scenario based tests.
+'''
+class descriptor_based_scenario_test(test_base):
+ test_index = 0
+ scenario_test_path = None
+
+ @classmethod
+ def setUpClass(cls):
+ cls.test_index = 1
+ cls.to_delete_list = []
+ cls.scenario_uuids = []
+ cls.instance_scenario_uuids = []
+ cls.scenario_test_path = test_config["test_directory"] + '/' + test_config["test_folder"]
+ logger.info("{}. {} {}".format(test_config["test_number"], cls.__name__, test_config["test_folder"]))
+
+ @classmethod
+ def tearDownClass(cls):
+ test_config["test_number"] += 1
+
+ def test_000_load_scenario(self):
+ self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index,
+ inspect.currentframe().f_code.co_name,
+ test_config["test_folder"])
+ self.__class__.test_index += 1
+ # load VNFD and NSD
+ descriptor_files = glob.glob(self.__class__.scenario_test_path+'/*.yaml')
+ vnf_descriptors = []
+ scenario_descriptors = []
+ for descriptor_file in descriptor_files:
+ with open(descriptor_file, 'r') as stream:
+ descriptor = yaml.load(stream)
+ if "vnf" in descriptor or "vnfd:vnfd-catalog" in descriptor or "vnfd-catalog" in descriptor:
+ vnf_descriptors.append(descriptor)
+ else:
+ scenario_descriptors.append(descriptor)
+
+ scenario_file = glob.glob(self.__class__.scenario_test_path + '/scenario_*.yaml')
+ if not vnf_descriptors or not scenario_descriptors or len(scenario_descriptors) > 1:
+ raise Exception("Test '{}' not valid. It must contain an scenario file and at least one vnfd file'".format(
+ test_config["test_folder"]))
+
+ # load all vnfd
+ for vnf_descriptor in vnf_descriptors:
+ logger.debug("VNF descriptor: {}".format(vnf_descriptor))
+ vnf = test_config["client"].create_vnf(descriptor=vnf_descriptor, image_name=test_config["image_name"])
+ logger.debug(vnf)
+ if 'vnf' in vnf:
+ vnf_uuid = vnf['vnf']['uuid']
+ else:
+ vnf_uuid = vnf['vnfd'][0]['uuid']
+ self.__class__.to_delete_list.insert(0, {"item": "vnf", "function": test_config["client"].delete_vnf,
+ "params": {"uuid": vnf_uuid}})
+
+ # load the scenario definition
+ for scenario_descriptor in scenario_descriptors:
+ # networks = scenario_descriptor['scenario']['networks']
+ # networks[test_config["mgmt_net"]] = networks.pop('mgmt')
+ logger.debug("Scenario descriptor: {}".format(scenario_descriptor))
+ scenario = test_config["client"].create_scenario(descriptor=scenario_descriptor)
+ logger.debug(scenario)
+ if 'scenario' in scenario:
+ scenario_uuid = scenario['scenario']['uuid']
+ else:
+ scenario_uuid = scenario['nsd'][0]['uuid']
+ self.__class__.to_delete_list.insert(0, {"item": "scenario",
+ "function": test_config["client"].delete_scenario,
+ "params": {"uuid": scenario_uuid}})
+ self.__class__.scenario_uuids.append(scenario_uuid)
+
+ def test_010_instantiate_scenario(self):
+ self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index,
+ inspect.currentframe().f_code.co_name,
+ test_config["test_folder"])
+ self.__class__.test_index += 1
+ for scenario_uuid in self.__class__.scenario_uuids:
+ instance_descriptor = {
+ "instance":{
+ "name": self.__class__.test_text,
+ "scenario": scenario_uuid,
+ "networks":{
+ "mgmt": {"sites": [ { "netmap-use": test_config["mgmt_net"]} ]}
+ }
+ }
+ }
+ instance = test_config["client"].create_instance(instance_descriptor)
+ self.__class__.instance_scenario_uuids.append(instance['uuid'])
+ logger.debug(instance)
+ self.__class__.to_delete_list.insert(0, {"item": "instance",
+ "function": test_config["client"].delete_instance,
+ "params": {"uuid": instance['uuid']}})
+
+ def test_020_check_deployent(self):
+ self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index,
+ inspect.currentframe().f_code.co_name,
+ test_config["test_folder"])
+ self.__class__.test_index += 1
+
+ if test_config["manual"]:
+ raw_input('Scenario has been deployed. Perform manual check and press any key to resume')
+ return
+
+ keep_waiting = test_config["timeout"]
+ pending_instance_scenario_uuids = list(self.__class__.instance_scenario_uuids) # make a copy
+ while pending_instance_scenario_uuids:
+ index = 0
+ while index < len(pending_instance_scenario_uuids):
+ result = check_instance_scenario_active(pending_instance_scenario_uuids[index])
+ if result[0]:
+ del pending_instance_scenario_uuids[index]
+ break
+ elif 'ERROR' in result[1]:
+ msg = 'Got error while waiting for the instance to get active: '+result[1]
+ logging.error(msg)
+ raise Exception(msg)
+ index += 1
+
+ if keep_waiting >= 5:
+ time.sleep(5)
+ keep_waiting -= 5
+ elif keep_waiting > 0:
+ time.sleep(keep_waiting)
+ keep_waiting = 0
+ else:
+ msg = 'Timeout reached while waiting instance scenario to get active'
+ logging.error(msg)
+ raise Exception(msg)
+
+ def test_030_clean_deployment(self):
+ self.__class__.test_text = "{}.{}. TEST {} {}".format(test_config["test_number"], self.__class__.test_index,
+ inspect.currentframe().f_code.co_name,
+ test_config["test_folder"])
+ self.__class__.test_index += 1
+ #At the moment if you delete an scenario right after creating it, in openstack datacenters
+ #sometimes scenario ports get orphaned. This sleep is just a dirty workaround
+ time.sleep(5)
+ for item in self.__class__.to_delete_list:
+ response = item["function"](**item["params"])
+ logger.debug(response)
+
+
+def _get_random_string(maxLength):
+ '''generates a string with random characters string.letters and string.digits
+ with a random length up to maxLength characters. If maxLength is <15 it will be changed automatically to 15
+ '''
+ prefix = 'testing_'
+ min_string = 15
+ minLength = min_string - len(prefix)
+ if maxLength < min_string: maxLength = min_string
+ maxLength -= len(prefix)
+ length = random.randint(minLength,maxLength)
+ return 'testing_'+"".join([random.choice(string.letters+string.digits) for i in xrange(length)])