KVM test: introduce exception classes for _remote_login() and _remote_scp()
PATCH 1/17 KVM test: introduce exception classes for _remote_login() and _remote_scp()
--- client/tests/kvm/kvm_utils.py | 68 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 66 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_utils.py +66 -2
@@ -437,8 +437,72 @@ def check_kvm_source_dir(source_dir): raise error.TestError("Unknown source dir layout, cannot proceed.") -# The following are functions used for SSH, SCP and Telnet communication with -# guests. +# Functions and classes used for logging into guests and transferring files + +class LoginError(Exception): + pass + + +class LoginAuthenticationError(LoginError): + pass + + +class LoginTimeoutError(LoginError): + def __init__(self, output): + LoginError.__init__(self, output) + self.output = output + + def __str__(self): + return "Timeout expired (output so far: %r)" % self.output + + +class LoginProcessTerminatedError(LoginError): + def __init__(self, status, output): + LoginError.__init__(self, status, output) + self.status = status + self.output = output + + def __str__(self): + return ("Client process terminated (status: %s, output: %r)" % + (self.status, self.output)) + + +class LoginBadClientError(LoginError): + def __init__(self, client): + LoginError.__init__(self, client) + self.client = client + + def __str__(self): + return "Unknown remote shell client: %r" % self.client + + +class SCPError(Exception): + pass + + +class SCPAuthenticationError(SCPError): + pass + + +class SCPTransferTimeoutError(SCPError): + def __init__(self, output): + SCPError.__init__(self, output) + self.output = output + + def __str__(self): + return "Transfer timeout expired (output so far: %r)" % self.output + + +class SCPTransferFailedError(SCPError): + def __init__(self, status, output): + SCPError.__init__(self, status, output) + self.status = status + self.output = output + + def __str__(self): + return "SCP transfer failed (status: %s, output: %r)" % (self.status, + self.output) + def _remote_login(session, username, password, prompt, timeout=10): """
Signature · 1 line
1.7.3.4
PATCH 2/17 KVM test: kvm_utils.py: reorder remote_login(), remote_scp(), copy_files_to(), etc
Reorder the definition of these functions so that login functions are clustered together, and higher level functions are further down in the file.
--- client/tests/kvm/kvm_utils.py | 180 ++++++++++++++++++++-------------------- 1 files changed, 90 insertions(+), 90 deletions(-)
client/tests/kvm/kvm_utils.py +90 -90
@@ -575,6 +575,49 @@ def _remote_login(session, username, password, prompt, timeout=10): return False +def remote_login(client, host, port, username, password, prompt, linesep="\n", + log_filename=None, timeout=10): + """ + Log into a remote host (guest) using SSH/Telnet/Netcat. + + @param client: The client to use ('ssh', 'telnet' or 'nc') + @param host: Hostname or IP address + @param port: Port to connect to + @param username: Username (if required) + @param password: Password (if required) + @param prompt: Shell prompt (regular expression) + @param linesep: The line separator to use when sending lines + (e.g. '\\n' or '\\r\\n') + @param log_filename: If specified, log all output to this file + @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. + """ + if client == "ssh": + cmd = ("ssh -o UserKnownHostsFile=/dev/null " + "-o PreferredAuthentications=password -p %s %s@%s" % + (port, username, host)) + elif client == "telnet": + cmd = "telnet -l %s %s %s" % (username, host, port) + elif client == "nc": + cmd = "nc %s %s" % (host, port) + else: + logging.error("Unknown remote shell client: %s" % client) + return + + 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: + session.close() + + def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): """ Transfer file(s) to a remote host (guest) using SCP. Wait for questions
@@ -627,49 +670,6 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): return e.status == 0 -def remote_login(client, host, port, username, password, prompt, linesep="\n", - log_filename=None, timeout=10): - """ - Log into a remote host (guest) using SSH/Telnet/Netcat. - - @param client: The client to use ('ssh', 'telnet' or 'nc') - @param host: Hostname or IP address - @param port: Port to connect to - @param username: Username (if required) - @param password: Password (if required) - @param prompt: Shell prompt (regular expression) - @param linesep: The line separator to use when sending lines - (e.g. '\\n' or '\\r\\n') - @param log_filename: If specified, log all output to this file - @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. - """ - if client == "ssh": - cmd = ("ssh -o UserKnownHostsFile=/dev/null " - "-o PreferredAuthentications=password -p %s %s@%s" % - (port, username, host)) - elif client == "telnet": - cmd = "telnet -l %s %s %s" % (username, host, port) - elif client == "nc": - cmd = "nc %s %s" % (host, port) - else: - logging.error("Unknown remote shell client: %s" % client) - return - - 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: - session.close() - - def remote_scp(command, password, log_filename=None, transfer_timeout=600, login_timeout=10): """
@@ -708,10 +708,54 @@ def remote_scp(command, password, log_filename=None, transfer_timeout=600, session.close() +def scp_to_remote(host, port, username, password, local_path, remote_path, + log_filename=None, timeout=600): + """ + Copy files to a remote host (guest) through scp. + + @param host: Hostname or IP address + @param username: Username (if required) + @param password: Password (if required) + @param local_path: Path on the local machine where we are copying from + @param remote_path: Path on the remote machine where we are copying to + @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. + """ + 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) + + +def scp_from_remote(host, port, username, password, remote_path, local_path, + log_filename=None, timeout=600): + """ + Copy files from a remote host (guest). + + @param host: Hostname or IP address + @param username: Username (if required) + @param password: Password (if required) + @param local_path: Path on the local machine where we are copying from + @param remote_path: Path on the remote machine where we are copying to + @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. + """ + 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) + + def copy_files_to(address, client, username, password, port, local_path, remote_path, log_filename=None, timeout=600): """ - Decide the transfer cleint and copy file to a remote host (guest). + Copy files to a remote host (guest) using the selected client. @param client: Type of transfer client @param username: Username (if required)
@@ -741,9 +785,9 @@ def copy_files_to(address, client, username, password, port, local_path, def copy_files_from(address, client, username, password, port, local_path, - remote_path, log_filename=None, timeout=600): + remote_path, log_filename=None, timeout=600): """ - Decide the transfer cleint and copy file from a remote host (guest). + Copy files from a remote host (guest) using the selected client. @param client: Type of transfer client @param username: Username (if required)
@@ -772,50 +816,6 @@ def copy_files_from(address, client, username, password, port, local_path, return True -def scp_to_remote(host, port, username, password, local_path, remote_path, - log_filename=None, timeout=600): - """ - Copy files to a remote host (guest) through scp. - - @param host: Hostname or IP address - @param username: Username (if required) - @param password: Password (if required) - @param local_path: Path on the local machine where we are copying from - @param remote_path: Path on the remote machine where we are copying to - @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. - """ - 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) - - -def scp_from_remote(host, port, username, password, remote_path, local_path, - log_filename=None, timeout=600): - """ - Copy files from a remote host (guest). - - @param host: Hostname or IP address - @param username: Username (if required) - @param password: Password (if required) - @param local_path: Path on the local machine where we are copying from - @param remote_path: Path on the remote machine where we are copying to - @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. - """ - 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) - - # The following are utility functions related to ports. def is_port_free(port, address):
Signature · 1 line
1.7.3.4
PATCH 15/17 KVM test: use VM.migrate() instead of kvm_test_utils.migrate()
In reply to Michael Goldish--- client/tests/kvm/tests/migration.py | 7 +++---- client/tests/kvm/tests/migration_multi_host.py | 3 +-- client/tests/kvm/tests/timedrift_with_migration.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-)
client/tests/kvm/tests/migration.py +3 -4
@@ -26,7 +26,7 @@ def run_migration(test, params, env): mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") - mig_cancel = bool(params.get("mig_cancel")) + mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2 offline = params.get("offline", "no") == "yes" check = params.get("vmstate_check", "no") == "yes"
@@ -49,12 +49,11 @@ def run_migration(test, params, env): session2.close() # Migrate the VM - dest_vm = kvm_test_utils.migrate(vm, env,mig_timeout, mig_protocol, - mig_cancel, offline, check) + vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay, offline, check) # Log into the guest again logging.info("Logging into guest after migration...") - session2 = dest_vm.wait_for_login(timeout=30) + session2 = vm.wait_for_login(timeout=30) logging.info("Logged in after migration") # Make sure the background process is still running
client/tests/kvm/tests/migration_multi_host.py +1 -2
@@ -67,8 +67,7 @@ def run_migration_multi_host(test, params, env): c_socket.close() logging.info("Start migrating now...") - kvm_test_utils.migrate(vm=vm, dest_host=dsthost, mig_port=mig_port, - env=env) + vm.migrate(dest_host=dsthost, remote_port=mig_port) # Wait up to 30 seconds for dest to reach this point test.job.barrier(srchost, 'mig_finished', 30).rendezvous(srchost,
client/tests/kvm/tests/timedrift_with_migration.py +1 -1
@@ -48,7 +48,7 @@ def run_timedrift_with_migration(test, params, env): # Run current iteration logging.info("Migrating: iteration %d of %d..." % (i + 1, migration_iterations)) - vm = kvm_test_utils.migrate(vm, env) + vm.migrate() # Log in logging.info("Logging in after migration...") session = vm.wait_for_login(timeout=30)
Signature · 1 line
1.7.3.4
PATCH 3/17 KVM test: use the new LoginError and SCPError exceptions
In reply to Michael Goldish- 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.
--- 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(-)
client/tests/kvm/kvm_preprocessing.py +3 -3
@@ -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
client/tests/kvm/kvm_test_utils.py +26 -22
93 lines not on this page · raw message
client/tests/kvm/kvm_utils.py +54 -66
247 lines not on this page · raw message
client/tests/kvm/kvm_vm.py +20 -29
110 lines not on this page · raw message
client/tests/kvm/tests/boot_savevm.py +3 -6
@@ -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")
client/tests/kvm/tests/clock_getres.py +1 -2
@@ -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:")
client/tests/kvm/tests/ethtool.py +4 -2
@@ -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:
client/tests/kvm/tests/file_transfer.py +4 -8
@@ -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:
client/tests/kvm/tests/guest_s4.py +3 -1
@@ -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")
client/tests/kvm/tests/ksm_overcommit.py +10 -13
@@ -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":
client/tests/kvm/tests/migration.py +3 -3
@@ -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
client/tests/kvm/tests/migration_with_file_transfer.py +2 -5
@@ -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)
client/tests/kvm/tests/migration_with_reboot.py +9 -4
@@ -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")
client/tests/kvm/tests/multicast.py +1 -2
@@ -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))
client/tests/kvm/tests/netperf.py +1 -2
@@ -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)
client/tests/kvm/tests/nic_promisc.py +8 -4
@@ -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")
client/tests/kvm/tests/nicdriver_unload.py +3 -7
@@ -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")
client/tests/kvm/tests/stress_boot.py +4 -9
@@ -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):
client/tests/kvm/tests/timedrift.py +0 -2
@@ -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
client/tests/kvm/tests/timedrift_with_migration.py +3 -3
@@ -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,
client/tests/kvm/tests/virtio_console.py +1 -2
@@ -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
Signature · 1 line
1.7.3.4
PATCH 4/17 KVM test: add VM.wait_for_login() and kvm_utils.wait_for_login()
In reply to Michael GoldishThese are intended as a replacement for kvm_test_utils.wait_for_login().
--- client/tests/kvm/kvm_utils.py | 29 +++++++++++++++++++++++++++ client/tests/kvm/kvm_vm.py | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_utils.py +29 -0
@@ -616,6 +616,35 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n", return session +def wait_for_login(client, host, port, username, password, prompt, linesep="\n", + log_filename=None, timeout=240, internal_timeout=10): + """ + Make multiple attempts to log into a remote host (guest) until one succeeds + or timeout expires. + + @param timeout: Total time duration to wait for a successful login + @param internal_timeout: The maximal time duration (in seconds) to wait for + each step of the login procedure (e.g. the "Are you sure" prompt + or the password prompt) + @see: remote_login() + @raise: Whatever remote_login() raises + @return: A ShellSession object. + """ + logging.debug("Attempting to log into %s:%s using %s (timeout %ds)" % + (host, port, client)) + end_time = time.time() + timeout + while time.time() < end_time: + try: + return remote_login(client, host, port, username, password, prompt, + linesep, log_filename, internal_timeout) + except LoginError, e: + logging.debug(e) + time.sleep(2) + # Timeout expired; try one more time but don't catch exceptions + return remote_login(client, host, port, username, password, prompt, + linesep, log_filename, internal_timeout) + + def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): """ Transfer file(s) to a remote host (guest) using SCP. Wait for questions
client/tests/kvm/kvm_vm.py +43 -0
55 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 5/17 KVM test: use the new wait_for_login()
In reply to Michael Goldish--- client/tests/kvm/kvm_test_utils.py | 4 +--- client/tests/kvm/tests/autotest.py | 2 +- client/tests/kvm/tests/balloon_check.py | 2 +- client/tests/kvm/tests/boot.py | 2 +- client/tests/kvm/tests/clock_getres.py | 2 +- client/tests/kvm/tests/ethtool.py | 6 ++---- client/tests/kvm/tests/file_transfer.py | 4 +--- client/tests/kvm/tests/guest_s4.py | 11 +++-------- client/tests/kvm/tests/guest_test.py | 7 ++++--- client/tests/kvm/tests/iofuzz.py | 4 ++-- client/tests/kvm/tests/ioquit.py | 8 +++----- client/tests/kvm/tests/iozone_windows.py | 2 +- client/tests/kvm/tests/jumbo.py | 3 +-- client/tests/kvm/tests/kdump.py | 6 +++--- client/tests/kvm/tests/ksm_overcommit.py | 12 +++--------- client/tests/kvm/tests/linux_s3.py | 2 +- client/tests/kvm/tests/mac_change.py | 10 ++++------ client/tests/kvm/tests/migration.py | 8 +++----- client/tests/kvm/tests/migration_multi_host.py | 6 +++--- .../kvm/tests/migration_with_file_transfer.py | 2 +- client/tests/kvm/tests/migration_with_reboot.py | 16 ++++------------ client/tests/kvm/tests/multicast.py | 3 +-- client/tests/kvm/tests/netperf.py | 2 +- client/tests/kvm/tests/nic_bonding.py | 3 +-- client/tests/kvm/tests/nic_promisc.py | 7 +++---- client/tests/kvm/tests/nicdriver_unload.py | 5 ++--- client/tests/kvm/tests/pci_hotplug.py | 2 +- client/tests/kvm/tests/physical_resources_check.py | 2 +- client/tests/kvm/tests/ping.py | 3 +-- client/tests/kvm/tests/qemu_img.py | 6 +++--- client/tests/kvm/tests/shutdown.py | 2 +- client/tests/kvm/tests/stress_boot.py | 6 ++---- client/tests/kvm/tests/timedrift.py | 2 +- client/tests/kvm/tests/timedrift_with_migration.py | 6 ++---- client/tests/kvm/tests/timedrift_with_reboot.py | 2 +- client/tests/kvm/tests/timedrift_with_stop.py | 2 +- client/tests/kvm/tests/virtio_console.py | 8 ++------ client/tests/kvm/tests/vlan.py | 8 +++----- client/tests/kvm/tests/vmstop.py | 2 +- client/tests/kvm/tests/whql_client_install.py | 2 +- client/tests/kvm/tests/whql_submission.py | 7 ++++--- client/tests/kvm/tests/yum_update.py | 2 +- 42 files changed, 78 insertions(+), 123 deletions(-)
client/tests/kvm/kvm_test_utils.py +1 -3
@@ -138,9 +138,7 @@ 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) - # Temporary hack - time.sleep(timeout) - session = vm.remote_login(nic_index=nic_index) + session = vm.wait_for_login(nic_index, timeout=timeout) logging.info("Guest is up again") return session
client/tests/kvm/tests/autotest.py +1 -1
@@ -14,7 +14,7 @@ def run_autotest(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) + session = vm.wait_for_login(timeout=timeout) # Collect test parameters timeout = int(params.get("test_timeout", 300))
client/tests/kvm/tests/balloon_check.py +1 -1
@@ -67,7 +67,7 @@ def run_balloon_check(test, params, env): fail = 0 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) + session = vm.wait_for_login(timeout=timeout) # Upper limit that we can raise the memory vm_assigned_mem = int(params.get("mem"))
client/tests/kvm/tests/boot.py +1 -1
@@ -17,7 +17,7 @@ def run_boot(test, params, env): """ vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) timeout = float(params.get("login_timeout", 240)) - session = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2) + session = vm.wait_for_login(timeout=timeout) try: if not params.get("reboot_method"):
client/tests/kvm/tests/clock_getres.py +1 -1
@@ -30,7 +30,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) + session = vm.wait_for_login(timeout=timeout) 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")
client/tests/kvm/tests/ethtool.py +2 -4
@@ -176,12 +176,10 @@ def run_ethtool(test, params, env): vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, - timeout=int(params.get("login_timeout", 360))) + session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) # Let's just error the test if we identify that there's no ethtool installed session.cmd("ethtool -h") - session2 = kvm_test_utils.wait_for_login(vm, - timeout=int(params.get("login_timeout", 360))) + session2 = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) mtu = 1514 feature_status = {} filename = "/tmp/ethtool.dd"
client/tests/kvm/tests/file_transfer.py +1 -3
@@ -20,9 +20,7 @@ def run_file_transfer(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 session: - raise error.TestFail("Could not log into guest '%s'" % vm.name) + session = vm.wait_for_login(timeout=timeout) dir_name = test.tmpdir transfer_timeout = int(params.get("transfer_timeout"))
client/tests/kvm/tests/guest_s4.py +3 -8
@@ -13,7 +13,7 @@ def run_guest_s4(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) + session = vm.wait_for_login(timeout=timeout) logging.info("Checking whether guest OS supports suspend to disk (S4)...") session.cmd(params.get("check_s4_support_cmd"))
@@ -28,7 +28,7 @@ def run_guest_s4(test, params, env): time.sleep(5) # Get the second session to start S4 - session2 = kvm_test_utils.wait_for_login(vm, timeout=timeout) + session2 = vm.wait_for_login(timeout=timeout) # Make sure the background program is running as expected check_s4_cmd = params.get("check_s4_cmd")
@@ -55,12 +55,7 @@ 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) - # 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") + session2 = vm.wait_for_login(timeout=relogin_timeout) # Check whether the test command is still alive logging.info("Checking if background command is still alive...")
client/tests/kvm/tests/guest_test.py +4 -3
@@ -20,9 +20,10 @@ def run_guest_test(test, params, env): reboot = params.get("reboot", "no") vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - serial_login = (params.get("serial_login", "no") == "yes") - session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout, - serial=serial_login) + if params.get("serial_login") == "yes": + session = vm.wait_for_serial_login(timeout=login_timeout) + else: + session = vm.wait_for_login(timeout=login_timeout) if reboot == "yes": logging.debug("Rebooting guest before test ...")
client/tests/kvm/tests/iofuzz.py +2 -2
@@ -79,7 +79,7 @@ def run_iofuzz(test, params, env): if vm.process.is_alive(): logging.debug("VM is alive, try to re-login") try: - session = kvm_test_utils.wait_for_login(vm, 0, 10, 0, 2) + session = vm.wait_for_login(timeout=10) except: logging.debug("Could not re-login, reboot the guest") session = kvm_test_utils.reboot(vm, session,
@@ -91,7 +91,7 @@ def run_iofuzz(test, params, env): login_timeout = float(params.get("login_timeout", 240)) vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, 0, login_timeout, 0, 2) + session = vm.wait_for_login(timeout=login_timeout) try: ports = {}
client/tests/kvm/tests/ioquit.py +3 -5
@@ -11,12 +11,10 @@ def run_ioquit(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, - timeout=int(params.get("login_timeout", 360))) - session2 = kvm_test_utils.wait_for_login(vm, - timeout=int(params.get("login_timeout", 360))) + login_timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=login_timeout) + session2 = vm.wait_for_login(timeout=login_timeout) try: bg_cmd = params.get("background_cmd") logging.info("Add IO workload for guest OS.")
client/tests/kvm/tests/iozone_windows.py +1 -1
@@ -19,7 +19,7 @@ def run_iozone_windows(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) + 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)
client/tests/kvm/tests/jumbo.py +1 -2
@@ -22,9 +22,8 @@ def run_jumbo(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm) + session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) mtu = params.get("mtu", "1500") flood_time = params.get("flood_time", "300") max_icmp_pkt_size = int(mtu) - 28
client/tests/kvm/tests/kdump.py +3 -3
@@ -17,7 +17,7 @@ def run_kdump(test, params, env): vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) timeout = float(params.get("login_timeout", 240)) crash_timeout = float(params.get("crash_timeout", 360)) - session = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2) + session = vm.wait_for_login(timeout=timeout) def_kernel_param_cmd = ("grubby --update-kernel=`grubby --default-kernel`" " --args=crashkernel=128M") kernel_param_cmd = params.get("kernel_param_cmd", def_kernel_param_cmd)
@@ -33,7 +33,7 @@ def run_kdump(test, params, env): @param vcpu: vcpu which is used to trigger a crash """ - session = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2) + session = vm.wait_for_login(timeout=timeout) session.cmd_output("rm -rf /var/crash/*") logging.info("Triggering crash on vcpu %d ...", vcpu)
@@ -45,7 +45,7 @@ def run_kdump(test, params, env): raise error.TestFail("Could not trigger crash on vcpu %d" % vcpu) logging.info("Waiting for kernel crash dump to complete") - session = kvm_test_utils.wait_for_login(vm, 0, crash_timeout, 0, 2) + session = vm.wait_for_login(timeout=crash_timeout) logging.info("Probing vmcore file...") session.cmd("ls -R /var/crash | grep vmcore")
client/tests/kvm/tests/ksm_overcommit.py +3 -9
@@ -249,9 +249,7 @@ def run_ksm_overcommit(test, params, env): session = lsessions[0] vm = lvms[0] for i in range(1, max_alloc): - # Temporary hack - time.sleep(360) - lsessions.append(vm.remote_login()) + lsessions.append(vm.wait_for_login(timeout=360)) session.cmd("swapoff -a", timeout=300)
@@ -552,9 +550,7 @@ def run_ksm_overcommit(test, params, env): logging.debug("Booting first guest %s", lvms[0].name) - # Temporary hack - time.sleep(360) - lsessions.append(lvms[0].remote_login()) + lsessions.append(lvms[0].wait_for_login(timeout=360)) # Associate vm PID try: tmp = open(params.get('pid_' + vm_name), 'r')
@@ -584,9 +580,7 @@ def run_ksm_overcommit(test, params, env): raise error.TestError("VM %s seems to be dead; Test requires a" "living VM" % lvms[i].name) - # Temporary hack - time.sleep(360) - lsessions.append(lvms[i].remote_login()) + lsessions.append(lvms[i].wait_for_login(timeout=360)) try: tmp = open(params.get('pid_' + vm_name), 'r') params['pid_' + vm_name] = int(tmp.readline())
client/tests/kvm/tests/linux_s3.py +1 -1
@@ -13,7 +13,7 @@ def run_linux_s3(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) + session = vm.wait_for_login(timeout=timeout) logging.info("Checking that VM supports S3") session.cmd("grep -q mem /sys/power/state")
client/tests/kvm/tests/mac_change.py +4 -6
@@ -15,12 +15,11 @@ def run_mac_change(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - timeout = int(params.get("login_timeout", 360)) vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session_serial = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2, - serial=True) + 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 = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2) + session = vm.wait_for_login(timeout=timeout) old_mac = vm.get_mac_address(0) while True: vm.free_mac_address(0)
@@ -53,8 +52,7 @@ def run_mac_change(test, params, env): # Re-log into guest and check if session is responsive logging.info("Re-log into the guest") - session = kvm_test_utils.wait_for_login(vm, - timeout=int(params.get("login_timeout", 360))) + session = vm.wait_for_login(timeout=timeout) if not session.is_responsive(): raise error.TestFail("The new session is not responsive.")
client/tests/kvm/tests/migration.py +3 -5
@@ -21,7 +21,7 @@ def run_migration(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) + session = vm.wait_for_login(timeout=timeout) mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp")
@@ -40,7 +40,7 @@ def run_migration(test, params, env): # Start another session with the guest and make sure the background # process is running - session2 = kvm_test_utils.wait_for_login(vm, timeout=timeout) + session2 = vm.wait_for_login(timeout=timeout) try: check_command = params.get("migration_bg_check_command", "")
@@ -53,9 +53,7 @@ def run_migration(test, params, env): # Log into the guest again logging.info("Logging into guest after migration...") - # Temporary hack - time.sleep(30) - session2 = dest_vm.remote_login() + session2 = dest_vm.wait_for_login(timeout=30) logging.info("Logged in after migration") # Make sure the background process is still running
client/tests/kvm/tests/migration_multi_host.py +3 -3
@@ -47,7 +47,7 @@ def run_migration_multi_host(test, params, env): comm_port = int(params.get("comm_port", 12324)) regain_ip_cmd = params.get("regain_ip_cmd", "dhclient") if role == 'source': - session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout) + session = vm.wait_for_login(timeout=login_timeout) # Listen on a port to get the migration port received from # dest machine
@@ -100,9 +100,9 @@ def run_migration_multi_host(test, params, env): # Log into the guest again logging.info("Logging into migrated guest after migration...") - session_serial = kvm_test_utils.wait_for_login(vm, timeout=login_timeout, serial=True) + session_serial = vm.wait_for_serial_login(timeout=login_timeout) session_serial.cmd(regain_ip_cmd) - session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout) + session = vm.wait_for_login(timeout=login_timeout) else: raise error.TestError('Invalid role specified')
client/tests/kvm/tests/migration_with_file_transfer.py +1 -1
@@ -21,7 +21,7 @@ def run_migration_with_file_transfer(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) + session = vm.wait_for_login(timeout=timeout) mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp")
client/tests/kvm/tests/migration_with_reboot.py +4 -12
@@ -38,23 +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 = 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") + session = kvm_utils.wait_for_login(client, address, port, username, + password, prompt, linesep, + log_filename, timeout) logging.info("Guest is up again") session.close() 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) + session = vm.wait_for_login(timeout=timeout) # params of reboot username = vm.params.get("username", "")
client/tests/kvm/tests/multicast.py +1 -2
@@ -19,8 +19,7 @@ def run_multicast(test, params, env): @param env: Dictionary with test environment. """ vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, - timeout=int(params.get("login_timeout", 360))) + session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) def run_guest(cmd): try:
client/tests/kvm/tests/netperf.py +1 -1
@@ -18,7 +18,7 @@ def run_netperf(test, params, env): """ vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) login_timeout = int(params.get("login_timeout", 360)) - session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout) + session = vm.wait_for_login(timeout=login_timeout) netperf_dir = os.path.join(os.environ['AUTODIR'], "tests/netperf2") setup_cmd = params.get("setup_cmd")
client/tests/kvm/tests/nic_bonding.py +1 -2
@@ -32,8 +32,7 @@ def run_nic_bonding(test, params, env): timeout = int(params.get("login_timeout", 1200)) vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session_serial = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2, - serial=True) + session_serial = vm.wait_for_serial_login(timeout=timeout) script_path = kvm_utils.get_path(test.bindir, "scripts/bonding_setup.py") vm.copy_files_to(script_path, "/tmp/bonding_setup.py") cmd = "python /tmp/bonding_setup.py %s" % vm.get_mac_address()
client/tests/kvm/tests/nic_promisc.py +3 -4
@@ -18,11 +18,10 @@ def run_nic_promisc(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - timeout = int(params.get("login_timeout", 360)) vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, timeout=timeout) - session_serial = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2, - serial=True) + timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=timeout) + session_serial = vm.wait_for_serial_login(timeout=timeout) def compare(filename): md5_host = utils.hash_file(filename, method="md5")
client/tests/kvm/tests/nicdriver_unload.py +2 -3
@@ -19,9 +19,8 @@ def run_nicdriver_unload(test, params, env): """ timeout = int(params.get("login_timeout", 360)) vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, timeout=timeout) - session_serial = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2, - serial=True) + session = vm.wait_for_login(timeout=timeout) + session_serial = vm.wait_for_serial_login(timeout=timeout) ethname = kvm_test_utils.get_linux_ifname(session, vm.get_mac_address(0)) sys_path = "/sys/class/net/%s/device/driver" % (ethname)
client/tests/kvm/tests/pci_hotplug.py +1 -1
@@ -21,7 +21,7 @@ def run_pci_hotplug(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) + session = vm.wait_for_login(timeout=timeout) # Modprobe the module if specified in config file module = params.get("modprobe_module")
client/tests/kvm/tests/physical_resources_check.py +1 -1
@@ -19,7 +19,7 @@ def run_physical_resources_check(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) + session = vm.wait_for_serial_login(timeout=timeout) logging.info("Starting physical resources check test") logging.info("Values assigned to VM are the values we expect "
client/tests/kvm/tests/ping.py +1 -2
@@ -18,9 +18,8 @@ def run_ping(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm) + session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) counts = params.get("ping_counts", 100) flood_minutes = float(params.get("flood_minutes", 10))
client/tests/kvm/tests/qemu_img.py +3 -3
@@ -292,7 +292,7 @@ def run_qemu_img(test, params, env): vm = env.get_vm(vm_name) vm.create() timeout = int(params.get("login_timeout", 360)) - session = kvm_test_utils.wait_for_login(vm, timeout=timeout) + session = vm.wait_for_login(timeout=timeout) # Do some changes to the backing_file harddisk try:
@@ -320,7 +320,7 @@ def run_qemu_img(test, params, env): vm = env.get_vm(vm_name) vm.create() timeout = int(params.get("login_timeout", 360)) - session = kvm_test_utils.wait_for_login(vm, timeout=timeout) + session = vm.wait_for_login(timeout=timeout) try: output = session.cmd("[ ! -e /commit_testfile ] && echo $?") logging.info("Output of [ ! -e /commit_testfile ] && echo $?: "
@@ -346,7 +346,7 @@ def run_qemu_img(test, params, env): vm = env.get_vm(vm_name) vm.create() timeout = int(params.get("login_timeout", 360)) - session = kvm_test_utils.wait_for_login(vm, timeout=timeout) + session = vm.wait_for_login(timeout=timeout) try: output = session.cmd("[ -e /commit_testfile ] && echo $?") logging.info("Output of [ -e /commit_testfile ] && echo $?: %s",
client/tests/kvm/tests/shutdown.py +1 -1
@@ -17,7 +17,7 @@ def run_shutdown(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) + session = vm.wait_for_login(timeout=timeout) try: if params.get("shutdown_method") == "shell":
client/tests/kvm/tests/stress_boot.py +2 -4
@@ -22,7 +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_test_utils.wait_for_login(vm, timeout=login_timeout) + session = vm.wait_for_login(timeout=login_timeout) num = 2 sessions = [session]
@@ -39,9 +39,7 @@ def run_stress_boot(tests, params, env): kvm_preprocessing.preprocess_vm(tests, vm_params, env, vm_name) params['vms'] += " " + vm_name - # Temporary hack - time.sleep(login_timeout) - sessions.append(curr_vm.remote_login()) + sessions.append(curr_vm.wait_for_login(timeout=login_timeout)) logging.info("Guest #%d boots up successfully" % num) # check whether all previous shell sessions are responsive
client/tests/kvm/tests/timedrift.py +1 -1
@@ -54,7 +54,7 @@ def run_timedrift(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) + session = vm.wait_for_login(timeout=timeout) # Collect test parameters: # Command to run to get the current time
client/tests/kvm/tests/timedrift_with_migration.py +2 -4
@@ -19,7 +19,7 @@ def run_timedrift_with_migration(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) + session = vm.wait_for_login(timeout=timeout) # Collect test parameters: # Command to run to get the current time
@@ -50,9 +50,7 @@ def run_timedrift_with_migration(test, params, env): vm = kvm_test_utils.migrate(vm, env) # Log in logging.info("Logging in after migration...") - # Temporary hack - time.sleep(30) - session = vm.remote_login() + session = vm.wait_for_login(timeout=30) logging.info("Logged in after migration") # Get time after current iteration (ht1_, gt1_) = kvm_test_utils.get_time(session, time_command,
client/tests/kvm/tests/timedrift_with_reboot.py +1 -1
@@ -19,7 +19,7 @@ def run_timedrift_with_reboot(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) + session = vm.wait_for_login(timeout=timeout) # Collect test parameters: # Command to run to get the current time
client/tests/kvm/tests/timedrift_with_stop.py +1 -1
@@ -22,7 +22,7 @@ def run_timedrift_with_stop(test, params, env): login_timeout = int(params.get("login_timeout", 360)) sleep_time = int(params.get("sleep_time", 30)) vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout) + session = vm.wait_for_login(timeout=login_timeout) # Collect test parameters: # Command to run to get the current time
client/tests/kvm/tests/virtio_console.py +2 -6
@@ -585,9 +585,7 @@ def run_virtio_console(test, params, env): vm = env.get_vm(params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, 0, - float(params.get("boot_timeout", 240)), - 0, 2) + session = vm.wait_for_login(float(params.get("boot_timeout", 240))) # connect the sockets for i in range(0, no_console):
@@ -1134,9 +1132,7 @@ def run_virtio_console(test, params, env): logging.error("Python died/is stucked/have remaining threads") logging.debug(tmp) vm[1].close() - vm[1] = kvm_test_utils.wait_for_login(vm[0], 0, - float(params.get("boot_timeout", 240)), - 0, 2) + vm[1] = vm[0].wait_for_login(float(params.get("boot_timeout", 240))) (match, data) = _on_guest("killall -9 python " "&& echo -n PASS: python killed" "|| echo -n PASS: python was death",
client/tests/kvm/tests/vlan.py +3 -5
@@ -18,7 +18,6 @@ def run_vlan(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = [] session = [] ifname = []
@@ -79,8 +78,8 @@ def run_vlan(test, params, env): session[dst].cmd_output("rm -f receive") for i in range(2): - session.append(kvm_test_utils.wait_for_login(vm[i], - timeout=int(params.get("login_timeout", 360)))) + session.append(vm[i].wait_for_login( + timeout=int(params.get("login_timeout", 360)))) if not session[i] : raise error.TestError("Could not log into guest(vm%d)" % i) logging.info("Logged in")
@@ -135,8 +134,7 @@ def run_vlan(test, params, env): # we must use a dedicated session becuase the kvm_subprocess # does not have the other method to interrupt the process in # the guest rather than close the session. - session_flood = kvm_test_utils.wait_for_login(vm[src], - timeout = 60) + session_flood = vm[src].wait_for_login(timeout=60) kvm_test_utils.ping(vlan_ip[dst], flood=True, interface=ifname[src], session=session_flood, timeout=10)
client/tests/kvm/tests/vmstop.py +1 -1
@@ -20,7 +20,7 @@ def run_vmstop(test, params, env): """ vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) timeout = float(params.get("login_timeout", 240)) - session = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2) + session = vm.wait_for_login(timeout=timeout) save_path = params.get("save_path", "/tmp") clean_save = params.get("clean_save") == "yes"
client/tests/kvm/tests/whql_client_install.py +1 -1
@@ -22,7 +22,7 @@ def run_whql_client_install(test, params, env): @param env: Dictionary with test environment. """ vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, 0, 240) + session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) # Collect test params server_address = params.get("server_address")
client/tests/kvm/tests/whql_submission.py +4 -3
@@ -19,17 +19,18 @@ def run_whql_submission(test, params, env): @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(kvm_test_utils.get_living_vm(env, vm_name)) - sessions.append(kvm_test_utils.wait_for_login(vms[-1], 0, 240)) + 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 = kvm_test_utils.wait_for_login(vm, nic_index, 600) + s = vm.wait_for_login(nic_index, 600) s.close() # Collect parameters
@@ -79,7 +80,7 @@ def run_whql_submission(test, params, env): for vm in vms: nics = vm.params.objects("nics") for nic_index in range(len(nics)): - s = kvm_test_utils.wait_for_login(vm, nic_index, 600) + s = vm.wait_for_login(nic_index, 600) s.close() # Run whql_pre_command and close the sessions
client/tests/kvm/tests/yum_update.py +1 -1
@@ -40,7 +40,7 @@ def run_yum_update(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) + session = vm.wait_for_login(timeout=timeout) internal_yum_update(session, "yum update", params.get("shell_prompt"), 600) internal_yum_update(session, "yum update kernel",
Signature · 1 line
1.7.3.4
PATCH 6/17 KVM test: rename VM.remote_login() to VM.login()
In reply to Michael GoldishKeep remote_login() as an alias for backward compatibility.
--- client/tests/kvm/kvm_preprocessing.py | 2 +- client/tests/kvm/kvm_test_utils.py | 2 +- client/tests/kvm/kvm_vm.py | 21 ++++++++++++++------- client/tests/kvm/tests/boot_savevm.py | 2 +- client/tests/kvm/tests/timedrift.py | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-)
client/tests/kvm/kvm_preprocessing.py +1 -1
@@ -341,7 +341,7 @@ def postprocess(test, params, env): for vm in env.get_all_vms(): if vm.is_alive(): try: - session = vm.remote_login() + session = vm.login() session.close() except kvm_utils.LoginError: vm.destroy(gracefully=False)
client/tests/kvm/kvm_test_utils.py +1 -1
@@ -76,7 +76,7 @@ def wait_for_login(vm, nic_index=0, timeout=240, start=0, step=2, serial=None): time.sleep(start) while time.time() < end_time: try: - session = vm.remote_login(nic_index=nic_index) + session = vm.login(nic_index=nic_index) break except kvm_utils.LoginError, e: logging.debug(e)
client/tests/kvm/kvm_vm.py +14 -7
@@ -795,7 +795,7 @@ class VM: # Try to destroy with shell command logging.debug("Trying to shutdown VM with shell command...") try: - session = self.remote_login() + session = self.login() except kvm_utils.LoginError, e: logging.debug(e) else:
@@ -1059,7 +1059,7 @@ class VM: return shm * 4.0 / 1024 - def remote_login(self, nic_index=0, timeout=10): + def login(self, nic_index=0, timeout=10): """ Log into the guest via SSH/Telnet/Netcat. If timeout expires while waiting for output from the guest (e.g. a
@@ -1091,13 +1091,20 @@ class VM: return session + def remote_login(self, nic_index=0, timeout=10): + """ + Alias for login() for backward compatibility. + """ + return self.login(nic_index, timeout) + + def wait_for_login(self, nic_index=0, timeout=240, internal_timeout=10): """ Make multiple attempts to log into the guest via SSH/Telnet/Netcat. @param nic_index: The index of the NIC to connect to. @param timeout: Time (seconds) to keep trying to log in. - @param internal_timeout: Timeout to pass to remote_login(). + @param internal_timeout: Timeout to pass to login(). @return: A ShellSession object. """ logging.debug("Attempting to log into '%s' (timeout %ds)" % (self.name,
@@ -1105,12 +1112,12 @@ class VM: end_time = time.time() + timeout while time.time() < end_time: try: - return self.remote_login(nic_index, internal_timeout) + return self.login(nic_index, internal_timeout) except kvm_utils.LoginError, e: logging.debug(e) time.sleep(2) # Timeout expired; try one more time but don't catch exceptions - return self.remote_login(nic_index, internal_timeout) + return self.login(nic_index, internal_timeout) def copy_files_to(self, local_path, remote_path, nic_index=0, timeout=600):
@@ -1253,7 +1260,7 @@ class VM: """ Get the cpu count of the VM. """ - session = self.remote_login() + session = self.login() try: return int(session.cmd(self.params.get("cpu_chk_cmd"))) finally:
@@ -1267,7 +1274,7 @@ class VM: @param check_cmd: Command used to check memory. If not provided, self.params.get("mem_chk_cmd") will be used. """ - session = self.remote_login() + session = self.login() try: if not cmd: cmd = self.params.get("mem_chk_cmd")
client/tests/kvm/tests/boot_savevm.py +1 -1
@@ -50,7 +50,7 @@ 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 = vm.remote_login() + session = vm.login() logging.info("Logged in to guest!") break
client/tests/kvm/tests/timedrift.py +1 -1
@@ -87,7 +87,7 @@ def run_timedrift(test, params, env): # Open shell sessions with the guest logging.info("Starting load on guest...") for i in range(guest_load_instances): - load_session = vm.remote_login() + load_session = vm.login() # 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
Signature · 1 line
1.7.3.4
PATCH 7/17 KVM test: introduce VM exceptions
In reply to Michael Goldish--- client/tests/kvm/kvm_vm.py | 146 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 146 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_vm.py +146 -0
@@ -11,6 +11,152 @@ from autotest_lib.client.common_lib import error from autotest_lib.client.bin import utils +class VMError(Exception): + pass + + +class VMCreateError(VMError): + def __init__(self, cmd, status, output): + VMError.__init__(self, cmd, status, output) + self.cmd = cmd + self.status = status + self.output = output + + def __str__(self): + return ("VM creation command failed: %r (status: %s, output: %r)" % + (self.cmd, self.status, self.output)) + + +class VMHashMismatchError(VMError): + def __init__(self, actual, expected): + VMError.__init__(self, actual, expected) + self.actual_hash = actual + self.expected_hash = expected + + def __str__(self): + return ("CD image hash (%s) differs from expected one (%s)" % + (self.actual_hash, self.expected_hash)) + + +class VMImageMissingError(VMError): + def __init__(self, filename): + VMError.__init__(self, filename) + self.filename = filename + + def __str__(self): + return "CD image file not found: %r" % self.filename + + +class VMBadPATypeError(VMError): + def __init__(self, pa_type): + VMError.__init__(self, pa_type) + self.pa_type = pa_type + + def __str__(self): + return "Unsupported PCI assignable type: %r" % self.pa_type + + +class VMPAError(VMError): + def __init__(self, pa_type): + VMError.__init__(self, pa_type) + self.pa_type = pa_type + + def __str__(self): + return ("No PCI assignable devices could be assigned " + "(pci_assignable=%r)" % self.pa_type) + + +class VMPostCreateError(VMError): + def __init__(self, cmd, output): + VMError.__init__(self, cmd, output) + self.cmd = cmd + self.output = output + + +class VMHugePageError(VMPostCreateError): + def __str__(self): + return ("Cannot allocate hugepage memory (command: %r, output: %r)" % + (self.cmd, self.output)) + + +class VMKVMInitError(VMPostCreateError): + def __str__(self): + return ("Cannot initialize KVM (command: %r, output: %r)" % + (self.cmd, self.output)) + + +class VMDeadError(VMError): + pass + + +class VMAddressError(VMError): + pass + + +class VMPortNotRedirectedError(VMAddressError): + def __init__(self, port): + VMAddressError.__init__(self, port) + self.port = port + + def __str__(self): + return "Port not redirected: %s" % self.port + + +class VMAddressVerificationError(VMAddressError): + def __init__(self, mac, ip): + VMAddressError.__init__(self, mac, ip) + self.mac = mac + self.ip = ip + + def __str__(self): + return "Cannot verify MAC-IP address mapping: %s ---> %s" % (self.mac, + self.ip) + + +class VMMACAddressMissingError(VMAddressError): + def __init__(self, nic_index): + VMAddressError.__init__(self, nic_index) + self.nic_index = nic_index + + def __str__(self): + return "No MAC address defined for NIC #%s" % self.nic_index + + +class VMIPAddressMissingError(VMAddressError): + def __init__(self, mac): + VMAddressError.__init__(self, mac) + self.mac = mac + + def __str__(self): + return "Cannot find IP address for MAC address %s" % self.mac + + +class VMMigrateError(VMError): + pass + + +class VMMigrateTimeoutError(VMMigrateError): + pass + + +class VMMigrateCancelError(VMMigrateError): + pass + + +class VMMigrateFailedError(VMMigrateError): + pass + + +class VMMigrateStateMismatchError(VMMigrateError): + def __init__(self, src_hash, dst_hash): + self.src_hash = src_hash + self.dst_hash = dst_hash + + def __str__(self): + return ("Mismatch of VM state before and after migration (%s != %s)" % + (self.src_hash, self.dst_hash)) + + def get_image_filename(params, root_dir): """ Generate an image path from params and root_dir.
Signature · 1 line
1.7.3.4
PATCH 8/17 KVM test: let kvm_vm.create_image() raise a CmdError if qemu-img fails
In reply to Michael Goldish--- client/tests/kvm/kvm_vm.py | 15 ++------------- 1 files changed, 2 insertions(+), 13 deletions(-)
client/tests/kvm/kvm_vm.py +2 -13
@@ -203,19 +203,8 @@ def create_image(params, root_dir): size = params.get("image_size", "10G") qemu_img_cmd += " %s" % size - try: - utils.system(qemu_img_cmd) - except error.CmdError, e: - logging.error("Could not create image; qemu-img command failed:\n%s", - str(e)) - return None - - if not os.path.exists(image_filename): - logging.error("Image could not be created for some reason; " - "qemu-img command:\n%s" % qemu_img_cmd) - return None - - logging.info("Image created in %s" % image_filename) + utils.system(qemu_img_cmd) + logging.info("Image created in %r" % image_filename) return image_filename
Signature · 1 line
1.7.3.4
PATCH 9/17 KVM test: use the new VM exceptions
In reply to Michael Goldish- Raise them where appropriate.
- Catch and handle them where appropriate.
- Modify docstrings.
--- client/tests/kvm/kvm_preprocessing.py | 9 +-- client/tests/kvm/kvm_test_utils.py | 5 +- client/tests/kvm/kvm_vm.py | 110 ++++++++++++++---------------- client/tests/kvm/tests/guest_s4.py | 3 +- client/tests/kvm/tests/ksm_overcommit.py | 3 +- 5 files changed, 57 insertions(+), 73 deletions(-)
client/tests/kvm/kvm_preprocessing.py +3 -6
@@ -80,13 +80,10 @@ def preprocess_vm(test, params, env, name): if start_vm: if migration_mode is not None: - if not vm.create(name, params, test.bindir, - migration_mode=migration_mode): - raise error.TestError("Could not start VM for migration") + vm.create(name, params, test.bindir, migration_mode=migration_mode) else: # Start the VM (or restart it if it's already up) - if not vm.create(name, params, test.bindir): - raise error.TestError("Could not start VM") + vm.create(name, params, test.bindir) else: # Don't start the VM, just update its params vm.params = params
@@ -343,7 +340,7 @@ def postprocess(test, params, env): try: session = vm.login() session.close() - except kvm_utils.LoginError: + except (kvm_utils.LoginError, kvm_vm.VMError): vm.destroy(gracefully=False) # Kill all kvm_subprocess tail threads
client/tests/kvm/kvm_test_utils.py +2 -3
@@ -78,7 +78,7 @@ def wait_for_login(vm, nic_index=0, timeout=240, start=0, step=2, serial=None): try: session = vm.login(nic_index=nic_index) break - except kvm_utils.LoginError, e: + except (kvm_utils.LoginError, kvm_vm.VMError), e: logging.debug(e) time.sleep(step) if not session:
@@ -205,8 +205,7 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp", + ' -S') if dest_host == 'localhost': - if not dest_vm.create(migration_mode=mig_protocol, mac_source=vm): - raise error.TestError("Could not create dest VM") + dest_vm.create(migration_mode=mig_protocol, mac_source=vm) try: try:
client/tests/kvm/kvm_vm.py +50 -60
233 lines not on this page · raw message
client/tests/kvm/tests/guest_s4.py +1 -2
@@ -49,8 +49,7 @@ def run_guest_s4(test, params, env): # Start vm, and check whether the program is still running logging.info("Resuming suspended VM...") - if not vm.create(): - raise error.TestError("Failed to start VM after suspend to disk") + vm.create() # Log into the resumed VM relogin_timeout = int(params.get("relogin_timeout", 240))
client/tests/kvm/tests/ksm_overcommit.py +1 -2
@@ -574,8 +574,7 @@ def run_ksm_overcommit(test, params, env): params['vms'] += " " + vm_name logging.debug("Booting guest %s" % lvms[i].name) - if not lvms[i].create(): - raise error.TestFail("Cannot create VM %s" % lvms[i].name) + lvms[i].create() if not lvms[i].is_alive(): raise error.TestError("VM %s seems to be dead; Test requires a" "living VM" % lvms[i].name)
Signature · 1 line
1.7.3.4
PATCH 10/17 KVM test: add VM.verify_alive() and Monitor.verify_responsive()
In reply to Michael Goldish--- client/tests/kvm/kvm_monitor.py | 31 +++++++++++++++---------------- client/tests/kvm/kvm_vm.py | 21 ++++++++++++++++----- 2 files changed, 31 insertions(+), 21 deletions(-)
client/tests/kvm/kvm_monitor.py +15 -16
@@ -128,6 +128,17 @@ class Monitor: return s + def is_responsive(self): + """ + Return True iff the monitor is responsive. + """ + try: + self.verify_responsive() + return True + except MonitorError: + return False + + class HumanMonitor(Monitor): """ Wraps "human monitor" commands.
@@ -248,17 +259,11 @@ class HumanMonitor(Monitor): self._lock.release() - def is_responsive(self): + def verify_responsive(self): """ Make sure the monitor is responsive by sending a command. - - @return: True if responsive, False otherwise """ - try: - self.cmd("info status") - return True - except MonitorError: - return False + self.cmd("info status") # Command wrappers
@@ -615,17 +620,11 @@ class QMPMonitor(Monitor): return self.cmd_obj(self._build_cmd(cmd, args, id), timeout) - def is_responsive(self): + def verify_responsive(self): """ Make sure the monitor is responsive by sending a command. - - @return: True if responsive, False otherwise """ - try: - self.cmd("query-status") - return True - except MonitorError: - return False + self.cmd("query-status") def get_events(self):
client/tests/kvm/kvm_vm.py +16 -5
@@ -856,6 +856,7 @@ class VM: monitor = kvm_monitor.HumanMonitor( monitor_name, self.get_monitor_filename(monitor_name)) + monitor.verify_responsive() break except kvm_monitor.MonitorError, e: logging.warn(e)
@@ -998,15 +999,25 @@ class VM: return self.monitors[0] + def verify_alive(self): + """ + Make sure the VM is alive and that the main monitor is responsive. + + @raise VMDeadError: If the VM is dead + @raise: Various monitor exceptions if the monitor is unresponsive + """ + if self.is_dead(): + raise VMDeadError("VM is dead") + if self.monitors: + self.monitor.verify_responsive() + + def is_alive(self): """ Return True if the VM is alive and its monitor is responsive. """ - # Check if the process is running - if self.is_dead(): - return False - # Try sending a monitor command - return bool(self.monitor) and self.monitor.is_responsive() + return not self.is_dead() and (not self.monitors or + self.monitor.is_responsive()) def is_dead(self):
Signature · 1 line
1.7.3.4
PATCH 11/17 KVM test: use VM.verify_alive() instead of kvm_test_utils.get_living_vm()
In reply to Michael GoldishIt looks cleaner even though it's 1 extra line.
--- client/tests/kvm/tests/autotest.py | 3 ++- client/tests/kvm/tests/balloon_check.py | 3 ++- client/tests/kvm/tests/boot.py | 3 ++- client/tests/kvm/tests/boot_savevm.py | 3 ++- client/tests/kvm/tests/clock_getres.py | 3 ++- client/tests/kvm/tests/ethtool.py | 3 ++- client/tests/kvm/tests/file_transfer.py | 3 ++- client/tests/kvm/tests/guest_s4.py | 3 ++- client/tests/kvm/tests/guest_test.py | 3 ++- client/tests/kvm/tests/iofuzz.py | 3 ++- client/tests/kvm/tests/ioquit.py | 3 ++- client/tests/kvm/tests/iozone_windows.py | 3 ++- client/tests/kvm/tests/jumbo.py | 3 ++- client/tests/kvm/tests/kdump.py | 3 ++- client/tests/kvm/tests/linux_s3.py | 3 ++- client/tests/kvm/tests/mac_change.py | 3 ++- client/tests/kvm/tests/migration.py | 3 ++- client/tests/kvm/tests/migration_multi_host.py | 3 ++- .../kvm/tests/migration_with_file_transfer.py | 3 ++- client/tests/kvm/tests/migration_with_reboot.py | 3 ++- client/tests/kvm/tests/multicast.py | 3 ++- client/tests/kvm/tests/netperf.py | 3 ++- client/tests/kvm/tests/nic_bonding.py | 3 ++- client/tests/kvm/tests/nic_promisc.py | 3 ++- client/tests/kvm/tests/nicdriver_unload.py | 3 ++- client/tests/kvm/tests/pci_hotplug.py | 3 ++- client/tests/kvm/tests/physical_resources_check.py | 3 ++- client/tests/kvm/tests/ping.py | 3 ++- client/tests/kvm/tests/pxe.py | 3 ++- client/tests/kvm/tests/qmp_basic.py | 3 ++- client/tests/kvm/tests/shutdown.py | 3 ++- client/tests/kvm/tests/stress_boot.py | 3 ++- client/tests/kvm/tests/timedrift.py | 3 ++- client/tests/kvm/tests/timedrift_with_migration.py | 3 ++- client/tests/kvm/tests/timedrift_with_reboot.py | 3 ++- client/tests/kvm/tests/timedrift_with_stop.py | 3 ++- client/tests/kvm/tests/unattended_install.py | 3 ++- client/tests/kvm/tests/vlan.py | 6 ++++-- client/tests/kvm/tests/vmstop.py | 3 ++- client/tests/kvm/tests/whql_client_install.py | 3 ++- client/tests/kvm/tests/whql_submission.py | 3 ++- client/tests/kvm/tests/yum_update.py | 3 ++- 42 files changed, 86 insertions(+), 43 deletions(-)
client/tests/kvm/tests/autotest.py +2 -1
@@ -12,7 +12,8 @@ def run_autotest(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/balloon_check.py +2 -1
@@ -65,7 +65,8 @@ def run_balloon_check(test, params, env): fail = 0 - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/boot.py +2 -1
@@ -15,7 +15,8 @@ def run_boot(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/boot_savevm.py +2 -1
@@ -13,7 +13,8 @@ def run_boot_savevm(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() savevm_delay = float(params.get("savevm_delay")) savevm_login_delay = float(params.get("savevm_login_delay")) logging.info("savevm_delay = %f" % savevm_delay)
client/tests/kvm/tests/clock_getres.py +2 -1
@@ -28,7 +28,8 @@ def run_clock_getres(test, params, env): if not os.path.isfile(test_clock): raise error.TestError("Could not find %s" % t_name) - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) vm.copy_files_to(test_clock, base_dir)
client/tests/kvm/tests/ethtool.py +2 -1
@@ -175,7 +175,8 @@ def run_ethtool(test, params, env): return True - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) # Let's just error the test if we identify that there's no ethtool installed session.cmd("ethtool -h")
client/tests/kvm/tests/file_transfer.py +2 -1
@@ -17,7 +17,8 @@ def run_file_transfer(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout=int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/guest_s4.py +2 -1
@@ -11,7 +11,8 @@ def run_guest_s4(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/guest_test.py +2 -1
@@ -19,7 +19,8 @@ def run_guest_test(test, params, env): login_timeout = int(params.get("login_timeout", 360)) reboot = params.get("reboot", "no") - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() if params.get("serial_login") == "yes": session = vm.wait_for_serial_login(timeout=login_timeout) else:
client/tests/kvm/tests/iofuzz.py +2 -1
@@ -90,7 +90,8 @@ def run_iofuzz(test, params, env): login_timeout = float(params.get("login_timeout", 240)) - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) try:
client/tests/kvm/tests/ioquit.py +2 -1
@@ -11,7 +11,8 @@ def run_ioquit(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() login_timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=login_timeout) session2 = vm.wait_for_login(timeout=login_timeout)
client/tests/kvm/tests/iozone_windows.py +2 -1
@@ -17,7 +17,8 @@ def run_iozone_windows(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + 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,
client/tests/kvm/tests/jumbo.py +2 -1
@@ -22,7 +22,8 @@ def run_jumbo(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) mtu = params.get("mtu", "1500") flood_time = params.get("flood_time", "300")
client/tests/kvm/tests/kdump.py +2 -1
@@ -14,7 +14,8 @@ def run_kdump(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = float(params.get("login_timeout", 240)) crash_timeout = float(params.get("crash_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/linux_s3.py +2 -1
@@ -11,7 +11,8 @@ def run_linux_s3(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/mac_change.py +2 -1
@@ -15,7 +15,8 @@ def run_mac_change(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + 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
client/tests/kvm/tests/migration.py +2 -1
@@ -19,7 +19,8 @@ def run_migration(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/migration_multi_host.py +2 -1
@@ -37,7 +37,8 @@ def run_migration_multi_host(test, params, env): else: return o.get("status") == "running" - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() login_timeout = int(params.get("login_timeout", 360)) role = params.get("role") srchost = params.get("srchost")
client/tests/kvm/tests/migration_with_file_transfer.py +2 -1
@@ -19,7 +19,8 @@ def run_migration_with_file_transfer(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/migration_with_reboot.py +2 -1
@@ -44,7 +44,8 @@ def run_migration_with_reboot(test, params, env): logging.info("Guest is up again") session.close() - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/multicast.py +2 -1
@@ -18,7 +18,8 @@ def run_multicast(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) def run_guest(cmd):
client/tests/kvm/tests/netperf.py +2 -1
@@ -16,7 +16,8 @@ def run_netperf(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() login_timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=login_timeout)
client/tests/kvm/tests/nic_bonding.py +2 -1
@@ -31,7 +31,8 @@ def run_nic_bonding(test, params, env): break timeout = int(params.get("login_timeout", 1200)) - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() session_serial = vm.wait_for_serial_login(timeout=timeout) script_path = kvm_utils.get_path(test.bindir, "scripts/bonding_setup.py") vm.copy_files_to(script_path, "/tmp/bonding_setup.py")
client/tests/kvm/tests/nic_promisc.py +2 -1
@@ -18,7 +18,8 @@ def run_nic_promisc(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) session_serial = vm.wait_for_serial_login(timeout=timeout)
client/tests/kvm/tests/nicdriver_unload.py +2 -1
@@ -18,7 +18,8 @@ def run_nicdriver_unload(test, params, env): @param env: Dictionary with test environment. """ timeout = int(params.get("login_timeout", 360)) - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + 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)
client/tests/kvm/tests/pci_hotplug.py +2 -1
@@ -19,7 +19,8 @@ def run_pci_hotplug(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/physical_resources_check.py +2 -1
@@ -17,7 +17,8 @@ def run_physical_resources_check(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_serial_login(timeout=timeout)
client/tests/kvm/tests/ping.py +2 -1
@@ -18,7 +18,8 @@ def run_ping(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) counts = params.get("ping_counts", 100)
client/tests/kvm/tests/pxe.py +2 -1
@@ -15,7 +15,8 @@ def run_pxe(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("pxe_timeout", 60)) logging.info("Try to boot from PXE")
client/tests/kvm/tests/qmp_basic.py +2 -1
@@ -381,7 +381,8 @@ def run_qmp_basic(test, params, env): check_error_resp(resp, "CommandNotFound", { "name": cmd }) - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() # Run all suites greeting_suite(vm.monitor)
client/tests/kvm/tests/shutdown.py +2 -1
@@ -15,7 +15,8 @@ def run_shutdown(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/stress_boot.py +2 -1
@@ -17,7 +17,8 @@ def run_stress_boot(tests, params, env): @param env: Dictionary with test environment. """ # boot the first vm - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() logging.info("Waiting for first guest to be up...")
client/tests/kvm/tests/timedrift.py +2 -1
@@ -52,7 +52,8 @@ def run_timedrift(test, params, env): for tid, mask in prev_masks.items(): commands.getoutput("taskset -p %s %s" % (mask, tid)) - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/timedrift_with_migration.py +2 -1
@@ -17,7 +17,8 @@ def run_timedrift_with_migration(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/timedrift_with_reboot.py +2 -1
@@ -17,7 +17,8 @@ def run_timedrift_with_reboot(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/timedrift_with_stop.py +2 -1
@@ -21,7 +21,8 @@ def run_timedrift_with_stop(test, params, env): """ login_timeout = int(params.get("login_timeout", 360)) sleep_time = int(params.get("sleep_time", 30)) - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) # Collect test parameters:
client/tests/kvm/tests/unattended_install.py +2 -1
@@ -14,7 +14,8 @@ def run_unattended_install(test, params, env): @param env: Dictionary with test environment. """ buf = 1024 - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() port = vm.get_port(int(params.get("guest_port_unattended_install"))) if params.get("post_install_delay"):
client/tests/kvm/tests/vlan.py +4 -2
@@ -30,8 +30,10 @@ def run_vlan(test, params, env): maximal = int(params.get("maximal")) file_size = params.get("file_size") - vm.append(kvm_test_utils.get_living_vm(env, params.get("main_vm"))) - vm.append(kvm_test_utils.get_living_vm(env, "vm2")) + vm.append(env.get_vm(params["main_vm"])) + vm.append(env.get_vm("vm2")) + for vm_ in vm: + vm_.verify_alive() def add_vlan(session, id, iface="eth0"): session.cmd("vconfig add %s %s" % (iface, id))
client/tests/kvm/tests/vmstop.py +2 -1
@@ -18,7 +18,8 @@ def run_vmstop(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout)
client/tests/kvm/tests/whql_client_install.py +2 -1
@@ -21,7 +21,8 @@ def run_whql_client_install(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) # Collect test params
client/tests/kvm/tests/whql_submission.py +2 -1
@@ -23,7 +23,8 @@ def run_whql_submission(test, params, env): vms = [] sessions = [] for vm_name in params.objects("vms"): - vms.append(kvm_test_utils.get_living_vm(env, vm_name)) + 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
client/tests/kvm/tests/yum_update.py +2 -1
@@ -38,7 +38,8 @@ def run_yum_update(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout)
Signature · 1 line
1.7.3.4
PATCH 12/17 KVM test: kvm_preprocessing.py: simplify handling of params['migration_mode']
In reply to Michael GoldishAlso reorder the if statements because if migration_mode is specified it causes an unconditional VM restart (unlike start_vm).
--- client/tests/kvm/kvm_preprocessing.py | 16 ++++++---------- 1 files changed, 6 insertions(+), 10 deletions(-)
client/tests/kvm/kvm_preprocessing.py +6 -10
@@ -60,11 +60,12 @@ def preprocess_vm(test, params, env, name): start_vm = False - migration_mode = params.get("migration_mode", None) - if params.get("restart_vm") == "yes": logging.debug("'restart_vm' specified; (re)starting VM...") start_vm = True + elif params.get("migration_mode"): + logging.debug("Starting VM in incoming migration mode...") + start_vm = True elif params.get("start_vm") == "yes": if not vm.is_alive(): logging.debug("VM is not alive; starting it...")
@@ -74,16 +75,11 @@ def preprocess_vm(test, params, env, name): logging.debug("VM's qemu command differs from requested one; " "restarting it...") start_vm = True - elif migration_mode is not None: - logging.debug("Starting VM on migration incoming mode...") - start_vm = True if start_vm: - if migration_mode is not None: - vm.create(name, params, test.bindir, migration_mode=migration_mode) - else: - # Start the VM (or restart it if it's already up) - vm.create(name, params, test.bindir) + # Start the VM (or restart it if it's already up) + vm.create(name, params, test.bindir, + migration_mode=params.get("migration_mode")) else: # Don't start the VM, just update its params vm.params = params
Signature · 1 line
1.7.3.4
PATCH 13/17 KVM test: make migrate() a VM method
In reply to Michael GoldishThis should make it easier to run things in parallel to migration, because the method switches the VM object's __dict__ instead of the VM object itself.
--- client/tests/kvm/kvm_vm.py | 142 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 142 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_vm.py +142 -0
@@ -1348,6 +1348,148 @@ class VM: return self.serial_login(internal_timeout) + def migrate(self, timeout=3600, protocol="tcp", cancel_delay=None, + offline=False, stable_check=False, clean=True, + save_path="/tmp", dest_host="localhost", remote_port=None): + """ + Migrate the VM. + + If the migration is local, the VM object's state is switched with that + of the destination VM. Otherwise, the state is switched with that of + a dead VM (returned by self.clone()). + + @param timeout: Time to wait for migration to complete. + @param protocol: Migration protocol ('tcp', 'unix' or 'exec'). + @param cancel_delay: If provided, specifies a time duration after which + migration will be canceled. Used for testing migrate_cancel. + @param offline: If True, pause the source VM before migration. + @param stable_check: If True, compare the VM's state after migration to + its state before migration and raise an exception if they + differ. + @param clean: If True, delete the saved state files (relevant only if + stable_check is also True). + @save_path: The path for state files. + @param dest_host: Destination host (defaults to 'localhost'). + @param remote_port: Port to use for remote migration. + """ + def mig_finished(): + o = self.monitor.info("migrate") + if isinstance(o, str): + return "status: active" not in o + else: + return o.get("status") != "active" + + def mig_succeeded(): + o = self.monitor.info("migrate") + if isinstance(o, str): + return "status: completed" in o + else: + return o.get("status") == "completed" + + def mig_failed(): + o = self.monitor.info("migrate") + if isinstance(o, str): + return "status: failed" in o + else: + return o.get("status") == "failed" + + def mig_cancelled(): + o = self.monitor.info("migrate") + if isinstance(o, str): + return ("Migration status: cancelled" in o or + "Migration status: canceled" in o) + else: + return (o.get("status") == "cancelled" or + o.get("status") == "canceled") + + def wait_for_migration(): + if not kvm_utils.wait_for(mig_finished, timeout, 2, 2, + "Waiting for migration to finish..."): + raise VMMigrateTimeoutError("Timeout expired while waiting " + "for migration to finish") + + local = dest_host == "localhost" + + clone = self.clone() + if local: + if stable_check: + # Pause the dest vm after creation + extra_params = clone.params.get("extra_params", "") + " -S" + clone.params["extra_params"] = extra_params + clone.create(migration_mode=protocol, mac_source=self) + + try: + if protocol == "tcp": + if local: + uri = "tcp:localhost:%d" % clone.migration_port + else: + uri = "tcp:%s:%d" % (dest_host, remote_port) + elif protocol == "unix": + uri = "unix:%s" % clone.migration_file + elif protocol == "exec": + uri = '"exec:nc localhost %s"' % clone.migration_port + + if offline: + self.monitor.cmd("stop") + + self.monitor.migrate(uri) + + if cancel_delay: + time.sleep(cancel_delay) + self.monitor.cmd("migrate_cancel") + if not kvm_utils.wait_for(mig_cancelled, 60, 2, 2, + "Waiting for migration " + "cancellation"): + raise VMMigrateCancelError("Cannot cancel migration") + return + + wait_for_migration() + + # Report migration status + if mig_succeeded(): + logging.info("Migration completed successfully") + elif mig_failed(): + raise VMMigrateFailedError("Migration failed") + else: + raise VMMigrateFailedError("Migration ended with unknown " + "status") + + # Switch self <-> clone + temp = self.clone(copy_state=True) + self.__dict__ = clone.__dict__ + clone = temp + + # From now on, clone is the source VM that will soon be destroyed + # and self is the destination VM that will remain alive. If this + # is remote migration, self is a dead VM object. + + if local and stable_check: + try: + save1 = os.path.join(save_path, "src-" + clone.instance) + save2 = os.path.join(save_path, "dst-" + self.instance) + clone.save_to_file(save1) + self.save_to_file(save2) + # Fail if we see deltas + md5_save1 = utils.hash_file(save1) + md5_save2 = utils.hash_file(save2) + if md5_save1 != md5_save2: + raise VMMigrateStateMismatchError(md5_save1, + md5_save2) + finally: + if clean: + if os.path.isfile(save1): + os.remove(save1) + if os.path.isfile(save2): + os.remove(save2) + + finally: + # If we're doing remote migration and it's completed successfully, + # self points to a dead VM object + if self.is_alive(): + self.monitor.cmd("cont") + clone.destroy(gracefully=False) + + def send_key(self, keystr): """ Send a key event to the VM.
Signature · 1 line
1.7.3.4
PATCH 14/17 KVM test: simplify migration_with_reboot and migration_with_file_transfer
In reply to Michael GoldishNow that migration can be performed without switching VMs (but rather by switching states) these tests can be greatly simplified.
--- .../kvm/tests/migration_with_file_transfer.py | 53 +++++++------------- client/tests/kvm/tests/migration_with_reboot.py | 54 ++----------------- 2 files changed, 24 insertions(+), 83 deletions(-)
client/tests/kvm/tests/migration_with_file_transfer.py +18 -35
@@ -21,21 +21,12 @@ def run_migration_with_file_transfer(test, params, env): """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() - timeout = int(params.get("login_timeout", 360)) - session = vm.wait_for_login(timeout=timeout) + login_timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=login_timeout) mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") - # params of transfer test - username = vm.params.get("username", "") - password = vm.params.get("password", "") - client = vm.params.get("file_transfer_client") - address = vm.get_address(0) - port = vm.get_port(int(params.get("file_transfer_port"))) - log_filename = ("migration-transfer-%s-to-%s-%s.log" % - (vm.name, address, - kvm_utils.generate_random_string(4))) host_path = "/tmp/file-%s" % kvm_utils.generate_random_string(6) host_path_returned = "%s-returned" % host_path guest_path = params.get("guest_path", "/tmp/file")
@@ -46,33 +37,26 @@ def run_migration_with_file_transfer(test, params, env): utils.run("dd if=/dev/urandom of=%s bs=1M count=%s" % (host_path, file_size)) + def run_and_migrate(bg): + bg.start() + try: + while bg.is_alive(): + logging.info("File transfer not ended, starting a round of " + "migration...") + vm.migrate(mig_timeout, mig_protocol) + finally: + bg.join() + logging.info("Transferring file from host to guest") - bg = kvm_utils.Thread(kvm_utils.copy_files_to, - (address, client, username, password, port, - host_path, guest_path, log_filename, - transfer_timeout)) - bg.start() - try: - while bg.is_alive(): - logging.info("File transfer not ended, starting a round of " - "migration...") - vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol) - finally: - bg.join() + bg = kvm_utils.Thread(vm.copy_files_to, + (host_path, guest_path, 0, transfer_timeout)) + run_and_migrate(bg) logging.info("Transferring file back from guest to host") - bg = kvm_utils.Thread(kvm_utils.copy_files_from, - (address, client, username, password, port, - host_path_returned, guest_path, log_filename, + bg = kvm_utils.Thread(vm.copy_files_from, + (guest_path, host_path_returned, 0, transfer_timeout)) - bg.start() - try: - while bg.is_alive(): - logging.info("File transfer not ended, starting a round of " - "migration...") - vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol) - finally: - bg.join() + run_and_migrate(bg) # Make sure the returned file is indentical to the original one orig_hash = client_utils.hash_file(host_path)
@@ -81,7 +65,6 @@ def run_migration_with_file_transfer(test, params, env): raise error.TestFail("Returned file hash (%s) differs from " "original one (%s)" % (returned_hash, orig_hash)) - finally: session.close() if os.path.isfile(host_path):
client/tests/kvm/tests/migration_with_reboot.py +6 -48
71 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 16/17 KVM test: reorder kvm_utils.copy_files_from() path parameters
In reply to Michael GoldishReorder path parameters in copy_files_from(). Currently it uses the same order as copy_files_to() (local_path, remote_path) which is counterintuitive IMO (because copy_files_from() copies from a remote host to localhost). Change it to remote_path, then local_path. This is a very low-impact change because the only use of kvm_utils.copy_files_*() is in kvm_vm.py.
VM.copy_files_*() remain unchanged.
--- client/tests/kvm/kvm_utils.py | 8 ++++---- client/tests/kvm/kvm_vm.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
client/tests/kvm/kvm_utils.py +4 -4
@@ -808,16 +808,16 @@ def copy_files_to(address, client, username, password, port, local_path, c.close() -def copy_files_from(address, client, username, password, port, local_path, - remote_path, log_filename=None, timeout=600): +def copy_files_from(address, client, username, password, port, remote_path, + local_path, log_filename=None, timeout=600): """ Copy files from a remote host (guest) using the selected client. @param client: Type of transfer client @param username: Username (if required) @param password: Password (if requried) - @param local_path: Path on the local machine where we are copying from - @param remote_path: Path on the remote machine where we are copying to + @param remote_path: Path on the remote machine where we are copying from + @param local_path: Path on the local machine where we are copying to @param address: Address of remote host(guest) @param log_filename: If specified, log all output to this file @param timeout: The time duration (in seconds) to wait for the transfer to
client/tests/kvm/kvm_vm.py +1 -1
@@ -1297,7 +1297,7 @@ class VM: (self.name, address, kvm_utils.generate_random_string(4))) kvm_utils.copy_files_from(address, client, username, password, port, - local_path, remote_path, log_filename, + remote_path, local_path, log_filename, timeout)
Signature · 1 line
1.7.3.4
PATCH 17/17 KVM test: rename path parameters in kvm_vm.copy_files_*()
In reply to Michael Goldishlocal_path -> host_pathremote_path -> guest_path
--- client/tests/kvm/kvm_vm.py | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-)
client/tests/kvm/kvm_vm.py +8 -9
@@ -1256,12 +1256,12 @@ class VM: return self.login(nic_index, internal_timeout) - def copy_files_to(self, local_path, remote_path, nic_index=0, timeout=600): + def copy_files_to(self, host_path, guest_path, nic_index=0, timeout=600): """ Transfer files to the remote host(guest). - @param local_path: Host path - @param remote_path: Guest path + @param host_path: Host path + @param guest_path: Guest path @param nic_index: The index of the NIC to connect to. @param timeout: Time (seconds) before giving up on doing the remote copy.
@@ -1275,15 +1275,15 @@ class VM: (self.name, address, kvm_utils.generate_random_string(4))) kvm_utils.copy_files_to(address, client, username, password, port, - local_path, remote_path, log_filename, timeout) + host_path, guest_path, log_filename, timeout) - def copy_files_from(self, remote_path, local_path, nic_index=0, timeout=600): + def copy_files_from(self, guest_path, host_path, nic_index=0, timeout=600): """ Transfer files from the guest. - @param local_path: Guest path - @param remote_path: Host path + @param host_path: Guest path + @param guest_path: Host path @param nic_index: The index of the NIC to connect to. @param timeout: Time (seconds) before giving up on doing the remote copy.
@@ -1297,8 +1297,7 @@ class VM: (self.name, address, kvm_utils.generate_random_string(4))) kvm_utils.copy_files_from(address, client, username, password, port, - remote_path, local_path, log_filename, - timeout) + guest_path, host_path, log_filename, timeout) def serial_login(self, timeout=10):
Signature · 1 line
1.7.3.4