def __create_specified_vm_and_wait_for_login(self): # create ports for VM vnic_count = int(self.params.get('vnics_count_per_vm', 1)) network_name = None vnics = [] if vnic_count > 1: vnics = test_utils.create_ports(self.params) for vnic in vnics: self.register_cleanup(vnic["id"], 'port') else: net = test_utils.get_test_network(self.params) network_name = net['name'] vm = self.compute_utils.create_vm( vm_name=self.vm_name, image_name=self.params.get('image_name'), flavor_name=self.params.get('flavor_name'), network_name=network_name, injected_key=self.pub_key, sec_group=None, nics=vnics) self.register_cleanup(vm) if not self.compute_utils.wait_for_vm_active(vm): raise exceptions.TestFail("Failed to build VM: %s" % vm) self.vm_fip = self.compute_utils.assign_floating_ip_to_vm(vm) self.log.info("Created VM '%s', try to login via %s" % (vm.name, self.vm_fip)) if not self.__wait_for_vm_responsive(vm.name, self.vm_fip): self.compute_utils.capture_vm_console_log(vm) raise exceptions.TestFail("Failed to wait for VM responsive: %s" % vm.name) return vm
def __create_vms_concurrently_with_params(self, concurrence_count): self.log.info("Test creating %d VMs concurrently!" % concurrence_count) self.is_vm_creation_test = True timeout = self.vm_creation_maximum_time net = test_utils.get_test_network(self.params) network_name = net['name'] vnics = [] if self.vnics_count_per_vm > 1: vnics = self.__create_ports() for vnic in vnics: self.register_cleanup(vnic["id"], 'port') network_name = None self.compute_utils.create_vm( vm_name=self.vm_name, image_name=self.params.get('image_name'), flavor_name=self.params.get('flavor_name'), network_name=network_name, injected_key=self.pub_key, sec_group=None, availability_zone=self.availability_zone, nics=vnics, min_count=concurrence_count) for i in range(1, concurrence_count + 1): _vm_name = self.vm_name + '-%d' % i self.vms_name.append(_vm_name) _vm = self.compute_utils.find_vm_from_name(_vm_name) self.vm_list.append(_vm) self.checking_vm_list.append(_vm) self.__check_vms_responsive(timeout)
def __create_ports(self): net = test_utils.get_test_network(self.params) _network_name = net['name'] vnic_count = int(self.params.get('vnics_count_per_vm', 1)) nets = self.network_utils.list_networks() vnics = [] for _k in nets: for _v in nets[_k]: if _network_name == _v['name']: net = _v break if not net: raise Exception( "Miss to specify network or can not to get network") else: _network_id = str(net["id"]) name_prefix = 'cloudtest_' + utils_misc.generate_random_string(6) for i in range(0, vnic_count): nic_name = name_prefix + '_%d' % i port = self.network_utils.create_port(nic_name, network_id=_network_id) self.log.info("Created port successfully!") vnics.append(port) return vnics
def lock_compute_node(self): vm_count = int(self.params.get("vm_count")) net = test_utils.get_test_network(self.params) network_name = net['name'] vm_name_list = self.compute_utils.create_vms_on_specific_node( node_name=self.node_for_lock, vm_count=vm_count, injected_key=self.pub_key, network_name=network_name) for vm_name in vm_name_list: vm = self.compute_utils.find_vm_from_name(vm_name) self.register_cleanup(vm) status = self.compute_utils.wait_for_vm_active( vm, delete_on_failure=False) if not status: raise exceptions.TestFail("Failed to create vm!") start_time = time.time() status = self.compute_utils.lock_compute_node(self.node_for_lock) if not status: raise exceptions.TestFail("Failed to lock compute node!") for vm_name in vm_name_list: vm = self.compute_utils.find_vm_from_name(vm_name) status = self.compute_utils.wait_for_vm_active( vm, delete_on_failure=False) if not status: raise exceptions.TestFail("Failed to migrate vm!") self.log.info("Time for lock node %s and vm migrate to another node " "is %5.0f sec" % (self.node_for_lock, time.time() - start_time))
def _create_vm(self, image_name): net = test_utils.get_test_network(self.params) _network_name = net['name'] vm = self.compute_utils.create_vm(vm_name=None, image_name=image_name, network_name=_network_name, injected_key=self.pub_key, sec_group=None) self.vm_list.append(vm) if not self.compute_utils.wait_for_vm_active(vm): raise exceptions.TestFail("Failed to build VM: %s" % vm) time.sleep(60) return vm
def __create_vms_sequentially(self): self.log.info("Test creating %d VMs concurrently!" % self.max_count) self.is_vm_creation_test = True start_time = time.time() benchmark = self.vm_creation_benchmark timeout = self.vm_creation_maximum_time net = test_utils.get_test_network(self.params) network_name = net['name'] threads = [] for i in range(1, self.max_count + 1): _vm_name = self.vm_name + '_%d' % i vnics = [] if self.vnics_count_per_vm > 1: vnics = self.__create_ports() for vnic in vnics: self.register_cleanup(vnic["id"], 'port') network_name = None _vm = self.compute_utils.create_vm( vm_name=_vm_name, image_name=self.params.get('image_name'), flavor_name=self.params.get('flavor_name'), network_name=network_name, injected_key=self.pub_key, sec_group=None, availability_zone=self.availability_zone, nics=vnics) self.vm_list.append(_vm) self.checking_vm_list.append(_vm) self.vms_name.append(_vm_name) for i in range(0, self.max_count): t = VMThread(self.compute_utils.wait_for_vm_in_status, args=(self.vm_list[i], 'ACTIVE', 3, timeout)) threads.append(t) for t in threads: t.setDaemon(True) t.start() for i in range(0, self.max_count): try: threads[i].join(timeout) if not threads[i].get_result(): raise Exception("Failed to create vm %d!" % (i + 1)) except Exception, e: raise exceptions.TestFail("Test failed for: %s" % str(e))
def test_vm_max_count(self): controller_session = test_utils.get_host_session(self.params, 'controller') vm_domain_name_list = [] extra_spec = {"hw:cpu_policy": "dedicated"} flavor = self.compute_utils.create_flavor(ram=self.ram, vcpus=self.vcpus, disk=self.disk, extra_spec=extra_spec) self.register_cleanup(flavor) nodes = self.compute_utils.get_all_hypervisors() host_name = nodes[0].hypervisor_hostname host_ip = nodes[0].host_ip vm_num = 0 vm_name_str = "cloudtest-" + utils_misc.generate_random_string(6) while True: vm_name = vm_name_str + "-" + str(vm_num) vm_num = vm_num +1 net = test_utils.get_test_network(self.params) self.compute_utils.create_vm_on_specific_node( node_name=host_name, flavor_name=flavor.name, injected_key=self.pub_key, network_name=net['name'], vm_name=vm_name) vm = self.compute_utils.find_vm_from_name(vm_name) self.register_cleanup(vm) status = self.compute_utils.wait_for_vm_active( vm, delete_on_failure=False) if not status: break vm_domain_name = self.compute_utils.get_vm_domain_name(vm_name) vm_domain_name_list.append(vm_domain_name) self.log.info("Can create %s vms on node %s when set " "cpu dedicated policy." % (str(vm_num - 1), host_name)) dpdk_core_list = self._get_dpdk_core(host_ip, controller_session) test_utils.check_vm_cpu_isolation(host_ip, controller_session, dpdk_core_list)