def run(test, params, env): """ Check VM after conversion """ target = params.get('target') check_obj = utils_v2v.LinuxVMCheck(test, params, env) logging.info("Check guest os info") os_info = check_obj.get_vm_os_info() os_vendor = check_obj.get_vm_os_vendor() if os_vendor == 'Red Hat': os_version = os_info.split()[6] else: raise error.TestFail("Only RHEL is supported now.") logging.info("Check guest kernel after conversion") kernel_version = check_obj.get_vm_kernel() if re.search('xen', kernel_version): raise error.TestFail("FAIL") else: logging.info("SUCCESS") logging.info("Check parted info after conversion") parted_info = check_obj.get_vm_parted() if os_version != '3': if re.findall('/dev/vd\S+', parted_info): logging.info("SUCCESS") else: raise error.TestFail("FAIL") logging.info("Check virtio_net module in modprobe conf") modprobe_conf = check_obj.get_vm_modprobe_conf() if not re.search('No such file', modprobe_conf): virtio_mod = re.findall(r'(?m)^alias.*virtio', modprobe_conf) net_blk_mod = re.findall(r'(?m)^alias\s+scsi|(?m)^alias\s+eth', modprobe_conf) if len(virtio_mod) == len(net_blk_mod): logging.info("SUCCESS") else: raise error.TestFail("FAIL") logging.info("Check virtio module") modules = check_obj.get_vm_modules() if os_version == '3': if re.search("e1000|^ide", modules): logging.info("SUCCESS") else: raise error.TestFail("FAIL") elif re.search("virtio", modules): logging.info("SUCCESS") else: raise error.TestFail("FAIL") logging.info("Check virtio pci devices") pci = check_obj.get_vm_pci_list() if os_version != '3': if (re.search('[Vv]irtio network', pci) and re.search('[Vv]irtio block', pci)): if target == "ovirt": logging.info("SUCCESS") elif (target != "ovirt" and re.search('[Vv]irtio memory', pci)): logging.info("SUCCESS") else: raise error.TestFail("FAIL") else: raise error.TestFail("FAIL") logging.info("Check in /etc/rc.local") rc_output = check_obj.get_vm_rc_local() if re.search('^[modprobe|insmod].*xen-vbd.*', rc_output): raise error.TestFail("FAIL") else: logging.info("SUCCESS") logging.info("Check vmware tools") if check_obj.has_vmware_tools() is False: logging.info("SUCCESS") else: raise error.TestFail("FAIL") logging.info("Check tty") tty = check_obj.get_vm_tty() if re.search('[xh]vc0', tty): raise error.TestFail("FAIL") else: logging.info("SUCCESS") logging.info("Check video") video = check_obj.get_vm_video() if not re.search('el6', kernel_version): if re.search('cirrus', video): logging.info("SUCCESS") else: raise error.TestFail("FAIL")
def run(test, params, env): """ Convert a local vm disk to local libvirt(KVM). """ # VM info vm_name = params.get("v2v_vm") # Remote host parameters remote_hostname = params.get("remote_hostname") username = params.get("remote_username", "root") password = params.get("remote_passwd") remote_hypervisor = params.get("remote_hypervisor") # Local pool parameters pool_type = params.get("pool_type", "dir") block_device = params.get("block_device", "/dev/BLOCK/EXAMPLE") if pool_type in ['disk', 'partition', 'lvm'] and \ re.search("EXAMPLE", block_device): raise error.TestNAError("Please set correct block device.") pool_name = params.get("pool_name", "v2v_test") target_path = params.get("target_path", "pool_path") vg_name = params.get("volume_group_name", "vg_v2v") local_tmp_path = params.get("local_tmp_path", data_dir.get_tmp_dir()) # If target_path is not an abs path, join it to data_dir.TMPDIR if os.path.dirname(target_path) is "": target_path = os.path.join(data_dir.get_tmp_dir(), target_path) # dir pool need an exist path if pool_type == "dir": if not os.path.exists(target_path): os.mkdir(target_path) # V2V parameters input = params.get("input_method") files = params.get("config_files") network = params.get("network", "default") # Result check about ignore_virtio = "yes" == params.get("ignore_virtio", "no") # Create remote uri for remote host # Remote virt-v2v uri's instance ruri = utils_v2v.Uri(remote_hypervisor) remote_uri = ruri.get_uri(remote_hostname) ssh_key.setup_ssh_key(remote_hostname, user=username, port=22, password=password) # Check remote vms remote_vm = libvirt_vm.VM(vm_name, params, test.bindir, env.get("address_cache")) remote_vm.connect_uri = remote_uri if not remote_vm.exists(): raise error.TestFail("Couldn't find vm '%s' to be converted " "on remote uri '%s'." % (vm_name, remote_uri)) # Copy remote vm's disk to local and create xml file for it tmp_xml_file = copy_remote_vm(remote_vm, local_tmp_path, remote_hostname, username, password) # Local storage pool's instance lsp = libvirt_storage.StoragePool() try: # Create storage pool for test if pool_type == "dir": if not create_dir_pool(lsp, pool_name, target_path): raise error.TestFail("Prepare directory storage pool for " "virt-v2v failed.") elif pool_type == "partition": if not create_partition_pool(lsp, pool_name, block_device, target_path): raise error.TestFail("Prepare partition storage pool for " "virt-v2v failed.") elif pool_type == "lvm": if not create_lvm_pool(lsp, pool_name, block_device, vg_name, target_path): raise error.TestFail("Prepare lvm storage pool for " "virt-v2v failed.") elif pool_type == "disk": if not create_disk_pool(lsp, pool_name, block_device, target_path): raise error.TestFail("Prepare disk storage pool for " "virt-v2v failed.") # Maintain a single params for v2v to avoid duplicate parameters v2v_params = { "hostname": remote_hostname, "username": username, "password": password, "hypervisor": remote_hypervisor, "storage": pool_name, "network": network, "target": "libvirtxml", "vms": tmp_xml_file, "input": input, "files": files } try: result = utils_v2v.v2v_cmd(v2v_params) logging.debug(result) except error.CmdError, detail: raise error.TestFail("Virt v2v failed:\n%s" % str(detail)) # v2v may be successful, but devices' driver may be not virtio error_info = [] # Check v2v vm on local host # Update parameters for local hypervisor and vm params['vms'] = vm_name params['target'] = "libvirt" vm_check = utils_v2v.LinuxVMCheck(test, params, env) try: if not vm_check.is_disk_virtio(): error_info.append("Error:disk type was not converted to " "virtio.") if not vm_check.is_net_virtio(): error_info.append("Error:nic type was not converted to " "virtio.") except (remote.LoginError, virt_vm.VMError), detail: error_info.append(str(detail))
def run_convert_remote_vm(test, params, env): """ Convert a remote vm to local libvirt(KVM). """ # VM info vm_name = params.get("v2v_vm") # Remote host parameters remote_hostname = params.get("remote_hostname") username = params.get("username", "root") password = params.get("password") remote_hypervisor = params.get("remote_hypervisor") # Local pool parameters pool_type = params.get("pool_type", "dir") pool_name = params.get("pool_name", "v2v_test") target_path = params.get("target_path", "pool_path") block_device = params.get("block_device", "/dev/BLOCK/EXAMPLE") vg_name = params.get("volume_group_name", "vg_v2v") # Confirm parameters have been set correctly. if (pool_type in ['partition', 'lvm'] and re.search("EXAMPLE", block_device)): raise error.TestNAError("Please set correct block device.") # If target_path is not an abs path, join it to data_dir.tmpdir if os.path.dirname(target_path) is "": target_path = os.path.join(data_dir.get_tmp_dir(), target_path) # dir pool need an exist path if pool_type == "dir": if not os.path.exists(target_path): os.mkdir(target_path) # V2V parameters input = params.get("input_method") files = params.get("config_files") network = params.get("network", "default") # Result check about ignore_virtio = "yes" == params.get("ignore_virtio", "no") # Create autologin to remote host esx_netrc = params.get("esx_netrc") % (remote_hostname, username, password) params['netrc'] = esx_netrc if remote_hypervisor == "esx": utils_v2v.build_esx_no_verify(params) else: ssh_key.setup_ssh_key(remote_hostname, user=username, port=22, password=password) # Create remote uri for remote host # Remote virt-v2v uri's instance ruri = utils_v2v.Uri(remote_hypervisor) remote_uri = ruri.get_uri(remote_hostname) # Check remote vms rvirsh_dargs = { 'uri': remote_uri, 'remote_ip': remote_hostname, 'remote_user': username, 'remote_pwd': password } rvirsh = virsh.VirshPersistent(**rvirsh_dargs) if not rvirsh.domain_exists(vm_name): rvirsh.close_session() raise error.TestFail("Couldn't find vm '%s' to be converted " "on remote uri '%s'." % (vm_name, remote_uri)) if remote_hypervisor != "esx": remote_vm = libvirt_vm.VM(vm_name, params, test.bindir, env.get("address_cache")) remote_vm.connect_uri = remote_uri # Remote storage pool's instance rsp = libvirt_storage.StoragePool(rvirsh) # Put remote vm's disk into a directory storage pool prepare_remote_sp(rsp, remote_vm, pool_name) # Local storage pool's instance lsp = libvirt_storage.StoragePool() try: # Create storage pool for test if pool_type == "dir": if not create_dir_pool(lsp, pool_name, target_path): raise error.TestFail("Prepare directory storage pool for " "virt-v2v failed.") elif pool_type == "partition": if not create_partition_pool(lsp, pool_name, block_device, target_path): raise error.TestFail("Prepare partition storage pool for " "virt-v2v failed.") elif pool_type == "lvm": if not create_lvm_pool(lsp, pool_name, block_device, vg_name, target_path): raise error.TestFail("Preapre lvm storage pool for " "virt-v2v failed.") # Maintain a single params for v2v to avoid duplicate parameters v2v_params = { "hostname": remote_hostname, "username": username, "password": password, "hypervisor": remote_hypervisor, "storage": pool_name, "network": network, "target": "libvirt", "vms": vm_name, "netrc": esx_netrc, "input": input, "files": files } try: result = utils_v2v.v2v_cmd(v2v_params) logging.debug(result) except error.CmdError, detail: raise error.TestFail("Virt v2v failed:\n%s" % str(detail)) # v2v may be successful, but devices' driver may be not virtio error_info = [] # Check v2v vm on local host # Update parameters for local hypervisor and vm params['vms'] = vm_name params['target'] = "libvirt" vm_check = utils_v2v.LinuxVMCheck(test, params, env) try: if not vm_check.is_disk_virtio(): error_info.append("Error:disk type was not converted to " "virtio.") if not vm_check.is_net_virtio(): error_info.append("Error:nic type was not converted to " "virtio.") except (remote.LoginError, virt_vm.VMError), detail: error_info.append(str(detail))
def run_convert_remote_vm(test, params, env): """ Convert a remote vm to local libvirt(KVM). """ # VM info vm_name = params.get("v2v_vm") # Remote host parameters remote_hostname = params.get("remote_hostname") username = params.get("username", "root") password = params.get("password") remote_hypervisor = params.get("remote_hypervisor") # Local pool parameters pool_type = params.get("pool_type", "dir") pool_name = params.get("pool_name", "v2v_test") target_path = params.get("target_path", "pool_path") block_device = params.get("block_device") vg_name = params.get("volume_group_name", "vg_v2v") # If target_path is not an abs path, join it to test.tmpdir if os.path.dirname(target_path) is "": target_path = os.path.join(test.tmpdir, target_path) # dir pool need an exist path if pool_type == "dir": if not os.path.exists(target_path): os.mkdir(target_path) # V2V parameters input = params.get("input_method") files = params.get("config_files") network = params.get("network", "default") # Result check about ignore_virtio = "yes" == params.get("ignore_virtio", "no") # Create remote uri for remote host # Remote virt-v2v uri's instance ruri = utils_v2v.Uri(remote_hypervisor) remote_uri = ruri.get_uri(remote_hostname) ssh_key.setup_ssh_key(remote_hostname, user=username, port=22, password=password) # Check remote vms remote_vm = libvirt_vm.VM(vm_name, params, test.bindir, env.get("address_cache")) remote_vm.connect_uri = remote_uri if not remote_vm.exists(): raise error.TestFail("Couldn't find vm '%s' to be converted " "on remote uri '%s'." % (vm_name, remote_uri)) # Remote storage pool's instance rsp = libvirt_storage.StoragePool(remote_uri) # Put remote vm's disk into a directory storage pool prepare_remote_sp(rsp, remote_vm, pool_name) # Local storage pool's instance lsp = libvirt_storage.StoragePool() try: # Create storage pool for test if pool_type == "dir": if not create_dir_pool(lsp, pool_name, target_path): raise error.TestFail("Prepare directory storage pool for " "virt-v2v failed.") elif pool_type == "partition": if not create_partition_pool(lsp, pool_name, block_device, target_path): raise error.TestFail("Prepare partition storage pool for " "virt-v2v failed.") elif pool_type == "lvm": if not create_lvm_pool(lsp, pool_name, block_device, vg_name, target_path): raise error.TestFail("Preapre lvm storage pool for " "virt-v2v failed.") # Maintain a single params for v2v to avoid duplicate parameters v2v_params = { "hostname": remote_hostname, "username": username, "password": password, "hypervisor": remote_hypervisor, "storage": pool_name, "network": network, "target": "libvirt", "vms": vm_name, "input": input, "files": files } try: result = utils_v2v.v2v_cmd(v2v_params) except error.CmdError: raise error.TestFail("Virt v2v failed.") # v2v may be successful, but devices' driver may be not virtio error_info = [] # Check v2v vm on local host # Update parameters for local hypervisor and vm params['vms'] = vm_name params['target'] = "libvirt" vm_check = utils_v2v.LinuxVMCheck(test, params, env) if not vm_check.is_disk_virtio(): error_info.append("Error:disk type was not converted to virtio.") if not vm_check.is_net_virtio(): error_info.append("Error:nic type was not converted to virtio.") # Close vm for cleanup if vm_check.vm is not None and vm_check.vm.is_alive(): vm_check.vm.destroy() if not ignore_virtio and len(error_info): raise error.TestFail(error_info) finally: cleanup_vm(vm_name) lsp.delete_pool(pool_name) rsp.delete_pool(pool_name)
def run(test, params, env): """ Convert a remote vm to local libvirt(KVM). """ # VM info xen_vm_name = params.get("v2v_xen_vm") vmware_vm_name = params.get("v2v_vmware_vm") # Remote host parameters xen_ip = params.get("remote_xen_ip", "XEN.EXAMPLE") vmware_ip = params.get("remote_vmware_ip", "VMWARE.EXAMPLE") username = params.get("username", "root") xen_pwd = params.get("remote_xen_pwd", "PWD.EXAMPLE") vmware_pwd = params.get("remote_vmware_pwd", "PWD.EXAMPLE") # To decide which type test it is remote_hypervisor = params.get("remote_hypervisor") # Local pool parameters pool_type = params.get("pool_type", "dir") pool_name = params.get("pool_name", "v2v_test") target_path = params.get("target_path", "pool_path") emulated_img = params.get("emulated_image_path", "v2v_emulated.img") emulated_size = params.get("emulated_image_size", "10G") # If target_path is not an abs path, join it to data_dir.tmpdir if os.path.dirname(target_path) is "": target_path = os.path.join(data_dir.get_tmp_dir(), target_path) # V2V parameters input = params.get("input_method") files = params.get("config_files") network = params.get("network") bridge = params.get("bridge") # Result check about ignore_virtio = "yes" == params.get("ignore_virtio", "no") # Create autologin to remote host esx_netrc = params.get("esx_netrc") % (vmware_ip, username, vmware_pwd) params['netrc'] = esx_netrc if remote_hypervisor == "esx": remote_ip = vmware_ip remote_pwd = vmware_pwd vm_name = vmware_vm_name if remote_ip.count("EXAMPLE") or remote_pwd.count("EXAMPLE"): raise error.TestNAError("Please provide host or password for " "vmware test.") utils_v2v.build_esx_no_verify(params) else: remote_ip = xen_ip remote_pwd = xen_pwd vm_name = xen_vm_name if remote_ip.count("EXAMPLE") or remote_pwd.count("EXAMPLE"): raise error.TestNAError("Please provide host or password for " "xen test.") ssh_key.setup_ssh_key(xen_ip, user=username, port=22, password=xen_pwd) # Create remote uri for remote host # Remote virt-v2v uri's instance ruri = utils_v2v.Uri(remote_hypervisor) remote_uri = ruri.get_uri(remote_ip) # Check remote vms rvirsh_dargs = { 'uri': remote_uri, 'remote_ip': remote_ip, 'remote_user': username, 'remote_pwd': remote_pwd } rvirsh = virsh.VirshPersistent(**rvirsh_dargs) if not rvirsh.domain_exists(vm_name): rvirsh.close_session() raise error.TestFail("Couldn't find vm '%s' to be converted " "on remote uri '%s'." % (vm_name, remote_uri)) if remote_hypervisor != "esx": remote_vm = libvirt_vm.VM(vm_name, params, test.bindir, env.get("address_cache")) remote_vm.connect_uri = remote_uri # Remote storage pool's instance rsp = libvirt_storage.StoragePool(rvirsh) # Put remote vm's disk into a directory storage pool prepare_remote_sp(rsp, remote_vm, pool_name) # Prepare local libvirt storage pool pvt = utlv.PoolVolumeTest(test, params) # Local storage pool's instance lsp = libvirt_storage.StoragePool() try: # Create storage pool for test pvt.pre_pool(pool_name, pool_type, target_path, emulated_img, emulated_size) logging.debug(lsp.pool_info(pool_name)) # Maintain a single params for v2v to avoid duplicate parameters v2v_params = { "hostname": remote_ip, "username": username, "password": remote_pwd, "hypervisor": remote_hypervisor, "storage": pool_name, "network": network, "bridge": bridge, "target": "libvirt", "vms": vm_name, "netrc": esx_netrc, "input": input, "files": files } try: result = utils_v2v.v2v_cmd(v2v_params) logging.debug(result) except error.CmdError, detail: raise error.TestFail("Virt v2v failed:\n%s" % str(detail)) # v2v may be successful, but devices' driver may be not virtio error_info = [] # Check v2v vm on local host # Update parameters for local hypervisor and vm logging.debug("XML info:\n%s", virsh.dumpxml(vm_name)) params['vms'] = vm_name params['target'] = "libvirt" vm_check = utils_v2v.LinuxVMCheck(test, params, env) try: if not vm_check.is_disk_virtio(): error_info.append("Error:disk type was not converted to " "virtio.") if not vm_check.is_net_virtio(): error_info.append("Error:nic type was not converted to " "virtio.") except (remote.LoginError, virt_vm.VMError), detail: error_info.append(str(detail))