- Raise these exceptions where appropriate (remote_login(), remote_scp(), etc) - Modify code that uses the functions that raise the new exceptions to account for their changed behavior. Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx> --- client/tests/kvm/kvm_preprocessing.py | 6 +- client/tests/kvm/kvm_test_utils.py | 48 ++++---- client/tests/kvm/kvm_utils.py | 120 +++++++++----------- client/tests/kvm/kvm_vm.py | 49 ++++----- client/tests/kvm/tests/boot_savevm.py | 9 +- client/tests/kvm/tests/clock_getres.py | 3 +- client/tests/kvm/tests/ethtool.py | 6 +- client/tests/kvm/tests/file_transfer.py | 12 +-- client/tests/kvm/tests/guest_s4.py | 4 +- client/tests/kvm/tests/ksm_overcommit.py | 23 ++-- client/tests/kvm/tests/migration.py | 6 +- .../kvm/tests/migration_with_file_transfer.py | 7 +- client/tests/kvm/tests/migration_with_reboot.py | 13 ++- client/tests/kvm/tests/multicast.py | 3 +- client/tests/kvm/tests/netperf.py | 3 +- client/tests/kvm/tests/nic_promisc.py | 12 ++- client/tests/kvm/tests/nicdriver_unload.py | 10 +- client/tests/kvm/tests/stress_boot.py | 13 +-- client/tests/kvm/tests/timedrift.py | 2 - client/tests/kvm/tests/timedrift_with_migration.py | 6 +- client/tests/kvm/tests/virtio_console.py | 3 +- 21 files changed, 163 insertions(+), 195 deletions(-) diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py index 4daafec..2997c8f 100644 --- a/client/tests/kvm/kvm_preprocessing.py +++ b/client/tests/kvm/kvm_preprocessing.py @@ -340,10 +340,10 @@ def postprocess(test, params, env): "that fail to respond to a remote login request...") for vm in env.get_all_vms(): if vm.is_alive(): - session = vm.remote_login() - if session: + try: + session = vm.remote_login() session.close() - else: + except kvm_utils.LoginError: vm.destroy(gracefully=False) # Kill all kvm_subprocess tail threads diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py index 7ed3330..caefa5e 100644 --- a/client/tests/kvm/kvm_test_utils.py +++ b/client/tests/kvm/kvm_test_utils.py @@ -55,18 +55,32 @@ def wait_for_login(vm, nic_index=0, timeout=240, start=0, step=2, serial=None): (ssh, rss) one. @return: A shell session object. """ - type = 'remote' + end_time = time.time() + timeout + session = None if serial: type = 'serial' logging.info("Trying to log into guest %s using serial connection," " timeout %ds", vm.name, timeout) - session = kvm_utils.wait_for(lambda: vm.serial_login(), timeout, - start, step) + time.sleep(start) + while time.time() < end_time: + try: + session = vm.serial_login() + break + except kvm_utils.LoginError, e: + logging.debug(e) + time.sleep(step) else: + type = 'remote' logging.info("Trying to log into guest %s using remote connection," " timeout %ds", vm.name, timeout) - session = kvm_utils.wait_for(lambda: vm.remote_login( - nic_index=nic_index), timeout, start, step) + time.sleep(start) + while time.time() < end_time: + try: + session = vm.remote_login(nic_index=nic_index) + break + except kvm_utils.LoginError, e: + logging.debug(e) + time.sleep(step) if not session: raise error.TestFail("Could not log into guest %s using %s connection" % (vm.name, type)) @@ -124,10 +138,9 @@ def reboot(vm, session, method="shell", sleep_before_reset=10, nic_index=0, # Try logging into the guest until timeout expires logging.info("Guest is down. Waiting for it to go up again, timeout %ds", timeout) - session = kvm_utils.wait_for(lambda: vm.remote_login(nic_index=nic_index), - timeout, 0, 2) - if not session: - raise error.TestFail("Could not log into guest after reboot") + # Temporary hack + time.sleep(timeout) + session = vm.remote_login(nic_index=nic_index) logging.info("Guest is up again") return session @@ -438,7 +451,6 @@ def run_autotest(vm, session, control_path, timeout, outputdir): @param local_path: Local path. @param remote_path: Remote path. """ - copy = False local_hash = utils.hash_file(local_path) basename = os.path.basename(local_path) output = session.cmd_output("md5sum %s" % remote_path) @@ -452,14 +464,9 @@ def run_autotest(vm, session, control_path, timeout, outputdir): # Let's be a little more lenient here and see if it wasn't a # temporary problem remote_hash = "0" - if remote_hash != local_hash: logging.debug("Copying %s to guest", basename) - copy = True - - if copy: - if not vm.copy_files_to(local_path, remote_path): - raise error.TestFail("Could not copy %s to guest" % local_path) + vm.copy_files_to(local_path, remote_path) def extract(vm, remote_path, dest_dir="."): @@ -484,9 +491,8 @@ def run_autotest(vm, session, control_path, timeout, outputdir): guest_results_dir = os.path.join(outputdir, "guest_autotest_results") if not os.path.exists(guest_results_dir): os.mkdir(guest_results_dir) - if not vm.copy_files_from("%s/results/default/*" % autotest_path, - guest_results_dir): - logging.error("Could not copy autotest results from guest") + vm.copy_files_from("%s/results/default/*" % autotest_path, + guest_results_dir) def get_results_summary(): @@ -536,9 +542,7 @@ def run_autotest(vm, session, control_path, timeout, outputdir): # Extract autotest.tar.bz2 extract(vm, compressed_autotest_path, "/") - if not vm.copy_files_to(control_path, - os.path.join(autotest_path, 'control')): - raise error.TestFail("Could not copy the test control file to guest") + vm.copy_files_to(control_path, os.path.join(autotest_path, 'control')) # Run the test logging.info("Running autotest control file %s on guest, timeout %ss", diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index c2918c9..24285d4 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -519,8 +519,10 @@ def _remote_login(session, username, password, prompt, timeout=10): @param timeout: The maximal time duration (in seconds) to wait for each step of the login procedure (i.e. the "Are you sure" prompt, the password prompt, the shell prompt, etc) - - @return: True on success and False otherwise. + @raise LoginTimeoutError: If timeout expires + @raise LoginAuthenticationError: If authentication fails + @raise LoginProcessTerminatedError: If the client terminates during login + @raise LoginError: If some other error occurs """ password_prompt_count = 0 login_prompt_count = 0 @@ -543,8 +545,7 @@ def _remote_login(session, username, password, prompt, timeout=10): password_prompt_count += 1 continue else: - logging.debug("Got password prompt again") - return False + raise LoginAuthenticationError("Got password prompt twice") elif match == 2: # "login:" if login_prompt_count == 0: logging.debug("Got username prompt; sending '%s'" % username) @@ -552,27 +553,22 @@ def _remote_login(session, username, password, prompt, timeout=10): login_prompt_count += 1 continue else: - logging.debug("Got username prompt again") - return False + raise LoginAuthenticationError("Got username prompt twice") elif match == 3: # "Connection closed" - logging.debug("Got 'Connection closed'") - return False + raise LoginError("Client said 'connection closed'") elif match == 4: # "Connection refused" - logging.debug("Got 'Connection refused'") - return False + raise LoginError("Client said 'connection refused'") elif match == 5: # "Please wait" logging.debug("Got 'Please wait'") timeout = 30 continue elif match == 6: # prompt logging.debug("Got shell prompt -- logged in") - return True + break except kvm_subprocess.ExpectTimeoutError, e: - logging.debug("Timeout elapsed (output so far: %r)" % e.output) - return False + raise LoginTimeoutError(e.output) except kvm_subprocess.ExpectProcessTerminatedError, e: - logging.debug("Process terminated (output so far: %r)" % e.output) - return False + raise LoginProcessTerminatedError(e.status, e.output) def remote_login(client, host, port, username, password, prompt, linesep="\n", @@ -592,8 +588,9 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n", @param timeout: The maximal time duration (in seconds) to wait for each step of the login procedure (i.e. the "Are you sure" prompt or the password prompt) - - @return: ShellSession object on success and None on failure. + @raise LoginBadClientError: If an unknown client is requested + @raise: Whatever _remote_login() raises + @return: A ShellSession object. """ if client == "ssh": cmd = ("ssh -o UserKnownHostsFile=/dev/null " @@ -604,18 +601,19 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n", elif client == "nc": cmd = "nc %s %s" % (host, port) else: - logging.error("Unknown remote shell client: %s" % client) - return + raise LoginBadClientError(client) logging.debug("Trying to login with command '%s'" % cmd) session = kvm_subprocess.ShellSession(cmd, linesep=linesep, prompt=prompt) - if _remote_login(session, username, password, prompt, timeout): - if log_filename: - session.set_output_func(log_line) - session.set_output_params((log_filename,)) - return session - else: + try: + _remote_login(session, username, password, prompt, timeout) + except: session.close() + raise + if log_filename: + session.set_output_func(log_line) + session.set_output_params((log_filename,)) + return session def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): @@ -634,11 +632,15 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): @param login_timeout: The maximal time duration (in seconds) to wait for each step of the login procedure (i.e. the "Are you sure" prompt or the password prompt) - - @return: True if the transfer succeeds and False on failure. + @raise SCPAuthenticationError: If authentication fails + @raise SCPTransferTimeoutError: If the transfer fails to complete in time + @raise SCPTransferFailedError: If the process terminates with a nonzero + exit code + @raise SCPError: If some other error occurs """ password_prompt_count = 0 timeout = login_timeout + authentication_done = False while True: try: @@ -655,19 +657,24 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): session.sendline(password) password_prompt_count += 1 timeout = transfer_timeout + authentication_done = True continue else: - logging.debug("Got password prompt again") - return False + raise SCPAuthenticationError("Got password prompt twice") elif match == 2: # "lost connection" - logging.debug("Got 'lost connection'") - return False + raise SCPError("SCP client said 'lost connection'") except kvm_subprocess.ExpectTimeoutError, e: - logging.debug("Timeout expired") - return False + if authentication_done: + raise SCPTransferTimeoutError(e.output) + else: + raise SCPAuthenticationError("Authentication timeout expired " + "(output so far: %r)" % e.output) except kvm_subprocess.ExpectProcessTerminatedError, e: - logging.debug("SCP process terminated with status %s", e.status) - return e.status == 0 + if e.status == 0: + logging.debug("SCP process terminated with status 0") + break + else: + raise SCPTransferFailedError(e.status, e.output) def remote_scp(command, password, log_filename=None, transfer_timeout=600, @@ -686,24 +693,21 @@ def remote_scp(command, password, log_filename=None, transfer_timeout=600, @param login_timeout: The maximal time duration (in seconds) to wait for each step of the login procedure (i.e. the "Are you sure" prompt or the password prompt) - - @return: True if the transfer succeeds and False on failure. + @raise: Whatever _remote_scp() raises """ logging.debug("Trying to SCP with command '%s', timeout %ss", command, transfer_timeout) - if log_filename: output_func = log_line output_params = (log_filename,) else: output_func = None output_params = () - session = kvm_subprocess.Expect(command, output_func=output_func, output_params=output_params) try: - return _remote_scp(session, password, transfer_timeout, login_timeout) + _remote_scp(session, password, transfer_timeout, login_timeout) finally: session.close() @@ -721,13 +725,12 @@ def scp_to_remote(host, port, username, password, local_path, remote_path, @param log_filename: If specified, log all output to this file @param timeout: The time duration (in seconds) to wait for the transfer to complete. - - @return: True on success and False on failure. + @raise: Whatever remote_scp() raises """ command = ("scp -v -o UserKnownHostsFile=/dev/null " "-o PreferredAuthentications=password -r -P %s %s %s@%s:%s" % (port, local_path, username, host, remote_path)) - return remote_scp(command, password, log_filename, timeout) + remote_scp(command, password, log_filename, timeout) def scp_from_remote(host, port, username, password, remote_path, local_path, @@ -743,13 +746,12 @@ def scp_from_remote(host, port, username, password, remote_path, local_path, @param log_filename: If specified, log all output to this file @param timeout: The time duration (in seconds) to wait for the transfer to complete. - - @return: True on success and False on failure. + @raise: Whatever remote_scp() raises """ command = ("scp -v -o UserKnownHostsFile=/dev/null " "-o PreferredAuthentications=password -r -P %s %s@%s:%s %s" % (port, username, host, remote_path, local_path)) - return remote_scp(command, password, log_filename, timeout) + remote_scp(command, password, log_filename, timeout) def copy_files_to(address, client, username, password, port, local_path, @@ -766,22 +768,15 @@ def copy_files_to(address, client, username, password, port, local_path, @param log_filename: If specified, log all output to this file @param timeout: The time duration (in seconds) to wait for the transfer to complete. - - @return: True on success and False on failure. + @raise: Whatever remote_scp() raises """ - - if not address or not port: - logging.debug("IP address or port unavailable") - return None - if client == "scp": - return scp_to_remote(address, port, username, password, local_path, - remote_path, log_filename, timeout) + scp_to_remote(address, port, username, password, local_path, + remote_path, log_filename, timeout) elif client == "rss": c = rss_file_transfer.FileUploadClient(address, port) c.upload(local_path, remote_path, timeout) c.close() - return True def copy_files_from(address, client, username, password, port, local_path, @@ -798,22 +793,15 @@ def copy_files_from(address, client, username, password, port, local_path, @param log_filename: If specified, log all output to this file @param timeout: The time duration (in seconds) to wait for the transfer to complete. - - @return: True on success and False on failure. + @raise: Whatever remote_scp() raises """ - - if not address or not port: - logging.debug("IP address or port unavailable") - return None - if client == "scp": - return scp_from_remote(address, port, username, password, remote_path, - local_path, log_filename, timeout) + scp_from_remote(address, port, username, password, remote_path, + local_path, log_filename, timeout) elif client == "rss": c = rss_file_transfer.FileDownloadClient(address, port) c.download(remote_path, local_path, timeout) c.close() - return True # The following are utility functions related to ports. diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index f6f1684..023926b 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -794,8 +794,11 @@ class VM: if gracefully and self.params.get("shutdown_command"): # Try to destroy with shell command logging.debug("Trying to shutdown VM with shell command...") - session = self.remote_login() - if session: + try: + session = self.remote_login() + except kvm_utils.LoginError, e: + logging.debug(e) + else: try: # Send the shutdown command session.sendline(self.params.get("shutdown_command")) @@ -1065,7 +1068,7 @@ class VM: @param nic_index: The index of the NIC to connect to. @param timeout: Time (seconds) before giving up logging into the guest. - @return: ShellSession object on success and None on failure. + @return: A ShellSession object. """ username = self.params.get("username", "") password = self.params.get("password", "") @@ -1078,16 +1081,13 @@ class VM: (self.name, kvm_utils.generate_random_string(4))) if not address or not port: - logging.debug("IP address or port unavailable") - return None + raise kvm_utils.LoginError("IP address or port unavailable") session = kvm_utils.remote_login(client, address, port, username, password, prompt, linesep, log_filename, timeout) - - if session: - session.set_status_test_command(self.params.get("status_test_" - "command", "")) + session.set_status_test_command(self.params.get("status_test_command", + "")) return session @@ -1106,13 +1106,11 @@ class VM: client = self.params.get("file_transfer_client") address = self.get_address(nic_index) port = self.get_port(int(self.params.get("file_transfer_port"))) - log_filename = ("transfer-%s-to-%s-%s.log" % (self.name, address, kvm_utils.generate_random_string(4))) - return kvm_utils.copy_files_to(address, client, username, password, - port, local_path, remote_path, - log_filename, timeout) + kvm_utils.copy_files_to(address, client, username, password, port, + local_path, remote_path, log_filename, timeout) def copy_files_from(self, remote_path, local_path, nic_index=0, timeout=600): @@ -1130,12 +1128,12 @@ class VM: client = self.params.get("file_transfer_client") address = self.get_address(nic_index) port = self.get_port(int(self.params.get("file_transfer_port"))) - log_filename = ("transfer-%s-from-%s-%s.log" % (self.name, address, kvm_utils.generate_random_string(4))) - return kvm_utils.copy_files_from(address, client, username, password, - port, local_path, remote_path, log_filename, timeout) + kvm_utils.copy_files_from(address, client, username, password, port, + local_path, remote_path, log_filename, + timeout) def serial_login(self, timeout=10): @@ -1153,18 +1151,15 @@ class VM: linesep = eval("'%s'" % self.params.get("shell_linesep", r"\n")) status_test_command = self.params.get("status_test_command", "") - if self.serial_console: - self.serial_console.set_linesep(linesep) - self.serial_console.set_status_test_command(status_test_command) - else: - return None + self.serial_console.set_linesep(linesep) + self.serial_console.set_status_test_command(status_test_command) - # Make sure we get a login prompt + # Try to get a login prompt self.serial_console.sendline() - if kvm_utils._remote_login(self.serial_console, username, password, - prompt, timeout): - return self.serial_console + kvm_utils._remote_login(self.serial_console, username, password, + prompt, timeout) + return self.serial_console def send_key(self, keystr): @@ -1216,8 +1211,6 @@ class VM: Get the cpu count of the VM. """ session = self.remote_login() - if not session: - return None try: return int(session.cmd(self.params.get("cpu_chk_cmd"))) finally: @@ -1232,8 +1225,6 @@ class VM: self.params.get("mem_chk_cmd") will be used. """ session = self.remote_login() - if not session: - return None try: if not cmd: cmd = self.params.get("mem_chk_cmd") diff --git a/client/tests/kvm/tests/boot_savevm.py b/client/tests/kvm/tests/boot_savevm.py index 3305695..cf5e433 100644 --- a/client/tests/kvm/tests/boot_savevm.py +++ b/client/tests/kvm/tests/boot_savevm.py @@ -50,12 +50,9 @@ def run_boot_savevm(test, params, env): if (time.time() > login_expire): login_expire = time.time() + savevm_login_delay logging.info("Logging in after loadvm...") - session = kvm_utils.wait_for(vm.remote_login, 1, 0, 1) - if not session: - logging.info("Failed to login") - else: - logging.info("Logged in to guest!") - break + session = vm.remote_login() + logging.info("Logged in to guest!") + break if (time.time() > end_time): raise error.TestFail("fail: timeout") diff --git a/client/tests/kvm/tests/clock_getres.py b/client/tests/kvm/tests/clock_getres.py index f85bb26..4bc558e 100644 --- a/client/tests/kvm/tests/clock_getres.py +++ b/client/tests/kvm/tests/clock_getres.py @@ -31,8 +31,7 @@ def run_clock_getres(test, params, env): vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) timeout = int(params.get("login_timeout", 360)) session = kvm_test_utils.wait_for_login(vm, timeout=timeout) - if not vm.copy_files_to(test_clock, base_dir): - raise error.TestError("Failed to copy %s to VM" % t_name) + vm.copy_files_to(test_clock, base_dir) session.cmd(os.path.join(base_dir, t_name)) logging.info("PASS: Guest reported appropriate clock resolution") logging.info("guest's dmesg:") diff --git a/client/tests/kvm/tests/ethtool.py b/client/tests/kvm/tests/ethtool.py index 8951fcb..1aa6d0f 100644 --- a/client/tests/kvm/tests/ethtool.py +++ b/client/tests/kvm/tests/ethtool.py @@ -124,8 +124,10 @@ def run_ethtool(test, params, env): return (False, "Tcpdump process wasn't launched") logging.info("Start to transfer file") - if not copy_files_fun(filename, filename): - return (False, "Child process transfer file failed") + try: + copy_files_fun(filename, filename): + except kvm_utils.SCPError, e: + return (False, "File transfer failed (%s)" % e) logging.info("Transfer file completed") session.cmd("killall tcpdump") try: diff --git a/client/tests/kvm/tests/file_transfer.py b/client/tests/kvm/tests/file_transfer.py index f02078e..7256c81 100644 --- a/client/tests/kvm/tests/file_transfer.py +++ b/client/tests/kvm/tests/file_transfer.py @@ -45,24 +45,20 @@ def run_file_transfer(test, params, env): logging.info("Transfering file host -> guest, timeout: %ss", transfer_timeout) t_begin = time.time() - success = vm.copy_files_to("%s/a.out" % dir_name, guest_path, - timeout=transfer_timeout) + vm.copy_files_to("%s/a.out" % dir_name, guest_path, + timeout=transfer_timeout) t_end = time.time() throughput = filesize / (t_end - t_begin) - if not success: - raise error.TestFail("Fail to transfer file from host to guest") logging.info("File transfer host -> guest succeed, " "estimated throughput: %.2fMB/s", throughput) logging.info("Transfering file guest -> host, timeout: %ss", transfer_timeout) t_begin = time.time() - success = vm.copy_files_from(guest_path, "%s/c.out" % dir_name, - timeout=transfer_timeout) + vm.copy_files_from(guest_path, "%s/c.out" % dir_name, + timeout=transfer_timeout) t_end = time.time() throughput = filesize / (t_end - t_begin) - if not success: - raise error.TestFail("Fail to transfer file from guest to host") logging.info("File transfer guest -> host succeed, " "estimated throughput: %.2fMB/s", throughput) else: diff --git a/client/tests/kvm/tests/guest_s4.py b/client/tests/kvm/tests/guest_s4.py index 0280f71..141e3d6 100644 --- a/client/tests/kvm/tests/guest_s4.py +++ b/client/tests/kvm/tests/guest_s4.py @@ -55,7 +55,9 @@ def run_guest_s4(test, params, env): # Log into the resumed VM relogin_timeout = int(params.get("relogin_timeout", 240)) logging.info("Logging into resumed VM, timeout %s", relogin_timeout) - session2 = kvm_utils.wait_for(vm.remote_login, relogin_timeout, 0, 2) + # Temporary hack + time.sleep(relogin_timeout) + session2 = vm.remote_login() if not session2: raise error.TestFail("Could not log into VM after resuming from " "suspend to disk") diff --git a/client/tests/kvm/tests/ksm_overcommit.py b/client/tests/kvm/tests/ksm_overcommit.py index c6368d3..375522a 100644 --- a/client/tests/kvm/tests/ksm_overcommit.py +++ b/client/tests/kvm/tests/ksm_overcommit.py @@ -249,10 +249,9 @@ def run_ksm_overcommit(test, params, env): session = lsessions[0] vm = lvms[0] for i in range(1, max_alloc): - lsessions.append(kvm_utils.wait_for(vm.remote_login, 360, 0, 2)) - if not lsessions[i]: - raise error.TestFail("Could not log into guest %s" % - vm.name) + # Temporary hack + time.sleep(360) + lsessions.append(vm.remote_login()) session.cmd("swapoff -a", timeout=300) @@ -553,9 +552,9 @@ def run_ksm_overcommit(test, params, env): logging.debug("Booting first guest %s", lvms[0].name) - lsessions.append(kvm_utils.wait_for(lvms[0].remote_login, 360, 0, 2)) - if not lsessions[0]: - raise error.TestFail("Could not log into first guest") + # Temporary hack + time.sleep(360) + lsessions.append(lvms[0].remote_login()) # Associate vm PID try: tmp = open(params.get('pid_' + vm_name), 'r') @@ -585,10 +584,9 @@ def run_ksm_overcommit(test, params, env): raise error.TestError("VM %s seems to be dead; Test requires a" "living VM" % lvms[i].name) - lsessions.append(kvm_utils.wait_for(lvms[i].remote_login, 360, 0, 2)) - if not lsessions[i]: - raise error.TestFail("Could not log into guest %s" % - lvms[i].name) + # Temporary hack + time.sleep(360) + lsessions.append(lvms[i].remote_login()) try: tmp = open(params.get('pid_' + vm_name), 'r') params['pid_' + vm_name] = int(tmp.readline()) @@ -606,8 +604,7 @@ def run_ksm_overcommit(test, params, env): vksmd_src = os.path.join(pwd, "scripts/allocator.py") dst_dir = "/tmp" for vm in lvms: - if not vm.copy_files_to(vksmd_src, dst_dir): - raise error.TestFail("copy_files_to failed %s" % vm.name) + vm.copy_files_to(vksmd_src, dst_dir) logging.info("Phase 0: PASS") if params['ksm_mode'] == "parallel": diff --git a/client/tests/kvm/tests/migration.py b/client/tests/kvm/tests/migration.py index 1c9f178..b9b86ba 100644 --- a/client/tests/kvm/tests/migration.py +++ b/client/tests/kvm/tests/migration.py @@ -53,9 +53,9 @@ def run_migration(test, params, env): # Log into the guest again logging.info("Logging into guest after migration...") - session2 = kvm_utils.wait_for(dest_vm.remote_login, 30, 0, 2) - if not session2: - raise error.TestFail("Could not log into guest after migration") + # Temporary hack + time.sleep(30) + session2 = dest_vm.remote_login() logging.info("Logged in after migration") # Make sure the background process is still running diff --git a/client/tests/kvm/tests/migration_with_file_transfer.py b/client/tests/kvm/tests/migration_with_file_transfer.py index d311350..97c726b 100644 --- a/client/tests/kvm/tests/migration_with_file_transfer.py +++ b/client/tests/kvm/tests/migration_with_file_transfer.py @@ -57,9 +57,7 @@ def run_migration_with_file_transfer(test, params, env): "migration...") vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol) finally: - # bg.join() returns the value returned by copy_files_to() - if not bg.join(): - raise error.TestFail("File transfer from host to guest failed") + bg.join() logging.info("Transferring file back from guest to host") bg = kvm_utils.Thread(kvm_utils.copy_files_from, @@ -73,8 +71,7 @@ def run_migration_with_file_transfer(test, params, env): "migration...") vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol) finally: - if not bg.join(): - raise error.TestFail("File transfer from guest to host failed") + bg.join() # Make sure the returned file is indentical to the original one orig_hash = client_utils.hash_file(host_path) diff --git a/client/tests/kvm/tests/migration_with_reboot.py b/client/tests/kvm/tests/migration_with_reboot.py index af5de64..cf25b6b 100644 --- a/client/tests/kvm/tests/migration_with_reboot.py +++ b/client/tests/kvm/tests/migration_with_reboot.py @@ -38,10 +38,15 @@ def run_migration_with_reboot(test, params, env): # Try logging into the guest until timeout expires logging.info("Guest is down. Waiting for it to go up again, timeout " "%ds", timeout) - session = kvm_utils.wait_for( - lambda: kvm_utils.remote_login(client, address, port, username, - password, prompt, linesep, - log_filename), timeout, 0, 2) + session = None + end_time = time.time() + timeout + while time.time() < end_time: + try: + session = kvm_utils.remote_login(client, address, port, + username, password, prompt, + linesep, log_filename) + except kvm_utils.LoginError, e: + logging.debug(e) if not session: raise error.TestFail("Could not log into guest after reboot") logging.info("Guest is up again") diff --git a/client/tests/kvm/tests/multicast.py b/client/tests/kvm/tests/multicast.py index 2a12b4f..39b580b 100644 --- a/client/tests/kvm/tests/multicast.py +++ b/client/tests/kvm/tests/multicast.py @@ -54,8 +54,7 @@ def run_multicast(test, params, env): suffix = int(re.findall("\d+", mcast)[-1]) # copy python script to guest for joining guest to multicast groups mcast_path = os.path.join(test.bindir, "scripts/join_mcast.py") - if not vm.copy_files_to(mcast_path, "/tmp"): - raise error.TestError("Fail to copy %s to guest" % mcast_path) + vm.copy_files_to(mcast_path, "/tmp") output = session.cmd_output("python /tmp/join_mcast.py %d %s %d" % (mgroup_count, prefix, suffix)) diff --git a/client/tests/kvm/tests/netperf.py b/client/tests/kvm/tests/netperf.py index 7c341fa..f1f3692 100644 --- a/client/tests/kvm/tests/netperf.py +++ b/client/tests/kvm/tests/netperf.py @@ -29,8 +29,7 @@ def run_netperf(test, params, env): session.cmd_output(firewall_flush) for i in params.get("netperf_files").split(): - if not vm.copy_files_to(os.path.join(netperf_dir, i), "/tmp"): - raise error.TestError("Could not copy file %s to guest" % i) + vm.copy_files_to(os.path.join(netperf_dir, i), "/tmp") try: session.cmd(firewall_flush) diff --git a/client/tests/kvm/tests/nic_promisc.py b/client/tests/kvm/tests/nic_promisc.py index f4bf1e4..16a38a3 100644 --- a/client/tests/kvm/tests/nic_promisc.py +++ b/client/tests/kvm/tests/nic_promisc.py @@ -70,8 +70,10 @@ def run_nic_promisc(test, params, env): utils.run(dd_cmd % (filename, int(size))) logging.info("Transfer file from host to guest") - if not vm.copy_files_to(filename, filename): - logging.error("File transfer failed") + try: + vm.copy_files_to(filename, filename) + except kvm_utils.SCPError, e: + logging.error("File transfer failed (%s)", e) continue if not compare(filename): logging.error("Compare file failed") @@ -83,8 +85,10 @@ def run_nic_promisc(test, params, env): session.cmd(dd_cmd % (filename, int(size)), timeout=100) logging.info("Transfer file from guest to host") - if not vm.copy_files_from(filename, filename): - logging.error("File transfer failed") + try: + vm.copy_files_from(filename, filename) + except kvm_utils.SCPError, e: + logging.error("File transfer failed (%s)", e) continue if not compare(filename): logging.error("Compare file failed") diff --git a/client/tests/kvm/tests/nicdriver_unload.py b/client/tests/kvm/tests/nicdriver_unload.py index a515d67..f964e35 100644 --- a/client/tests/kvm/tests/nicdriver_unload.py +++ b/client/tests/kvm/tests/nicdriver_unload.py @@ -33,11 +33,8 @@ def run_nicdriver_unload(test, params, env): def run(self): remote_file = '/tmp/' + self.getName() file_list.append(remote_file) - ret = vm.copy_files_to(file_name, remote_file, timeout=scp_timeout) - if ret: - logging.debug("File %s was transfered successfuly", remote_file) - else: - logging.debug("Failed to transfer file %s", remote_file) + vm.copy_files_to(file_name, remote_file, timeout=scp_timeout) + logging.debug("File %s was transfered successfuly", remote_file) def compare(origin_file, receive_file): check_sum1 = utils.hash_file(origin_file, method="md5") @@ -97,8 +94,7 @@ def run_nicdriver_unload(test, params, env): raise error.TestFail("Fail to compare (guest) file %s" % f) logging.info("Test nic function after load/unload") - if not vm.copy_files_to(file_name, file_name): - raise error.TestFail("Fail to copy file from host to guest") + vm.copy_files_to(file_name, file_name) if not compare(file_name, file_name): raise error.TestFail("Test nic function after load/unload fail") diff --git a/client/tests/kvm/tests/stress_boot.py b/client/tests/kvm/tests/stress_boot.py index 37d853b..8bdee95 100644 --- a/client/tests/kvm/tests/stress_boot.py +++ b/client/tests/kvm/tests/stress_boot.py @@ -22,9 +22,7 @@ def run_stress_boot(tests, params, env): logging.info("Waiting for first guest to be up...") login_timeout = float(params.get("login_timeout", 240)) - session = kvm_utils.wait_for(vm.remote_login, login_timeout, 0, 2) - if not session: - raise error.TestFail("Could not log into first guest") + session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout) num = 2 sessions = [session] @@ -41,13 +39,10 @@ def run_stress_boot(tests, params, env): kvm_preprocessing.preprocess_vm(tests, vm_params, env, vm_name) params['vms'] += " " + vm_name - curr_vm_session = kvm_utils.wait_for(curr_vm.remote_login, - login_timeout, 0, 2) - if not curr_vm_session: - raise error.TestFail("Could not log into guest #%d" % num) - + # Temporary hack + time.sleep(login_timeout) + sessions.append(curr_vm.remote_login()) logging.info("Guest #%d boots up successfully" % num) - sessions.append(curr_vm_session) # check whether all previous shell sessions are responsive for i, se in enumerate(sessions): diff --git a/client/tests/kvm/tests/timedrift.py b/client/tests/kvm/tests/timedrift.py index e5aa316..7951d6e 100644 --- a/client/tests/kvm/tests/timedrift.py +++ b/client/tests/kvm/tests/timedrift.py @@ -88,8 +88,6 @@ def run_timedrift(test, params, env): logging.info("Starting load on guest...") for i in range(guest_load_instances): load_session = vm.remote_login() - if not load_session: - raise error.TestFail("Could not log into guest") # Set output func to None to stop it from being called so we # can change the callback function and the parameters it takes # with no problems diff --git a/client/tests/kvm/tests/timedrift_with_migration.py b/client/tests/kvm/tests/timedrift_with_migration.py index e953ed3..199a414 100644 --- a/client/tests/kvm/tests/timedrift_with_migration.py +++ b/client/tests/kvm/tests/timedrift_with_migration.py @@ -50,9 +50,9 @@ def run_timedrift_with_migration(test, params, env): vm = kvm_test_utils.migrate(vm, env) # Log in logging.info("Logging in after migration...") - session = kvm_utils.wait_for(vm.remote_login, 30, 0, 2) - if not session: - raise error.TestFail("Could not log in after migration") + # Temporary hack + time.sleep(30) + session = vm.remote_login() logging.info("Logged in after migration") # Get time after current iteration (ht1_, gt1_) = kvm_test_utils.get_time(session, time_command, diff --git a/client/tests/kvm/tests/virtio_console.py b/client/tests/kvm/tests/virtio_console.py index fea3685..5c651a3 100644 --- a/client/tests/kvm/tests/virtio_console.py +++ b/client/tests/kvm/tests/virtio_console.py @@ -1218,8 +1218,7 @@ def run_virtio_console(test, params, env): pwd = os.path.join(os.environ['AUTODIR'], 'tests/kvm') vksmd_src = os.path.join(pwd, "scripts/virtio_guest.py") dst_dir = "/tmp" - if not vm[0].copy_files_to(vksmd_src, dst_dir): - raise error.TestFail("copy_files_to failed %s" % vm[0].name) + vm[0].copy_files_to(vksmd_src, dst_dir) # ACTUAL TESTING # Defines all available consoles; tests udev and sysfs -- 1.7.3.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html