def blockdev_backup(self): parallel_tests = self.params.objects("parallel_tests") targets = list( [getattr(self, t) for t in parallel_tests if hasattr(self, t)]) backup_func = super(BlockdevBackupParallelTest, self).blockdev_backup targets.append(backup_func) utils_misc.parallel(targets)
def wait_mirror_jobs_completed(self): """Wait till all mirror jobs completed in parallel""" targets = [partial(job_utils.wait_until_block_job_completed, vm=self.main_vm, job_id=j) for j in self._jobs] try: utils_misc.parallel(targets) finally: memory.drop_caches()
def fio_on_vms(): """Run fio on all started vms at the same time.""" logging.info("Start to do fio on multi-vms:") fio_parallel_params = [] for vm, session in zip(vms, sessions): fio_parallel_params.append((fio_on_vm, (vm, session))) utils_misc.parallel(fio_parallel_params) logging.info("Done fio on multi-vms.")
def rebase_inc_onto_full(self): # rebase target 'incbk' onto target 'fullbk' rebase_funcs = [] for i, tag in enumerate(self.inc_backup_tags): incbk = self.params['client_image_%s' % tag] fullbk = self.params['client_image_%s' % self.full_backup_tags[i]] image_params = self.params.object_params(incbk) image_params['image_chain'] = '%s %s' % (fullbk, incbk) disk = self.source_disk_define_by_params(image_params, incbk) rebase_funcs.append(partial(disk.rebase, params=image_params)) utils_misc.parallel(rebase_funcs)
def pull_data_and_reboot_vm_in_parallel(self): """run data copy and vm reboot in parallel""" targets = [ self._reboot_vm_during_data_copy, self._copy_full_data_from_export ] try: utils_misc.parallel(targets) except Exception as e: if self._is_qemu_aborted(): self.test.fail('qemu aborted(core dumped)') else: raise
def test(self): cpu_model, extra_flags = parse_cpu_model() logging.debug("Run tests with cpu model %s.", (cpu_model)) flags = HgFlags(cpu_model, extra_flags) (self.vm, session) = start_guest_with_cpuflags(cpu_model, smp) def encap(timeout): random.seed() begin = time.time() end = begin if smp > 1: while end - begin < 60: cpu = random.randint(1, smp - 1) if random.randint(0, 1): disable_cpu(session, cpu, True) else: disable_cpu(session, cpu, False) end = time.time() return True else: logging.warning("For this test is necessary smp > 1.") return False timeout = 60 test_flags = flags.guest_flags if all_host_supported_flags == "yes": test_flags = flags.all_possible_guest_flags result = utils_misc.parallel([(encap, [timeout]), (run_stress, [self.vm, timeout, test_flags])]) if not (result[0] and result[1]): test.fail("Stress tests failed before end of testing.")
def migrate_vms_src(self, mig_data): """ Migrate vms source. :param mig_Data: Data for migration. For change way how machine migrates is necessary re implement this method. """ def mig_wrapper(vm, cancel_delay, mig_offline, dsthost, mig_exec_cmd, not_wait_for_migration, mig_data): vm.migrate( cancel_delay=cancel_delay, offline=mig_offline, dest_host=dsthost, not_wait_for_migration=not_wait_for_migration, protocol="exec", migration_exec_cmd_src=mig_exec_cmd, ) self.post_migration( vm, cancel_delay, mig_offline, dsthost, mig_exec_cmd, not_wait_for_migration, None, mig_data ) logging.info("Start migrating now...") cancel_delay = mig_data.params.get("cancel_delay") if cancel_delay is not None: cancel_delay = int(cancel_delay) not_wait_for_migration = mig_data.params.get("not_wait_for_migration") if not_wait_for_migration == "yes": not_wait_for_migration = True mig_offline = mig_data.params.get("mig_offline") if mig_offline == "yes": mig_offline = True else: mig_offline = False multi_mig = [] for vm in mig_data.vms: mig_exec_cmd = vm.params.get("migration_exec_cmd_src") multi_mig.append( ( mig_wrapper, (vm, cancel_delay, mig_offline, mig_data.dst, mig_exec_cmd, not_wait_for_migration, mig_data), ) ) utils_misc.parallel(multi_mig)
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 run(test, params, env): """ Transfer a file back and forth between host and guest. 1) Boot up a VM. 2) Create a large file by dd on host. 3) Copy this file from host to guest. 4) Copy this file from guest to host. 5) Check if file transfers ended good. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ login_timeout = int(params.get("login_timeout", 360)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() error_context.context("Login to guest", logging.info) session = vm.wait_for_login(timeout=login_timeout) scp_sessions = int(params.get("scp_para_sessions", 1)) try: stress_timeout = float(params.get("stress_timeout", "3600")) error_context.context("Do file transfer between host and guest", logging.info) start_time = time.time() stop_time = start_time + stress_timeout # here when set a run flag, when other case call this case as a # subprocess backgroundly, can set this run flag to False to stop # the stress test. env["file_transfer_run"] = True while (env["file_transfer_run"] and time.time() < stop_time): scp_threads = [] for index in range(scp_sessions): scp_threads.append((utils_test.run_file_transfer, (test, params, env))) utils_misc.parallel(scp_threads) finally: env["file_transfer_run"] = False if session: session.close()
def migrate_vms_src(self, mig_data): """ Migrate vms source. :param mig_Data: Data for migration. For change way how machine migrates is necessary re implement this method. """ def mig_wrapper(vm, cancel_delay, mig_offline, dsthost, mig_exec_cmd, not_wait_for_migration, mig_data): vm.migrate(cancel_delay=cancel_delay, offline=mig_offline, dest_host=dsthost, not_wait_for_migration=not_wait_for_migration, protocol="exec", migration_exec_cmd_src=mig_exec_cmd) self.post_migration(vm, cancel_delay, mig_offline, dsthost, mig_exec_cmd, not_wait_for_migration, None, mig_data) logging.info("Start migrating now...") cancel_delay = mig_data.params.get("cancel_delay") if cancel_delay is not None: cancel_delay = int(cancel_delay) not_wait_for_migration = mig_data.params.get("not_wait_for_migration") if not_wait_for_migration == "yes": not_wait_for_migration = True mig_offline = mig_data.params.get("mig_offline") if mig_offline == "yes": mig_offline = True else: mig_offline = False multi_mig = [] for vm in mig_data.vms: mig_exec_cmd = vm.params.get("migration_exec_cmd_src") multi_mig.append((mig_wrapper, (vm, cancel_delay, mig_offline, mig_data.dst, mig_exec_cmd, not_wait_for_migration, mig_data))) utils_misc.parallel(multi_mig)
def run(test, params, env): """ Transfer a file back and forth between host and guest. 1) Boot up a VM. 2) Create a large file by dd on host. 3) Copy this file from host to guest. 4) Copy this file from guest to host. 5) Check if file transfers ended good. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ login_timeout = int(params.get("login_timeout", 360)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() error_context.context("Login to guest", logging.info) session = vm.wait_for_login(timeout=login_timeout) scp_sessions = int(params.get("scp_para_sessions", 1)) try: stress_timeout = float(params.get("stress_timeout", "3600")) error_context.context("Do file transfer between host and guest", logging.info) start_time = time.time() stop_time = start_time + stress_timeout # here when set a run flag, when other case call this case as a # subprocess backgroundly, can set this run flag to False to stop # the stress test. env["file_transfer_run"] = True while (env["file_transfer_run"] and time.time() < stop_time): scp_threads = [] for index in range(scp_sessions): scp_threads.append( (utils_test.run_file_transfer, (test, params, env))) utils_misc.parallel(scp_threads) finally: env["file_transfer_run"] = False if session: session.close()
def pull_data_and_poweroff_vm_in_parallel(self): """pull data and poweroff vm in parallel""" results = [] list(map(lambda p: p.start(), self._clients)) try: self._poweroff_vm_during_data_copy() parallel(self._targets) # never do join again when p.exitcode is None, # in case qemu-io hangs, process never returns results = list( map(lambda p: p.exitcode is not None and p.exitcode == 0, self._clients)) finally: list(map(lambda p: p.terminate(), self._clients)) list(map(lambda p: p.join(), self._clients)) if not all(results): # timeout(still running) or process quit unexpectedly self._check_qemu_responsive()
def blockdev_stream(self): """ Run block-stream and other operations in parallel parallel_tests includes function names separated by space e.g. parallel_tests = 'stress_test', we should define stress_test function with no argument """ parallel_tests = self.params.objects("parallel_tests") targets = list( [getattr(self, t) for t in parallel_tests if hasattr(self, t)]) targets.append( partial(backup_utils.blockdev_stream, vm=self.main_vm, device=self._top_device, **self._stream_options)) try: utils_misc.parallel(targets) finally: memory.drop_caches()
def blockdev_mirror(self): """Run block-mirror and other operations in parallel""" # parallel_tests includes function names separated by space # e.g. parallel_tests = 'stress_test', we should define stress_test # function with no argument parallel_tests = self.params.objects("parallel_tests") targets = list( [getattr(self, t) for t in parallel_tests if hasattr(self, t)]) # block-mirror on all source nodes is in parallel too for idx, source_node in enumerate(self._source_nodes): targets.append( partial(backup_utils.blockdev_mirror, vm=self.main_vm, source=source_node, target=self._target_nodes[idx], **self._backup_options[idx])) try: utils_misc.parallel(targets) finally: memory.drop_caches()
def rebase_target_disk(self): return utils_misc.parallel(self.rebase_targets)
f = open(os.path.join(test.debugdir, "summary"), "w") print_summary_line(f, fmt % ("ID", "Job", "Status", "Pass", "Fail", "NotRun", "NotApplicable")) print_summary_line(f, fmt % ("--", "---", "------", "----", "----", "------", "-------------")) for r in results: print_summary_line(f, fmt % (r["id"], r["job"], r["status"], r["pass"], r["fail"], r["notrun"], r["notapplicable"])) f.close() logging.info("(see logs and HTML reports in %s)", test.debugdir) # Kill the client VMs and fail if the automation program did not terminate # on time if not done: utils_misc.parallel(vm.destroy for vm in vms) raise error.TestFail("The automation program did not terminate " "on time") # Fail if there are failed or incomplete jobs (kill the client VMs if there # are incomplete jobs) failed_jobs = [r["job"] for r in results if r["status"].lower() == "investigate"] running_jobs = [r["job"] for r in results if r["status"].lower() == "inprogress"] errors = [] if failed_jobs: errors += ["Jobs failed: %s." % failed_jobs] if running_jobs: for vm in vms: vm.destroy()
def run_whql_submission(test, params, env): """ WHQL submission test: 1) Log into the client machines and into a DTM server machine 2) Copy the automation program binary (dsso_test_binary) to the server machine 3) Run the automation program 4) Pass the program all relevant parameters (e.g. device_data) 5) Wait for the program to terminate 6) Parse and report job results (logs and HTML reports are placed in test.debugdir) :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ # Log into all client VMs login_timeout = int(params.get("login_timeout", 360)) vms = [] sessions = [] for vm_name in params.objects("vms"): vms.append(env.get_vm(vm_name)) vms[-1].verify_alive() sessions.append(vms[-1].wait_for_login(timeout=login_timeout)) # Make sure all NICs of all client VMs are up for vm in vms: nics = vm.params.objects("nics") for nic_index in range(len(nics)): s = vm.wait_for_login(nic_index, 600) s.close() # Collect parameters server_address = params.get("server_address") server_shell_port = int(params.get("server_shell_port")) server_file_transfer_port = int(params.get("server_file_transfer_port")) server_studio_path = params.get("server_studio_path", "%programfiles%\\ " "Microsoft Driver Test Manager\\Studio") dsso_test_binary = params.get("dsso_test_binary", "deps/whql_submission_15.exe") dsso_test_binary = utils_misc.get_path(test.virtdir, dsso_test_binary) dsso_delete_machine_binary = params.get("dsso_delete_machine_binary", "deps/whql_delete_machine_15.exe") dsso_delete_machine_binary = utils_misc.get_path(test.virtdir, dsso_delete_machine_binary) test_timeout = float(params.get("test_timeout", 600)) # Copy dsso binaries to the server for filename in dsso_test_binary, dsso_delete_machine_binary: rss_client.upload(server_address, server_file_transfer_port, filename, server_studio_path, timeout=60) # Open a shell session with the server server_session = remote.remote_login("nc", server_address, server_shell_port, "", "", sessions[0].prompt, sessions[0].linesep) server_session.set_status_test_command(sessions[0].status_test_command) # Get the computer names of the server and clients cmd = "echo %computername%" server_name = server_session.cmd_output(cmd).strip() client_names = [session.cmd_output(cmd).strip() for session in sessions] # Delete all client machines from the server's data store server_session.cmd("cd %s" % server_studio_path) for client_name in client_names: cmd = "%s %s %s" % (os.path.basename(dsso_delete_machine_binary), server_name, client_name) server_session.cmd(cmd, print_func=logging.debug) # Reboot the client machines sessions = utils_misc.parallel((vm.reboot, (session,)) for vm, session in zip(vms, sessions)) # Check the NICs again for vm in vms: nics = vm.params.objects("nics") for nic_index in range(len(nics)): s = vm.wait_for_login(nic_index, 600) s.close() # Run whql_pre_command and close the sessions if params.get("whql_pre_command"): for session in sessions: session.cmd(params.get("whql_pre_command"), int(params.get("whql_pre_command_timeout", 600))) session.close() # Run the automation program on the server pool_name = "%s_pool" % client_names[0] submission_name = "%s_%s" % (client_names[0], params.get("submission_name")) cmd = "%s %s %s %s %s %s" % (os.path.basename(dsso_test_binary), server_name, pool_name, submission_name, test_timeout, " ".join(client_names)) server_session.sendline(cmd) # Helper function: wait for a given prompt and raise an exception if an # error occurs def find_prompt(prompt): m, o = server_session.read_until_last_line_matches( [prompt, server_session.prompt], print_func=logging.info, timeout=600) if m != 0: errors = re.findall("^Error:.*$", o, re.I | re.M) if errors: raise error.TestError(errors[0]) else: raise error.TestError("Error running automation program: " "could not find '%s' prompt" % prompt) # Tell the automation program which device to test find_prompt("Device to test:") server_session.sendline(params.get("test_device")) # Tell the automation program which jobs to run find_prompt("Jobs to run:") server_session.sendline(params.get("job_filter", ".*")) # Set submission DeviceData find_prompt("DeviceData name:") for dd in params.objects("device_data"): dd_params = params.object_params(dd) if dd_params.get("dd_name") and dd_params.get("dd_data"): server_session.sendline(dd_params.get("dd_name")) server_session.sendline(dd_params.get("dd_data")) server_session.sendline() # Set submission descriptors find_prompt("Descriptor path:") for desc in params.objects("descriptors"): desc_params = params.object_params(desc) if desc_params.get("desc_path"): server_session.sendline(desc_params.get("desc_path")) server_session.sendline() # Set machine dimensions for each client machine for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) find_prompt(r"Dimension name\b.*:") for dp in vm_params.objects("dimensions"): dp_params = vm_params.object_params(dp) if dp_params.get("dim_name") and dp_params.get("dim_value"): server_session.sendline(dp_params.get("dim_name")) server_session.sendline(dp_params.get("dim_value")) server_session.sendline() # Set extra parameters for tests that require them (e.g. NDISTest) for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) find_prompt(r"Parameter name\b.*:") for dp in vm_params.objects("device_params"): dp_params = vm_params.object_params(dp) if dp_params.get("dp_name") and dp_params.get("dp_regex"): server_session.sendline(dp_params.get("dp_name")) server_session.sendline(dp_params.get("dp_regex")) # Make sure the prompt appears again (if the device isn't found # the automation program will terminate) find_prompt(r"Parameter name\b.*:") server_session.sendline() # Wait for the automation program to terminate try: o = server_session.read_up_to_prompt(print_func=logging.info, timeout=test_timeout + 300) # (test_timeout + 300 is used here because the automation program is # supposed to terminate cleanly on its own when test_timeout expires) done = True except aexpect.ExpectError, e: o = e.output done = False
f, fmt % ("ID", "Job", "Status", "Pass", "Fail", "NotRun", "NotApplicable")) print_summary_line( f, fmt % ("--", "---", "------", "----", "----", "------", "-------------")) for r in results: print_summary_line( f, fmt % (r["id"], r["job"], r["status"], r["pass"], r["fail"], r["notrun"], r["notapplicable"])) f.close() logging.info("(see logs and HTML reports in %s)", test.debugdir) # Kill the client VMs and fail if the automation program did not terminate # on time if not done: utils_misc.parallel(vm.destroy for vm in vms) raise error.TestFail("The automation program did not terminate " "on time") # Fail if there are failed or incomplete jobs (kill the client VMs if there # are incomplete jobs) failed_jobs = [ r["job"] for r in results if r["status"].lower() == "investigate" ] running_jobs = [ r["job"] for r in results if r["status"].lower() == "inprogress" ] errors = [] if failed_jobs: errors += ["Jobs failed: %s." % failed_jobs] if running_jobs:
def run(test, params, env): """ WHQL submission test: 1) Log into the client machines and into a DTM server machine 2) Copy the automation program binary (dsso_test_binary) to the server machine 3) Run the automation program 4) Pass the program all relevant parameters (e.g. device_data) 5) Wait for the program to terminate 6) Parse and report job results (logs and HTML reports are placed in test.debugdir) :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ # Log into all client VMs login_timeout = int(params.get("login_timeout", 360)) vms = [] sessions = [] for vm_name in params.objects("vms"): vms.append(env.get_vm(vm_name)) vms[-1].verify_alive() sessions.append(vms[-1].wait_for_login(timeout=login_timeout)) # Make sure all NICs of all client VMs are up for vm in vms: nics = vm.params.objects("nics") for nic_index in range(len(nics)): s = vm.wait_for_login(nic_index, 600) s.close() # Collect parameters server_address = params.get("server_address") server_shell_port = int(params.get("server_shell_port")) server_file_transfer_port = int(params.get("server_file_transfer_port")) server_studio_path = params.get( "server_studio_path", "%programfiles%\\ " "Microsoft Driver Test Manager\\Studio") dsso_test_binary = params.get("dsso_test_binary", "deps/whql_submission_15.exe") dsso_test_binary = utils_misc.get_path(test.virtdir, dsso_test_binary) dsso_delete_machine_binary = params.get("dsso_delete_machine_binary", "deps/whql_delete_machine_15.exe") dsso_delete_machine_binary = utils_misc.get_path( test.virtdir, dsso_delete_machine_binary) test_timeout = float(params.get("test_timeout", 600)) # Copy dsso binaries to the server for filename in dsso_test_binary, dsso_delete_machine_binary: rss_client.upload(server_address, server_file_transfer_port, filename, server_studio_path, timeout=60) # Open a shell session with the server server_session = remote.remote_login("nc", server_address, server_shell_port, "", "", sessions[0].prompt, sessions[0].linesep) server_session.set_status_test_command(sessions[0].status_test_command) # Get the computer names of the server and clients cmd = "echo %computername%" server_name = server_session.cmd_output(cmd).strip() client_names = [session.cmd_output(cmd).strip() for session in sessions] # Delete all client machines from the server's data store server_session.cmd("cd %s" % server_studio_path) for client_name in client_names: cmd = "%s %s %s" % (os.path.basename(dsso_delete_machine_binary), server_name, client_name) server_session.cmd(cmd, print_func=logging.debug) # Reboot the client machines sessions = utils_misc.parallel( (vm.reboot, (session, )) for vm, session in zip(vms, sessions)) # Check the NICs again for vm in vms: nics = vm.params.objects("nics") for nic_index in range(len(nics)): s = vm.wait_for_login(nic_index, 600) s.close() # Run whql_pre_command and close the sessions if params.get("whql_pre_command"): for session in sessions: session.cmd(params.get("whql_pre_command"), int(params.get("whql_pre_command_timeout", 600))) session.close() # Run the automation program on the server pool_name = "%s_pool" % client_names[0] submission_name = "%s_%s" % (client_names[0], params.get("submission_name")) cmd = "%s %s %s %s %s %s" % (os.path.basename(dsso_test_binary), server_name, pool_name, submission_name, test_timeout, " ".join(client_names)) server_session.sendline(cmd) # Helper function: wait for a given prompt and raise an exception if an # error occurs def find_prompt(prompt): m, o = server_session.read_until_last_line_matches( [prompt, server_session.prompt], print_func=logging.info, timeout=600) if m != 0: errors = re.findall("^Error:.*$", o, re.I | re.M) if errors: raise error.TestError(errors[0]) else: raise error.TestError("Error running automation program: " "could not find '%s' prompt" % prompt) # Tell the automation program which device to test find_prompt("Device to test:") server_session.sendline(params.get("test_device")) # Tell the automation program which jobs to run find_prompt("Jobs to run:") server_session.sendline(params.get("job_filter", ".*")) # Set submission DeviceData find_prompt("DeviceData name:") for dd in params.objects("device_data"): dd_params = params.object_params(dd) if dd_params.get("dd_name") and dd_params.get("dd_data"): server_session.sendline(dd_params.get("dd_name")) server_session.sendline(dd_params.get("dd_data")) server_session.sendline() # Set submission descriptors find_prompt("Descriptor path:") for desc in params.objects("descriptors"): desc_params = params.object_params(desc) if desc_params.get("desc_path"): server_session.sendline(desc_params.get("desc_path")) server_session.sendline() # Set machine dimensions for each client machine for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) find_prompt(r"Dimension name\b.*:") for dp in vm_params.objects("dimensions"): dp_params = vm_params.object_params(dp) if dp_params.get("dim_name") and dp_params.get("dim_value"): server_session.sendline(dp_params.get("dim_name")) server_session.sendline(dp_params.get("dim_value")) server_session.sendline() # Set extra parameters for tests that require them (e.g. NDISTest) for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) find_prompt(r"Parameter name\b.*:") for dp in vm_params.objects("device_params"): dp_params = vm_params.object_params(dp) if dp_params.get("dp_name") and dp_params.get("dp_regex"): server_session.sendline(dp_params.get("dp_name")) server_session.sendline(dp_params.get("dp_regex")) # Make sure the prompt appears again (if the device isn't found # the automation program will terminate) find_prompt(r"Parameter name\b.*:") server_session.sendline() # Wait for the automation program to terminate try: o = server_session.read_up_to_prompt(print_func=logging.info, timeout=test_timeout + 300) # (test_timeout + 300 is used here because the automation program is # supposed to terminate cleanly on its own when test_timeout expires) done = True except aexpect.ExpectError, e: o = e.output done = False
def run(test, params, env): """ Transfer a file back and forth between host and guest. 1) Boot up a VM. 2) Create a large file by dd on host. 3) Copy this file from host to guest. 4) Copy this file from guest to host. 5) Check if file transfers ended good. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ @error.context_aware def do_file_copy(src_file, guest_file, dst_file, transfer_timeout): error.context( "Transferring file host -> guest," " timeout: %ss" % transfer_timeout, logging.info) vm.copy_files_to(src_file, guest_file, timeout=transfer_timeout) error.context( "Transferring file guest -> host," " timeout: %ss" % transfer_timeout, logging.info) vm.copy_files_from(guest_file, dst_file, timeout=transfer_timeout) error.context( "Compare md5sum between original file and" " transferred file", logging.info) if (utils.hash_file(src_file, method="md5") != utils.hash_file( dst_file, method="md5")): raise error.TestFail("File changed after transfer host -> guest " "and guest -> host") login_timeout = int(params.get("login_timeout", 360)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() error.context("Login to guest", logging.info) session = vm.wait_for_login(timeout=login_timeout) dir_name = data_dir.get_tmp_dir() tmp_dir = params.get("tmp_dir", "/var/tmp/") clean_cmd = params.get("clean_cmd", "rm -f") scp_sessions = int(params.get("scp_para_sessions", 1)) filesize = float(params.get("filesize", 4000)) transfer_timeout = float(params.get("transfer_timeout", 600)) src_path = [] dst_path = [] guest_path = [] for _ in range(scp_sessions): random_file_name = utils_misc.generate_random_string(8) src_path.append(os.path.join(dir_name, "h-src-%s" % random_file_name)) guest_path.append(tmp_dir + "g-tmp-%s" % random_file_name) dst_path.append(os.path.join(dir_name, "h-dst-%s" % random_file_name)) cmd = "dd if=/dev/zero of=%s bs=1M count=%d" try: for src_file in src_path: error.context("Create %dMB file on host" % filesize, logging.info) utils.run(cmd % (src_file, filesize)) stress_timeout = float(params.get("stress_timeout", "3600")) error.context("Do file transfer between host and guest", logging.info) start_time = time.time() stop_time = start_time + stress_timeout #here when set a run flag, when other case call this case as a #subprocess backgroundly, can set this run flag to False to stop #the stress test. env["file_transfer_run"] = True while (env["file_transfer_run"] and time.time() < stop_time): scp_threads = [] for index in range(scp_sessions): scp_threads.append( (do_file_copy, (src_path[index], guest_path[index], dst_path[index], transfer_timeout))) utils_misc.parallel(scp_threads) finally: env["file_transfer_run"] = False logging.info('Cleaning temp file on host and guest') for del_file in guest_path: session.cmd("%s %s" % (clean_cmd, del_file), ignore_all_errors=True) for del_file in src_path + dst_path: utils.system("%s %s" % (clean_cmd, del_file), ignore_status=True) if session: session.close()
def run(test, params, env): """ WHQL submission test: 1) Log into the client machines and into a DTM server machine 2) Copy the automation program binary (dsso_test_binary) to the server machine 3) Run the automation program 4) Pass the program all relevant parameters (e.g. device_data) 5) Wait for the program to terminate 6) Parse and report job results (logs and HTML reports are placed in test.debugdir) :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ # Log into all client VMs login_timeout = int(params.get("login_timeout", 360)) vms = [] sessions = [] for vm_name in params.objects("vms"): vms.append(env.get_vm(vm_name)) vms[-1].verify_alive() sessions.append(vms[-1].wait_for_login(timeout=login_timeout)) # Make sure all NICs of all client VMs are up for vm in vms: nics = vm.params.objects("nics") for nic_index in range(len(nics)): s = vm.wait_for_login(nic_index, 600) s.close() # Collect parameters server_address = params.get("server_address") server_shell_port = int(params.get("server_shell_port")) server_file_transfer_port = int(params.get("server_file_transfer_port")) server_studio_path = params.get("server_studio_path", "%programfiles%\\ " "Microsoft Driver Test Manager\\Studio") dsso_test_binary = params.get("dsso_test_binary", "deps/whql_submission_15.exe") dsso_test_binary = utils_misc.get_path(test.virtdir, dsso_test_binary) dsso_delete_machine_binary = params.get("dsso_delete_machine_binary", "deps/whql_delete_machine_15.exe") dsso_delete_machine_binary = utils_misc.get_path(test.virtdir, dsso_delete_machine_binary) test_timeout = float(params.get("test_timeout", 600)) # Copy dsso binaries to the server for filename in dsso_test_binary, dsso_delete_machine_binary: rss_client.upload(server_address, server_file_transfer_port, filename, server_studio_path, timeout=60) # Open a shell session with the server server_session = remote.remote_login("nc", server_address, server_shell_port, "", "", sessions[0].prompt, sessions[0].linesep) server_session.set_status_test_command(sessions[0].status_test_command) # Get the computer names of the server and clients cmd = "echo %computername%" server_name = server_session.cmd_output(cmd).strip() client_names = [session.cmd_output(cmd).strip() for session in sessions] # Delete all client machines from the server's data store server_session.cmd("cd %s" % server_studio_path) for client_name in client_names: cmd = "%s %s %s" % (os.path.basename(dsso_delete_machine_binary), server_name, client_name) server_session.cmd(cmd, print_func=logging.debug) # Reboot the client machines sessions = utils_misc.parallel((vm.reboot, (session,)) for vm, session in zip(vms, sessions)) # Check the NICs again for vm in vms: nics = vm.params.objects("nics") for nic_index in range(len(nics)): s = vm.wait_for_login(nic_index, 600) s.close() # Run whql_pre_command and close the sessions if params.get("whql_pre_command"): for session in sessions: session.cmd(params.get("whql_pre_command"), int(params.get("whql_pre_command_timeout", 600))) session.close() # Run the automation program on the server pool_name = "%s_pool" % client_names[0] submission_name = "%s_%s" % (client_names[0], params.get("submission_name")) cmd = "%s %s %s %s %s %s" % (os.path.basename(dsso_test_binary), server_name, pool_name, submission_name, test_timeout, " ".join(client_names)) server_session.sendline(cmd) # Helper function: wait for a given prompt and raise an exception if an # error occurs def find_prompt(test, prompt): m, o = server_session.read_until_last_line_matches( [prompt, server_session.prompt], print_func=logging.info, timeout=600) if m != 0: errors = re.findall("^Error:.*$", o, re.I | re.M) if errors: test.error(errors[0]) else: test.error("Error running automation program: " "could not find '%s' prompt" % prompt) # Tell the automation program which device to test find_prompt(test, "Device to test:") server_session.sendline(params.get("test_device")) # Tell the automation program which jobs to run find_prompt(test, "Jobs to run:") server_session.sendline(params.get("job_filter", ".*")) # Set submission DeviceData find_prompt(test, "DeviceData name:") for dd in params.objects("device_data"): dd_params = params.object_params(dd) if dd_params.get("dd_name") and dd_params.get("dd_data"): server_session.sendline(dd_params.get("dd_name")) server_session.sendline(dd_params.get("dd_data")) server_session.sendline() # Set submission descriptors find_prompt(test, "Descriptor path:") for desc in params.objects("descriptors"): desc_params = params.object_params(desc) if desc_params.get("desc_path"): server_session.sendline(desc_params.get("desc_path")) server_session.sendline() # Set machine dimensions for each client machine for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) find_prompt(test, r"Dimension name\b.*:") for dp in vm_params.objects("dimensions"): dp_params = vm_params.object_params(dp) if dp_params.get("dim_name") and dp_params.get("dim_value"): server_session.sendline(dp_params.get("dim_name")) server_session.sendline(dp_params.get("dim_value")) server_session.sendline() # Set extra parameters for tests that require them (e.g. NDISTest) for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) find_prompt(test, r"Parameter name\b.*:") for dp in vm_params.objects("device_params"): dp_params = vm_params.object_params(dp) if dp_params.get("dp_name") and dp_params.get("dp_regex"): server_session.sendline(dp_params.get("dp_name")) server_session.sendline(dp_params.get("dp_regex")) # Make sure the prompt appears again (if the device isn't found # the automation program will terminate) find_prompt(test, r"Parameter name\b.*:") server_session.sendline() # Wait for the automation program to terminate try: o = server_session.read_up_to_prompt(print_func=logging.info, timeout=test_timeout + 300) # (test_timeout + 300 is used here because the automation program is # supposed to terminate cleanly on its own when test_timeout expires) done = True except aexpect.ExpectError as e: o = e.output done = False server_session.close() # Look for test results in the automation program's output result_summaries = re.findall(r"---- \[.*?\] ----", o, re.DOTALL) if not result_summaries: test.error("The automation program did not return any results") results = result_summaries[-1].strip("-") results = eval("".join(results.splitlines())) # Download logs and HTML reports from the server for r in results: if "report" in r: try: rss_client.download(server_address, server_file_transfer_port, r["report"], test.debugdir) except rss_client.FileTransferNotFoundError: pass if "logs" in r: try: rss_client.download(server_address, server_file_transfer_port, r["logs"], test.debugdir) except rss_client.FileTransferNotFoundError: pass else: try: # Create symlinks to test log dirs to make it easier # to access them (their original names are not human # readable) link_name = "logs_%s" % r["report"].split("\\")[-1] link_name = link_name.replace(" ", "_") link_name = link_name.replace("/", "_") os.symlink(r["logs"].split("\\")[-1], os.path.join(test.debugdir, link_name)) except (KeyError, OSError): pass # Print result summary (both to the regular logs and to a file named # 'summary' in test.debugdir) def print_summary_line(f, line): logging.info(line) f.write(line + "\n") if results: # Make sure all results have the required keys for r in results: r["id"] = str(r.get("id")) r["job"] = str(r.get("job")) r["status"] = str(r.get("status")) r["pass"] = int(r.get("pass", 0)) r["fail"] = int(r.get("fail", 0)) r["notrun"] = int(r.get("notrun", 0)) r["notapplicable"] = int(r.get("notapplicable", 0)) # Sort the results by failures and total test count in descending order results = [(r["fail"], r["pass"] + r["fail"] + r["notrun"] + r["notapplicable"], r) for r in results] results.sort(reverse=True) results = [r[-1] for r in results] # Print results logging.info("") logging.info("Result summary:") name_length = max(len(r["job"]) for r in results) fmt = "%%-6s %%-%ds %%-15s %%-8s %%-8s %%-8s %%-15s" % name_length f = open(os.path.join(test.debugdir, "summary"), "w") print_summary_line(f, fmt % ("ID", "Job", "Status", "Pass", "Fail", "NotRun", "NotApplicable")) print_summary_line(f, fmt % ("--", "---", "------", "----", "----", "------", "-------------")) for r in results: print_summary_line(f, fmt % (r["id"], r["job"], r["status"], r["pass"], r["fail"], r["notrun"], r["notapplicable"])) f.close() logging.info("(see logs and HTML reports in %s)", test.debugdir) # Kill the client VMs and fail if the automation program did not terminate # on time if not done: utils_misc.parallel(vm.destroy for vm in vms) test.fail("The automation program did not terminate on time") # Fail if there are failed or incomplete jobs (kill the client VMs if there # are incomplete jobs) failed_jobs = [r["job"] for r in results if r["status"].lower() == "investigate"] running_jobs = [r["job"] for r in results if r["status"].lower() == "inprogress"] errors = [] if failed_jobs: errors += ["Jobs failed: %s." % failed_jobs] if running_jobs: for vm in vms: vm.destroy() errors += ["Jobs did not complete on time: %s." % running_jobs] if errors: test.fail(" ".join(errors))
def rebase_inc_onto_base(self): return utils_misc.parallel(self.rebase_funcs)
def run(test, params, env): """ Transfer a file back and forth between host and guest. 1) Boot up a VM. 2) Create a large file by dd on host. 3) Copy this file from host to guest. 4) Copy this file from guest to host. 5) Check if file transfers ended good. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ @error.context_aware def do_file_copy(src_file, guest_file, dst_file, transfer_timeout): error.context("Transferring file host -> guest," " timeout: %ss" % transfer_timeout, logging.info) vm.copy_files_to(src_file, guest_file, timeout=transfer_timeout) error.context("Transferring file guest -> host," " timeout: %ss" % transfer_timeout, logging.info) vm.copy_files_from(guest_file, dst_file, timeout=transfer_timeout) error.context("Compare md5sum between original file and" " transferred file", logging.info) if (utils.hash_file(src_file, method="md5") != utils.hash_file(dst_file, method="md5")): raise error.TestFail("File changed after transfer host -> guest " "and guest -> host") login_timeout = int(params.get("login_timeout", 360)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() error.context("Login to guest", logging.info) session = vm.wait_for_login(timeout=login_timeout) dir_name = data_dir.get_tmp_dir() tmp_dir = params.get("tmp_dir", "/var/tmp/") clean_cmd = params.get("clean_cmd", "rm -f") scp_sessions = int(params.get("scp_para_sessions", 1)) filesize = float(params.get("filesize", 4000)) transfer_timeout = float(params.get("transfer_timeout", 600)) src_path = [] dst_path = [] guest_path = [] for _ in range(scp_sessions): random_file_name = utils_misc.generate_random_string(8) src_path.append(os.path.join(dir_name, "h-src-%s" % random_file_name)) guest_path.append(tmp_dir + "g-tmp-%s" % random_file_name) dst_path.append(os.path.join(dir_name, "h-dst-%s" % random_file_name)) cmd = "dd if=/dev/zero of=%s bs=1M count=%d" try: for src_file in src_path: error.context("Create %dMB file on host" % filesize, logging.info) utils.run(cmd % (src_file, filesize)) stress_timeout = float(params.get("stress_timeout", "3600")) error.context("Do file transfer between host and guest", logging.info) start_time = time.time() stop_time = start_time + stress_timeout #here when set a run flag, when other case call this case as a #subprocess backgroundly, can set this run flag to False to stop #the stress test. env["file_transfer_run"] = True while (env["file_transfer_run"] and time.time() < stop_time): scp_threads = [] for index in range(scp_sessions): scp_threads.append((do_file_copy, (src_path[index], guest_path[index], dst_path[index], transfer_timeout))) utils_misc.parallel(scp_threads) finally: env["file_transfer_run"] = False logging.info('Cleaning temp file on host and guest') for del_file in guest_path: session.cmd("%s %s" % (clean_cmd, del_file), ignore_all_errors=True) for del_file in src_path + dst_path: utils.system("%s %s" % (clean_cmd, del_file), ignore_status=True) if session: session.close()