def run(test, params, env): """ Run IOzone for windows on a windows guest: 1) Log into a guest 2) Execute the IOzone test contained in the winutils.iso 3) Get results 4) Postprocess it with the IOzone postprocessing module :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) results_path = os.path.join(test.resultsdir, "raw_output_%s" % test.iteration) analysisdir = os.path.join(test.resultsdir, "analysis_%s" % test.iteration) # Run IOzone and record its results drive_letter = utils_misc.get_winutils_vol(session) c = params["iozone_cmd"] % drive_letter t = int(params.get("iozone_timeout")) logging.info("Running IOzone command on guest, timeout %ss", t) results = session.cmd_output(cmd=c, timeout=t) utils.open_write_close(results_path, results) # Postprocess the results using the IOzone postprocessing module logging.info("Iteration succeed, postprocessing") a = postprocess_iozone.IOzoneAnalyzer(list_files=[results_path], output_dir=analysisdir) a.analyze() p = postprocess_iozone.IOzonePlotter(results_file=results_path, output_dir=analysisdir) p.plot_all()
def __init__(self, params, session): label = params.get('win_utils_label', 'WIN_UTILS') drive_letter = utils_misc.get_winutils_vol(session, label) self.cmd = 'set nodosfilewarning=1 && set CYGWIN=nodosfilewarning' self.iozone_path = drive_letter + r':\Iozone\iozone.exe' self.setups = {'session_cmd': (self.cmd, 300)} self.setups_order = ['session_cmd']
def install_driver(session, operation): """ Install / Uninstall / Query driver. :param session: VM session. :param operation: Install / Uninstall / Query driver. """ driver_name = params["driver_name"] device_name = params["device_name"] driver_path = get_driver_path(session, driver_name) driver_install_cmd = params["driver_install_cmd"] driver_name = r"--driver_name %s" % driver_name device_name = "--device_name \"%s\"" % device_name operation = r"--%s" % operation vol_utils = utils_misc.get_winutils_vol(session) driver_install_cmd = re.sub("WIN_UTILS", vol_utils, driver_install_cmd) vol_utils = r"--vol_utils %s:" % vol_utils driver_path = r"--driver_path %s" % driver_path driver_install_cmd = driver_install_cmd % (operation, driver_path, driver_name, device_name, vol_utils) install_timeout = int(params.get("driver_install_timeout", 600)) session.cmd(driver_install_cmd, timeout=install_timeout)
def run(test, params, env): """ KVM reboot test: 1) Log into a guest with virtio data disk 2) Format the disk and copy file to it 3) Stop the guest and boot up it again with the data disk set to readonly 4) Try to copy file to the data disk 5) Try to copy file from the data disk :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ error.context("Try to log into guest.", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout) vols = utils_misc.get_winutils_vol(session) if not vols: raise error.TestError("Can not find winutils in guest.") filen = 0 error.context("Format the disk and copy file to it", logging.info) os_type = params["os_type"] copy_cmd = params.get("copy_cmd", "copy %s %s") disk_idx = params.get("disk_index", 1) fs_type = params.get("fstype", "ntfs") drive_letter = params.get("drive_letter", "I") disk_size = params.get("partition_size_data", "200M") src_file = params.get("src_file", "").replace("WIN_UTIL", vols) utils_misc.format_guest_disk(session, disk_idx, drive_letter, disk_size, fs_type, os_type) dst_file = drive_letter + ":\\" + str(filen) session.cmd(copy_cmd % (src_file, dst_file)) filen += 1 msg = "Stop the guest and boot up it again with the data disk" msg += " set to readonly" error.context(msg, logging.info) session.close() vm.destroy() data_img = params.get("images").split()[-1] params["image_readonly_%s" % data_img] = "yes" params["force_create_image_%s" % data_img] = "no" env_process.preprocess(test, params, env) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) try: error.context("Try to write to the readonly disk", logging.info) dst_file_readonly = drive_letter + ":\\" + str(filen) session.cmd(copy_cmd % (src_file, dst_file_readonly)) raise error.TestFail("Write in readonly disk should failed.") except aexpect.ShellCmdError: error.context("Try to read from the readonly disk", logging.info) session.cmd(copy_cmd % (dst_file, "C:\\")) session.close()
def run(test, params, env): """ Run Iometer for Windows on a Windows guest: 1) Boot guest with additional disk 2) Format the additional disk 3) Install and register Iometer 4) Perpare icf to Iometer.exe 5) Run Iometer.exe with icf 6) Copy result to host :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) # format the target disk utils_test.run_virt_sub_test(test, params, env, "format_disk") error_context.context("Install Iometer", logging.info) cmd_timeout = int(params.get("cmd_timeout", 360)) ins_cmd = params["install_cmd"] vol_utils = utils_misc.get_winutils_vol(session) if not vol_utils: raise exceptions.TestError("WIN_UTILS CDROM not found") ins_cmd = re.sub("WIN_UTILS", vol_utils, ins_cmd) session.cmd(cmd=ins_cmd, timeout=cmd_timeout) time.sleep(0.5) error_context.context("Register Iometer", logging.info) reg_cmd = params["register_cmd"] reg_cmd = re.sub("WIN_UTILS", vol_utils, reg_cmd) session.cmd_output(cmd=reg_cmd, timeout=cmd_timeout) error_context.context("Prepare icf for Iometer", logging.info) icf_name = params["icf_name"] ins_path = params["install_path"] res_file = params["result_file"] icf_file = os.path.join(data_dir.get_deps_dir(), "iometer", icf_name) vm.copy_files_to(icf_file, "%s\\%s" % (ins_path, icf_name)) # Run Iometer error_context.context("Start Iometer", logging.info) session.cmd("cd %s" % ins_path) logging.info("Change dir to: %s" % ins_path) run_cmd = params["run_cmd"] run_timeout = int(params.get("run_timeout", 1000)) logging.info("Set Timeout: %ss" % run_timeout) run_cmd = run_cmd % (icf_name, res_file) logging.info("Execute Command: %s" % run_cmd) s, o = session.cmd_status_output(cmd=run_cmd, timeout=100) error_context.context("Copy result '%s' to host" % res_file, logging.info) vm.copy_files_from(res_file, test.resultsdir) if s != 0: raise exceptions.TestFail("iometer test failed. {}".format(o))
def run(test, params, env): """ Run Iometer for Windows on a Windows guest: 1) Boot guest with additional disk 2) Format the additional disk 3) Install and register Iometer 4) Perpare icf to Iometer.exe 5) Run Iometer.exe with icf 6) Copy result to host :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) # format the target disk utils_test.run_virt_sub_test(test, params, env, "format_disk") error_context.context("Install Iometer", logging.info) cmd_timeout = int(params.get("cmd_timeout", 360)) ins_cmd = params["install_cmd"] vol_utils = utils_misc.get_winutils_vol(session) if not vol_utils: raise exceptions.TestError("WIN_UTILS CDROM not found") ins_cmd = re.sub("WIN_UTILS", vol_utils, ins_cmd) session.cmd(cmd=ins_cmd, timeout=cmd_timeout) time.sleep(0.5) error_context.context("Register Iometer", logging.info) reg_cmd = params["register_cmd"] reg_cmd = re.sub("WIN_UTILS", vol_utils, reg_cmd) session.cmd_output(cmd=reg_cmd, timeout=cmd_timeout) error_context.context("Prepare icf for Iometer", logging.info) icf_name = params["icf_name"] ins_path = params["install_path"] res_file = params["result_file"] icf_file = os.path.join(data_dir.get_deps_dir(), "iometer", icf_name) vm.copy_files_to(icf_file, "%s\\%s" % (ins_path, icf_name)) # Run Iometer error_context.context("Start Iometer", logging.info) session.cmd("cd %s" % ins_path) logging.info("Change dir to: %s" % ins_path) run_cmd = params["run_cmd"] run_timeout = int(params.get("run_timeout", 1000)) logging.info("Set Timeout: %ss" % run_timeout) run_cmd = run_cmd % (icf_name, res_file) logging.info("Execute Command: %s" % run_cmd) s, o = session.cmd_status_output(cmd=run_cmd, timeout=run_timeout) error_context.context("Copy result '%s' to host" % res_file, logging.info) vm.copy_files_from(res_file, test.resultsdir) if s != 0: raise exceptions.TestFail("iometer test failed. {}".format(o))
def run(test, params, env): """ KVM guest stop test: 1) Log into a guest 2) Check is fio.msi installed, install it if not installed. 3) Start fio test on both sys and data disk in guest 4) Get the result :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ install_path = params["install_path"].rstrip("\\") fio_log_file = params.get("fio_log_file") fio_cmd = params.get("fio_cmd") timeout = float(params.get("login_timeout", 360)) cmd_timeout = int(params.get("cmd_timeout", "360")) check_installed_cmd = 'dir "%s"|findstr /I fio' % install_path check_installed_cmd = params.get("check_installed_cmd", check_installed_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) if not params.get('image_backend') == 'nvme_direct': error_context.context("Format disk", logging.info) utils_misc.format_windows_disk(session, params["disk_index"], mountpoint=params["disk_letter"]) try: installed = session.cmd_status(check_installed_cmd) == 0 if not installed: dst = r"%s:\\" % utils_misc.get_winutils_vol(session) error_context.context("Install fio in guest", logging.info) install_cmd = params["install_cmd"] install_cmd = re.sub(r"DRIVE:\\+", dst, install_cmd) session.cmd(install_cmd, timeout=180) time.sleep(30) config_cmd = params.get("config_cmd") if config_cmd: session.cmd(config_cmd) error_context.context("Start fio in guest.", logging.info) status, output = session.cmd_status_output(fio_cmd, timeout=(cmd_timeout * 2)) if status: test.error("Failed to run fio, output: %s" % output) finally: error_context.context("Copy fio log from guest to host.", logging.info) try: vm.copy_files_from(fio_log_file, test.resultsdir) except Exception as err: logging.warn("Log file copy failed: %s", err) if session: session.close()
def launch_client(sessions, servers, server_ctl, clients, l, nf_args, port, params): """ Launch netperf clients """ # Start netserver error.context("Start Netserver on guest", logging.info) remote_dir = params.get("remote_dir", "/var/tmp") client_path = os.path.join(remote_dir, "netperf-2.6.0/src/netperf") server_path = os.path.join(remote_dir, "netperf-2.6.0/src/netserver") if params.get("os_type") == "windows": winutils_vol = utils_misc.get_winutils_vol(server_ctl) client_path = "%s:\\netperf" % winutils_vol netserv_start_cmd = params.get("netserv_start_cmd") % winutils_vol logging.info("Netserver start cmd is '%s'" % netserv_start_cmd) if "NETSERVER.EXE" not in server_ctl.cmd_output("tasklist"): server_ctl.cmd_output(netserv_start_cmd) o_tasklist = server_ctl.cmd_output("tasklist") if "NETSERVER.EXE" not in o_tasklist.upper(): msg = "Can not start netserver in Windows guest" raise error.TestError(msg) else: logging.info("Netserver start cmd is '%s'" % server_path) ssh_cmd(server_ctl, "pidof netserver || %s" % server_path) logging.info("Netserver start successfully") # start netperf error.context("Start netperf client threads", logging.info) client_threads = [] for client in clients: test_timeout = len(clients) * l server = servers[clients.index(client) % len(servers)] netperf_cmd = "%s -H %s -l %s %s" % (client_path, server, int(l), nf_args) client_threads.append([ssh_cmd, (client, netperf_cmd, test_timeout)]) result_info = utils_misc.parallel(client_threads) counts = 5 for server in servers: if not re.findall("TEST.*to %s" % server, str(result_info)): raise error.TestError("Nerperf stress on nic %s failed" % server) logging.info("Network stress on %s successfully" % server) status, output = utils_test.ping(server, counts, timeout=float(counts) * 1.5) if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output) package_lost = utils_test.get_loss_ratio(output) if package_lost != 0: raise error.TestFail("%s packeage lost when ping server ip %s " % (package_lost, server))
def set_winutils_letter(cmd, session, params): """ Replace 'X:' in command to real cdrom drive letter. """ vol = "X:" if params["os_type"] != "linux": vol = utils_misc.get_winutils_vol(session) vol = "%s:" % vol return cmd.replace("X:", vol)
def heavyload_install(): if session.cmd_status(test_installed_cmd) != 0: logging.warning("Could not find installed heavyload in guest, will" " install it via winutils.iso ") winutil_drive = utils_misc.get_winutils_vol(session) if not winutil_drive: test.cancel("WIN_UTILS CDROM not found.") install_cmd = params["install_cmd"] % winutil_drive session.cmd(install_cmd)
def run(test, params, env): """ KVM guest stop test: 1) Log into a guest 2) Check is fio.msi installed, install it if not installed. 3) Start fio test on both sys and data disk in guest 4) Get the result :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ install_path = params["install_path"].rstrip("\\") fio_log_file = params.get("fio_log_file") fio_cmd = params.get("fio_cmd") timeout = float(params.get("login_timeout", 360)) cmd_timeout = int(params.get("cmd_timeout", "360")) check_installed_cmd = 'dir "%s"|findstr /I fio' % install_path check_installed_cmd = params.get("check_installed_cmd", check_installed_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) error_context.context("Format disk", logging.info) utils_misc.format_windows_disk(session, params["disk_index"], mountpoint=params["disk_letter"]) try: installed = session.cmd_status(check_installed_cmd) == 0 if not installed: dst = r"%s:\\" % utils_misc.get_winutils_vol(session) error_context.context("Install fio in guest", logging.info) install_cmd = params["install_cmd"] install_cmd = re.sub(r"DRIVE:\\+", dst, install_cmd) session.cmd(install_cmd, timeout=180) time.sleep(30) config_cmd = params.get("config_cmd") if config_cmd: session.cmd(config_cmd) error_context.context("Start fio in guest.", logging.info) status, output = session.cmd_status_output(fio_cmd, timeout=(cmd_timeout*2)) if status: test.error("Failed to run fio, output: %s" % output) finally: error_context.context("Copy fio log from guest to host.", logging.info) try: vm.copy_files_from(fio_log_file, test.resultsdir) except Exception as err: logging.warn("Log file copy failed: %s" % err) if session: session.close()
def __init__(self, params, session): label = params.get('win_utils_label', 'WIN_UTILS') utils_letter = utils_misc.get_winutils_vol(session, label) arch = params.get('vm_arch_name', 'x84_64') self.fio_inst = {'x86_64': r'C:\Program Files (x86)\fio', 'i686': r'C:\Program Files\fio'} self.fio_msi = {'x86_64': r'%s:\fio-x64.msi' % utils_letter, 'i686': r'%s:\fio-x86.msi' % utils_letter} self.fio_path = r'"%s\fio\fio.exe"' % self.fio_inst[arch] self.setups = {'install': (self.fio_msi[arch], self.fio_inst[arch], 300)} self.setups_order = ['install']
def __init__(self, params, session): label = params.get('win_utils_label', 'WIN_UTILS') utils_letter = utils_misc.get_winutils_vol(session, label) arch = params.get('vm_arch_name', 'x84_64') fio_ver = params.get('fio_ver', 'fio-3.1') self.fio_inst = {'x86_64': r'C:\Program Files (x86)\fio', 'i686': r'C:\Program Files\fio'} self.fio_msi = {'x86_64': r'%s:\%s-x64.msi' % (utils_letter, fio_ver), 'i686': r'%s:\%s-x86.msi' % (utils_letter, fio_ver)} self.fio_path = r'"%s\fio\fio.exe"' % self.fio_inst[arch] install = attrgetter('install') self.setups = {install: (self.fio_msi[arch], self.fio_inst[arch], 300)} self.setup_orders = (install, )
def heavyload_install(install_path): """ Install heavyload in windows guest """ test_installed_cmd = 'dir "%s" | findstr /I heavyload' % install_path if session.cmd_status(test_installed_cmd) != 0: logging.warning("Could not find installed heavyload in guest, will" " install it via winutils.iso ") winutil_drive = utils_misc.get_winutils_vol(session) if not winutil_drive: test.cancel("WIN_UTILS CDROM not found.") install_cmd = params["install_cmd"] % winutil_drive session.cmd(install_cmd)
def run(test, params, env): """ KVM guest stop test: 1) Log into a guest 2) Check is fio.msi installed, install it if not installed. 3) Start fio in guest 4) Get the result :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ install_path = params["install_path"].rstrip("\\") log_file = params.get("log_file") fio_cmd = params.get("fio_cmd") timeout = float(params.get("login_timeout", 360)) test_timeout = int(params.get("test_timeout", "360")) check_installed_cmd = 'dir "%s"|findstr /I fio' % install_path check_installed_cmd = params.get("check_installed_cmd", check_installed_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) try: installed = session.cmd_status(check_installed_cmd) == 0 if not installed: dst = r"%s:\\" % utils_misc.get_winutils_vol(session) error_context.context("Install fio in guest", logging.info) install_cmd = params["install_cmd"] install_cmd = re.sub(r"DRIVE:\\+", dst, install_cmd) session.cmd(install_cmd, timeout=180) time.sleep(30) config_cmd = params.get("config_cmd") if config_cmd: session.cmd(config_cmd) error_context.context("Start fio in guest.", logging.info) s, o = session.cmd_status_output(fio_cmd, timeout=(test_timeout+60)) if s: raise exceptions.TestError("Failed to run fio, output: %s") % o finally: error_context.context("Copy fio log from guest to host.", logging.info) vm.copy_files_from(log_file, test.resultsdir) if session: session.close()
def run(test, params, env): """ KVM guest stop test: 1) Log into a guest 2) Check is fio.msi installed, install it if not installed. 3) Start fio in guest 4) Get the result :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ install_path = params["install_path"].rstrip("\\") log_file = params.get("log_file") fio_cmd = params.get("fio_cmd") timeout = float(params.get("login_timeout", 360)) test_timeout = int(params.get("test_timeout", "360")) check_installed_cmd = 'dir "%s"|findstr /I fio' % install_path check_installed_cmd = params.get("check_installed_cmd", check_installed_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) try: installed = session.cmd_status(check_installed_cmd) == 0 if not installed: dst = r"%s:\\" % utils_misc.get_winutils_vol(session) error_context.context("Install fio in guest", logging.info) install_cmd = params["install_cmd"] install_cmd = re.sub(r"DRIVE:\\+", dst, install_cmd) session.cmd(install_cmd, timeout=180) time.sleep(30) config_cmd = params.get("config_cmd") if config_cmd: session.cmd(config_cmd) error_context.context("Start fio in guest.", logging.info) s, o = session.cmd_status_output(fio_cmd, timeout=(test_timeout + 60)) if s: raise exceptions.TestError("Failed to run fio, output: %s") % o finally: error_context.context("Copy fio log from guest to host.", logging.info) vm.copy_files_from(log_file, test.resultsdir) if session: session.close()
def save_file(self, dst): login_timeout = int(self.params.get("login_timeout", 360)) cmd = self.params.get("sync_bin", "sync") error.context("save file('%s') md5sum in guest" % dst, logging.info) self.__create_file(dst) session = self.vm.wait_for_login(timeout=login_timeout) logging.info("sync guest data") if "X:" in cmd: vol = utils_misc.get_winutils_vol(session) cmd = cmd.replace("X:", "%s:" % vol) status, output = session.cmd_status_output(cmd) if status != 0: logging.error("Execute '%s' with failures('%s') " % (cmd, output)) return None session.close() return self.__md5sum(dst)
def get_testing_cdrom_device(session, cdrom_dev_list): """ Get the testing cdrom used for eject :param session: VM session :param cdrom_dev_list: cdrom_dev_list """ if params["os_type"] == "windows": winutil_drive = utils_misc.get_winutils_vol(session) winutil_drive = "%s:" % winutil_drive cdrom_dev_list.remove(winutil_drive) try: testing_cdrom_device = cdrom_dev_list[-1] except IndexError: raise error.TestFail("Could not find the testing cdrom device") return testing_cdrom_device
def __init__(self, params, session): label = params.get('win_utils_label', 'WIN_UTILS') utils_letter = utils_misc.get_winutils_vol(session, label) arch = params.get('vm_arch_name', 'x84_64') self.fio_inst = { 'x86_64': r'C:\Program Files (x86)\fio', 'i686': r'C:\Program Files\fio' } self.fio_msi = { 'x86_64': r'%s:\fio-x64.msi' % utils_letter, 'i686': r'%s:\fio-x86.msi' % utils_letter } self.fio_path = r'"%s\fio\fio.exe"' % self.fio_inst[arch] self.setups = { 'install': (self.fio_msi[arch], self.fio_inst[arch], 300) } self.setups_order = ['install']
def prepare_traceview_windows(session, timeout): """ First check the driver installation status, then copy traceview.exe and corresponding pdb file to drive c: for future use. :param session: a session to send command :timeout: the command execute timeout :return: the session after driver checking. """ # verify driver error_context.context( "Check if the driver is installed and " "verified", logging.info) driver_name = params.get("driver_name", "netkvm") session = utils_test.qemu.windrv_check_running_verifier( session, vm, test, driver_name, timeout) # copy traceview.exe error_context.context("Copy traceview.exe to drive C", logging.info) traceview_path_template = params.get("traceview_path_template") cd_drive = utils_misc.get_winutils_vol(session) traceview_path = traceview_path_template % cd_drive _copy_file(session, traceview_path, "c:\\") # copy Netkvm.pdb error_context.context("Find Netkvm.pdb and copy to drive C", logging.info) viowin_ltr = virtio_win.drive_letter_iso(session) if not viowin_ltr: test.error("Could not find virtio-win drive in guest") guest_name = virtio_win.product_dirname_iso(session) if not guest_name: test.error("Could not get product dirname of the vm") guest_arch = virtio_win.arch_dirname_iso(session) if not guest_arch: test.error("Could not get architecture dirname of the vm") pdb_middle_path = "%s\\%s" % (guest_name, guest_arch) pdb_find_cmd = 'dir /b /s %s\\%s.pdb | findstr "\\%s\\\\"' pdb_find_cmd %= (viowin_ltr, driver_name, pdb_middle_path) pdb_path = session.cmd(pdb_find_cmd, timeout=timeout).strip() logging.info("Found Netkvm.pdb file at '%s'", pdb_path) _copy_file(session, pdb_path, "c:\\") return session
def prepare_traceview_windows(session, timeout): """ First check the driver installation status, then copy traceview.exe and corresponding pdb file to drive c: for future use. :param session: a session to send command :timeout: the command execute timeout :return: the session after driver checking. """ # verify driver error_context.context("Check if the driver is installed and " "verified", logging.info) driver_name = params.get("driver_name", "netkvm") session = utils_test.qemu.windrv_check_running_verifier(session, vm, test, driver_name, timeout) # copy traceview.exe error_context.context("Copy traceview.exe to drive C", logging.info) traceview_path_template = params.get("traceview_path_template") cd_drive = utils_misc.get_winutils_vol(session) traceview_path = traceview_path_template % cd_drive _copy_file(session, traceview_path, "c:\\") # copy Netkvm.pdb error_context.context("Find Netkvm.pdb and copy to drive C", logging.info) viowin_ltr = virtio_win.drive_letter_iso(session) if not viowin_ltr: test.error("Could not find virtio-win drive in guest") guest_name = virtio_win.product_dirname_iso(session) if not guest_name: test.error("Could not get product dirname of the vm") guest_arch = virtio_win.arch_dirname_iso(session) if not guest_arch: test.error("Could not get architecture dirname of the vm") pdb_middle_path = "%s\\%s" % (guest_name, guest_arch) pdb_find_cmd = 'dir /b /s %s\\%s.pdb | findstr "\\%s\\\\"' pdb_find_cmd %= (viowin_ltr, driver_name, pdb_middle_path) pdb_path = session.cmd(pdb_find_cmd, timeout=timeout).strip() logging.info("Found Netkvm.pdb file at '%s'", pdb_path) _copy_file(session, pdb_path, "c:\\") return session
def get_testing_cdrom_device(vm, session, cdrom_dev_list, serial_num=None): """ Get the testing cdrom used for eject :param session: VM session :param cdrom_dev_list: cdrom_dev_list """ try: if params["os_type"] == "windows": winutil_drive = utils_misc.get_winutils_vol(session) winutil_drive = "%s:" % winutil_drive cdrom_dev_list.remove(winutil_drive) testing_cdrom_device = cdrom_dev_list[-1] else: testing_cdrom_device = get_match_cdrom(vm, session, serial_num) except IndexError: test.fail("Could not find the testing cdrom device") return testing_cdrom_device
def run_iozone_windows(test, params, env): """ Run IOzone for windows on a windows guest: 1) Log into a guest 2) Execute the IOzone test contained in the winutils.iso 3) Get results 4) Postprocess it with the IOzone postprocessing module :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) results_path = os.path.join(test.resultsdir, 'raw_output_%s' % test.iteration) analysisdir = os.path.join(test.resultsdir, 'analysis_%s' % test.iteration) # Run IOzone and record its results drive_letter = utils_misc.get_winutils_vol(session) c = params["iozone_cmd"] % drive_letter t = int(params.get("iozone_timeout")) logging.info("Running IOzone command on guest, timeout %ss", t) results = session.cmd_output(cmd=c, timeout=t) utils.open_write_close(results_path, results) # Postprocess the results using the IOzone postprocessing module logging.info("Iteration succeed, postprocessing") a = postprocess_iozone.IOzoneAnalyzer(list_files=[results_path], output_dir=analysisdir) a.analyze() p = postprocess_iozone.IOzonePlotter(results_file=results_path, output_dir=analysisdir) p.plot_all()
def install_driver(session, operation): """ Install / Uninstall / Query driver. :param session: VM session. :param operation: Install / Uninstall / Query driver. """ driver_name = params["driver_name"] device_name = params["device_name"] driver_path = get_driver_path(session, driver_name) driver_install_cmd = params["driver_install_cmd"] driver_name = r"--driver_name %s" % driver_name device_name = "--device_name \"%s\"" % device_name operation = r"--%s" % operation vol_utils = utils_misc.get_winutils_vol(session) driver_install_cmd = re.sub("WIN_UTILS", vol_utils, driver_install_cmd) vol_utils = r"--vol_utils %s:" % vol_utils driver_path = r"--driver_path %s" % driver_path driver_install_cmd = driver_install_cmd % ( operation, driver_path, driver_name, device_name, vol_utils) install_timeout = int(params.get("driver_install_timeout", 600)) session.cmd(driver_install_cmd, timeout=install_timeout)
def run(test, params, env): """ Test multi disk suport of guest, this case will: 1) Create disks image in configuration file. 2) Start the guest with those disks. 3) Checks qtree vs. test params. (Optional) 4) Create partition on those disks. 5) Get disk dev filenames in guest. 6) Format those disks in guest. 7) Copy file into / out of those disks. 8) Compare the original file and the copied file using md5 or fc comand. 9) Repeat steps 3-5 if needed. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def _add_param(name, value): """ Converts name+value to stg_params string """ if value: value = re.sub(' ', '\\ ', value) return " %s:%s " % (name, value) else: return '' def _do_post_cmd(session): cmd = params.get("post_cmd") if cmd: session.cmd_status_output(cmd) session.close() error.context("Parsing test configuration", logging.info) stg_image_num = 0 stg_params = params.get("stg_params", "") # Compatibility stg_params += _add_param("image_size", params.get("stg_image_size")) stg_params += _add_param("image_format", params.get("stg_image_format")) stg_params += _add_param("image_boot", params.get("stg_image_boot", "no")) stg_params += _add_param("drive_format", params.get("stg_drive_format")) stg_params += _add_param("drive_cache", params.get("stg_drive_cache")) if params.get("stg_assign_index") != "no": # Assume 0 and 1 are already occupied (hd0 and cdrom) stg_params += _add_param("drive_index", 'range(2,n)') param_matrix = {} stg_params = stg_params.split(' ') i = 0 while i < len(stg_params) - 1: if not stg_params[i].strip(): i += 1 continue if stg_params[i][-1] == '\\': stg_params[i] = '%s %s' % (stg_params[i][:-1], stg_params.pop(i + 1)) i += 1 rerange = [] has_name = False for i in xrange(len(stg_params)): if not stg_params[i].strip(): continue (cmd, parm) = stg_params[i].split(':', 1) if cmd == "image_name": has_name = True if _RE_RANGE1.match(parm): parm = _range(parm) if parm is False: raise error.TestError("Incorrect cfg: stg_params %s looks " "like range(..) but doesn't contain " "numbers." % cmd) param_matrix[cmd] = parm if type(parm) is str: # When we know the stg_image_num, substitute it. rerange.append(cmd) continue else: # ',' separated list of values parm = parm.split(',') j = 0 while j < len(parm) - 1: if parm[j][-1] == '\\': parm[j] = '%s,%s' % (parm[j][:-1], parm.pop(j + 1)) j += 1 param_matrix[cmd] = parm stg_image_num = max(stg_image_num, len(parm)) stg_image_num = int(params.get('stg_image_num', stg_image_num)) for cmd in rerange: param_matrix[cmd] = _range(param_matrix[cmd], stg_image_num) # param_table* are for pretty print of param_matrix param_table = [] param_table_header = ['name'] if not has_name: param_table_header.append('image_name') for _ in param_matrix: param_table_header.append(_) stg_image_name = params.get('stg_image_name', 'images/%s') for i in xrange(stg_image_num): name = "stg%d" % i params['images'] += " %s" % name param_table.append([]) param_table[-1].append(name) if not has_name: params["image_name_%s" % name] = stg_image_name % name param_table[-1].append(params.get("image_name_%s" % name)) for parm in param_matrix.iteritems(): params['%s_%s' % (parm[0], name)] = str(parm[1][i % len(parm[1])]) param_table[-1].append(params.get('%s_%s' % (parm[0], name))) if params.get("multi_disk_params_only") == 'yes': # Only print the test param_matrix and finish logging.info('Newly added disks:\n%s', utils.matrix_to_string(param_table, param_table_header)) return # Always recreate VMs and disks error.context("Start the guest with new disks", logging.info) for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) env_process.process_images(env_process.preprocess_image, test, vm_params) error.context("Start the guest with those disks", logging.info) vm = env.get_vm(params["main_vm"]) vm.create(timeout=max(10, stg_image_num), params=params) session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) n_repeat = int(params.get("n_repeat", "1")) file_system = [_.strip() for _ in params.get("file_system").split()] cmd_timeout = float(params.get("cmd_timeout", 360)) re_str = params["re_str"] black_list = params["black_list"].split() have_qtree = True out = vm.monitor.human_monitor_cmd("info qtree", debug=False) if "unknown command" in str(out): have_qtree = False if (params.get("check_guest_proc_scsi") == "yes") and have_qtree: error.context("Verifying qtree vs. test params") err = 0 qtree = qemu_qtree.QtreeContainer() qtree.parse_info_qtree(vm.monitor.info('qtree')) disks = qemu_qtree.QtreeDisksContainer(qtree.get_nodes()) (tmp1, tmp2) = disks.parse_info_block(vm.monitor.info_block()) err += tmp1 + tmp2 err += disks.generate_params() err += disks.check_disk_params(params) (tmp1, tmp2, _, _) = disks.check_guests_proc_scsi( session.cmd_output('cat /proc/scsi/scsi')) err += tmp1 + tmp2 if err: raise error.TestFail("%s errors occurred while verifying" " qtree vs. params" % err) if params.get('multi_disk_only_qtree') == 'yes': return try: cmd = params.get("clean_cmd") if cmd: session.cmd_status_output(cmd) cmd = params.get("pre_cmd") if cmd: error.context("Create partition on those disks", logging.info) s, output = session.cmd_status_output(cmd, timeout=cmd_timeout) if s != 0: raise error.TestFail("Create partition on disks failed.\n" "Output is: %s\n" % output) error.context("Get disks dev filenames in guest", logging.info) cmd = params["list_volume_command"] s, output = session.cmd_status_output(cmd, timeout=cmd_timeout) if s != 0: raise error.TestFail("List volume command failed with cmd '%s'.\n" "Output is: %s\n" % (cmd, output)) output = session.cmd_output(cmd, timeout=cmd_timeout) disks = re.findall(re_str, output) disks = map(string.strip, disks) disks.sort() logging.debug("Volume list that meet regular expressions: %s", " ".join(disks)) images = params.get("images").split() if len(disks) < len(images): logging.debug("disks: %s , images: %s", len(disks), len(images)) raise error.TestFail("Fail to list all the volumes!") if params.get("os_type") == "linux": output = session.cmd_output("mount") li = re.findall(r"^/dev/(%s)\d*" % re_str, output, re.M) if li: black_list.extend(li) else: black_list.extend(utils_misc.get_winutils_vol(session)) disks = set(disks) black_list = set(black_list) logging.info("No need to check volume '%s'", (disks & black_list)) disks = disks - black_list except Exception: _do_post_cmd(session) raise try: for i in range(n_repeat): logging.info("iterations: %s", (i + 1)) error.context("Format those disks in guest", logging.info) for disk in disks: disk = disk.strip() error.context("Preparing disk: %s..." % disk) # Random select one file system from file_system index = random.randint(0, (len(file_system) - 1)) fs = file_system[index].strip() cmd = params["format_command"] % (fs, disk) error.context("formatting test disk") session.cmd(cmd, timeout=cmd_timeout) cmd = params.get("mount_command") if cmd: cmd = cmd % (disk, disk, disk) session.cmd(cmd) error.context("Cope file into / out of those disks", logging.info) for disk in disks: disk = disk.strip() error.context("Performing I/O on disk: %s..." % disk) cmd_list = params["cmd_list"].split() for cmd_l in cmd_list: cmd = params.get(cmd_l) if cmd: session.cmd(cmd % disk, timeout=cmd_timeout) cmd = params["compare_command"] key_word = params["check_result_key_word"] output = session.cmd_output(cmd) if key_word not in output: raise error.TestFail("Files on guest os root fs and disk " "differ") if params.get("umount_command"): cmd = params.get("show_mount_cmd") output = session.cmd_output(cmd) disks = re.findall(re_str, output) disks.sort() for disk in disks: disk = disk.strip() error.context("Unmounting disk: %s..." % disk) cmd = params.get("umount_command") % (disk, disk) session.cmd(cmd) finally: cmd = params.get("show_mount_cmd") if cmd: try: output = session.cmd_output(cmd) disks = re.findall(re_str, output) disks.sort() for disk in disks: error.context("Unmounting disk: %s..." % disk) cmd = params["umount_command"] % (disk, disk) session.cmd(cmd) except Exception, err: logging.warn("Get error when cleanup, '%s'", err) _do_post_cmd(session) session.close()
def run(test, params, env): """ KVM driver load test: 1) Log into a guest 2) Get the driver device id(Windows) or module name(Linux) from guest 3) Unload/load the device driver 4) Check if the device still works properly 5) Repeat step 3-4 several times :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def load_driver(session, cmd, driver_id): if params["os_type"] == "windows": cmd = cmd.replace("DRIVER_ID", driver_id) status, output = session.cmd_status_output(cmd) if status != 0: raise error.TestFail("failed to load driver, %s" % output) if params["os_type"] == "windows": if "device(s) are enabled" not in output: raise error.TestFail("failed to load driver, %s" % output) def unload_driver(session, cmd, driver_id): if params["os_type"] == "windows": cmd = cmd.replace("DRIVER_ID", driver_id) status, output = session.cmd_status_output(cmd) if status != 0: raise error.TestFail("failed to unload driver, %s" % output) if params["os_type"] == "windows": if "device(s) disabled" not in output: raise error.TestFail("failed to unload driver, %s" % output) def check_driver(session, cmd, pattern): output = session.cmd_output(cmd) driver_id = re.findall(pattern, output) if not driver_id: raise error.TestFail("Didn't find driver info from guest %s" % output) driver_id = driver_id[0] if params["os_type"] == "windows": driver_id = "^&".join(driver_id.split("&")) return driver_id error.context("Try to log into guest.", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = float(params.get("login_timeout", 240)) # Use the last nic for send driver load/unload command nic_index = len(vm.virtnet) - 1 session = vm.wait_for_login(nic_index=nic_index, timeout=timeout) driver_id_cmd = params["driver_id_cmd"] driver_id_pattern = params["driver_id_pattern"] driver_load_cmd = params["driver_load_cmd"] driver_unload_cmd = params["driver_unload_cmd"] devcon = params.get("devcon") if devcon: error.context("Copy devcon.exe from winutils.iso to C:\\") copy_devcon_cmd = params.get("devcon") % utils_misc.get_winutils_vol(session) session.cmd(copy_devcon_cmd) for repeat in range(0, int(params.get("repeats", 1))): error.context("Unload and load the driver. Round %s" % repeat, logging.info) error.context("Get driver info from guest", logging.info) driver_id = check_driver(session, driver_id_cmd, driver_id_pattern) error.context("Unload the driver", logging.info) unload_driver(session, driver_unload_cmd, driver_id) time.sleep(5) error.context("Load the driver", logging.info) load_driver(session, driver_load_cmd, driver_id) time.sleep(5) test_after_load = params.get("test_after_load") if test_after_load: utils_test.run_virt_sub_test(test, params, env, sub_type=test_after_load)
def run(test, params, env): """ KVM guest stop test: 1) Log into a guest 2) Check is fio.msi installed, install it if not installed. 3) Start fio test on both sys and data disk in guest 4) Get the result :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ install_path = params["install_path"].rstrip("\\") fio_log_file = params.objects("fio_log_file") fio_file_name = params.objects("fio_file_name") fio_cmd_sys = params.get("fio_cmd") % (fio_file_name[0], "sys", fio_log_file[0]) fio_cmd_data = params.get("fio_cmd") % (fio_file_name[1], "data", fio_log_file[1]) timeout = float(params.get("login_timeout", 360)) cmd_timeout = int(params.get("cmd_timeout", "360")) check_installed_cmd = 'dir "%s"|findstr /I fio' % install_path check_installed_cmd = params.get("check_installed_cmd", check_installed_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session_sys = vm.wait_for_login(timeout=timeout) session_data = vm.wait_for_login(timeout=timeout) error_context.context("Format disk", logging.info) utils_misc.format_windows_disk(session_sys, params["disk_index"], mountpoint=params["disk_letter"]) try: installed = session_sys.cmd_status(check_installed_cmd) == 0 if not installed: dst = r"%s:\\" % utils_misc.get_winutils_vol(session_sys) error_context.context("Install fio in guest", logging.info) install_cmd = params["install_cmd"] install_cmd = re.sub(r"DRIVE:\\+", dst, install_cmd) session_sys.cmd(install_cmd, timeout=180) time.sleep(30) config_cmd = params.get("config_cmd") if config_cmd: session_sys.cmd(config_cmd) error_context.context("Start fio in guest.", logging.info) # FIXME:Here use the timeout=(cmd_timeout*2) # Will determine a better specific calculation later fio_thread_data = utils_misc.InterruptedThread(session_data.cmd_status_output, (fio_cmd_data, (cmd_timeout*2))) fio_thread_data.start() status_sys, output_sys = session_sys.cmd_status_output(fio_cmd_sys, timeout=(cmd_timeout*2)) status_data, output_data = fio_thread_data.join() if status_sys or status_data: test.error("Failed to run fio, output: %s\n%s" % (output_sys, output_data)) finally: error_context.context("Copy fio log from guest to host.", logging.info) try: vm.copy_files_from(fio_log_file[0], test.resultsdir) vm.copy_files_from(fio_log_file[1], test.resultsdir) except Exception, err: logging.warn("Log file copy failed: %s" % err) session_data.close() if session_sys: session_sys.close()
def run(test, params, env): """ KVM guest stop test: 1) Log into a guest 2) Check is fio.msi installed, install it if not installed. 3) Start fio test on both sys and data disk in guest 4) Get the result :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ install_path = params["install_path"].rstrip("\\") fio_log_file = params.objects("fio_log_file") fio_file_name = params.objects("fio_file_name") fio_cmd_sys = params.get("fio_cmd") % (fio_file_name[0], "sys", fio_log_file[0]) fio_cmd_data = params.get("fio_cmd") % (fio_file_name[1], "data", fio_log_file[1]) timeout = float(params.get("login_timeout", 360)) cmd_timeout = int(params.get("cmd_timeout", "360")) check_installed_cmd = 'dir "%s"|findstr /I fio' % install_path check_installed_cmd = params.get("check_installed_cmd", check_installed_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session_sys = vm.wait_for_login(timeout=timeout) session_data = vm.wait_for_login(timeout=timeout) error_context.context("Format disk", logging.info) utils_misc.format_windows_disk(session_sys, params["disk_index"], mountpoint=params["disk_letter"]) try: installed = session_sys.cmd_status(check_installed_cmd) == 0 if not installed: dst = r"%s:\\" % utils_misc.get_winutils_vol(session_sys) error_context.context("Install fio in guest", logging.info) install_cmd = params["install_cmd"] install_cmd = re.sub(r"DRIVE:\\+", dst, install_cmd) session_sys.cmd(install_cmd, timeout=180) time.sleep(30) config_cmd = params.get("config_cmd") if config_cmd: session_sys.cmd(config_cmd) error_context.context("Start fio in guest.", logging.info) # FIXME:Here use the timeout=(cmd_timeout*2) # Will determine a better specific calculation later fio_thread_data = utils_misc.InterruptedThread( session_data.cmd_status_output, (fio_cmd_data, (cmd_timeout * 2))) fio_thread_data.start() status_sys, output_sys = session_sys.cmd_status_output( fio_cmd_sys, timeout=(cmd_timeout * 2)) status_data, output_data = fio_thread_data.join() if status_sys or status_data: test.error("Failed to run fio, output: %s\n%s" % (output_sys, output_data)) finally: error_context.context("Copy fio log from guest to host.", logging.info) try: vm.copy_files_from(fio_log_file[0], test.resultsdir) vm.copy_files_from(fio_log_file[1], test.resultsdir) except Exception, err: logging.warn("Log file copy failed: %s" % err) session_data.close() if session_sys: session_sys.close()
def launch_client(sessions, server, server_ctl, host, clients, l, nf_args, port, params, server_cyg, test): """ Launch netperf clients """ netperf_version = params.get("netperf_version", "2.6.0") client_path = "/tmp/netperf-%s/src/netperf" % netperf_version server_path = "/tmp/netperf-%s/src/netserver" % netperf_version get_status_flag = params.get("get_status_in_guest", "no") == "yes" global _netserver_started # Start netserver if _netserver_started: logging.debug("Netserver already started.") else: error_context.context("Start Netserver on guest", logging.info) if params.get("os_type") == "windows": timeout = float(params.get("timeout", "240")) cdrom_drv = utils_misc.get_winutils_vol(server_ctl) if params.get("use_cygwin") == "yes": netserv_start_cmd = params.get("netserv_start_cmd") netperf_src = params.get("netperf_src") % cdrom_drv cygwin_root = params.get("cygwin_root") netserver_path = params.get("netserver_path") netperf_install_cmd = params.get("netperf_install_cmd") start_session = server_cyg logging.info("Start netserver with cygwin, cmd is: %s", netserv_start_cmd) if "netserver" not in server_ctl.cmd_output("tasklist"): netperf_pack = "netperf-%s" % params.get("netperf_version") s_check_cmd = "dir %s" % netserver_path p_check_cmd = "dir %s" % cygwin_root if not ("netserver.exe" in server_ctl.cmd(s_check_cmd) and netperf_pack in server_ctl.cmd(p_check_cmd)): error_context.context( "Install netserver in Windows guest cygwin", logging.info) cmd = "xcopy %s %s /S /I /Y" % (netperf_src, cygwin_root) server_ctl.cmd(cmd) server_cyg.cmd_output(netperf_install_cmd, timeout=timeout) if "netserver.exe" not in server_ctl.cmd(s_check_cmd): err_msg = "Install netserver cygwin failed" test.error(err_msg) logging.info( "Install netserver in cygwin successfully") else: start_session = server_ctl netserv_start_cmd = params.get("netserv_start_cmd") % cdrom_drv logging.info("Start netserver without cygwin, cmd is: %s", netserv_start_cmd) error_context.context("Start netserver on windows guest", logging.info) start_netserver_win(start_session, netserv_start_cmd, test) else: logging.info("Netserver start cmd is '%s'", server_path) netperf_base.ssh_cmd(server_ctl, "pidof netserver || %s" % server_path) ncpu = netperf_base.ssh_cmd( server_ctl, "cat /proc/cpuinfo |grep processor |wc -l") ncpu = re.findall(r"\d+", ncpu)[-1] logging.info("Netserver start successfully") def count_interrupt(name): """ Get a list of interrut number for each queue @param name: the name of interrupt, such as "virtio0-input" """ sum = 0 intr = [] stat = netperf_base.ssh_cmd(server_ctl, "grep %s /proc/interrupts" % name) for i in stat.strip().split("\n"): for cpu in range(int(ncpu)): sum += int(i.split()[cpu + 1]) intr.append(sum) sum = 0 return intr def get_state(): for i in netperf_base.ssh_cmd(server_ctl, "ifconfig").split("\n\n"): if server in i: ifname = re.findall(r"(\w+\d+)[:\s]", i)[0] path = "find /sys/devices|grep net/%s/statistics" % ifname cmd = "%s/rx_packets|xargs cat;%s/tx_packets|xargs cat;" \ "%s/rx_bytes|xargs cat;%s/tx_bytes|xargs cat" % (path, path, path, path) output = netperf_base.ssh_cmd(server_ctl, cmd).split()[-4:] nrx = int(output[0]) ntx = int(output[1]) nrxb = int(output[2]) ntxb = int(output[3]) nre = int( netperf_base.ssh_cmd( server_ctl, "grep Tcp /proc/net/snmp|tail -1").split()[12]) state_list = [ 'rx_pkts', nrx, 'tx_pkts', ntx, 'rx_byts', nrxb, 'tx_byts', ntxb, 're_pkts', nre ] try: nrx_intr = count_interrupt("virtio.-input") ntx_intr = count_interrupt("virtio.-output") sum = 0 for i in range(len(nrx_intr)): state_list.append('rx_intr_%s' % i) state_list.append(nrx_intr[i]) sum += nrx_intr[i] state_list.append('rx_intr_sum') state_list.append(sum) sum = 0 for i in range(len(ntx_intr)): state_list.append('tx_intr_%s' % i) state_list.append(ntx_intr[i]) sum += ntx_intr[i] state_list.append('tx_intr_sum') state_list.append(sum) except IndexError: ninit = count_interrupt("virtio.") state_list.append('intr') state_list.append(ninit) exits = int( netperf_base.ssh_cmd(host, "cat /sys/kernel/debug/kvm/exits")) state_list.append('exits') state_list.append(exits) return state_list def thread_cmd(params, i, numa_enable, client_s, timeout): fname = "/tmp/netperf.%s.nf" % pid option = "`command -v python python3 ` " option += "/tmp/netperf_agent.py %d %s -D 1 -H %s -l %s %s" % ( i, client_path, server, int(l) * 1.5, nf_args) option += " >> %s" % fname netperf_base.netperf_thread(params, numa_enable, client_s, option, fname) def all_clients_up(): try: content = netperf_base.ssh_cmd(clients[-1], "cat %s" % fname) except: content = "" return False if int(sessions) == len(re.findall("MIGRATE", content)): return True return False def stop_netperf_clients(): if params.get("os_type_client") == "linux": netperf_base.ssh_cmd(clients[-1], params.get("client_kill_linux"), ignore_status=True) else: netperf_base.ssh_cmd(clients[-1], params.get("client_kill_windows"), ignore_status=True) def parse_demo_result(fname, sessions): """ Process the demo result, remove the noise from head, and compute the final throughout. :param fname: result file name :param sessions: sessions' number """ fd = open(fname) lines = fd.readlines() fd.close() for i in range(1, len(lines) + 1): if "AF_INET" in lines[-i]: break nresult = i - 1 if nresult < int(sessions): test.error("We couldn't expect this parallism, expect %s get %s" % (sessions, nresult)) niteration = nresult // sessions result = 0.0 for this in lines[-sessions * niteration:]: if "Interim" in this: result += float(re.findall(r"Interim result: *(\S+)", this)[0]) result = result / niteration logging.debug("niteration: %s", niteration) return result tries = int(params.get("tries", 1)) while tries > 0: error_context.context("Start netperf client threads", logging.info) pid = str(os.getpid()) fname = "/tmp/netperf.%s.nf" % pid netperf_base.ssh_cmd(clients[-1], "rm -f %s" % fname) numa_enable = params.get("netperf_with_numa", "yes") == "yes" timeout_netperf_start = int(l) * 0.5 client_thread = threading.Thread(target=thread_cmd, kwargs={ "params": params, "i": int(sessions), "numa_enable": numa_enable, "client_s": clients[0], "timeout": timeout_netperf_start }) client_thread.start() ret = {} ret['pid'] = pid if utils_misc.wait_for(all_clients_up, timeout_netperf_start, 0.0, 0.2, "Wait until all netperf clients start to work"): logging.debug("All netperf clients start to work.") # real & effective test starts if get_status_flag: start_state = get_state() ret['mpstat'] = netperf_base.ssh_cmd( host, "mpstat 1 %d |tail -n 1" % (l - 1)) finished_result = netperf_base.ssh_cmd(clients[-1], "cat %s" % fname) # stop netperf clients stop_netperf_clients() # real & effective test ends if get_status_flag: end_state = get_state() if len(start_state) != len(end_state): msg = "Initial state not match end state:\n" msg += " start state: %s\n" % start_state msg += " end state: %s\n" % end_state logging.warn(msg) else: for i in range(len(end_state) // 2): ret[end_state[i * 2]] = (end_state[i * 2 + 1] - start_state[i * 2 + 1]) client_thread.join() error_context.context("Testing Results Treatment and Report", logging.info) f = open(fname, "w") f.write(finished_result) f.close() ret['thu'] = parse_demo_result(fname, int(sessions)) return ret break else: stop_netperf_clients() tries = tries - 1 logging.debug("left %s times", tries)
def run(test, params, env): """ Run IOzone for windows on a windows guest: 1) Log into a guest 2) Execute the IOzone test contained in the winutils.iso 3) Get results 4) Postprocess it with the IOzone postprocessing module :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def post_result(results_path, analysisdir): """ Pick results from an IOzone run, generate a series graphs :params results_path: iozone test result path :params analysisdir: output of analysis result """ a = postprocess_iozone.IOzoneAnalyzer(list_files=[results_path], output_dir=analysisdir) a.analyze() p = postprocess_iozone.IOzonePlotter(results_file=results_path, output_dir=analysisdir) p.plot_all() def get_driver(): """ Get driver name """ driver_name = params.get("driver_name", "") drive_format = params.get("drive_format") if not driver_name: if "scsi" in drive_format: driver_name = "vioscsi" elif "virtio" in drive_format: driver_name = "viostor" else: driver_name = None return driver_name timeout = int(params.get("login_timeout", 360)) iozone_timeout = int(params.get("iozone_timeout")) disk_letter = params["disk_letter"] disk_index = params.get("disk_index", "2") results_path = os.path.join(test.resultsdir, 'raw_output_%s' % test.iteration) analysisdir = os.path.join(test.resultsdir, 'analysis_%s' % test.iteration) vm = env.get_vm(params["main_vm"]) vm.verify_alive() driver_name = get_driver() if driver_name: utils_test.qemu.setup_win_driver_verifier(driver_name, vm, timeout) session = vm.wait_for_login(timeout=timeout) if params.get("format_disk", "no") == "yes": error_context.context("Format disk", logging.info) utils_misc.format_windows_disk(session, disk_index, mountpoint=disk_letter) winutils = utils_misc.get_winutils_vol(session) cmd = params["iozone_cmd"] iozone_cmd = re.sub("WIN_UTILS", winutils, cmd) error_context.context( "Running IOzone command on guest, timeout %ss" % iozone_timeout, logging.info) status, results = session.cmd_status_output(cmd=iozone_cmd, timeout=iozone_timeout) error_context.context("Write results to %s" % results_path, logging.info) if status != 0: raise exceptions.TestFail("iozone test failed: %s" % results) utils.open_write_close(results_path, results) if params.get("post_result", "no") == "yes": error_context.context("Generate graph of test result", logging.info) post_result(results_path, analysisdir)
def run(test, params, env): """ Test the RX jumbo frame function of vnics: 1) Boot the VM. 2) Change the MTU of guest nics and host taps depending on the NIC model. 3) Add the static ARP entry for guest NIC. 4) Wait for the MTU ok. 5) Verify the path MTU using ping. 6) Ping the guest with large frames. 7) Increment size ping. 8) Flood ping the guest with large frames. 9) Verify the path MTU. 10) Recover the MTU. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def get_ovs_ports(ovs): ''' get the ovs bridge all Interface list. :param ovs: Ovs bridge name ''' cmd = "ovs-vsctl list-ports %s" % ovs return process.getoutput(cmd, shell=True) netdst = params.get("netdst", "switch") host_bridges = utils_net.find_bridge_manager(netdst) if not isinstance(host_bridges, utils_net.Bridge): ovs = host_bridges host_hw_interface = get_ovs_ports(netdst) tmp_ports = re.findall(r"t[0-9]{1,}-[a-zA-Z0-9]{6}", host_hw_interface) if tmp_ports: for p in tmp_ports: process.system_output("ovs-vsctl del-port %s %s" % (netdst, p)) params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params["main_vm"]) timeout = int(params.get("login_timeout", 360)) mtu_default = 1500 mtu = params.get("mtu", "1500") def_max_icmp_size = int(mtu) - 28 max_icmp_pkt_size = int(params.get("max_icmp_pkt_size", def_max_icmp_size)) flood_time = params.get("flood_time", "300") os_type = params.get("os_type") os_variant = params.get("os_variant") vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) session_serial = vm.wait_for_serial_login(timeout=timeout) ifname = vm.get_ifname(0) guest_ip = vm.get_address(0) if guest_ip is None: test.error("Could not get the guest ip address") host_mtu_cmd = "ifconfig %s mtu %s" if not isinstance(host_bridges, utils_net.Bridge): target_ifaces = set(get_ovs_ports(netdst).splitlines()) else: br_in_use = host_bridges.list_br() ifaces_in_use = host_bridges.list_iface() target_ifaces = set(ifaces_in_use) - set(br_in_use) error_context.context("Change all Bridge NICs MTU to %s" % mtu, logging.info) for iface in target_ifaces: process.run(host_mtu_cmd % (iface, mtu), shell=True) try: error_context.context("Changing the MTU of guest", logging.info) # Environment preparation mac = vm.get_mac_address(0) if os_type == "linux": ethname = utils_net.get_linux_ifname(session, mac) guest_mtu_cmd = "ifconfig %s mtu %s" % (ethname, mtu) else: connection_id = utils_net.get_windows_nic_attribute( session, "macaddress", mac, "netconnectionid") index = utils_net.get_windows_nic_attribute( session, "netconnectionid", connection_id, "index") if os_variant == "winxp": pnpdevice_id = utils_net.get_windows_nic_attribute( session, "netconnectionid", connection_id, "pnpdeviceid") cd_num = utils_misc.get_winutils_vol(session) copy_cmd = r"xcopy %s:\devcon\wxp_x86\devcon.exe c:\ " % cd_num session.cmd(copy_cmd) reg_set_mtu_pattern = params.get("reg_mtu_cmd") mtu_key_word = params.get("mtu_key", "MTU") reg_set_mtu = reg_set_mtu_pattern % (int(index), mtu_key_word, int(mtu)) guest_mtu_cmd = "%s " % reg_set_mtu session.cmd(guest_mtu_cmd) if os_type == "windows": mode = "netsh" if os_variant == "winxp": connection_id = pnpdevice_id.split("&")[-1] mode = "devcon" utils_net.restart_windows_guest_network(session_serial, connection_id, mode=mode) error_context.context("Chaning the MTU of host tap ...", logging.info) host_mtu_cmd = "ifconfig %s mtu %s" # Before change macvtap mtu, must set the base interface mtu if params.get("nettype") == "macvtap": base_if = utils_net.get_macvtap_base_iface(params.get("netdst")) process.run(host_mtu_cmd % (base_if, mtu), shell=True) process.run(host_mtu_cmd % (ifname, mtu), shell=True) error_context.context("Add a temporary static ARP entry ...", logging.info) arp_add_cmd = "arp -s %s %s -i %s" % (guest_ip, mac, ifname) process.run(arp_add_cmd, shell=True) def is_mtu_ok(): status, _ = utils_test.ping(guest_ip, 1, packetsize=max_icmp_pkt_size, hint="do", timeout=2) return status == 0 def verify_mtu(): logging.info("Verify the path MTU") status, output = utils_test.ping(guest_ip, 10, packetsize=max_icmp_pkt_size, hint="do", timeout=15) if status != 0: logging.error(output) test.fail("Path MTU is not as expected") if utils_test.get_loss_ratio(output) != 0: logging.error(output) test.fail("Packet loss ratio during MTU " "verification is not zero") def flood_ping(): logging.info("Flood with large frames") utils_test.ping(guest_ip, packetsize=max_icmp_pkt_size, flood=True, timeout=float(flood_time)) def large_frame_ping(count=100): logging.info("Large frame ping") _, output = utils_test.ping(guest_ip, count, packetsize=max_icmp_pkt_size, timeout=float(count) * 2) ratio = utils_test.get_loss_ratio(output) if ratio != 0: test.fail("Loss ratio of large frame ping is %s" % ratio) def size_increase_ping(step=random.randrange(90, 110)): logging.info("Size increase ping") for size in range(0, max_icmp_pkt_size + 1, step): logging.info("Ping %s with size %s", guest_ip, size) status, output = utils_test.ping(guest_ip, 1, packetsize=size, hint="do", timeout=1) if status != 0: status, output = utils_test.ping(guest_ip, 10, packetsize=size, adaptive=True, hint="do", timeout=20) fail_ratio = int(params.get("fail_ratio", 50)) if utils_test.get_loss_ratio(output) > fail_ratio: test.fail("Ping loss ratio is greater " "than 50% for size %s" % size) logging.info("Waiting for the MTU to be OK") wait_mtu_ok = 10 if not utils_misc.wait_for(is_mtu_ok, wait_mtu_ok, 0, 1): logging.debug(process.getoutput("ifconfig -a", verbose=False, ignore_status=True, shell=True)) test.error("MTU is not as expected even after %s " "seconds" % wait_mtu_ok) # Functional Test error_context.context("Checking whether MTU change is ok", logging.info) verify_mtu() large_frame_ping() size_increase_ping() # Stress test flood_ping() verify_mtu() finally: # Environment clean if session: session.close() grep_cmd = "grep '%s.*%s' /proc/net/arp" % (guest_ip, ifname) if process.system(grep_cmd, shell=True) == '0': process.run("arp -d %s -i %s" % (guest_ip, ifname), shell=True) logging.info("Removing the temporary ARP entry successfully") logging.info("Change back Bridge NICs MTU to %s" % mtu_default) for iface in target_ifaces: process.run(host_mtu_cmd % (iface, mtu_default), shell=True)
def run_mac_change(test, params, env): """ Change MAC address of guest. 1) Get a new mac from pool, and the old mac addr of guest. 2) Set new mac in guest and regain new IP. 3) Re-log into guest with new MAC. @param test: QEMU test object. @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session_serial = vm.wait_for_serial_login(timeout=timeout) # This session will be used to assess whether the IP change worked session = vm.wait_for_login(timeout=timeout) old_mac = vm.get_mac_address(0) while True: vm.virtnet.free_mac_address(0) new_mac = vm.virtnet.generate_mac_address(0) if old_mac != new_mac: break os_type = params.get("os_type") os_variant = params.get("os_variant") change_cmd_pattern = params.get("change_cmd") logging.info("The initial MAC address is %s", old_mac) if os_type == "linux": interface = utils_net.get_linux_ifname(session_serial, old_mac) if params.get("shutdown_int", "yes") == "yes": int_shutdown_cmd = params.get("int_shutdown_cmd", "ifconfig %s down") session_serial.cmd(int_shutdown_cmd % interface) else: connection_id = utils_net.get_windows_nic_attribute( session, "macaddress", old_mac, "netconnectionid") nic_index = utils_net.get_windows_nic_attribute( session, "netconnectionid", connection_id, "index") if os_variant == "winxp": pnpdevice_id = utils_net.get_windows_nic_attribute( session, "netconnectionid", connection_id, "pnpdeviceid") cd_drive = utils_misc.get_winutils_vol(session) copy_cmd = r"xcopy %s:\devcon\wxp_x86\devcon.exe c:\ " % cd_drive session.cmd(copy_cmd) # Start change MAC address error.context("Changing MAC address to %s" % new_mac, logging.info) if os_type == "linux": change_cmd = change_cmd_pattern % (interface, new_mac) else: change_cmd = change_cmd_pattern % (int(nic_index), "".join( new_mac.split(":"))) try: session_serial.cmd(change_cmd) # Verify whether MAC address was changed to the new one error.context("Verify the new mac address, and restart the network", logging.info) if os_type == "linux": if params.get("shutdown_int", "yes") == "yes": int_activate_cmd = params.get("int_activate_cmd", "ifconfig %s up") session_serial.cmd(int_activate_cmd % interface) session_serial.cmd("ifconfig | grep -i %s" % new_mac) logging.info("Mac address change successfully, net restart...") dhclient_cmd = "dhclient -r && dhclient %s" % interface session_serial.sendline(dhclient_cmd) else: mode = "netsh" if os_variant == "winxp": connection_id = pnpdevice_id.split("&")[-1] mode = "devcon" utils_net.restart_windows_guest_network(session_serial, connection_id, mode=mode) o = session_serial.cmd("ipconfig /all") if not re.findall("%s" % "-".join(new_mac.split(":")), o, re.I): raise error.TestFail("Guest mac change failed") logging.info("Guest mac have been modified successfully") # Re-log into the guest after changing mac address if utils_misc.wait_for(session.is_responsive, 120, 20, 3): # Just warning when failed to see the session become dead, # because there is a little chance the ip does not change. logging.warn("The session is still responsive, settings may fail.") session.close() # Re-log into guest and check if session is responsive error.context("Re-log into the guest", logging.info) session = vm.wait_for_login(timeout=timeout) if not session.is_responsive(): raise error.TestFail("The new session is not responsive.") finally: if os_type == "windows": clean_cmd_pattern = params.get("clean_cmd") clean_cmd = clean_cmd_pattern % int(nic_index) session_serial.cmd(clean_cmd) utils_net.restart_windows_guest_network(session_serial, connection_id, mode=mode) nic = vm.virtnet[0] nic.mac = old_mac vm.virtnet.update_db() session.close()
def run(test, params, env): """ This Test is mainly used as subtests 1) Boot up VM 2) Uninstall driver (Optional) 3) Reboot vm (Based on step 2) 4) Update / Downgrade / Install driver 5) Reboot vm 6) Verify installed driver :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ inst_timeout = int(params.get("driver_install_timeout", INSTALL_TIMEOUT)) driver_name = params["driver_name"] device_name = params["device_name"] device_hwid = params["device_hwid"] vm = env.get_vm(params["main_vm"]) session = vm.wait_for_login() # wait for cdroms having driver installed in case that # they are new appeared in this test utils_misc.wait_for(lambda: utils_misc.get_winutils_vol(session), timeout=OPERATION_TIMEOUT, step=10) devcon_path = utils_misc.set_winutils_letter(session, params["devcon_path"]) status, output = session.cmd_status_output("dir %s" % devcon_path, timeout=OPERATION_TIMEOUT) if status: test.error("Not found devcon.exe, details: %s" % output) media_type = params["virtio_win_media_type"] try: get_drive_letter = getattr(virtio_win, "drive_letter_%s" % media_type) get_product_dirname = getattr(virtio_win, "product_dirname_%s" % media_type) get_arch_dirname = getattr(virtio_win, "arch_dirname_%s" % media_type) except AttributeError: test.error("Not supported virtio win media type '%s'", media_type) viowin_ltr = get_drive_letter(session) if not viowin_ltr: test.error("Could not find virtio-win drive in guest") guest_name = get_product_dirname(session) if not guest_name: test.error("Could not get product dirname of the vm") guest_arch = get_arch_dirname(session) if not guest_arch: test.error("Could not get architecture dirname of the vm") inf_middle_path = ("{name}\\{arch}" if media_type == "iso" else "{arch}\\{name}").format(name=guest_name, arch=guest_arch) inf_find_cmd = 'dir /b /s %s\\%s.inf | findstr "\\%s\\\\"' inf_find_cmd %= (viowin_ltr, driver_name, inf_middle_path) inf_path = session.cmd(inf_find_cmd, timeout=OPERATION_TIMEOUT).strip() logging.info("Found inf file '%s'", inf_path) expected_ver = session.cmd("findstr DriverVer= %s" % inf_path, timeout=OPERATION_TIMEOUT) expected_ver = expected_ver.strip().split(",", 1)[-1] if not expected_ver: test.error("Failed to find driver version from inf file") logging.info("Target version is '%s'", expected_ver) if params.get("need_uninstall", "no") == "yes": error_context.context("Uninstalling previous installed driver", logging.info) for inf_name in _pnpdrv_info(session, device_name, ["InfName"]): uninst_store_cmd = "pnputil /f /d %s" % inf_name status, output = session.cmd_status_output(uninst_store_cmd, inst_timeout) if status: test.error("Failed to uninstall driver '%s' from store, " "details:\n%s" % (driver_name, output)) uninst_cmd = "%s remove %s" % (devcon_path, device_hwid) status, output = session.cmd_status_output(uninst_cmd, inst_timeout) # acceptable status: OK(0), REBOOT(1) if status > 1: test.error("Failed to uninstall driver '%s', details:\n" "%s" % (driver_name, output)) session = vm.reboot(session) error_context.context("Installing certificates", logging.info) cert_files = utils_misc.set_winutils_letter(session, params.get("cert_files", "")) cert_files = [cert.split("=", 1) for cert in cert_files.split()] for store, cert in cert_files: _chk_cert(session, cert) _add_cert(session, cert, store) error_context.context("Installing target driver", logging.info) inst_cmd = "%s updateni %s %s" % (devcon_path, inf_path, device_hwid) status, output = session.cmd_status_output(inst_cmd, inst_timeout) if status > 1: test.fail("Failed to install driver '%s', " "details:\n%s" % (driver_name, output)) error_context.context("Verifying target driver", logging.info) session = vm.reboot(session) windrv_verify_running(session, test, driver_name) ver_list = _pnpdrv_info(session, device_name, ["DriverVersion"]) if expected_ver not in ver_list: test.fail("The expected driver version is '%s', but " "found '%s'" % (expected_ver, ver_list)) session.close()
def run(test, params, env): """ KVM driver load test: 1) Log into a guest 2) Get the driver device id(Windows) or module name(Linux) from guest 3) Unload/load the device driver 4) Check if the device still works properly(Optinal) 5) Repeat step 3-4 several times :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def load_driver(session, cmd, driver_id): if params["os_type"] == "windows": cmd = cmd.replace("DRIVER_ID", driver_id) status, output = session.cmd_status_output(cmd) if status != 0: raise error.TestFail("failed to load driver, %s" % output) if params["os_type"] == "windows": if "device(s) are enabled" not in output: raise error.TestFail("failed to load driver, %s" % output) def unload_driver(session, cmd, driver_id): if params["os_type"] == "windows": cmd = cmd.replace("DRIVER_ID", driver_id) status, output = session.cmd_status_output(cmd) if status != 0: raise error.TestFail("failed to unload driver, %s" % output) if params["os_type"] == "windows": if "device(s) disabled" not in output: raise error.TestFail("failed to unload driver, %s" % output) def check_driver(session, cmd, pattern): output = session.cmd_output(cmd) driver_id = re.findall(pattern, output) if not driver_id: raise error.TestFail("Didn't find driver info from guest %s" % output) driver_id = driver_id[0] if params["os_type"] == "windows": driver_id = '^&'.join(driver_id.split('&')) return driver_id error.context("Try to log into guest.", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = float(params.get("login_timeout", 240)) # Use the last nic for send driver load/unload command nics = vm.virtnet nic_index = len(vm.virtnet) - 1 session = vm.wait_for_login(nic_index=nic_index, timeout=timeout) driver_id_cmd = params["driver_id_cmd"] driver_id_pattern = params["driver_id_pattern"] driver_load_cmd = params["driver_load_cmd"] driver_unload_cmd = params["driver_unload_cmd"] devcon = params.get("devcon") if devcon: error.context("Copy devcon.exe from winutils.iso to C:\\") copy_devcon_cmd = params.get("devcon") % \ utils_misc.get_winutils_vol(session) session.cmd(copy_devcon_cmd) for repeat in range(0, int(params.get("repeats", 1))): error.context("Unload and load the driver. Round %s" % repeat, logging.info) error.context("Get driver info from guest", logging.info) driver_id = check_driver(session, driver_id_cmd, driver_id_pattern) error.context("Unload the driver", logging.info) unload_driver(session, driver_unload_cmd, driver_id) time.sleep(5) error.context("Load the driver", logging.info) load_driver(session, driver_load_cmd, driver_id) time.sleep(5) if params.get("test_after_load"): test_after_load = params.get("test_after_load") utils_test.run_virt_sub_test(test, params, env, sub_type=test_after_load)
def run(test, params, env): """ Run IOzone for windows on a windows guest: 1) Log into a guest 2) Execute the IOzone test contained in the winutils.iso 3) Get results 4) Postprocess it with the IOzone postprocessing module :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def post_result(results_path, analysisdir): """ Pick results from an IOzone run, generate a series graphs :params results_path: iozone test result path :params analysisdir: output of analysis result """ a = postprocess_iozone.IOzoneAnalyzer(list_files=[results_path], output_dir=analysisdir) a.analyze() p = postprocess_iozone.IOzonePlotter(results_file=results_path, output_dir=analysisdir) p.plot_all() def get_driver(): """ Get driver name """ driver_name = params.get("driver_name", "") drive_format = params.get("drive_format") if not driver_name: if "scsi" in drive_format: driver_name = "vioscsi" elif "virtio" in drive_format: driver_name = "viostor" else: driver_name = None return driver_name timeout = int(params.get("login_timeout", 360)) iozone_timeout = int(params.get("iozone_timeout")) disk_letter = params["disk_letter"] disk_index = params.get("disk_index", "2") results_path = os.path.join(test.resultsdir, 'raw_output_%s' % test.iteration) analysisdir = os.path.join(test.resultsdir, 'analysis_%s' % test.iteration) vm = env.get_vm(params["main_vm"]) vm.verify_alive() driver_name = get_driver() if driver_name: utils_test.qemu.setup_win_driver_verifier(driver_name, vm, timeout) session = vm.wait_for_login(timeout=timeout) if params.get("format_disk", "no") == "yes": error_context.context("Format disk", logging.info) utils_misc.format_windows_disk(session, disk_index, mountpoint=disk_letter) winutils = utils_misc.get_winutils_vol(session) cmd = params["iozone_cmd"] iozone_cmd = re.sub("WIN_UTILS", winutils, cmd) error_context.context("Running IOzone command on guest, timeout %ss" % iozone_timeout, logging.info) status, results = session.cmd_status_output(cmd=iozone_cmd, timeout=iozone_timeout) error_context.context("Write results to %s" % results_path, logging.info) if status != 0: raise exceptions.TestFail("iozone test failed: %s" % results) utils.open_write_close(results_path, results) if params.get("post_result", "no") == "yes": error_context.context("Generate graph of test result", logging.info) post_result(results_path, analysisdir)
def run_jumbo(test, params, env): """ Test the RX jumbo frame function of vnics: 1) Boot the VM. 2) Change the MTU of guest nics and host taps depending on the NIC model. 3) Add the static ARP entry for guest NIC. 4) Wait for the MTU ok. 5) Verify the path MTU using ping. 6) Ping the guest with large frames. 7) Increment size ping. 8) Flood ping the guest with large frames. 9) Verify the path MTU. 10) Recover the MTU. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ timeout = int(params.get("login_timeout", 360)) mtu = params.get("mtu", "1500") max_icmp_pkt_size = int(mtu) - 28 flood_time = params.get("flood_time", "300") os_type = params.get("os_type") os_variant = params.get("os_variant") vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) session_serial = vm.wait_for_serial_login(timeout=timeout) ifname = vm.get_ifname(0) ip = vm.get_address(0) if ip is None: raise error.TestError("Could not get the IP address") try: error.context("Changing the MTU of guest", logging.info) # Environment preparation mac = vm.get_mac_address(0) if os_type == "linux": ethname = utils_net.get_linux_ifname(session, mac) guest_mtu_cmd = "ifconfig %s mtu %s" % (ethname, mtu) else: connection_id = utils_net.get_windows_nic_attribute(session, "macaddress", mac, "netconnectionid") index = utils_net.get_windows_nic_attribute(session, "netconnectionid", connection_id, "index") if os_variant == "winxp": pnpdevice_id = utils_net.get_windows_nic_attribute(session, "netconnectionid", connection_id, "pnpdeviceid") cd_num = utils_misc.get_winutils_vol(session) copy_cmd = r"xcopy %s:\devcon\wxp_x86\devcon.exe c:\ " % cd_num session.cmd(copy_cmd) reg_set_mtu_pattern = params.get("reg_mtu_cmd") mtu_key_word = params.get("mtu_key", "MTU") reg_set_mtu = reg_set_mtu_pattern % (int(index), mtu_key_word, int(mtu)) guest_mtu_cmd = "%s " % reg_set_mtu session.cmd(guest_mtu_cmd) if os_type == "windows": mode = "netsh" if os_variant == "winxp": connection_id = pnpdevice_id.split("&")[-1] mode = "devcon" utils_net.restart_windows_guest_network(session_serial, connection_id, mode=mode) error.context("Chaning the MTU of host tap ...", logging.info) host_mtu_cmd = "ifconfig %s mtu %s" % (ifname, mtu) utils.run(host_mtu_cmd) error.context("Add a temporary static ARP entry ...", logging.info) arp_add_cmd = "arp -s %s %s -i %s" % (ip, mac, ifname) utils.run(arp_add_cmd) def is_mtu_ok(): s, _ = utils_test.ping(ip, 1, interface=ifname, packetsize=max_icmp_pkt_size, hint="do", timeout=2) return s == 0 def verify_mtu(): logging.info("Verify the path MTU") s, o = utils_test.ping(ip, 10, interface=ifname, packetsize=max_icmp_pkt_size, hint="do", timeout=15) if s != 0: logging.error(o) raise error.TestFail("Path MTU is not as expected") if utils_test.get_loss_ratio(o) != 0: logging.error(o) raise error.TestFail("Packet loss ratio during MTU " "verification is not zero") def flood_ping(): logging.info("Flood with large frames") utils_test.ping(ip, interface=ifname, packetsize=max_icmp_pkt_size, flood=True, timeout=float(flood_time)) def large_frame_ping(count=100): logging.info("Large frame ping") _, o = utils_test.ping(ip, count, interface=ifname, packetsize=max_icmp_pkt_size, timeout=float(count) * 2) ratio = utils_test.get_loss_ratio(o) if ratio != 0: raise error.TestFail("Loss ratio of large frame ping is %s" % ratio) def size_increase_ping(step=random.randrange(90, 110)): logging.info("Size increase ping") for size in range(0, max_icmp_pkt_size + 1, step): logging.info("Ping %s with size %s", ip, size) s, o = utils_test.ping(ip, 1, interface=ifname, packetsize=size, hint="do", timeout=1) if s != 0: s, o = utils_test.ping(ip, 10, interface=ifname, packetsize=size, adaptive=True, hint="do", timeout=20) if utils_test.get_loss_ratio(o) > int(params.get( "fail_ratio", 50)): raise error.TestFail("Ping loss ratio is greater " "than 50% for size %s" % size) logging.info("Waiting for the MTU to be OK") wait_mtu_ok = 10 if not utils_misc.wait_for(is_mtu_ok, wait_mtu_ok, 0, 1): logging.debug(commands.getoutput("ifconfig -a")) raise error.TestError("MTU is not as expected even after %s " "seconds" % wait_mtu_ok) # Functional Test error.context("Checking whether MTU change is ok", logging.info) verify_mtu() large_frame_ping() size_increase_ping() # Stress test flood_ping() verify_mtu() finally: # Environment clean if session: session.close() if utils.system("grep '%s.*%s' /proc/net/arp" % (ip, ifname)) == '0': utils.run("arp -d %s -i %s" % (ip, ifname)) logging.info("Removing the temporary ARP entry successfully")
def run(test, params, env): """ Run Iometer for Windows on a Windows guest: 1) Boot guest with additional disk 2) Format the additional disk 3) Install and register Iometer 4) Perpare icf to Iometer.exe 5) Run Iometer.exe with icf 6) Copy result to host :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def install_iometer(): error_context.context("Install Iometer", logging.info) session.cmd(re.sub("WIN_UTILS", vol_utils, ins_cmd), cmd_timeout) time.sleep(0.5) def register_iometer(): error_context.context("Register Iometer", logging.info) session.cmd_output( re.sub("WIN_UTILS", vol_utils, params["register_cmd"]), cmd_timeout) def prepare_ifc_file(): error_context.context("Prepare icf for Iometer", logging.info) icf_file = os.path.join(data_dir.get_deps_dir(), "iometer", icf_name) vm.copy_files_to(icf_file, "%s\\%s" % (ins_path, icf_name)) def _run_backgroud(args): thread_session = vm.wait_for_login(timeout=360) thread = utils_misc.InterruptedThread(thread_session.cmd, args) thread.start() cmd = 'TASKLIST /FI "IMAGENAME eq Iometer.exe' if not utils_misc.wait_for( lambda: 'Iometer.exe' in session.cmd_output(cmd), 180, step=3.0): test.fail("Iometer is not alive!") def run_iometer(): error_context.context("Start Iometer", logging.info) args = ( ' && '.join((("cd %s" % ins_path), run_cmd % (icf_name, res_file))), run_timeout) if params.get('bg_mode', 'no') == 'yes': _run_backgroud(args) time.sleep(int(params.get('sleep_time', '900'))) else: session.cmd(*args) error_context.context( "Copy result '%s' to host" % res_file, logging.info) vm.copy_files_from(res_file, test.resultsdir) def change_vm_status(): method, command = params.get('command_opts').split(',') logging.info('Sending command(%s): %s' % (method, command)) if method == 'shell': session = vm.wait_for_login(timeout=360) session.sendline(command) session.close() else: getattr(vm.monitor, command)() def check_vm_status(timeout=600): action = 'shutdown' if shutdown_vm else 'login' if not getattr(vm, 'wait_for_%s' % action)(timeout=timeout): test.fail('Failed to %s vm.' % action) cmd_timeout = int(params.get("cmd_timeout", 360)) ins_cmd = params["install_cmd"] icf_name = params["icf_name"] ins_path = params["install_path"] res_file = params["result_file"] run_cmd = params["run_cmd"] run_timeout = int(params.get("run_timeout", 1000)) shutdown_vm = params.get('shutdown_vm', 'no') == 'yes' reboot_vm = params.get('reboot_vm', 'no') == 'yes' vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=360) vol_utils = utils_misc.get_winutils_vol(session) if not vol_utils: test.error("WIN_UTILS CDROM not found.") # diskpart requires windows volume INF file and volume setup # events ready, add 10s to wait events done. time.sleep(10) # format the target disk utils_test.run_virt_sub_test(test, params, env, "format_disk") install_iometer() register_iometer() prepare_ifc_file() run_iometer() if shutdown_vm or reboot_vm: change_vm_status() check_vm_status()
def run_jumbo(test, params, env): """ Test the RX jumbo frame function of vnics: 1) Boot the VM. 2) Change the MTU of guest nics and host taps depending on the NIC model. 3) Add the static ARP entry for guest NIC. 4) Wait for the MTU ok. 5) Verify the path MTU using ping. 6) Ping the guest with large frames. 7) Increment size ping. 8) Flood ping the guest with large frames. 9) Verify the path MTU. 10) Recover the MTU. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ timeout = int(params.get("login_timeout", 360)) mtu = params.get("mtu", "1500") max_icmp_pkt_size = int(mtu) - 28 flood_time = params.get("flood_time", "300") os_type = params.get("os_type") os_variant = params.get("os_variant") vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) session_serial = vm.wait_for_serial_login(timeout=timeout) ifname = vm.get_ifname(0) ip = vm.get_address(0) if ip is None: raise error.TestError("Could not get the IP address") try: error.context("Changing the MTU of guest", logging.info) # Environment preparation mac = vm.get_mac_address(0) if os_type == "linux": ethname = utils_net.get_linux_ifname(session, mac) guest_mtu_cmd = "ifconfig %s mtu %s" % (ethname, mtu) else: connection_id = utils_net.get_windows_nic_attribute( session, "macaddress", mac, "netconnectionid") index = utils_net.get_windows_nic_attribute( session, "netconnectionid", connection_id, "index") if os_variant == "winxp": pnpdevice_id = utils_net.get_windows_nic_attribute( session, "netconnectionid", connection_id, "pnpdeviceid") cd_num = utils_misc.get_winutils_vol(session) copy_cmd = r"xcopy %s:\devcon\wxp_x86\devcon.exe c:\ " % cd_num session.cmd(copy_cmd) reg_set_mtu_pattern = params.get("reg_mtu_cmd") mtu_key_word = params.get("mtu_key", "MTU") reg_set_mtu = reg_set_mtu_pattern % (int(index), mtu_key_word, int(mtu)) guest_mtu_cmd = "%s " % reg_set_mtu session.cmd(guest_mtu_cmd) if os_type == "windows": mode = "netsh" if os_variant == "winxp": connection_id = pnpdevice_id.split("&")[-1] mode = "devcon" utils_net.restart_windows_guest_network(session_serial, connection_id, mode=mode) error.context("Chaning the MTU of host tap ...", logging.info) host_mtu_cmd = "ifconfig %s mtu %s" % (ifname, mtu) utils.run(host_mtu_cmd) error.context("Add a temporary static ARP entry ...", logging.info) arp_add_cmd = "arp -s %s %s -i %s" % (ip, mac, ifname) utils.run(arp_add_cmd) def is_mtu_ok(): s, _ = utils_test.ping(ip, 1, interface=ifname, packetsize=max_icmp_pkt_size, hint="do", timeout=2) return s == 0 def verify_mtu(): logging.info("Verify the path MTU") s, o = utils_test.ping(ip, 10, interface=ifname, packetsize=max_icmp_pkt_size, hint="do", timeout=15) if s != 0: logging.error(o) raise error.TestFail("Path MTU is not as expected") if utils_test.get_loss_ratio(o) != 0: logging.error(o) raise error.TestFail("Packet loss ratio during MTU " "verification is not zero") def flood_ping(): logging.info("Flood with large frames") utils_test.ping(ip, interface=ifname, packetsize=max_icmp_pkt_size, flood=True, timeout=float(flood_time)) def large_frame_ping(count=100): logging.info("Large frame ping") _, o = utils_test.ping(ip, count, interface=ifname, packetsize=max_icmp_pkt_size, timeout=float(count) * 2) ratio = utils_test.get_loss_ratio(o) if ratio != 0: raise error.TestFail("Loss ratio of large frame ping is %s" % ratio) def size_increase_ping(step=random.randrange(90, 110)): logging.info("Size increase ping") for size in range(0, max_icmp_pkt_size + 1, step): logging.info("Ping %s with size %s", ip, size) s, o = utils_test.ping(ip, 1, interface=ifname, packetsize=size, hint="do", timeout=1) if s != 0: s, o = utils_test.ping(ip, 10, interface=ifname, packetsize=size, adaptive=True, hint="do", timeout=20) if utils_test.get_loss_ratio(o) > int( params.get("fail_ratio", 50)): raise error.TestFail("Ping loss ratio is greater " "than 50% for size %s" % size) logging.info("Waiting for the MTU to be OK") wait_mtu_ok = 10 if not utils_misc.wait_for(is_mtu_ok, wait_mtu_ok, 0, 1): logging.debug(commands.getoutput("ifconfig -a")) raise error.TestError("MTU is not as expected even after %s " "seconds" % wait_mtu_ok) # Functional Test error.context("Checking whether MTU change is ok", logging.info) verify_mtu() large_frame_ping() size_increase_ping() # Stress test flood_ping() verify_mtu() finally: # Environment clean if session: session.close() if utils.system("grep '%s.*%s' /proc/net/arp" % (ip, ifname)) == '0': utils.run("arp -d %s -i %s" % (ip, ifname)) logging.info("Removing the temporary ARP entry successfully")
def run(test, params, env): """ Run Iometer for Windows on a Windows guest: 1) Boot guest with additional disk 2) Format the additional disk 3) Install and register Iometer 4) Perpare icf to Iometer.exe 5) Run Iometer.exe with icf 6) Copy result to host :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def install_iometer(): error_context.context("Install Iometer", logging.info) session.cmd(re.sub("WIN_UTILS", vol_utils, ins_cmd), cmd_timeout) time.sleep(0.5) def register_iometer(): error_context.context("Register Iometer", logging.info) session.cmd_output( re.sub("WIN_UTILS", vol_utils, params["register_cmd"]), cmd_timeout) def prepare_ifc_file(): error_context.context("Prepare icf for Iometer", logging.info) icf_file = os.path.join(data_dir.get_deps_dir(), "iometer", icf_name) vm.copy_files_to(icf_file, "%s\\%s" % (ins_path, icf_name)) def _is_iometer_alive(): cmd = 'TASKLIST /FI "IMAGENAME eq Iometer.exe' _session = vm.wait_for_login(timeout=360) if not utils_misc.wait_for( lambda: 'Iometer.exe' in _session.cmd_output(cmd, timeout=180), 600, step=3.0): test.fail("Iometer is not alive!") _session.close() def _run_backgroud(args): thread_session = vm.wait_for_login(timeout=360) thread = utils_misc.InterruptedThread(thread_session.cmd, args) thread.start() def run_iometer(): error_context.context("Start Iometer", logging.info) args = (' && '.join((("cd %s" % ins_path), run_cmd % (icf_name, res_file))), run_timeout) if params.get('bg_mode', 'no') == 'yes': _run_backgroud(args) _is_iometer_alive() time.sleep(int(params.get('sleep_time', '180'))) _is_iometer_alive() else: session.cmd(*args) error_context.context("Copy result '%s' to host" % res_file, logging.info) vm.copy_files_from(res_file, test.resultsdir) def change_vm_status(): method, command = params.get('command_opts').split(',') logging.info('Sending command(%s): %s' % (method, command)) if method == 'shell': vm.wait_for_login(timeout=360).sendline(command) else: getattr(vm.monitor, command)() if shutdown_vm: if not utils_misc.wait_for( lambda: vm.monitor.get_event("SHUTDOWN"), 600): raise test.fail("Not received SHUTDOWN QMP event.") def check_vm_status(timeout=600): action = 'shutdown' if shutdown_vm else 'login' if not getattr(vm, 'wait_for_%s' % action)(timeout=timeout): test.fail('Failed to %s vm.' % action) cmd_timeout = int(params.get("cmd_timeout", 360)) ins_cmd = params["install_cmd"] icf_name = params["icf_name"] ins_path = params["install_path"] res_file = params["result_file"] run_cmd = params["run_cmd"] run_timeout = int(params.get("run_timeout", 1000)) shutdown_vm = params.get('shutdown_vm', 'no') == 'yes' reboot_vm = params.get('reboot_vm', 'no') == 'yes' vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=360) vol_utils = utils_misc.get_winutils_vol(session) if not vol_utils: test.error("WIN_UTILS CDROM not found.") # diskpart requires windows volume INF file and volume setup # events ready, add 10s to wait events done. time.sleep(10) # format the target disk utils_test.run_virt_sub_test(test, params, env, "format_disk") install_iometer() register_iometer() prepare_ifc_file() run_iometer() if shutdown_vm or reboot_vm: change_vm_status() check_vm_status()
def run(test, params, env): """ Test multi disk suport of guest, this case will: 1) Create disks image in configuration file. 2) Start the guest with those disks. 3) Checks qtree vs. test params. (Optional) 4) Create partition on those disks. 5) Get disk dev filenames in guest. 6) Format those disks in guest. 7) Copy file into / out of those disks. 8) Compare the original file and the copied file using md5 or fc comand. 9) Repeat steps 3-5 if needed. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def _add_param(name, value): """ Converts name+value to stg_params string """ if value: value = re.sub(' ', '\\ ', value) return " %s:%s " % (name, value) else: return '' def _do_post_cmd(session): cmd = params.get("post_cmd") if cmd: session.cmd_status_output(cmd) session.close() error_context.context("Parsing test configuration", logging.info) stg_image_num = 0 stg_params = params.get("stg_params", "") # Compatibility stg_params += _add_param("image_size", params.get("stg_image_size")) stg_params += _add_param("image_format", params.get("stg_image_format")) stg_params += _add_param("image_boot", params.get("stg_image_boot", "no")) stg_params += _add_param("drive_format", params.get("stg_drive_format")) stg_params += _add_param("drive_cache", params.get("stg_drive_cache")) if params.get("stg_assign_index") != "no": # Assume 0 and 1 are already occupied (hd0 and cdrom) stg_params += _add_param("drive_index", 'range(2,n)') param_matrix = {} stg_params = stg_params.split(' ') i = 0 while i < len(stg_params) - 1: if not stg_params[i].strip(): i += 1 continue if stg_params[i][-1] == '\\': stg_params[i] = '%s %s' % (stg_params[i][:-1], stg_params.pop(i + 1)) i += 1 rerange = [] has_name = False for i in range(len(stg_params)): if not stg_params[i].strip(): continue (cmd, parm) = stg_params[i].split(':', 1) if cmd == "image_name": has_name = True if _RE_RANGE1.match(parm): parm = _range(parm) if parm is False: test.error("Incorrect cfg: stg_params %s looks " "like range(..) but doesn't contain " "numbers." % cmd) param_matrix[cmd] = parm if type(parm) is str: # When we know the stg_image_num, substitute it. rerange.append(cmd) continue else: # ',' separated list of values parm = parm.split(',') j = 0 while j < len(parm) - 1: if parm[j][-1] == '\\': parm[j] = '%s,%s' % (parm[j][:-1], parm.pop(j + 1)) j += 1 param_matrix[cmd] = parm stg_image_num = max(stg_image_num, len(parm)) stg_image_num = int(params.get('stg_image_num', stg_image_num)) for cmd in rerange: param_matrix[cmd] = _range(param_matrix[cmd], stg_image_num) # param_table* are for pretty print of param_matrix param_table = [] param_table_header = ['name'] if not has_name: param_table_header.append('image_name') for _ in param_matrix: param_table_header.append(_) stg_image_name = params.get('stg_image_name', 'images/%s') for i in range(stg_image_num): name = "stg%d" % i params['images'] += " %s" % name param_table.append([]) param_table[-1].append(name) if not has_name: params["image_name_%s" % name] = stg_image_name % name param_table[-1].append(params.get("image_name_%s" % name)) for parm in param_matrix.items(): params['%s_%s' % (parm[0], name)] = str(parm[1][i % len(parm[1])]) param_table[-1].append(params.get('%s_%s' % (parm[0], name))) if params.get("multi_disk_params_only") == 'yes': # Only print the test param_matrix and finish logging.info('Newly added disks:\n%s', astring.tabular_output(param_table, param_table_header)) return # Always recreate VMs and disks error_context.context("Start the guest with new disks", logging.info) for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) env_process.process_images(env_process.preprocess_image, test, vm_params) error_context.context("Start the guest with those disks", logging.info) vm = env.get_vm(params["main_vm"]) vm.create(timeout=max(10, stg_image_num), params=params) login_timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=login_timeout) n_repeat = int(params.get("n_repeat", "1")) file_system = [_.strip() for _ in params["file_system"].split()] cmd_timeout = float(params.get("cmd_timeout", 360)) black_list = params["black_list"].split() drive_letters = int(params.get("drive_letters", "26")) stg_image_size = params["stg_image_size"] dd_test = params.get("dd_test", "no") pre_command = params.get("pre_command", "") labeltype = params.get("labeltype", "gpt") iozone_target_num = int(params.get('iozone_target_num', '5')) iozone_options = params.get('iozone_options') iozone_timeout = float(params.get('iozone_timeout', '7200')) have_qtree = True out = vm.monitor.human_monitor_cmd("info qtree", debug=False) if "unknown command" in str(out): have_qtree = False if (params.get("check_guest_proc_scsi") == "yes") and have_qtree: error_context.context("Verifying qtree vs. test params") err = 0 qtree = qemu_qtree.QtreeContainer() qtree.parse_info_qtree(vm.monitor.info('qtree')) disks = qemu_qtree.QtreeDisksContainer(qtree.get_nodes()) (tmp1, tmp2) = disks.parse_info_block(vm.monitor.info_block()) err += tmp1 + tmp2 err += disks.generate_params() err += disks.check_disk_params(params) (tmp1, tmp2, _, _) = disks.check_guests_proc_scsi( session.cmd_output('cat /proc/scsi/scsi')) err += tmp1 + tmp2 if err: test.fail("%s errors occurred while verifying qtree vs." " params" % err) if params.get('multi_disk_only_qtree') == 'yes': return try: err_msg = "Set disks num: %d" % stg_image_num err_msg += ", Get disks num in guest: %d" ostype = params["os_type"] if ostype == "windows": error_context.context( "Get windows disk index that to " "be formatted", logging.info) disks = utils_disk.get_windows_disks_index(session, stg_image_size) if len(disks) < stg_image_num: test.fail("Fail to list all the volumes" ", %s" % err_msg % len(disks)) if len(disks) > drive_letters: black_list.extend(utils_misc.get_winutils_vol(session)) disks = random.sample(disks, drive_letters - len(black_list)) error_context.context( "Clear readonly for all disks and online " "them in windows guest.", logging.info) if not utils_disk.update_windows_disk_attributes(session, disks): test.fail("Failed to update windows disk attributes.") dd_test = "no" else: error_context.context("Get linux disk that to be " "formatted", logging.info) disks = sorted(utils_disk.get_linux_disks(session).keys()) if len(disks) < stg_image_num: test.fail("Fail to list all the volumes" ", %s" % err_msg % len(disks)) except Exception: _do_post_cmd(session) raise try: if iozone_options: iozone = generate_instance(params, session, 'iozone') random.shuffle(disks) for i in range(n_repeat): logging.info("iterations: %s", (i + 1)) for n, disk in enumerate(disks): error_context.context("Format disk in guest: '%s'" % disk, logging.info) # Random select one file system from file_system index = random.randint(0, (len(file_system) - 1)) fstype = file_system[index].strip() partitions = utils_disk.configure_empty_disk( session, disk, stg_image_size, ostype, fstype=fstype, labeltype=labeltype) if not partitions: test.fail("Fail to format disks.") cmd_list = params["cmd_list"] for partition in partitions: orig_partition = partition if "/" not in partition: partition += ":" else: partition = partition.split("/")[-1] error_context.context( "Copy file into / out of partition:" " %s..." % partition, logging.info) for cmd_l in cmd_list.split(): cmd = params.get(cmd_l) if cmd: session.cmd(cmd % partition, timeout=cmd_timeout) cmd = params["compare_command"] key_word = params["check_result_key_word"] output = session.cmd_output(cmd) if iozone_options and n < iozone_target_num: iozone.run(iozone_options.format(orig_partition), iozone_timeout) if key_word not in output: test.fail("Files on guest os root fs and disk differ") if dd_test != "no": error_context.context( "dd test on partition: %s..." % partition, logging.info) status, output = session.cmd_status_output( dd_test % (partition, partition), timeout=cmd_timeout) if status != 0: test.fail("dd test fail: %s" % output) # When multiple SCSI disks are simulated by scsi_debug, # they could be viewed as multiple paths to the same # storage device. So need umount partition before operate # next disk, in order to avoid corrupting the filesystem # (xfs integrity checks error). if ostype == "linux" and "scsi_debug add_host" in pre_command: status, output = session.cmd_status_output( "umount /dev/%s" % partition, timeout=cmd_timeout) if status != 0: test.fail("Failed to umount partition '%s': %s" % (partition, output)) need_reboot = params.get("need_reboot", "no") need_shutdown = params.get("need_shutdown", "no") if need_reboot == "yes": error_context.context("Rebooting guest ...", logging.info) session = vm.reboot(session=session, timeout=login_timeout) if need_shutdown == "yes": error_context.context("Shutting down guest ...", logging.info) vm.graceful_shutdown(timeout=login_timeout) if vm.is_alive(): test.fail("Fail to shut down guest.") error_context.context("Start the guest again.", logging.info) vm = env.get_vm(params["main_vm"]) vm.create(params=params) session = vm.wait_for_login(timeout=login_timeout) error_context.context("Delete partitions in guest.", logging.info) for disk in disks: utils_disk.clean_partition(session, disk, ostype) finally: if iozone_options: iozone.clean() _do_post_cmd(session)
def run(test, params, env): """ Test multi disk suport of guest, this case will: 1) Create disks image in configuration file. 2) Start the guest with those disks. 3) Checks qtree vs. test params. (Optional) 4) Create partition on those disks. 5) Get disk dev filenames in guest. 6) Format those disks in guest. 7) Copy file into / out of those disks. 8) Compare the original file and the copied file using md5 or fc comand. 9) Repeat steps 3-5 if needed. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def _add_param(name, value): """ Converts name+value to stg_params string """ if value: value = re.sub(' ', '\\ ', value) return " %s:%s " % (name, value) else: return '' def _do_post_cmd(session): cmd = params.get("post_cmd") if cmd: session.cmd_status_output(cmd) session.close() error_context.context("Parsing test configuration", logging.info) stg_image_num = 0 stg_params = params.get("stg_params", "") # Compatibility stg_params += _add_param("image_size", params.get("stg_image_size")) stg_params += _add_param("image_format", params.get("stg_image_format")) stg_params += _add_param("image_boot", params.get("stg_image_boot", "no")) stg_params += _add_param("drive_format", params.get("stg_drive_format")) stg_params += _add_param("drive_cache", params.get("stg_drive_cache")) if params.get("stg_assign_index") != "no": # Assume 0 and 1 are already occupied (hd0 and cdrom) stg_params += _add_param("drive_index", 'range(2,n)') param_matrix = {} stg_params = stg_params.split(' ') i = 0 while i < len(stg_params) - 1: if not stg_params[i].strip(): i += 1 continue if stg_params[i][-1] == '\\': stg_params[i] = '%s %s' % (stg_params[i][:-1], stg_params.pop(i + 1)) i += 1 rerange = [] has_name = False for i in range(len(stg_params)): if not stg_params[i].strip(): continue (cmd, parm) = stg_params[i].split(':', 1) if cmd == "image_name": has_name = True if _RE_RANGE1.match(parm): parm = _range(parm) if parm is False: test.error("Incorrect cfg: stg_params %s looks " "like range(..) but doesn't contain " "numbers." % cmd) param_matrix[cmd] = parm if type(parm) is str: # When we know the stg_image_num, substitute it. rerange.append(cmd) continue else: # ',' separated list of values parm = parm.split(',') j = 0 while j < len(parm) - 1: if parm[j][-1] == '\\': parm[j] = '%s,%s' % (parm[j][:-1], parm.pop(j + 1)) j += 1 param_matrix[cmd] = parm stg_image_num = max(stg_image_num, len(parm)) stg_image_num = int(params.get('stg_image_num', stg_image_num)) for cmd in rerange: param_matrix[cmd] = _range(param_matrix[cmd], stg_image_num) # param_table* are for pretty print of param_matrix param_table = [] param_table_header = ['name'] if not has_name: param_table_header.append('image_name') for _ in param_matrix: param_table_header.append(_) stg_image_name = params.get('stg_image_name', 'images/%s') for i in range(stg_image_num): name = "stg%d" % i params['images'] += " %s" % name param_table.append([]) param_table[-1].append(name) if not has_name: params["image_name_%s" % name] = stg_image_name % name param_table[-1].append(params.get("image_name_%s" % name)) for parm in param_matrix.items(): params['%s_%s' % (parm[0], name)] = str(parm[1][i % len(parm[1])]) param_table[-1].append(params.get('%s_%s' % (parm[0], name))) if params.get("multi_disk_params_only") == 'yes': # Only print the test param_matrix and finish logging.info('Newly added disks:\n%s', astring.tabular_output(param_table, param_table_header)) return # Always recreate VMs and disks error_context.context("Start the guest with new disks", logging.info) for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) env_process.process_images(env_process.preprocess_image, test, vm_params) error_context.context("Start the guest with those disks", logging.info) vm = env.get_vm(params["main_vm"]) vm.create(timeout=max(10, stg_image_num), params=params) login_timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=login_timeout) n_repeat = int(params.get("n_repeat", "1")) file_system = [_.strip() for _ in params["file_system"].split()] cmd_timeout = float(params.get("cmd_timeout", 360)) black_list = params["black_list"].split() drive_letters = int(params.get("drive_letters", "26")) stg_image_size = params["stg_image_size"] dd_test = params.get("dd_test", "no") labeltype = params.get("labeltype", "gpt") have_qtree = True out = vm.monitor.human_monitor_cmd("info qtree", debug=False) if "unknown command" in str(out): have_qtree = False if (params.get("check_guest_proc_scsi") == "yes") and have_qtree: error_context.context("Verifying qtree vs. test params") err = 0 qtree = qemu_qtree.QtreeContainer() qtree.parse_info_qtree(vm.monitor.info('qtree')) disks = qemu_qtree.QtreeDisksContainer(qtree.get_nodes()) (tmp1, tmp2) = disks.parse_info_block(vm.monitor.info_block()) err += tmp1 + tmp2 err += disks.generate_params() err += disks.check_disk_params(params) (tmp1, tmp2, _, _) = disks.check_guests_proc_scsi( session.cmd_output('cat /proc/scsi/scsi')) err += tmp1 + tmp2 if err: test.fail("%s errors occurred while verifying qtree vs." " params" % err) if params.get('multi_disk_only_qtree') == 'yes': return try: err_msg = "Set disks num: %d" % stg_image_num err_msg += ", Get disks num in guest: %d" ostype = params["os_type"] if ostype == "windows": error_context.context("Get windows disk index that to " "be formatted", logging.info) disks = utils_disk.get_windows_disks_index(session, stg_image_size) if len(disks) < stg_image_num: test.fail("Fail to list all the volumes" ", %s" % err_msg % len(disks)) if len(disks) > drive_letters: black_list.extend(utils_misc.get_winutils_vol(session)) disks = random.sample(disks, drive_letters - len(black_list)) error_context.context("Clear readonly for all disks and online " "them in windows guest.", logging.info) if not utils_disk.update_windows_disk_attributes(session, disks): test.fail("Failed to update windows disk attributes.") dd_test = "no" else: error_context.context("Get linux disk that to be " "formatted", logging.info) disks = sorted(utils_disk.get_linux_disks(session).keys()) if len(disks) < stg_image_num: test.fail("Fail to list all the volumes" ", %s" % err_msg % len(disks)) except Exception: _do_post_cmd(session) raise try: for i in range(n_repeat): logging.info("iterations: %s", (i + 1)) for disk in disks: error_context.context("Format disk in guest: '%s'" % disk, logging.info) # Random select one file system from file_system index = random.randint(0, (len(file_system) - 1)) fstype = file_system[index].strip() partitions = utils_disk.configure_empty_disk( session, disk, stg_image_size, ostype, fstype=fstype, labeltype=labeltype) if not partitions: test.fail("Fail to format disks.") cmd_list = params["cmd_list"] for partition in partitions: if "/" not in partition: partition += ":" else: partition = partition.split("/")[-1] error_context.context("Copy file into / out of partition:" " %s..." % partition, logging.info) for cmd_l in cmd_list.split(): cmd = params.get(cmd_l) if cmd: session.cmd(cmd % partition, timeout=cmd_timeout) cmd = params["compare_command"] key_word = params["check_result_key_word"] output = session.cmd_output(cmd) if key_word not in output: test.fail("Files on guest os root fs and disk differ") if dd_test != "no": error_context.context("dd test on partition: %s..." % partition, logging.info) status, output = session.cmd_status_output( dd_test % (partition, partition), timeout=cmd_timeout) if status != 0: test.fail("dd test fail: %s" % output) need_reboot = params.get("need_reboot", "no") need_shutdown = params.get("need_shutdown", "no") if need_reboot == "yes": error_context.context("Rebooting guest ...", logging.info) session = vm.reboot(session=session, timeout=login_timeout) if need_shutdown == "yes": error_context.context("Shutting down guest ...", logging.info) vm.graceful_shutdown(timeout=login_timeout) if vm.is_alive(): test.fail("Fail to shut down guest.") error_context.context("Start the guest again.", logging.info) vm = env.get_vm(params["main_vm"]) vm.create(params=params) session = vm.wait_for_login(timeout=login_timeout) error_context.context("Delete partitions in guest.", logging.info) for disk in disks: utils_disk.clean_partition(session, disk, ostype) finally: _do_post_cmd(session)
error_context.context("Enable %s driver verifier" % driver_name, logging.info) try: session = utils_test.qemu.setup_win_driver_verifier( session, driver_name, vm, timeout) funcatexit.register(env, params.get("type"), utils_test.qemu.clear_win_driver_verifier, session, vm, timeout) except Exception, e: raise exceptions.TestFail(e) if params.get("format_disk", "no") == "yes": error_context.context("Format disk", logging.info) utils_misc.format_windows_disk(session, disk_index, mountpoint=disk_letter) winutils = utils_misc.get_winutils_vol(session) cmd = params["iozone_cmd"] iozone_cmd = re.sub("WIN_UTILS", winutils, cmd) error_context.context("Running IOzone command on guest, timeout %ss" % iozone_timeout, logging.info) status, results = session.cmd_status_output(cmd=iozone_cmd, timeout=iozone_timeout) error_context.context("Write results to %s" % results_path, logging.info) if status != 0: raise exceptions.TestFail("iozone test failed: %s" % results) utils.open_write_close(results_path, results) if params.get("post_result", "no") == "yes": error_context.context("Generate graph of test result", logging.info) post_result(results_path, analysisdir)
def run(test, params, env): """ Test multi disk suport of guest, this case will: 1) Create disks image in configuration file. 2) Start the guest with those disks. 3) Checks qtree vs. test params. (Optional) 4) Create partition on those disks. 5) Get disk dev filenames in guest. 6) Format those disks in guest. 7) Copy file into / out of those disks. 8) Compare the original file and the copied file using md5 or fc comand. 9) Repeat steps 3-5 if needed. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def _add_param(name, value): """ Converts name+value to stg_params string """ if value: value = re.sub(' ', '\\ ', value) return " %s:%s " % (name, value) else: return '' def _do_post_cmd(session): cmd = params.get("post_cmd") if cmd: session.cmd_status_output(cmd) session.close() def _get_disk_index(session, image_size, disk_indexs): list_disk_cmd = "echo list disk > disk && " list_disk_cmd += "echo exit >> disk && diskpart /s disk" disks = session.cmd_output(list_disk_cmd) size_type = image_size[-1] + "B" disk_size = "" if size_type == "MB": disk_size = image_size[:-1] + " MB" elif size_type == "GB" and int(image_size[:-1]) < 8: disk_size = str(int(image_size[:-1]) * 1024) + " MB" else: disk_size = image_size[:-1] + " GB" regex_str = 'Disk (\d+).*?%s.*?%s' % (disk_size, disk_size) for disk in disks.splitlines(): if disk.startswith(" Disk"): o = re.findall(regex_str, disk, re.I | re.M) if o: disk_indexs.append(o[0]) error.context("Parsing test configuration", logging.info) stg_image_num = 0 stg_params = params.get("stg_params", "") # Compatibility stg_params += _add_param("image_size", params.get("stg_image_size")) stg_params += _add_param("image_format", params.get("stg_image_format")) stg_params += _add_param("image_boot", params.get("stg_image_boot", "no")) stg_params += _add_param("drive_format", params.get("stg_drive_format")) stg_params += _add_param("drive_cache", params.get("stg_drive_cache")) if params.get("stg_assign_index") != "no": # Assume 0 and 1 are already occupied (hd0 and cdrom) stg_params += _add_param("drive_index", 'range(2,n)') param_matrix = {} stg_params = stg_params.split(' ') i = 0 while i < len(stg_params) - 1: if not stg_params[i].strip(): i += 1 continue if stg_params[i][-1] == '\\': stg_params[i] = '%s %s' % (stg_params[i][:-1], stg_params.pop(i + 1)) i += 1 rerange = [] has_name = False for i in xrange(len(stg_params)): if not stg_params[i].strip(): continue (cmd, parm) = stg_params[i].split(':', 1) if cmd == "image_name": has_name = True if _RE_RANGE1.match(parm): parm = _range(parm) if parm is False: raise error.TestError("Incorrect cfg: stg_params %s looks " "like range(..) but doesn't contain " "numbers." % cmd) param_matrix[cmd] = parm if type(parm) is str: # When we know the stg_image_num, substitute it. rerange.append(cmd) continue else: # ',' separated list of values parm = parm.split(',') j = 0 while j < len(parm) - 1: if parm[j][-1] == '\\': parm[j] = '%s,%s' % (parm[j][:-1], parm.pop(j + 1)) j += 1 param_matrix[cmd] = parm stg_image_num = max(stg_image_num, len(parm)) stg_image_num = int(params.get('stg_image_num', stg_image_num)) for cmd in rerange: param_matrix[cmd] = _range(param_matrix[cmd], stg_image_num) # param_table* are for pretty print of param_matrix param_table = [] param_table_header = ['name'] if not has_name: param_table_header.append('image_name') for _ in param_matrix: param_table_header.append(_) stg_image_name = params.get('stg_image_name', 'images/%s') for i in xrange(stg_image_num): name = "stg%d" % i params['images'] += " %s" % name param_table.append([]) param_table[-1].append(name) if not has_name: params["image_name_%s" % name] = stg_image_name % name param_table[-1].append(params.get("image_name_%s" % name)) for parm in param_matrix.iteritems(): params['%s_%s' % (parm[0], name)] = str(parm[1][i % len(parm[1])]) param_table[-1].append(params.get('%s_%s' % (parm[0], name))) if params.get("multi_disk_params_only") == 'yes': # Only print the test param_matrix and finish logging.info('Newly added disks:\n%s', utils.matrix_to_string(param_table, param_table_header)) return # Always recreate VMs and disks error.context("Start the guest with new disks", logging.info) for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) env_process.process_images(env_process.preprocess_image, test, vm_params) error.context("Start the guest with those disks", logging.info) vm = env.get_vm(params["main_vm"]) vm.create(timeout=max(10, stg_image_num), params=params) session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) n_repeat = int(params.get("n_repeat", "1")) file_system = [_.strip() for _ in params.get("file_system").split()] cmd_timeout = float(params.get("cmd_timeout", 360)) re_str = params["re_str"] black_list = params["black_list"].split() os_type = params["os_type"] stg_image_size = params.get("stg_image_size") disk_indexs = [] have_qtree = True out = vm.monitor.human_monitor_cmd("info qtree", debug=False) if "unknown command" in str(out): have_qtree = False if (params.get("check_guest_proc_scsi") == "yes") and have_qtree: error.context("Verifying qtree vs. test params") err = 0 qtree = qemu_qtree.QtreeContainer() qtree.parse_info_qtree(vm.monitor.info('qtree')) disks = qemu_qtree.QtreeDisksContainer(qtree.get_nodes()) (tmp1, tmp2) = disks.parse_info_block(vm.monitor.info_block()) err += tmp1 + tmp2 err += disks.generate_params() err += disks.check_disk_params(params) (tmp1, tmp2, _, _) = disks.check_guests_proc_scsi( session.cmd_output('cat /proc/scsi/scsi')) err += tmp1 + tmp2 if err: raise error.TestFail("%s errors occurred while verifying" " qtree vs. params" % err) if params.get('multi_disk_only_qtree') == 'yes': return try: cmd = params.get("clean_cmd") if cmd: session.cmd_status_output(cmd) if params.get("os_type") == "windows": error.context("Create partition on those disks", logging.info) # Get the disk index _get_disk_index(session, stg_image_size, disk_indexs) # Random select one file system from file_system index = random.randint(0, (len(file_system) - 1)) fs_type = file_system[index].strip() for i in xrange(stg_image_num): utils_misc.format_windows_disk(session, disk_indexs[i], None, None, fs_type) error.context("Get disks dev filenames in guest", logging.info) cmd = params["list_volume_command"] s, output = session.cmd_status_output(cmd, timeout=cmd_timeout) if s != 0: raise error.TestFail("List volume command failed with cmd '%s'.\n" "Output is: %s\n" % (cmd, output)) output = session.cmd_output(cmd, timeout=cmd_timeout) disks = re.findall(re_str, output) disks = map(string.strip, disks) disks.sort() logging.debug("Volume list that meet regular expressions: %s", " ".join(disks)) images = params.get("images").split() if len(disks) < len(images): logging.debug("disks: %s , images: %s", len(disks), len(images)) raise error.TestFail("Fail to list all the volumes!") if params.get("os_type") == "linux": output = session.cmd_output("mount") li = re.findall(r"^/dev/(%s)\d*" % re_str, output, re.M) if li: black_list.extend(li) else: black_list.extend(utils_misc.get_winutils_vol(session)) disks = set(disks) black_list = set(black_list) logging.info("No need to check volume '%s'", (disks & black_list)) disks = disks - black_list except Exception: _do_post_cmd(session) raise try: for i in range(n_repeat): logging.info("iterations: %s", (i + 1)) error.context("Format those disks in guest", logging.info) for disk in disks: disk = disk.strip() error.context("Preparing disk: %s..." % disk) # Random select one file system from file_system index = random.randint(0, (len(file_system) - 1)) fs = file_system[index].strip() cmd = params["format_command"] % (fs, disk) error.context("formatting test disk") session.cmd(cmd, timeout=cmd_timeout) cmd = params.get("mount_command") if cmd: cmd = cmd % (disk, disk, disk) session.cmd(cmd) error.context("Cope file into / out of those disks", logging.info) for disk in disks: disk = disk.strip() error.context("Performing I/O on disk: %s..." % disk) cmd_list = params["cmd_list"].split() for cmd_l in cmd_list: cmd = params.get(cmd_l) if cmd: session.cmd(cmd % disk, timeout=cmd_timeout) cmd = params["compare_command"] key_word = params["check_result_key_word"] output = session.cmd_output(cmd) if key_word not in output: raise error.TestFail("Files on guest os root fs and disk " "differ") if params.get("umount_command"): cmd = params.get("show_mount_cmd") output = session.cmd_output(cmd) disks = re.findall(re_str, output) disks.sort() for disk in disks: disk = disk.strip() error.context("Unmounting disk: %s..." % disk) cmd = params.get("umount_command") % (disk, disk) session.cmd(cmd) finally: cmd = params.get("show_mount_cmd") if cmd: try: output = session.cmd_output(cmd) disks = re.findall(re_str, output) disks.sort() for disk in disks: error.context("Unmounting disk: %s..." % disk) cmd = params["umount_command"] % (disk, disk) session.cmd(cmd) except Exception, err: logging.warn("Get error when cleanup, '%s'", err) _do_post_cmd(session) session.close()
def launch_client(sessions, server, server_ctl, host, clients, l, nf_args, port, params, server_cyg): """ Launch netperf clients """ netperf_version = params.get("netperf_version", "2.6.0") client_path = "/tmp/netperf-%s/src/netperf" % netperf_version server_path = "/tmp/netperf-%s/src/netserver" % netperf_version # Start netserver error.context("Start Netserver on guest", logging.info) if params.get("os_type") == "windows": timeout = float(params.get("timeout", "240")) cdrom_drv = utils_misc.get_winutils_vol(server_ctl) get_status_flag = False if params.get("use_cygwin") == "yes": netserv_start_cmd = params.get("netserv_start_cmd") netperf_src = params.get("netperf_src") % cdrom_drv cygwin_root = params.get("cygwin_root") netserver_path = params.get("netserver_path") netperf_install_cmd = params.get("netperf_install_cmd") start_session = server_cyg logging.info("Start netserver with cygwin, cmd is: %s" % netserv_start_cmd) if "netserver" not in server_ctl.cmd_output("tasklist"): netperf_pack = "netperf-%s" % params.get("netperf_version") s_check_cmd = "dir %s" % netserver_path p_check_cmd = "dir %s" % cygwin_root if not ("netserver.exe" in server_ctl.cmd(s_check_cmd) and netperf_pack in server_ctl.cmd(p_check_cmd)): error.context("Install netserver in Windows guest cygwin", logging.info) cmd = "xcopy %s %s /S /I /Y" % (netperf_src, cygwin_root) server_ctl.cmd(cmd) server_cyg.cmd_output(netperf_install_cmd, timeout=timeout) if "netserver.exe" not in server_ctl.cmd(s_check_cmd): err_msg = "Install netserver cygwin failed" raise error.TestNAError(err_msg) logging.info("Install netserver in cygwin successfully") else: start_session = server_ctl netserv_start_cmd = params.get("netserv_start_cmd") % cdrom_drv logging.info("Start netserver without cygwin, cmd is: %s" % netserv_start_cmd) error.context("Start netserver on windows guest", logging.info) start_netserver_win(start_session, netserv_start_cmd) else: logging.info("Netserver start cmd is '%s'" % server_path) ssh_cmd(server_ctl, "pidof netserver || %s" % server_path) get_status_flag = True ncpu = ssh_cmd(server_ctl, "cat /proc/cpuinfo |grep processor |wc -l") ncpu = re.findall(r"\d+", ncpu)[0] logging.info("Netserver start successfully") def count_interrupt(name): """ :param name: the name of interrupt, such as "virtio0-input" """ intr = 0 stat = ssh_cmd(server_ctl, "cat /proc/interrupts |grep %s" % name) stat = stat.strip().split("\n")[-1] for cpu in range(int(ncpu)): intr += int(stat.split()[cpu + 1]) return intr def get_state(): for i in ssh_cmd(server_ctl, "ifconfig").split("\n\n"): if server in i: ifname = re.findall(r"(\w+\d+)[:\s]", i)[0] path = "find /sys/devices|grep net/%s/statistics" % ifname cmd = "%s/rx_packets|xargs cat;%s/tx_packets|xargs cat;" \ "%s/rx_bytes|xargs cat;%s/tx_bytes|xargs cat" % (path, path, path, path) output = ssh_cmd(server_ctl, cmd).split()[-4:] nrx = int(output[0]) ntx = int(output[1]) nrxb = int(output[2]) ntxb = int(output[3]) nre = int(ssh_cmd(server_ctl, "grep Tcp /proc/net/snmp|tail -1" ).split()[12]) state_list = ['rx_pkts', nrx, 'tx_pkts', ntx, 'rx_byts', nrxb, 'tx_byts', ntxb, 're_pkts', nre] try: nrx_intr = count_interrupt("virtio.-input") ntx_intr = count_interrupt("virtio.-output") state_list.append('rx_intr') state_list.append(nrx_intr) state_list.append('tx_intr') state_list.append(ntx_intr) except IndexError: ninit = count_interrupt("virtio.") state_list.append('intr') state_list.append(ninit) io_exit = int(ssh_cmd(host, "cat /sys/kernel/debug/kvm/io_exits")) irq_inj = int( ssh_cmd(host, "cat /sys/kernel/debug/kvm/irq_injections")) state_list.append('io_exit') state_list.append(io_exit) state_list.append('irq_inj') state_list.append(irq_inj) return state_list def netperf_thread(i, numa_enable, client_s, timeout): cmd = "" fname = "/tmp/netperf.%s.nf" % pid if numa_enable: output = ssh_cmd(client_s, "numactl --hardware") n = int(re.findall(r"available: (\d+) nodes", output)[0]) - 1 cmd += "numactl --cpunodebind=%s --membind=%s " % (n, n) cmd += "/tmp/netperf_agent.py %d %s -D 1 -H %s -l %s %s" % (i, client_path, server, int(l) * 1.5, nf_args) cmd += " >> %s" % fname logging.info("Start netperf thread by cmd '%s'" % cmd) ssh_cmd(client_s, cmd, timeout) logging.info("Netperf thread completed successfully") def all_clients_up(): try: content = ssh_cmd(clients[-1], "cat %s" % fname) except: content = "" return False if int(sessions) == len(re.findall("MIGRATE", content)): return True return False def parse_demo_result(fname, sessions): """ Process the demo result, remove the noise from head, and compute the final throughout. :param fname: result file name :param sessions: sessions' number """ fd = open(fname) lines = fd.readlines() fd.close() for i in range(1, len(lines) + 1): if "AF_INET" in lines[-i]: break nresult = i - 1 if nresult < int(sessions): raise error.TestError("We couldn't expect this parallism," "expect %s get %s" % (sessions, nresult)) niteration = nresult / sessions result = 0.0 for this in lines[-sessions * niteration:]: if "Interim" in this: result += float(re.findall(r"Interim result: *(\S+)", this)[0]) result = result / niteration logging.debug("niteration: %s" % niteration) return result error.context("Start netperf client threads", logging.info) pid = str(os.getpid()) fname = "/tmp/netperf.%s.nf" % pid ssh_cmd(clients[-1], "rm -f %s" % fname) numa_enable = params.get("netperf_with_numa", "yes") == "yes" timeout_netperf_start = float(params.get("netperf_start_timeout", 360)) client_thread = threading.Thread(target=netperf_thread, kwargs={"i": int(sessions), "numa_enable": numa_enable, "client_s": clients[0], "timeout": timeout_netperf_start}) client_thread.start() ret = {} ret['pid'] = pid if utils_misc.wait_for(all_clients_up, timeout_netperf_start, 30, 5, "Wait until all netperf clients start to work"): logging.debug("All netperf clients start to work.") else: raise error.TestNAError("Error, not all netperf clients at work") # real & effective test starts if get_status_flag: start_state = get_state() ret['mpstat'] = ssh_cmd(host, "mpstat 1 %d |tail -n 1" % (l - 1)) finished_result = ssh_cmd(clients[-1], "cat %s" % fname) # real & effective test ends if get_status_flag: end_state = get_state() if len(start_state) != len(end_state): msg = "Initial state not match end state:\n" msg += " start state: %s\n" % start_state msg += " end state: %s\n" % end_state logging.warn(msg) else: for i in range(len(end_state) / 2): ret[end_state[i * 2]] = (end_state[i * 2 + 1] - start_state[i * 2 + 1]) client_thread.join() error.context("Testing Results Treatment and Report", logging.info) f = open(fname, "w") f.write(finished_result) f.close() ret['thu'] = parse_demo_result(fname, int(sessions)) return ret
def run_mac_change(test, params, env): """ Change MAC address of guest. 1) Get a new mac from pool, and the old mac addr of guest. 2) Set new mac in guest and regain new IP. 3) Re-log into guest with new MAC. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session_serial = vm.wait_for_serial_login(timeout=timeout) # This session will be used to assess whether the IP change worked session = vm.wait_for_login(timeout=timeout) old_mac = vm.get_mac_address(0) while True: vm.virtnet.free_mac_address(0) new_mac = vm.virtnet.generate_mac_address(0) if old_mac != new_mac: break os_type = params.get("os_type") os_variant = params.get("os_variant") change_cmd_pattern = params.get("change_cmd") logging.info("The initial MAC address is %s", old_mac) if os_type == "linux": interface = utils_net.get_linux_ifname(session_serial, old_mac) if params.get("shutdown_int", "yes") == "yes": int_shutdown_cmd = params.get("int_shutdown_cmd", "ifconfig %s down") session_serial.cmd(int_shutdown_cmd % interface) else: connection_id = utils_net.get_windows_nic_attribute(session, "macaddress", old_mac, "netconnectionid") nic_index = utils_net.get_windows_nic_attribute(session, "netconnectionid", connection_id, "index") if os_variant == "winxp": pnpdevice_id = utils_net.get_windows_nic_attribute(session, "netconnectionid", connection_id, "pnpdeviceid") cd_drive = utils_misc.get_winutils_vol(session) copy_cmd = r"xcopy %s:\devcon\wxp_x86\devcon.exe c:\ " % cd_drive session.cmd(copy_cmd) # Start change MAC address error.context("Changing MAC address to %s" % new_mac, logging.info) if os_type == "linux": change_cmd = change_cmd_pattern % (interface, new_mac) else: change_cmd = change_cmd_pattern % (int(nic_index), "".join(new_mac.split(":"))) try: session_serial.cmd(change_cmd) # Verify whether MAC address was changed to the new one error.context("Verify the new mac address, and restart the network", logging.info) if os_type == "linux": if params.get("shutdown_int", "yes") == "yes": int_activate_cmd = params.get("int_activate_cmd", "ifconfig %s up") session_serial.cmd(int_activate_cmd % interface) session_serial.cmd("ifconfig | grep -i %s" % new_mac) logging.info("Mac address change successfully, net restart...") dhclient_cmd = "dhclient -r && dhclient %s" % interface session_serial.sendline(dhclient_cmd) else: mode = "netsh" if os_variant == "winxp": connection_id = pnpdevice_id.split("&")[-1] mode = "devcon" utils_net.restart_windows_guest_network(session_serial, connection_id, mode=mode) o = session_serial.cmd("ipconfig /all") if not re.findall("%s" % "-".join(new_mac.split(":")), o, re.I): raise error.TestFail("Guest mac change failed") logging.info("Guest mac have been modified successfully") # Re-log into the guest after changing mac address if utils_misc.wait_for(session.is_responsive, 120, 20, 3): # Just warning when failed to see the session become dead, # because there is a little chance the ip does not change. logging.warn("The session is still responsive, settings may fail.") session.close() # Re-log into guest and check if session is responsive error.context("Re-log into the guest", logging.info) session = vm.wait_for_login(timeout=timeout) if not session.is_responsive(): raise error.TestFail("The new session is not responsive.") finally: if os_type == "windows": clean_cmd_pattern = params.get("clean_cmd") clean_cmd = clean_cmd_pattern % int(nic_index) session_serial.cmd(clean_cmd) utils_net.restart_windows_guest_network(session_serial, connection_id, mode=mode) nic = vm.virtnet[0] nic.mac = old_mac vm.virtnet.update_db() session.close()
def run(test, params, env): """ KVM guest stop test: 1) Log into a guest 2) Check is HeavyLoad.exe installed , download and install it if not installed. 3) Start Heavyload to make guest in heavyload 4) Check vm is alive 5) Stop heavyload process and clean temp file. :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def loop_session_cmd(session, cmd): def session_cmd(session, cmd): try: return session.cmd_status(cmd) == 0 except (aexpect.ShellStatusError, aexpect.ShellTimeoutError): pass count = 0 while count < 3: ret = session_cmd(session, cmd) if ret is not None: return ret count += 1 return None def add_option(cmd, key, val): """ Append options into command; """ if re.match(r".*/%s.*", cmd, re.I): if val: rex = r"/%s\b+\S+\b+" % key val = "/%s %s " % (key, val) cmd = re.sub(rex, val, cmd, re.I) else: cmd += " /%s %s " % (key, val) return cmd tmp_dir = data_dir.get_tmp_dir() install_path = params["install_path"].rstrip("\\") heavyload_bin = '"%s\heavyload.exe"' % install_path start_cmd = "%s /CPU /MEMORY /FILE " % heavyload_bin stop_cmd = "taskkill /T /F /IM heavyload.exe" stop_cmd = params.get("stop_cmd", stop_cmd) start_cmd = params.get("start_cmd", start_cmd) check_running_cmd = "tasklist|findstr /I heavyload" check_running_cmd = params.get("check_running_cmd", check_running_cmd) test_installed_cmd = "dir '%s'|findstr /I heavyload" % install_path test_installed_cmd = params.get("check_installed_cmd", test_installed_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout) try: installed = session.cmd_status(test_installed_cmd) == 0 if not installed: download_url = params.get("download_url") if download_url: dst = r"c:\\" pkg_md5sum = params["pkg_md5sum"] error.context("Download HeavyLoadSetup.exe", logging.info) pkg = utils.unmap_url_cache(tmp_dir, download_url, pkg_md5sum) vm.copy_files_to(pkg, dst) else: dst = r"%s:\\" % utils_misc.get_winutils_vol(session) error.context("Install HeavyLoad in guest", logging.info) install_cmd = params["install_cmd"] install_cmd = re.sub(r"DRIVE:\\+", dst, install_cmd) session.cmd(install_cmd) config_cmd = params.get("config_cmd") if config_cmd: session.cmd(config_cmd) error.context("Start heavyload in guest", logging.info) # genery heavyload command automaticly if params.get("autostress") == "yes": free_mem = utils_misc.get_free_mem(session, "windows") free_disk = utils_misc.get_free_disk(session, "C:") start_cmd = '"%s\heavyload.exe"' % params["install_path"] start_cmd = add_option(start_cmd, 'CPU', params["smp"]) start_cmd = add_option(start_cmd, 'MEMORY', free_mem) start_cmd = add_option(start_cmd, 'FILE', free_disk) else: start_cmd = params["start_cmd"] # reformat command to ensure heavyload started as except test_timeout = int(params.get("timeout", "60")) steping = 60 if test_timeout < 60: logging.warn("Heavyload use minis as unit of timeout," "values is too small, use default: 60s") test_timeout = 60 steping = 30 test_timeout = test_timeout / 60 start_cmd = add_option(start_cmd, 'DURATION', test_timeout) start_cmd = add_option(start_cmd, 'START', '') start_cmd = add_option(start_cmd, 'AUTOEXIT', '') logging.info("heavyload cmd: %s" % start_cmd) session.sendline(start_cmd) if not loop_session_cmd(session, check_running_cmd): raise error.TestError("heavyload process is not started") error.context("Verify vm is alive", logging.info) utils_misc.wait_for(vm.verify_alive, timeout=test_timeout, step=steping) finally: error.context("Stop load and clean tmp files", logging.info) if not installed and download_url: utils.system("rm -f %s/HeavyLoad*.exe" % tmp_dir) session.cmd("del /f /s %sHeavyLoad*.exe" % dst) if loop_session_cmd(session, check_running_cmd): if not loop_session_cmd(session, stop_cmd): raise error.TestFail("Unable to terminate heavyload process") if session: session.close()
def run(test, params, env): """ This Test is mainly used as subtests 1) Boot up VM 2) Uninstall driver (Optional) 3) Reboot vm (Based on step 2) 4) Update / Downgrade / Install driver 5) Reboot vm 6) Verify installed driver :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ inst_timeout = int(params.get("driver_install_timeout", INSTALL_TIMEOUT)) driver_name = params["driver_name"] device_name = params["device_name"] device_hwid = params["device_hwid"] vm = env.get_vm(params["main_vm"]) session = vm.wait_for_login() # wait for cdroms having driver installed in case that # they are new appeared in this test utils_misc.wait_for(lambda: utils_misc.get_winutils_vol(session), timeout=OPERATION_TIMEOUT, step=10) devcon_path = utils_misc.set_winutils_letter(session, params["devcon_path"]) status, output = session.cmd_status_output("dir %s" % devcon_path, timeout=OPERATION_TIMEOUT) if status: test.error("Not found devcon.exe, details: %s" % output) media_type = params["virtio_win_media_type"] try: get_drive_letter = getattr(virtio_win, "drive_letter_%s" % media_type) get_product_dirname = getattr(virtio_win, "product_dirname_%s" % media_type) get_arch_dirname = getattr(virtio_win, "arch_dirname_%s" % media_type) except AttributeError: test.error("Not supported virtio win media type '%s'", media_type) viowin_ltr = get_drive_letter(session) if not viowin_ltr: test.error("Could not find virtio-win drive in guest") guest_name = get_product_dirname(session) if not guest_name: test.error("Could not get product dirname of the vm") guest_arch = get_arch_dirname(session) if not guest_arch: test.error("Could not get architecture dirname of the vm") inf_middle_path = ("{name}\\{arch}" if media_type == "iso" else "{arch}\\{name}").format(name=guest_name, arch=guest_arch) inf_find_cmd = 'dir /b /s %s\\%s.inf | findstr "\\%s\\\\"' inf_find_cmd %= (viowin_ltr, driver_name, inf_middle_path) inf_path = session.cmd(inf_find_cmd, timeout=OPERATION_TIMEOUT).strip() logging.info("Found inf file '%s'", inf_path) expected_ver = session.cmd("findstr DriverVer= %s" % inf_path, timeout=OPERATION_TIMEOUT) expected_ver = expected_ver.strip().split(",", 1)[-1] if not expected_ver: test.error("Failed to find driver version from inf file") logging.info("Target version is '%s'", expected_ver) if params.get("need_uninstall", "no") == "yes": error_context.context("Uninstalling previous installed driver", logging.info) for inf_name in _pnpdrv_info(session, device_name, ["InfName"]): uninst_store_cmd = "pnputil /f /d %s" % inf_name status, output = session.cmd_status_output(uninst_store_cmd, inst_timeout) if status: test.error("Failed to uninstall driver '%s' from store, " "details:\n%s" % (driver_name, output)) uninst_cmd = "%s remove %s" % (devcon_path, device_hwid) status, output = session.cmd_status_output(uninst_cmd, inst_timeout) # acceptable status: OK(0), REBOOT(1) if status > 1: test.error("Failed to uninstall driver '%s', details:\n" "%s" % (driver_name, output)) session = vm.reboot(session) error_context.context("Installing certificates", logging.info) cert_files = utils_misc.set_winutils_letter(session, params.get("cert_files", "")) cert_files = [cert.split("=", 1) for cert in cert_files.split()] for store, cert in cert_files: _chk_cert(session, cert) _add_cert(session, cert, store) error_context.context("Installing target driver", logging.info) installed_any = False for hwid in device_hwid.split(): output = session.cmd_output("%s find %s" % (devcon_path, hwid)) if re.search("No matching devices found", output, re.I): continue inst_cmd = "%s updateni %s %s" % (devcon_path, inf_path, hwid) status, output = session.cmd_status_output(inst_cmd, inst_timeout) # acceptable status: OK(0), REBOOT(1) if status > 1: test.fail("Failed to install driver '%s', " "details:\n%s" % (driver_name, output)) installed_any |= True if not installed_any: test.error("Failed to find target devices " "by hwids: '%s'" % device_hwid) error_context.context("Verifying target driver", logging.info) session = vm.reboot(session) windrv_verify_running(session, test, driver_name) ver_list = _pnpdrv_info(session, device_name, ["DriverVersion"]) if expected_ver not in ver_list: test.fail("The expected driver version is '%s', but " "found '%s'" % (expected_ver, ver_list)) session.close()
def run(test, params, env): """ Test the RX jumbo frame function of vnics: 1) Boot the VM. 2) Change the MTU of guest nics and host taps depending on the NIC model. 3) Add the static ARP entry for guest NIC. 4) Wait for the MTU ok. 5) Verify the path MTU using ping. 6) Ping the guest with large frames. 7) Increment size ping. 8) Flood ping the guest with large frames. 9) Verify the path MTU. 10) Recover the MTU. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def get_ovs_ports(ovs): ''' get the ovs bridge all Interface list. :param ovs: Ovs bridge name ''' cmd = "ovs-vsctl list-ports %s" % ovs return process.getoutput(cmd, shell=True) netdst = params.get("netdst", "switch") host_bridges = utils_net.find_bridge_manager(netdst) if not isinstance(host_bridges, utils_net.Bridge): ovs = host_bridges host_hw_interface = get_ovs_ports(netdst) tmp_ports = re.findall(r"t[0-9]{1,}-[a-zA-Z0-9]{6}", host_hw_interface) if tmp_ports: for p in tmp_ports: process.system_output("ovs-vsctl del-port %s %s" % (netdst, p)) params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params["main_vm"]) timeout = int(params.get("login_timeout", 360)) mtu_default = 1500 mtu = params.get("mtu", "1500") def_max_icmp_size = int(mtu) - 28 max_icmp_pkt_size = int(params.get("max_icmp_pkt_size", def_max_icmp_size)) flood_time = params.get("flood_time", "300") os_type = params.get("os_type") os_variant = params.get("os_variant") vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) session_serial = vm.wait_for_serial_login(timeout=timeout) ifname = vm.get_ifname(0) guest_ip = vm.get_address(0) if guest_ip is None: test.error("Could not get the guest ip address") host_mtu_cmd = "ifconfig %s mtu %s" if not isinstance(host_bridges, utils_net.Bridge): target_ifaces = set(get_ovs_ports(netdst).splitlines()) else: br_in_use = host_bridges.list_br() ifaces_in_use = host_bridges.list_iface() target_ifaces = set(ifaces_in_use) - set(br_in_use) error_context.context("Change all Bridge NICs MTU to %s" % mtu, logging.info) for iface in target_ifaces: process.run(host_mtu_cmd % (iface, mtu), shell=True) try: error_context.context("Changing the MTU of guest", logging.info) # Environment preparation mac = vm.get_mac_address(0) if os_type == "linux": ethname = utils_net.get_linux_ifname(session, mac) guest_mtu_cmd = "ifconfig %s mtu %s" % (ethname, mtu) else: connection_id = utils_net.get_windows_nic_attribute( session, "macaddress", mac, "netconnectionid") index = utils_net.get_windows_nic_attribute( session, "netconnectionid", connection_id, "index") if os_variant == "winxp": pnpdevice_id = utils_net.get_windows_nic_attribute( session, "netconnectionid", connection_id, "pnpdeviceid") cd_num = utils_misc.get_winutils_vol(session) copy_cmd = r"xcopy %s:\devcon\wxp_x86\devcon.exe c:\ " % cd_num session.cmd(copy_cmd) reg_set_mtu_pattern = params.get("reg_mtu_cmd") mtu_key_word = params.get("mtu_key", "MTU") reg_set_mtu = reg_set_mtu_pattern % (int(index), mtu_key_word, int(mtu)) guest_mtu_cmd = "%s " % reg_set_mtu session.cmd(guest_mtu_cmd) if os_type == "windows": mode = "netsh" if os_variant == "winxp": connection_id = pnpdevice_id.split("&")[-1] mode = "devcon" utils_net.restart_windows_guest_network(session_serial, connection_id, mode=mode) error_context.context("Chaning the MTU of host tap ...", logging.info) host_mtu_cmd = "ifconfig %s mtu %s" # Before change macvtap mtu, must set the base interface mtu if params.get("nettype") == "macvtap": base_if = utils_net.get_macvtap_base_iface(params.get("netdst")) process.run(host_mtu_cmd % (base_if, mtu), shell=True) process.run(host_mtu_cmd % (ifname, mtu), shell=True) error_context.context("Add a temporary static ARP entry ...", logging.info) arp_add_cmd = "arp -s %s %s -i %s" % (guest_ip, mac, ifname) process.run(arp_add_cmd, shell=True) def is_mtu_ok(): status, _ = utils_test.ping(guest_ip, 1, packetsize=max_icmp_pkt_size, hint="do", timeout=2) return status == 0 def verify_mtu(): logging.info("Verify the path MTU") status, output = utils_test.ping(guest_ip, 10, packetsize=max_icmp_pkt_size, hint="do", timeout=15) if status != 0: logging.error(output) test.fail("Path MTU is not as expected") if utils_test.get_loss_ratio(output) != 0: logging.error(output) test.fail("Packet loss ratio during MTU " "verification is not zero") def flood_ping(): logging.info("Flood with large frames") utils_test.ping(guest_ip, packetsize=max_icmp_pkt_size, flood=True, timeout=float(flood_time)) def large_frame_ping(count=100): logging.info("Large frame ping") _, output = utils_test.ping(guest_ip, count, packetsize=max_icmp_pkt_size, timeout=float(count) * 2) ratio = utils_test.get_loss_ratio(output) if ratio != 0: test.fail("Loss ratio of large frame ping is %s" % ratio) def size_increase_ping(step=random.randrange(90, 110)): logging.info("Size increase ping") for size in range(0, max_icmp_pkt_size + 1, step): logging.info("Ping %s with size %s", guest_ip, size) status, output = utils_test.ping(guest_ip, 1, packetsize=size, hint="do", timeout=1) if status != 0: status, output = utils_test.ping(guest_ip, 10, packetsize=size, adaptive=True, hint="do", timeout=20) fail_ratio = int(params.get("fail_ratio", 50)) if utils_test.get_loss_ratio(output) > fail_ratio: test.fail("Ping loss ratio is greater " "than 50% for size %s" % size) logging.info("Waiting for the MTU to be OK") wait_mtu_ok = 10 if not utils_misc.wait_for(is_mtu_ok, wait_mtu_ok, 0, 1): logging.debug( process.getoutput("ifconfig -a", verbose=False, ignore_status=True, shell=True)) test.error("MTU is not as expected even after %s " "seconds" % wait_mtu_ok) # Functional Test error_context.context("Checking whether MTU change is ok", logging.info) verify_mtu() large_frame_ping() size_increase_ping() # Stress test flood_ping() verify_mtu() finally: # Environment clean if session: session.close() grep_cmd = "grep '%s.*%s' /proc/net/arp" % (guest_ip, ifname) if process.system(grep_cmd, shell=True) == '0': process.run("arp -d %s -i %s" % (guest_ip, ifname), shell=True) logging.info("Removing the temporary ARP entry successfully") logging.info("Change back Bridge NICs MTU to %s", mtu_default) for iface in target_ifaces: process.run(host_mtu_cmd % (iface, mtu_default), shell=True)
def run(test, params, env): """ KVM guest stop test: 1) Log into a guest 2) Check is HeavyLoad.exe installed , download and install it if not installed. 3) Start Heavyload to make guest in heavyload 4) Check vm is alive 5) Stop heavyload process and clean temp file. :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def loop_session_cmd(session, cmd): def session_cmd(session, cmd): try: return session.cmd_status(cmd) == 0 except (aexpect.ShellStatusError, aexpect.ShellTimeoutError): pass count = 0 while count < 3: ret = session_cmd(session, cmd) if ret is not None: return ret count += 1 return None def add_option(cmd, key, val): """ Append options into command; """ if re.match(r".*/%s.*", cmd, re.I): if val: rex = r"/%s\b+\S+\b+" % key val = "/%s %s " % (key, val) cmd = re.sub(rex, val, cmd, re.I) else: cmd += " /%s %s " % (key, val) return cmd tmp_dir = data_dir.get_tmp_dir() install_path = params["install_path"].rstrip("\\") heavyload_bin = '"%s\heavyload.exe"' % install_path start_cmd = "%s /CPU /MEMORY /FILE " % heavyload_bin stop_cmd = "taskkill /T /F /IM heavyload.exe" stop_cmd = params.get("stop_cmd", stop_cmd) start_cmd = params.get("start_cmd", start_cmd) check_running_cmd = "tasklist|findstr /I heavyload" check_running_cmd = params.get("check_running_cmd", check_running_cmd) test_installed_cmd = "dir '%s'|findstr /I heavyload" % install_path test_installed_cmd = params.get("check_installed_cmd", test_installed_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout) try: installed = session.cmd_status(test_installed_cmd) == 0 if not installed: download_url = params.get("download_url") if download_url: dst = r"c:\\" pkg_md5sum = params["pkg_md5sum"] error.context("Download HeavyLoadSetup.exe", logging.info) pkg = utils.unmap_url_cache(tmp_dir, download_url, pkg_md5sum) vm.copy_files_to(pkg, dst) else: dst = r"%s:\\" % utils_misc.get_winutils_vol(session) error.context("Install HeavyLoad in guest", logging.info) install_cmd = params["install_cmd"] install_cmd = re.sub(r"DRIVE:\\+", dst, install_cmd) session.cmd(install_cmd) config_cmd = params.get("config_cmd") if config_cmd: session.cmd(config_cmd) error.context("Start heavyload in guest", logging.info) # genery heavyload command automaticly if params.get("autostress") == "yes": free_mem = utils_misc.get_free_mem(session, "windows") free_disk = utils_misc.get_free_disk(session, "C:") start_cmd = '"%s\heavyload.exe"' % params["install_path"] start_cmd = add_option(start_cmd, 'CPU', params["smp"]) start_cmd = add_option(start_cmd, 'MEMORY', free_mem) start_cmd = add_option(start_cmd, 'FILE', free_disk) else: start_cmd = params["start_cmd"] # reformat command to ensure heavyload started as except test_timeout = int(params.get("timeout", "60")) steping = 60 if test_timeout < 60: logging.warn("Heavyload use minis as unit of timeout," "values is too small, use default: 60s") test_timeout = 60 steping = 30 test_timeout = test_timeout / 60 start_cmd = add_option(start_cmd, 'DURATION', test_timeout) start_cmd = add_option(start_cmd, 'START', '') start_cmd = add_option(start_cmd, 'AUTOEXIT', '') logging.info("heavyload cmd: %s" % start_cmd) session.sendline(start_cmd) if not loop_session_cmd(session, check_running_cmd): raise error.TestError("heavyload process is not started") sleep_before_migration = int(params.get("sleep_before_migration", "0")) time.sleep(sleep_before_migration) error.context("Verify vm is alive", logging.info) utils_misc.wait_for(vm.verify_alive, timeout=test_timeout, step=steping) finally: # in migration test, no need to stop heavyload on src host cleanup_in_the_end = params.get("unload_stress_in_the_end", "yes") if cleanup_in_the_end == "yes": error.context("Stop load and clean tmp files", logging.info) if not installed and download_url: utils.system("rm -f %s/HeavyLoad*.exe" % tmp_dir) session.cmd("del /f /s %sHeavyLoad*.exe" % dst) if loop_session_cmd(session, check_running_cmd): if not loop_session_cmd(session, stop_cmd): raise error.TestFail("Unable to terminate heavyload " "process") if session: session.close()