* [KVM-AUTOTEST PATCH 02/17] KVM test: kvm_utils.py: reorder remote_login(), remote_scp(), copy_files_to(), etc
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 03/17] KVM test: use the new LoginError and SCPError exceptions Michael Goldish
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
Reorder the definition of these functions so that login functions are clustered
together, and higher level functions are further down in the file.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_utils.py | 180 ++++++++++++++++++++--------------------
1 files changed, 90 insertions(+), 90 deletions(-)
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 41117e3..c2918c9 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -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):
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 03/17] KVM test: use the new LoginError and SCPError exceptions
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 02/17] KVM test: kvm_utils.py: reorder remote_login(), remote_scp(), copy_files_to(), etc Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 04/17] KVM test: add VM.wait_for_login() and kvm_utils.wait_for_login() Michael Goldish
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
- Raise these exceptions where appropriate (remote_login(), remote_scp(), etc)
- Modify code that uses the functions that raise the new exceptions to account
for their changed behavior.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_preprocessing.py | 6 +-
client/tests/kvm/kvm_test_utils.py | 48 ++++----
client/tests/kvm/kvm_utils.py | 120 +++++++++-----------
client/tests/kvm/kvm_vm.py | 49 ++++-----
client/tests/kvm/tests/boot_savevm.py | 9 +-
client/tests/kvm/tests/clock_getres.py | 3 +-
client/tests/kvm/tests/ethtool.py | 6 +-
client/tests/kvm/tests/file_transfer.py | 12 +--
client/tests/kvm/tests/guest_s4.py | 4 +-
client/tests/kvm/tests/ksm_overcommit.py | 23 ++--
client/tests/kvm/tests/migration.py | 6 +-
.../kvm/tests/migration_with_file_transfer.py | 7 +-
client/tests/kvm/tests/migration_with_reboot.py | 13 ++-
client/tests/kvm/tests/multicast.py | 3 +-
client/tests/kvm/tests/netperf.py | 3 +-
client/tests/kvm/tests/nic_promisc.py | 12 ++-
client/tests/kvm/tests/nicdriver_unload.py | 10 +-
client/tests/kvm/tests/stress_boot.py | 13 +--
client/tests/kvm/tests/timedrift.py | 2 -
client/tests/kvm/tests/timedrift_with_migration.py | 6 +-
client/tests/kvm/tests/virtio_console.py | 3 +-
21 files changed, 163 insertions(+), 195 deletions(-)
diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py
index 4daafec..2997c8f 100644
--- a/client/tests/kvm/kvm_preprocessing.py
+++ b/client/tests/kvm/kvm_preprocessing.py
@@ -340,10 +340,10 @@ def postprocess(test, params, env):
"that fail to respond to a remote login request...")
for vm in env.get_all_vms():
if vm.is_alive():
- session = vm.remote_login()
- if session:
+ try:
+ session = vm.remote_login()
session.close()
- else:
+ except kvm_utils.LoginError:
vm.destroy(gracefully=False)
# Kill all kvm_subprocess tail threads
diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py
index 7ed3330..caefa5e 100644
--- a/client/tests/kvm/kvm_test_utils.py
+++ b/client/tests/kvm/kvm_test_utils.py
@@ -55,18 +55,32 @@ def wait_for_login(vm, nic_index=0, timeout=240, start=0, step=2, serial=None):
(ssh, rss) one.
@return: A shell session object.
"""
- type = 'remote'
+ end_time = time.time() + timeout
+ session = None
if serial:
type = 'serial'
logging.info("Trying to log into guest %s using serial connection,"
" timeout %ds", vm.name, timeout)
- session = kvm_utils.wait_for(lambda: vm.serial_login(), timeout,
- start, step)
+ time.sleep(start)
+ while time.time() < end_time:
+ try:
+ session = vm.serial_login()
+ break
+ except kvm_utils.LoginError, e:
+ logging.debug(e)
+ time.sleep(step)
else:
+ type = 'remote'
logging.info("Trying to log into guest %s using remote connection,"
" timeout %ds", vm.name, timeout)
- session = kvm_utils.wait_for(lambda: vm.remote_login(
- nic_index=nic_index), timeout, start, step)
+ time.sleep(start)
+ while time.time() < end_time:
+ try:
+ session = vm.remote_login(nic_index=nic_index)
+ break
+ except kvm_utils.LoginError, e:
+ logging.debug(e)
+ time.sleep(step)
if not session:
raise error.TestFail("Could not log into guest %s using %s connection" %
(vm.name, type))
@@ -124,10 +138,9 @@ def reboot(vm, session, method="shell", sleep_before_reset=10, nic_index=0,
# Try logging into the guest until timeout expires
logging.info("Guest is down. Waiting for it to go up again, timeout %ds",
timeout)
- session = kvm_utils.wait_for(lambda: vm.remote_login(nic_index=nic_index),
- timeout, 0, 2)
- if not session:
- raise error.TestFail("Could not log into guest after reboot")
+ # Temporary hack
+ time.sleep(timeout)
+ session = vm.remote_login(nic_index=nic_index)
logging.info("Guest is up again")
return session
@@ -438,7 +451,6 @@ def run_autotest(vm, session, control_path, timeout, outputdir):
@param local_path: Local path.
@param remote_path: Remote path.
"""
- copy = False
local_hash = utils.hash_file(local_path)
basename = os.path.basename(local_path)
output = session.cmd_output("md5sum %s" % remote_path)
@@ -452,14 +464,9 @@ def run_autotest(vm, session, control_path, timeout, outputdir):
# Let's be a little more lenient here and see if it wasn't a
# temporary problem
remote_hash = "0"
-
if remote_hash != local_hash:
logging.debug("Copying %s to guest", basename)
- copy = True
-
- if copy:
- if not vm.copy_files_to(local_path, remote_path):
- raise error.TestFail("Could not copy %s to guest" % local_path)
+ vm.copy_files_to(local_path, remote_path)
def extract(vm, remote_path, dest_dir="."):
@@ -484,9 +491,8 @@ def run_autotest(vm, session, control_path, timeout, outputdir):
guest_results_dir = os.path.join(outputdir, "guest_autotest_results")
if not os.path.exists(guest_results_dir):
os.mkdir(guest_results_dir)
- if not vm.copy_files_from("%s/results/default/*" % autotest_path,
- guest_results_dir):
- logging.error("Could not copy autotest results from guest")
+ vm.copy_files_from("%s/results/default/*" % autotest_path,
+ guest_results_dir)
def get_results_summary():
@@ -536,9 +542,7 @@ def run_autotest(vm, session, control_path, timeout, outputdir):
# Extract autotest.tar.bz2
extract(vm, compressed_autotest_path, "/")
- if not vm.copy_files_to(control_path,
- os.path.join(autotest_path, 'control')):
- raise error.TestFail("Could not copy the test control file to guest")
+ vm.copy_files_to(control_path, os.path.join(autotest_path, 'control'))
# Run the test
logging.info("Running autotest control file %s on guest, timeout %ss",
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index c2918c9..24285d4 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -519,8 +519,10 @@ def _remote_login(session, username, password, prompt, timeout=10):
@param timeout: The maximal time duration (in seconds) to wait for each
step of the login procedure (i.e. the "Are you sure" prompt, the
password prompt, the shell prompt, etc)
-
- @return: True on success and False otherwise.
+ @raise LoginTimeoutError: If timeout expires
+ @raise LoginAuthenticationError: If authentication fails
+ @raise LoginProcessTerminatedError: If the client terminates during login
+ @raise LoginError: If some other error occurs
"""
password_prompt_count = 0
login_prompt_count = 0
@@ -543,8 +545,7 @@ def _remote_login(session, username, password, prompt, timeout=10):
password_prompt_count += 1
continue
else:
- logging.debug("Got password prompt again")
- return False
+ raise LoginAuthenticationError("Got password prompt twice")
elif match == 2: # "login:"
if login_prompt_count == 0:
logging.debug("Got username prompt; sending '%s'" % username)
@@ -552,27 +553,22 @@ def _remote_login(session, username, password, prompt, timeout=10):
login_prompt_count += 1
continue
else:
- logging.debug("Got username prompt again")
- return False
+ raise LoginAuthenticationError("Got username prompt twice")
elif match == 3: # "Connection closed"
- logging.debug("Got 'Connection closed'")
- return False
+ raise LoginError("Client said 'connection closed'")
elif match == 4: # "Connection refused"
- logging.debug("Got 'Connection refused'")
- return False
+ raise LoginError("Client said 'connection refused'")
elif match == 5: # "Please wait"
logging.debug("Got 'Please wait'")
timeout = 30
continue
elif match == 6: # prompt
logging.debug("Got shell prompt -- logged in")
- return True
+ break
except kvm_subprocess.ExpectTimeoutError, e:
- logging.debug("Timeout elapsed (output so far: %r)" % e.output)
- return False
+ raise LoginTimeoutError(e.output)
except kvm_subprocess.ExpectProcessTerminatedError, e:
- logging.debug("Process terminated (output so far: %r)" % e.output)
- return False
+ raise LoginProcessTerminatedError(e.status, e.output)
def remote_login(client, host, port, username, password, prompt, linesep="\n",
@@ -592,8 +588,9 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n",
@param timeout: The maximal time duration (in seconds) to wait for
each step of the login procedure (i.e. the "Are you sure" prompt
or the password prompt)
-
- @return: ShellSession object on success and None on failure.
+ @raise LoginBadClientError: If an unknown client is requested
+ @raise: Whatever _remote_login() raises
+ @return: A ShellSession object.
"""
if client == "ssh":
cmd = ("ssh -o UserKnownHostsFile=/dev/null "
@@ -604,18 +601,19 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n",
elif client == "nc":
cmd = "nc %s %s" % (host, port)
else:
- logging.error("Unknown remote shell client: %s" % client)
- return
+ raise LoginBadClientError(client)
logging.debug("Trying to login with command '%s'" % cmd)
session = kvm_subprocess.ShellSession(cmd, linesep=linesep, prompt=prompt)
- if _remote_login(session, username, password, prompt, timeout):
- if log_filename:
- session.set_output_func(log_line)
- session.set_output_params((log_filename,))
- return session
- else:
+ try:
+ _remote_login(session, username, password, prompt, timeout)
+ except:
session.close()
+ raise
+ if log_filename:
+ session.set_output_func(log_line)
+ session.set_output_params((log_filename,))
+ return session
def _remote_scp(session, password, transfer_timeout=600, login_timeout=10):
@@ -634,11 +632,15 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10):
@param login_timeout: The maximal time duration (in seconds) to wait for
each step of the login procedure (i.e. the "Are you sure" prompt or
the password prompt)
-
- @return: True if the transfer succeeds and False on failure.
+ @raise SCPAuthenticationError: If authentication fails
+ @raise SCPTransferTimeoutError: If the transfer fails to complete in time
+ @raise SCPTransferFailedError: If the process terminates with a nonzero
+ exit code
+ @raise SCPError: If some other error occurs
"""
password_prompt_count = 0
timeout = login_timeout
+ authentication_done = False
while True:
try:
@@ -655,19 +657,24 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10):
session.sendline(password)
password_prompt_count += 1
timeout = transfer_timeout
+ authentication_done = True
continue
else:
- logging.debug("Got password prompt again")
- return False
+ raise SCPAuthenticationError("Got password prompt twice")
elif match == 2: # "lost connection"
- logging.debug("Got 'lost connection'")
- return False
+ raise SCPError("SCP client said 'lost connection'")
except kvm_subprocess.ExpectTimeoutError, e:
- logging.debug("Timeout expired")
- return False
+ if authentication_done:
+ raise SCPTransferTimeoutError(e.output)
+ else:
+ raise SCPAuthenticationError("Authentication timeout expired "
+ "(output so far: %r)" % e.output)
except kvm_subprocess.ExpectProcessTerminatedError, e:
- logging.debug("SCP process terminated with status %s", e.status)
- return e.status == 0
+ if e.status == 0:
+ logging.debug("SCP process terminated with status 0")
+ break
+ else:
+ raise SCPTransferFailedError(e.status, e.output)
def remote_scp(command, password, log_filename=None, transfer_timeout=600,
@@ -686,24 +693,21 @@ def remote_scp(command, password, log_filename=None, transfer_timeout=600,
@param login_timeout: The maximal time duration (in seconds) to wait for
each step of the login procedure (i.e. the "Are you sure" prompt
or the password prompt)
-
- @return: True if the transfer succeeds and False on failure.
+ @raise: Whatever _remote_scp() raises
"""
logging.debug("Trying to SCP with command '%s', timeout %ss",
command, transfer_timeout)
-
if log_filename:
output_func = log_line
output_params = (log_filename,)
else:
output_func = None
output_params = ()
-
session = kvm_subprocess.Expect(command,
output_func=output_func,
output_params=output_params)
try:
- return _remote_scp(session, password, transfer_timeout, login_timeout)
+ _remote_scp(session, password, transfer_timeout, login_timeout)
finally:
session.close()
@@ -721,13 +725,12 @@ def scp_to_remote(host, port, username, password, local_path, remote_path,
@param log_filename: If specified, log all output to this file
@param timeout: The time duration (in seconds) to wait for the transfer
to complete.
-
- @return: True on success and False on failure.
+ @raise: Whatever remote_scp() raises
"""
command = ("scp -v -o UserKnownHostsFile=/dev/null "
"-o PreferredAuthentications=password -r -P %s %s %s@%s:%s" %
(port, local_path, username, host, remote_path))
- return remote_scp(command, password, log_filename, timeout)
+ remote_scp(command, password, log_filename, timeout)
def scp_from_remote(host, port, username, password, remote_path, local_path,
@@ -743,13 +746,12 @@ def scp_from_remote(host, port, username, password, remote_path, local_path,
@param log_filename: If specified, log all output to this file
@param timeout: The time duration (in seconds) to wait for the transfer
to complete.
-
- @return: True on success and False on failure.
+ @raise: Whatever remote_scp() raises
"""
command = ("scp -v -o UserKnownHostsFile=/dev/null "
"-o PreferredAuthentications=password -r -P %s %s@%s:%s %s" %
(port, username, host, remote_path, local_path))
- return remote_scp(command, password, log_filename, timeout)
+ remote_scp(command, password, log_filename, timeout)
def copy_files_to(address, client, username, password, port, local_path,
@@ -766,22 +768,15 @@ def copy_files_to(address, client, username, password, port, local_path,
@param log_filename: If specified, log all output to this file
@param timeout: The time duration (in seconds) to wait for the transfer to
complete.
-
- @return: True on success and False on failure.
+ @raise: Whatever remote_scp() raises
"""
-
- if not address or not port:
- logging.debug("IP address or port unavailable")
- return None
-
if client == "scp":
- return scp_to_remote(address, port, username, password, local_path,
- remote_path, log_filename, timeout)
+ scp_to_remote(address, port, username, password, local_path,
+ remote_path, log_filename, timeout)
elif client == "rss":
c = rss_file_transfer.FileUploadClient(address, port)
c.upload(local_path, remote_path, timeout)
c.close()
- return True
def copy_files_from(address, client, username, password, port, local_path,
@@ -798,22 +793,15 @@ def copy_files_from(address, client, username, password, port, local_path,
@param log_filename: If specified, log all output to this file
@param timeout: The time duration (in seconds) to wait for the transfer to
complete.
-
- @return: True on success and False on failure.
+ @raise: Whatever remote_scp() raises
"""
-
- if not address or not port:
- logging.debug("IP address or port unavailable")
- return None
-
if client == "scp":
- return scp_from_remote(address, port, username, password, remote_path,
- local_path, log_filename, timeout)
+ scp_from_remote(address, port, username, password, remote_path,
+ local_path, log_filename, timeout)
elif client == "rss":
c = rss_file_transfer.FileDownloadClient(address, port)
c.download(remote_path, local_path, timeout)
c.close()
- return True
# The following are utility functions related to ports.
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index f6f1684..023926b 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -794,8 +794,11 @@ class VM:
if gracefully and self.params.get("shutdown_command"):
# Try to destroy with shell command
logging.debug("Trying to shutdown VM with shell command...")
- session = self.remote_login()
- if session:
+ try:
+ session = self.remote_login()
+ except kvm_utils.LoginError, e:
+ logging.debug(e)
+ else:
try:
# Send the shutdown command
session.sendline(self.params.get("shutdown_command"))
@@ -1065,7 +1068,7 @@ class VM:
@param nic_index: The index of the NIC to connect to.
@param timeout: Time (seconds) before giving up logging into the
guest.
- @return: ShellSession object on success and None on failure.
+ @return: A ShellSession object.
"""
username = self.params.get("username", "")
password = self.params.get("password", "")
@@ -1078,16 +1081,13 @@ class VM:
(self.name, kvm_utils.generate_random_string(4)))
if not address or not port:
- logging.debug("IP address or port unavailable")
- return None
+ raise kvm_utils.LoginError("IP address or port unavailable")
session = kvm_utils.remote_login(client, address, port, username,
password, prompt, linesep,
log_filename, timeout)
-
- if session:
- session.set_status_test_command(self.params.get("status_test_"
- "command", ""))
+ session.set_status_test_command(self.params.get("status_test_command",
+ ""))
return session
@@ -1106,13 +1106,11 @@ class VM:
client = self.params.get("file_transfer_client")
address = self.get_address(nic_index)
port = self.get_port(int(self.params.get("file_transfer_port")))
-
log_filename = ("transfer-%s-to-%s-%s.log" %
(self.name, address,
kvm_utils.generate_random_string(4)))
- return kvm_utils.copy_files_to(address, client, username, password,
- port, local_path, remote_path,
- log_filename, timeout)
+ kvm_utils.copy_files_to(address, client, username, password, port,
+ local_path, remote_path, log_filename, timeout)
def copy_files_from(self, remote_path, local_path, nic_index=0, timeout=600):
@@ -1130,12 +1128,12 @@ class VM:
client = self.params.get("file_transfer_client")
address = self.get_address(nic_index)
port = self.get_port(int(self.params.get("file_transfer_port")))
-
log_filename = ("transfer-%s-from-%s-%s.log" %
(self.name, address,
kvm_utils.generate_random_string(4)))
- return kvm_utils.copy_files_from(address, client, username, password,
- port, local_path, remote_path, log_filename, timeout)
+ kvm_utils.copy_files_from(address, client, username, password, port,
+ local_path, remote_path, log_filename,
+ timeout)
def serial_login(self, timeout=10):
@@ -1153,18 +1151,15 @@ class VM:
linesep = eval("'%s'" % self.params.get("shell_linesep", r"\n"))
status_test_command = self.params.get("status_test_command", "")
- if self.serial_console:
- self.serial_console.set_linesep(linesep)
- self.serial_console.set_status_test_command(status_test_command)
- else:
- return None
+ self.serial_console.set_linesep(linesep)
+ self.serial_console.set_status_test_command(status_test_command)
- # Make sure we get a login prompt
+ # Try to get a login prompt
self.serial_console.sendline()
- if kvm_utils._remote_login(self.serial_console, username, password,
- prompt, timeout):
- return self.serial_console
+ kvm_utils._remote_login(self.serial_console, username, password,
+ prompt, timeout)
+ return self.serial_console
def send_key(self, keystr):
@@ -1216,8 +1211,6 @@ class VM:
Get the cpu count of the VM.
"""
session = self.remote_login()
- if not session:
- return None
try:
return int(session.cmd(self.params.get("cpu_chk_cmd")))
finally:
@@ -1232,8 +1225,6 @@ class VM:
self.params.get("mem_chk_cmd") will be used.
"""
session = self.remote_login()
- if not session:
- return None
try:
if not cmd:
cmd = self.params.get("mem_chk_cmd")
diff --git a/client/tests/kvm/tests/boot_savevm.py b/client/tests/kvm/tests/boot_savevm.py
index 3305695..cf5e433 100644
--- a/client/tests/kvm/tests/boot_savevm.py
+++ b/client/tests/kvm/tests/boot_savevm.py
@@ -50,12 +50,9 @@ def run_boot_savevm(test, params, env):
if (time.time() > login_expire):
login_expire = time.time() + savevm_login_delay
logging.info("Logging in after loadvm...")
- session = kvm_utils.wait_for(vm.remote_login, 1, 0, 1)
- if not session:
- logging.info("Failed to login")
- else:
- logging.info("Logged in to guest!")
- break
+ session = vm.remote_login()
+ logging.info("Logged in to guest!")
+ break
if (time.time() > end_time):
raise error.TestFail("fail: timeout")
diff --git a/client/tests/kvm/tests/clock_getres.py b/client/tests/kvm/tests/clock_getres.py
index f85bb26..4bc558e 100644
--- a/client/tests/kvm/tests/clock_getres.py
+++ b/client/tests/kvm/tests/clock_getres.py
@@ -31,8 +31,7 @@ def run_clock_getres(test, params, env):
vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
timeout = int(params.get("login_timeout", 360))
session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
- if not vm.copy_files_to(test_clock, base_dir):
- raise error.TestError("Failed to copy %s to VM" % t_name)
+ vm.copy_files_to(test_clock, base_dir)
session.cmd(os.path.join(base_dir, t_name))
logging.info("PASS: Guest reported appropriate clock resolution")
logging.info("guest's dmesg:")
diff --git a/client/tests/kvm/tests/ethtool.py b/client/tests/kvm/tests/ethtool.py
index 8951fcb..1aa6d0f 100644
--- a/client/tests/kvm/tests/ethtool.py
+++ b/client/tests/kvm/tests/ethtool.py
@@ -124,8 +124,10 @@ def run_ethtool(test, params, env):
return (False, "Tcpdump process wasn't launched")
logging.info("Start to transfer file")
- if not copy_files_fun(filename, filename):
- return (False, "Child process transfer file failed")
+ try:
+ copy_files_fun(filename, filename):
+ except kvm_utils.SCPError, e:
+ return (False, "File transfer failed (%s)" % e)
logging.info("Transfer file completed")
session.cmd("killall tcpdump")
try:
diff --git a/client/tests/kvm/tests/file_transfer.py b/client/tests/kvm/tests/file_transfer.py
index f02078e..7256c81 100644
--- a/client/tests/kvm/tests/file_transfer.py
+++ b/client/tests/kvm/tests/file_transfer.py
@@ -45,24 +45,20 @@ def run_file_transfer(test, params, env):
logging.info("Transfering file host -> guest, timeout: %ss",
transfer_timeout)
t_begin = time.time()
- success = vm.copy_files_to("%s/a.out" % dir_name, guest_path,
- timeout=transfer_timeout)
+ vm.copy_files_to("%s/a.out" % dir_name, guest_path,
+ timeout=transfer_timeout)
t_end = time.time()
throughput = filesize / (t_end - t_begin)
- if not success:
- raise error.TestFail("Fail to transfer file from host to guest")
logging.info("File transfer host -> guest succeed, "
"estimated throughput: %.2fMB/s", throughput)
logging.info("Transfering file guest -> host, timeout: %ss",
transfer_timeout)
t_begin = time.time()
- success = vm.copy_files_from(guest_path, "%s/c.out" % dir_name,
- timeout=transfer_timeout)
+ vm.copy_files_from(guest_path, "%s/c.out" % dir_name,
+ timeout=transfer_timeout)
t_end = time.time()
throughput = filesize / (t_end - t_begin)
- if not success:
- raise error.TestFail("Fail to transfer file from guest to host")
logging.info("File transfer guest -> host succeed, "
"estimated throughput: %.2fMB/s", throughput)
else:
diff --git a/client/tests/kvm/tests/guest_s4.py b/client/tests/kvm/tests/guest_s4.py
index 0280f71..141e3d6 100644
--- a/client/tests/kvm/tests/guest_s4.py
+++ b/client/tests/kvm/tests/guest_s4.py
@@ -55,7 +55,9 @@ def run_guest_s4(test, params, env):
# Log into the resumed VM
relogin_timeout = int(params.get("relogin_timeout", 240))
logging.info("Logging into resumed VM, timeout %s", relogin_timeout)
- session2 = kvm_utils.wait_for(vm.remote_login, relogin_timeout, 0, 2)
+ # Temporary hack
+ time.sleep(relogin_timeout)
+ session2 = vm.remote_login()
if not session2:
raise error.TestFail("Could not log into VM after resuming from "
"suspend to disk")
diff --git a/client/tests/kvm/tests/ksm_overcommit.py b/client/tests/kvm/tests/ksm_overcommit.py
index c6368d3..375522a 100644
--- a/client/tests/kvm/tests/ksm_overcommit.py
+++ b/client/tests/kvm/tests/ksm_overcommit.py
@@ -249,10 +249,9 @@ def run_ksm_overcommit(test, params, env):
session = lsessions[0]
vm = lvms[0]
for i in range(1, max_alloc):
- lsessions.append(kvm_utils.wait_for(vm.remote_login, 360, 0, 2))
- if not lsessions[i]:
- raise error.TestFail("Could not log into guest %s" %
- vm.name)
+ # Temporary hack
+ time.sleep(360)
+ lsessions.append(vm.remote_login())
session.cmd("swapoff -a", timeout=300)
@@ -553,9 +552,9 @@ def run_ksm_overcommit(test, params, env):
logging.debug("Booting first guest %s", lvms[0].name)
- lsessions.append(kvm_utils.wait_for(lvms[0].remote_login, 360, 0, 2))
- if not lsessions[0]:
- raise error.TestFail("Could not log into first guest")
+ # Temporary hack
+ time.sleep(360)
+ lsessions.append(lvms[0].remote_login())
# Associate vm PID
try:
tmp = open(params.get('pid_' + vm_name), 'r')
@@ -585,10 +584,9 @@ def run_ksm_overcommit(test, params, env):
raise error.TestError("VM %s seems to be dead; Test requires a"
"living VM" % lvms[i].name)
- lsessions.append(kvm_utils.wait_for(lvms[i].remote_login, 360, 0, 2))
- if not lsessions[i]:
- raise error.TestFail("Could not log into guest %s" %
- lvms[i].name)
+ # Temporary hack
+ time.sleep(360)
+ lsessions.append(lvms[i].remote_login())
try:
tmp = open(params.get('pid_' + vm_name), 'r')
params['pid_' + vm_name] = int(tmp.readline())
@@ -606,8 +604,7 @@ def run_ksm_overcommit(test, params, env):
vksmd_src = os.path.join(pwd, "scripts/allocator.py")
dst_dir = "/tmp"
for vm in lvms:
- if not vm.copy_files_to(vksmd_src, dst_dir):
- raise error.TestFail("copy_files_to failed %s" % vm.name)
+ vm.copy_files_to(vksmd_src, dst_dir)
logging.info("Phase 0: PASS")
if params['ksm_mode'] == "parallel":
diff --git a/client/tests/kvm/tests/migration.py b/client/tests/kvm/tests/migration.py
index 1c9f178..b9b86ba 100644
--- a/client/tests/kvm/tests/migration.py
+++ b/client/tests/kvm/tests/migration.py
@@ -53,9 +53,9 @@ def run_migration(test, params, env):
# Log into the guest again
logging.info("Logging into guest after migration...")
- session2 = kvm_utils.wait_for(dest_vm.remote_login, 30, 0, 2)
- if not session2:
- raise error.TestFail("Could not log into guest after migration")
+ # Temporary hack
+ time.sleep(30)
+ session2 = dest_vm.remote_login()
logging.info("Logged in after migration")
# Make sure the background process is still running
diff --git a/client/tests/kvm/tests/migration_with_file_transfer.py b/client/tests/kvm/tests/migration_with_file_transfer.py
index d311350..97c726b 100644
--- a/client/tests/kvm/tests/migration_with_file_transfer.py
+++ b/client/tests/kvm/tests/migration_with_file_transfer.py
@@ -57,9 +57,7 @@ def run_migration_with_file_transfer(test, params, env):
"migration...")
vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol)
finally:
- # bg.join() returns the value returned by copy_files_to()
- if not bg.join():
- raise error.TestFail("File transfer from host to guest failed")
+ bg.join()
logging.info("Transferring file back from guest to host")
bg = kvm_utils.Thread(kvm_utils.copy_files_from,
@@ -73,8 +71,7 @@ def run_migration_with_file_transfer(test, params, env):
"migration...")
vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol)
finally:
- if not bg.join():
- raise error.TestFail("File transfer from guest to host failed")
+ bg.join()
# Make sure the returned file is indentical to the original one
orig_hash = client_utils.hash_file(host_path)
diff --git a/client/tests/kvm/tests/migration_with_reboot.py b/client/tests/kvm/tests/migration_with_reboot.py
index af5de64..cf25b6b 100644
--- a/client/tests/kvm/tests/migration_with_reboot.py
+++ b/client/tests/kvm/tests/migration_with_reboot.py
@@ -38,10 +38,15 @@ def run_migration_with_reboot(test, params, env):
# Try logging into the guest until timeout expires
logging.info("Guest is down. Waiting for it to go up again, timeout "
"%ds", timeout)
- session = kvm_utils.wait_for(
- lambda: kvm_utils.remote_login(client, address, port, username,
- password, prompt, linesep,
- log_filename), timeout, 0, 2)
+ session = None
+ end_time = time.time() + timeout
+ while time.time() < end_time:
+ try:
+ session = kvm_utils.remote_login(client, address, port,
+ username, password, prompt,
+ linesep, log_filename)
+ except kvm_utils.LoginError, e:
+ logging.debug(e)
if not session:
raise error.TestFail("Could not log into guest after reboot")
logging.info("Guest is up again")
diff --git a/client/tests/kvm/tests/multicast.py b/client/tests/kvm/tests/multicast.py
index 2a12b4f..39b580b 100644
--- a/client/tests/kvm/tests/multicast.py
+++ b/client/tests/kvm/tests/multicast.py
@@ -54,8 +54,7 @@ def run_multicast(test, params, env):
suffix = int(re.findall("\d+", mcast)[-1])
# copy python script to guest for joining guest to multicast groups
mcast_path = os.path.join(test.bindir, "scripts/join_mcast.py")
- if not vm.copy_files_to(mcast_path, "/tmp"):
- raise error.TestError("Fail to copy %s to guest" % mcast_path)
+ vm.copy_files_to(mcast_path, "/tmp")
output = session.cmd_output("python /tmp/join_mcast.py %d %s %d" %
(mgroup_count, prefix, suffix))
diff --git a/client/tests/kvm/tests/netperf.py b/client/tests/kvm/tests/netperf.py
index 7c341fa..f1f3692 100644
--- a/client/tests/kvm/tests/netperf.py
+++ b/client/tests/kvm/tests/netperf.py
@@ -29,8 +29,7 @@ def run_netperf(test, params, env):
session.cmd_output(firewall_flush)
for i in params.get("netperf_files").split():
- if not vm.copy_files_to(os.path.join(netperf_dir, i), "/tmp"):
- raise error.TestError("Could not copy file %s to guest" % i)
+ vm.copy_files_to(os.path.join(netperf_dir, i), "/tmp")
try:
session.cmd(firewall_flush)
diff --git a/client/tests/kvm/tests/nic_promisc.py b/client/tests/kvm/tests/nic_promisc.py
index f4bf1e4..16a38a3 100644
--- a/client/tests/kvm/tests/nic_promisc.py
+++ b/client/tests/kvm/tests/nic_promisc.py
@@ -70,8 +70,10 @@ def run_nic_promisc(test, params, env):
utils.run(dd_cmd % (filename, int(size)))
logging.info("Transfer file from host to guest")
- if not vm.copy_files_to(filename, filename):
- logging.error("File transfer failed")
+ try:
+ vm.copy_files_to(filename, filename)
+ except kvm_utils.SCPError, e:
+ logging.error("File transfer failed (%s)", e)
continue
if not compare(filename):
logging.error("Compare file failed")
@@ -83,8 +85,10 @@ def run_nic_promisc(test, params, env):
session.cmd(dd_cmd % (filename, int(size)), timeout=100)
logging.info("Transfer file from guest to host")
- if not vm.copy_files_from(filename, filename):
- logging.error("File transfer failed")
+ try:
+ vm.copy_files_from(filename, filename)
+ except kvm_utils.SCPError, e:
+ logging.error("File transfer failed (%s)", e)
continue
if not compare(filename):
logging.error("Compare file failed")
diff --git a/client/tests/kvm/tests/nicdriver_unload.py b/client/tests/kvm/tests/nicdriver_unload.py
index a515d67..f964e35 100644
--- a/client/tests/kvm/tests/nicdriver_unload.py
+++ b/client/tests/kvm/tests/nicdriver_unload.py
@@ -33,11 +33,8 @@ def run_nicdriver_unload(test, params, env):
def run(self):
remote_file = '/tmp/' + self.getName()
file_list.append(remote_file)
- ret = vm.copy_files_to(file_name, remote_file, timeout=scp_timeout)
- if ret:
- logging.debug("File %s was transfered successfuly", remote_file)
- else:
- logging.debug("Failed to transfer file %s", remote_file)
+ vm.copy_files_to(file_name, remote_file, timeout=scp_timeout)
+ logging.debug("File %s was transfered successfuly", remote_file)
def compare(origin_file, receive_file):
check_sum1 = utils.hash_file(origin_file, method="md5")
@@ -97,8 +94,7 @@ def run_nicdriver_unload(test, params, env):
raise error.TestFail("Fail to compare (guest) file %s" % f)
logging.info("Test nic function after load/unload")
- if not vm.copy_files_to(file_name, file_name):
- raise error.TestFail("Fail to copy file from host to guest")
+ vm.copy_files_to(file_name, file_name)
if not compare(file_name, file_name):
raise error.TestFail("Test nic function after load/unload fail")
diff --git a/client/tests/kvm/tests/stress_boot.py b/client/tests/kvm/tests/stress_boot.py
index 37d853b..8bdee95 100644
--- a/client/tests/kvm/tests/stress_boot.py
+++ b/client/tests/kvm/tests/stress_boot.py
@@ -22,9 +22,7 @@ def run_stress_boot(tests, params, env):
logging.info("Waiting for first guest to be up...")
login_timeout = float(params.get("login_timeout", 240))
- session = kvm_utils.wait_for(vm.remote_login, login_timeout, 0, 2)
- if not session:
- raise error.TestFail("Could not log into first guest")
+ session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout)
num = 2
sessions = [session]
@@ -41,13 +39,10 @@ def run_stress_boot(tests, params, env):
kvm_preprocessing.preprocess_vm(tests, vm_params, env, vm_name)
params['vms'] += " " + vm_name
- curr_vm_session = kvm_utils.wait_for(curr_vm.remote_login,
- login_timeout, 0, 2)
- if not curr_vm_session:
- raise error.TestFail("Could not log into guest #%d" % num)
-
+ # Temporary hack
+ time.sleep(login_timeout)
+ sessions.append(curr_vm.remote_login())
logging.info("Guest #%d boots up successfully" % num)
- sessions.append(curr_vm_session)
# check whether all previous shell sessions are responsive
for i, se in enumerate(sessions):
diff --git a/client/tests/kvm/tests/timedrift.py b/client/tests/kvm/tests/timedrift.py
index e5aa316..7951d6e 100644
--- a/client/tests/kvm/tests/timedrift.py
+++ b/client/tests/kvm/tests/timedrift.py
@@ -88,8 +88,6 @@ def run_timedrift(test, params, env):
logging.info("Starting load on guest...")
for i in range(guest_load_instances):
load_session = vm.remote_login()
- if not load_session:
- raise error.TestFail("Could not log into guest")
# Set output func to None to stop it from being called so we
# can change the callback function and the parameters it takes
# with no problems
diff --git a/client/tests/kvm/tests/timedrift_with_migration.py b/client/tests/kvm/tests/timedrift_with_migration.py
index e953ed3..199a414 100644
--- a/client/tests/kvm/tests/timedrift_with_migration.py
+++ b/client/tests/kvm/tests/timedrift_with_migration.py
@@ -50,9 +50,9 @@ def run_timedrift_with_migration(test, params, env):
vm = kvm_test_utils.migrate(vm, env)
# Log in
logging.info("Logging in after migration...")
- session = kvm_utils.wait_for(vm.remote_login, 30, 0, 2)
- if not session:
- raise error.TestFail("Could not log in after migration")
+ # Temporary hack
+ time.sleep(30)
+ session = vm.remote_login()
logging.info("Logged in after migration")
# Get time after current iteration
(ht1_, gt1_) = kvm_test_utils.get_time(session, time_command,
diff --git a/client/tests/kvm/tests/virtio_console.py b/client/tests/kvm/tests/virtio_console.py
index fea3685..5c651a3 100644
--- a/client/tests/kvm/tests/virtio_console.py
+++ b/client/tests/kvm/tests/virtio_console.py
@@ -1218,8 +1218,7 @@ def run_virtio_console(test, params, env):
pwd = os.path.join(os.environ['AUTODIR'], 'tests/kvm')
vksmd_src = os.path.join(pwd, "scripts/virtio_guest.py")
dst_dir = "/tmp"
- if not vm[0].copy_files_to(vksmd_src, dst_dir):
- raise error.TestFail("copy_files_to failed %s" % vm[0].name)
+ vm[0].copy_files_to(vksmd_src, dst_dir)
# ACTUAL TESTING
# Defines all available consoles; tests udev and sysfs
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 04/17] KVM test: add VM.wait_for_login() and kvm_utils.wait_for_login()
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 02/17] KVM test: kvm_utils.py: reorder remote_login(), remote_scp(), copy_files_to(), etc Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 03/17] KVM test: use the new LoginError and SCPError exceptions Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 05/17] KVM test: use the new wait_for_login() Michael Goldish
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
These are intended as a replacement for kvm_test_utils.wait_for_login().
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_utils.py | 29 +++++++++++++++++++++++++++
client/tests/kvm/kvm_vm.py | 43 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 24285d4..cb79c59 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -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
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 023926b..0bc8a8b 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -1091,6 +1091,28 @@ class VM:
return session
+ 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().
+ @return: A ShellSession object.
+ """
+ logging.debug("Attempting to log into '%s' (timeout %ds)" % (self.name,
+ timeout))
+ end_time = time.time() + timeout
+ while time.time() < end_time:
+ try:
+ return self.remote_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)
+
+
def copy_files_to(self, local_path, remote_path, nic_index=0, timeout=600):
"""
Transfer files to the remote host(guest).
@@ -1162,6 +1184,27 @@ class VM:
return self.serial_console
+ def wait_for_serial_login(self, timeout=240, internal_timeout=10):
+ """
+ Make multiple attempts to log into the guest via serial console.
+
+ @param timeout: Time (seconds) to keep trying to log in.
+ @param internal_timeout: Timeout to pass to serial_login().
+ @return: A ShellSession object.
+ """
+ logging.debug("Attempting to log into '%s' via serial console "
+ "(timeout %ds)" % (self.name, timeout))
+ end_time = time.time() + timeout
+ while time.time() < end_time:
+ try:
+ return self.serial_login(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.serial_login(internal_timeout)
+
+
def send_key(self, keystr):
"""
Send a key event to the VM.
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 05/17] KVM test: use the new wait_for_login()
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (2 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 04/17] KVM test: add VM.wait_for_login() and kvm_utils.wait_for_login() Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 06/17] KVM test: rename VM.remote_login() to VM.login() Michael Goldish
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
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(-)
diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py
index caefa5e..539bb10 100644
--- a/client/tests/kvm/kvm_test_utils.py
+++ b/client/tests/kvm/kvm_test_utils.py
@@ -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
diff --git a/client/tests/kvm/tests/autotest.py b/client/tests/kvm/tests/autotest.py
index 2916ebd..ec4bd9f 100644
--- a/client/tests/kvm/tests/autotest.py
+++ b/client/tests/kvm/tests/autotest.py
@@ -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))
diff --git a/client/tests/kvm/tests/balloon_check.py b/client/tests/kvm/tests/balloon_check.py
index 1ee05bf..a9226c3 100644
--- a/client/tests/kvm/tests/balloon_check.py
+++ b/client/tests/kvm/tests/balloon_check.py
@@ -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"))
diff --git a/client/tests/kvm/tests/boot.py b/client/tests/kvm/tests/boot.py
index 8cc0218..936ce65 100644
--- a/client/tests/kvm/tests/boot.py
+++ b/client/tests/kvm/tests/boot.py
@@ -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"):
diff --git a/client/tests/kvm/tests/clock_getres.py b/client/tests/kvm/tests/clock_getres.py
index 4bc558e..7c828f2 100644
--- a/client/tests/kvm/tests/clock_getres.py
+++ b/client/tests/kvm/tests/clock_getres.py
@@ -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")
diff --git a/client/tests/kvm/tests/ethtool.py b/client/tests/kvm/tests/ethtool.py
index 1aa6d0f..be8f1d2 100644
--- a/client/tests/kvm/tests/ethtool.py
+++ b/client/tests/kvm/tests/ethtool.py
@@ -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"
diff --git a/client/tests/kvm/tests/file_transfer.py b/client/tests/kvm/tests/file_transfer.py
index 7256c81..eb856d4 100644
--- a/client/tests/kvm/tests/file_transfer.py
+++ b/client/tests/kvm/tests/file_transfer.py
@@ -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"))
diff --git a/client/tests/kvm/tests/guest_s4.py b/client/tests/kvm/tests/guest_s4.py
index 141e3d6..9376222 100644
--- a/client/tests/kvm/tests/guest_s4.py
+++ b/client/tests/kvm/tests/guest_s4.py
@@ -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...")
diff --git a/client/tests/kvm/tests/guest_test.py b/client/tests/kvm/tests/guest_test.py
index b9786b5..54f64ca 100644
--- a/client/tests/kvm/tests/guest_test.py
+++ b/client/tests/kvm/tests/guest_test.py
@@ -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 ...")
diff --git a/client/tests/kvm/tests/iofuzz.py b/client/tests/kvm/tests/iofuzz.py
index e77540e..0642e79 100644
--- a/client/tests/kvm/tests/iofuzz.py
+++ b/client/tests/kvm/tests/iofuzz.py
@@ -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 = {}
diff --git a/client/tests/kvm/tests/ioquit.py b/client/tests/kvm/tests/ioquit.py
index 25d3ac9..ca08b96 100644
--- a/client/tests/kvm/tests/ioquit.py
+++ b/client/tests/kvm/tests/ioquit.py
@@ -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.")
diff --git a/client/tests/kvm/tests/iozone_windows.py b/client/tests/kvm/tests/iozone_windows.py
index febf898..6171906 100644
--- a/client/tests/kvm/tests/iozone_windows.py
+++ b/client/tests/kvm/tests/iozone_windows.py
@@ -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)
diff --git a/client/tests/kvm/tests/jumbo.py b/client/tests/kvm/tests/jumbo.py
index 1fbce8b..fd9fb3e 100644
--- a/client/tests/kvm/tests/jumbo.py
+++ b/client/tests/kvm/tests/jumbo.py
@@ -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
diff --git a/client/tests/kvm/tests/kdump.py b/client/tests/kvm/tests/kdump.py
index ccc4307..3d9f142 100644
--- a/client/tests/kvm/tests/kdump.py
+++ b/client/tests/kvm/tests/kdump.py
@@ -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")
diff --git a/client/tests/kvm/tests/ksm_overcommit.py b/client/tests/kvm/tests/ksm_overcommit.py
index 375522a..129811d 100644
--- a/client/tests/kvm/tests/ksm_overcommit.py
+++ b/client/tests/kvm/tests/ksm_overcommit.py
@@ -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())
diff --git a/client/tests/kvm/tests/linux_s3.py b/client/tests/kvm/tests/linux_s3.py
index 8a0f5eb..7758d08 100644
--- a/client/tests/kvm/tests/linux_s3.py
+++ b/client/tests/kvm/tests/linux_s3.py
@@ -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")
diff --git a/client/tests/kvm/tests/mac_change.py b/client/tests/kvm/tests/mac_change.py
index 78fbab2..4876719 100644
--- a/client/tests/kvm/tests/mac_change.py
+++ b/client/tests/kvm/tests/mac_change.py
@@ -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.")
diff --git a/client/tests/kvm/tests/migration.py b/client/tests/kvm/tests/migration.py
index b9b86ba..234120c 100644
--- a/client/tests/kvm/tests/migration.py
+++ b/client/tests/kvm/tests/migration.py
@@ -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
diff --git a/client/tests/kvm/tests/migration_multi_host.py b/client/tests/kvm/tests/migration_multi_host.py
index 15af0c8..4569531 100644
--- a/client/tests/kvm/tests/migration_multi_host.py
+++ b/client/tests/kvm/tests/migration_multi_host.py
@@ -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')
diff --git a/client/tests/kvm/tests/migration_with_file_transfer.py b/client/tests/kvm/tests/migration_with_file_transfer.py
index 97c726b..f614d63 100644
--- a/client/tests/kvm/tests/migration_with_file_transfer.py
+++ b/client/tests/kvm/tests/migration_with_file_transfer.py
@@ -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")
diff --git a/client/tests/kvm/tests/migration_with_reboot.py b/client/tests/kvm/tests/migration_with_reboot.py
index cf25b6b..3d7ace8 100644
--- a/client/tests/kvm/tests/migration_with_reboot.py
+++ b/client/tests/kvm/tests/migration_with_reboot.py
@@ -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", "")
diff --git a/client/tests/kvm/tests/multicast.py b/client/tests/kvm/tests/multicast.py
index 39b580b..9b63146 100644
--- a/client/tests/kvm/tests/multicast.py
+++ b/client/tests/kvm/tests/multicast.py
@@ -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:
diff --git a/client/tests/kvm/tests/netperf.py b/client/tests/kvm/tests/netperf.py
index f1f3692..eaa868e 100644
--- a/client/tests/kvm/tests/netperf.py
+++ b/client/tests/kvm/tests/netperf.py
@@ -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")
diff --git a/client/tests/kvm/tests/nic_bonding.py b/client/tests/kvm/tests/nic_bonding.py
index 087b099..222ace2 100644
--- a/client/tests/kvm/tests/nic_bonding.py
+++ b/client/tests/kvm/tests/nic_bonding.py
@@ -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()
diff --git a/client/tests/kvm/tests/nic_promisc.py b/client/tests/kvm/tests/nic_promisc.py
index 16a38a3..abcef25 100644
--- a/client/tests/kvm/tests/nic_promisc.py
+++ b/client/tests/kvm/tests/nic_promisc.py
@@ -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")
diff --git a/client/tests/kvm/tests/nicdriver_unload.py b/client/tests/kvm/tests/nicdriver_unload.py
index f964e35..3c629bf 100644
--- a/client/tests/kvm/tests/nicdriver_unload.py
+++ b/client/tests/kvm/tests/nicdriver_unload.py
@@ -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)
diff --git a/client/tests/kvm/tests/pci_hotplug.py b/client/tests/kvm/tests/pci_hotplug.py
index 27b81de..1270f15 100644
--- a/client/tests/kvm/tests/pci_hotplug.py
+++ b/client/tests/kvm/tests/pci_hotplug.py
@@ -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")
diff --git a/client/tests/kvm/tests/physical_resources_check.py b/client/tests/kvm/tests/physical_resources_check.py
index 3234da7..1875f07 100644
--- a/client/tests/kvm/tests/physical_resources_check.py
+++ b/client/tests/kvm/tests/physical_resources_check.py
@@ -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 "
diff --git a/client/tests/kvm/tests/ping.py b/client/tests/kvm/tests/ping.py
index 9b2308f..d206848 100644
--- a/client/tests/kvm/tests/ping.py
+++ b/client/tests/kvm/tests/ping.py
@@ -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))
diff --git a/client/tests/kvm/tests/qemu_img.py b/client/tests/kvm/tests/qemu_img.py
index 6351a84..b1df0ea 100644
--- a/client/tests/kvm/tests/qemu_img.py
+++ b/client/tests/kvm/tests/qemu_img.py
@@ -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",
diff --git a/client/tests/kvm/tests/shutdown.py b/client/tests/kvm/tests/shutdown.py
index bfc5477..1150211 100644
--- a/client/tests/kvm/tests/shutdown.py
+++ b/client/tests/kvm/tests/shutdown.py
@@ -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":
diff --git a/client/tests/kvm/tests/stress_boot.py b/client/tests/kvm/tests/stress_boot.py
index 8bdee95..620d5f0 100644
--- a/client/tests/kvm/tests/stress_boot.py
+++ b/client/tests/kvm/tests/stress_boot.py
@@ -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
diff --git a/client/tests/kvm/tests/timedrift.py b/client/tests/kvm/tests/timedrift.py
index 7951d6e..489cf9d 100644
--- a/client/tests/kvm/tests/timedrift.py
+++ b/client/tests/kvm/tests/timedrift.py
@@ -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
diff --git a/client/tests/kvm/tests/timedrift_with_migration.py b/client/tests/kvm/tests/timedrift_with_migration.py
index 199a414..6cb79dc 100644
--- a/client/tests/kvm/tests/timedrift_with_migration.py
+++ b/client/tests/kvm/tests/timedrift_with_migration.py
@@ -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,
diff --git a/client/tests/kvm/tests/timedrift_with_reboot.py b/client/tests/kvm/tests/timedrift_with_reboot.py
index 22dfd45..7668bdd 100644
--- a/client/tests/kvm/tests/timedrift_with_reboot.py
+++ b/client/tests/kvm/tests/timedrift_with_reboot.py
@@ -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
diff --git a/client/tests/kvm/tests/timedrift_with_stop.py b/client/tests/kvm/tests/timedrift_with_stop.py
index 3473276..27a1472 100644
--- a/client/tests/kvm/tests/timedrift_with_stop.py
+++ b/client/tests/kvm/tests/timedrift_with_stop.py
@@ -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
diff --git a/client/tests/kvm/tests/virtio_console.py b/client/tests/kvm/tests/virtio_console.py
index 5c651a3..d7aaaf6 100644
--- a/client/tests/kvm/tests/virtio_console.py
+++ b/client/tests/kvm/tests/virtio_console.py
@@ -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",
diff --git a/client/tests/kvm/tests/vlan.py b/client/tests/kvm/tests/vlan.py
index 69a136b..f35e3a7 100644
--- a/client/tests/kvm/tests/vlan.py
+++ b/client/tests/kvm/tests/vlan.py
@@ -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)
diff --git a/client/tests/kvm/tests/vmstop.py b/client/tests/kvm/tests/vmstop.py
index 876c3ef..c3a4cb5 100644
--- a/client/tests/kvm/tests/vmstop.py
+++ b/client/tests/kvm/tests/vmstop.py
@@ -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"
diff --git a/client/tests/kvm/tests/whql_client_install.py b/client/tests/kvm/tests/whql_client_install.py
index c2616c6..589f258 100644
--- a/client/tests/kvm/tests/whql_client_install.py
+++ b/client/tests/kvm/tests/whql_client_install.py
@@ -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")
diff --git a/client/tests/kvm/tests/whql_submission.py b/client/tests/kvm/tests/whql_submission.py
index ae71942..2c0f367 100644
--- a/client/tests/kvm/tests/whql_submission.py
+++ b/client/tests/kvm/tests/whql_submission.py
@@ -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
diff --git a/client/tests/kvm/tests/yum_update.py b/client/tests/kvm/tests/yum_update.py
index 1a2bfae..62bb4f3 100644
--- a/client/tests/kvm/tests/yum_update.py
+++ b/client/tests/kvm/tests/yum_update.py
@@ -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",
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 06/17] KVM test: rename VM.remote_login() to VM.login()
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (3 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 05/17] KVM test: use the new wait_for_login() Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 07/17] KVM test: introduce VM exceptions Michael Goldish
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
Keep remote_login() as an alias for backward compatibility.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
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(-)
diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py
index 2997c8f..830ee99 100644
--- a/client/tests/kvm/kvm_preprocessing.py
+++ b/client/tests/kvm/kvm_preprocessing.py
@@ -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)
diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py
index 539bb10..cad4bea 100644
--- a/client/tests/kvm/kvm_test_utils.py
+++ b/client/tests/kvm/kvm_test_utils.py
@@ -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)
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 0bc8a8b..e310401 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -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")
diff --git a/client/tests/kvm/tests/boot_savevm.py b/client/tests/kvm/tests/boot_savevm.py
index cf5e433..c805816 100644
--- a/client/tests/kvm/tests/boot_savevm.py
+++ b/client/tests/kvm/tests/boot_savevm.py
@@ -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
diff --git a/client/tests/kvm/tests/timedrift.py b/client/tests/kvm/tests/timedrift.py
index 489cf9d..1dea364 100644
--- a/client/tests/kvm/tests/timedrift.py
+++ b/client/tests/kvm/tests/timedrift.py
@@ -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
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 07/17] KVM test: introduce VM exceptions
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (4 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 06/17] KVM test: rename VM.remote_login() to VM.login() Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 08/17] KVM test: let kvm_vm.create_image() raise a CmdError if qemu-img fails Michael Goldish
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_vm.py | 146 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 146 insertions(+), 0 deletions(-)
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index e310401..c237fbe 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -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.
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 08/17] KVM test: let kvm_vm.create_image() raise a CmdError if qemu-img fails
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (5 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 07/17] KVM test: introduce VM exceptions Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 09/17] KVM test: use the new VM exceptions Michael Goldish
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_vm.py | 15 ++-------------
1 files changed, 2 insertions(+), 13 deletions(-)
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index c237fbe..32be55e 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -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
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 09/17] KVM test: use the new VM exceptions
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (6 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 08/17] KVM test: let kvm_vm.create_image() raise a CmdError if qemu-img fails Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 10/17] KVM test: add VM.verify_alive() and Monitor.verify_responsive() Michael Goldish
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
- Raise them where appropriate.
- Catch and handle them where appropriate.
- Modify docstrings.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
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(-)
diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py
index 830ee99..450cf59 100644
--- a/client/tests/kvm/kvm_preprocessing.py
+++ b/client/tests/kvm/kvm_preprocessing.py
@@ -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
diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py
index cad4bea..9e05186 100644
--- a/client/tests/kvm/kvm_test_utils.py
+++ b/client/tests/kvm/kvm_test_utils.py
@@ -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:
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 32be55e..dc943cf 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -672,6 +672,16 @@ class VM:
(e.g. 'gzip -c -d filename') if migration_mode is 'exec'
@param mac_source: A VM object from which to copy MAC addresses. If not
specified, new addresses will be generated.
+
+ @raise VMCreateError: If qemu terminates unexpectedly
+ @raise VMKVMInitError: If KVM initialization fails
+ @raise VMHugePageError: If hugepage initialization fails
+ @raise VMImageMissingError: If a CD image is missing
+ @raise VMHashMismatchError: If a CD image hash has doesn't match the
+ expected hash
+ @raise VMBadPATypeError: If an unsupported PCI assignment type is
+ requested
+ @raise VMPAError: If no PCI assignable devices could be assigned
"""
self.destroy()
@@ -692,8 +702,7 @@ class VM:
if iso:
iso = kvm_utils.get_path(root_dir, iso)
if not os.path.exists(iso):
- logging.error("ISO file not found: %s" % iso)
- return False
+ raise VMImageMissingError(iso)
compare = False
if cdrom_params.get("md5sum_1m"):
logging.debug("Comparing expected MD5 sum with MD5 sum of "
@@ -717,8 +726,7 @@ class VM:
if actual_hash == expected_hash:
logging.debug("Hashes match")
else:
- logging.error("Actual hash differs from expected one")
- return False
+ raise VMHashMismatchError(actual_hash, expected_hash)
# Make sure the following code is not executed by more than one thread
# at the same time
@@ -768,7 +776,7 @@ class VM:
# Assign a PCI assignable device
self.pci_assignable = None
pa_type = params.get("pci_assignable")
- if pa_type in ["vf", "pf", "mixed"]:
+ if pa_type and pa_type != "no":
pa_devices_requested = params.get("devices_requested")
# Virtual Functions (VF) assignable devices
@@ -792,6 +800,8 @@ class VM:
driver_option=params.get("driver_option"),
names=params.get("device_names"),
devices_requested=pa_devices_requested)
+ else:
+ raise VMBadPATypeError(pa_type)
self.pa_pci_ids = self.pci_assignable.request_devs()
@@ -799,14 +809,7 @@ class VM:
logging.debug("Successfuly assigned devices: %s",
self.pa_pci_ids)
else:
- logging.error("No PCI assignable devices were assigned "
- "and 'pci_assignable' is defined to %s "
- "on your config file. Aborting VM creation.",
- pa_type)
- return False
-
- elif pa_type and pa_type != "no":
- logging.warn("Unsupported pci_assignable type: %s", pa_type)
+ raise VMPAError(pa_type)
# Make qemu command
qemu_command = self.make_qemu_command()
@@ -829,13 +832,11 @@ class VM:
# Make sure the process was started successfully
if not self.process.is_alive():
- logging.error("VM could not be created; "
- "qemu command failed:\n%s" % qemu_command)
- logging.error("Status: %s" % self.process.get_status())
- logging.error("Output:" + kvm_utils.format_str_for_message(
- self.process.get_output()))
+ e = VMCreateError(qemu_command,
+ self.process.get_status(),
+ self.process.get_output())
self.destroy()
- return False
+ raise e
# Establish monitor connections
self.monitors = []
@@ -855,17 +856,13 @@ class VM:
monitor = kvm_monitor.HumanMonitor(
monitor_name,
self.get_monitor_filename(monitor_name))
+ break
except kvm_monitor.MonitorError, e:
logging.warn(e)
- else:
- if monitor.is_responsive():
- break
- time.sleep(1)
+ time.sleep(1)
else:
- logging.error("Could not connect to monitor '%s'" %
- monitor_name)
self.destroy()
- return False
+ raise e
# Add this monitor to the list
self.monitors += [monitor]
@@ -874,20 +871,14 @@ class VM:
output = self.process.get_output()
if re.search("Could not initialize KVM", output, re.IGNORECASE):
- logging.error("Could not initialize KVM; "
- "qemu command:\n%s" % qemu_command)
- logging.error("Output:" + kvm_utils.format_str_for_message(
- self.process.get_output()))
+ e = VMKVMInitError(qemu_command, self.process.get_output())
self.destroy()
- return False
+ raise e
if "alloc_mem_area" in output:
- logging.error("Could not allocate hugepage memory; "
- "qemu command:\n%s" % qemu_command)
- logging.error("Output:" + kvm_utils.format_str_for_message(
- self.process.get_output()))
+ e = VMHugePageError(qemu_command, self.process.get_output())
self.destroy()
- return False
+ raise e
logging.debug("VM appears to be alive with PID %s", self.get_pid())
@@ -899,8 +890,6 @@ class VM:
output_func=kvm_utils.log_line,
output_params=("serial-%s.log" % name,))
- return True
-
finally:
fcntl.lockf(lockfile, fcntl.LOCK_UN)
lockfile.close()
@@ -931,7 +920,7 @@ class VM:
logging.debug("Trying to shutdown VM with shell command...")
try:
session = self.login()
- except kvm_utils.LoginError, e:
+ except (kvm_utils.LoginError, VMError), e:
logging.debug(e)
else:
try:
@@ -1073,28 +1062,26 @@ class VM:
address of its own). Otherwise return the NIC's IP address.
@param index: Index of the NIC whose address is requested.
+ @raise VMMACAddressMissingError: If no MAC address is defined for the
+ requested NIC
+ @raise VMIPAddressMissingError: If no IP address is found for the the
+ NIC's MAC address
+ @raise VMAddressVerificationError: If the MAC-IP address mapping cannot
+ be verified (using arping)
"""
nics = self.params.objects("nics")
nic_name = nics[index]
nic_params = self.params.object_params(nic_name)
if nic_params.get("nic_mode") == "tap":
- mac = self.get_mac_address(index)
- if not mac:
- logging.debug("MAC address unavailable")
- return None
- mac = mac.lower()
+ mac = self.get_mac_address(index).lower()
# Get the IP address from the cache
ip = self.address_cache.get(mac)
if not ip:
- logging.debug("Could not find IP address for MAC address: %s" %
- mac)
- return None
+ raise VMIPAddressMissingError(mac)
# Make sure the IP address is assigned to this guest
macs = [self.get_mac_address(i) for i in range(len(nics))]
if not kvm_utils.verify_ip_address_ownership(ip, macs):
- logging.debug("Could not verify MAC-IP address mapping: "
- "%s ---> %s" % (mac, ip))
- return None
+ raise VMAddressVerificationError(mac, ip)
return ip
else:
return "localhost"
@@ -1108,16 +1095,18 @@ class VM:
@param nic_index: Index of the NIC.
@return: If port redirection is used, return the host port redirected
to guest port port. Otherwise return port.
+ @raise VMPortNotRedirectedError: If an unredirected port is requested
+ in user mode
"""
nic_name = self.params.objects("nics")[nic_index]
nic_params = self.params.object_params(nic_name)
if nic_params.get("nic_mode") == "tap":
return port
else:
- if not self.redirs.has_key(port):
- logging.warn("Warning: guest port %s requested but not "
- "redirected" % port)
- return self.redirs.get(port)
+ try:
+ return self.redirs[port]
+ except KeyError:
+ raise VMPortNotRedirectedError(port)
def get_ifname(self, nic_index=0):
@@ -1140,8 +1129,13 @@ class VM:
Return the MAC address of a NIC.
@param nic_index: Index of the NIC
+ @raise VMMACAddressMissingError: If no MAC address is defined for the
+ requested NIC
"""
- return kvm_utils.get_mac_address(self.instance, nic_index)
+ mac = kvm_utils.get_mac_address(self.instance, nic_index)
+ if not mac:
+ raise VMMACAddressMissingError(nic_index)
+ return mac
def free_mac_address(self, nic_index=0):
@@ -1214,10 +1208,6 @@ class VM:
port = self.get_port(int(self.params.get("shell_port")))
log_filename = ("session-%s-%s.log" %
(self.name, kvm_utils.generate_random_string(4)))
-
- if not address or not port:
- raise kvm_utils.LoginError("IP address or port unavailable")
-
session = kvm_utils.remote_login(client, address, port, username,
password, prompt, linesep,
log_filename, timeout)
@@ -1248,7 +1238,7 @@ class VM:
while time.time() < end_time:
try:
return self.login(nic_index, internal_timeout)
- except kvm_utils.LoginError, e:
+ except (kvm_utils.LoginError, VMError), e:
logging.debug(e)
time.sleep(2)
# Timeout expired; try one more time but don't catch exceptions
diff --git a/client/tests/kvm/tests/guest_s4.py b/client/tests/kvm/tests/guest_s4.py
index 9376222..72f255d 100644
--- a/client/tests/kvm/tests/guest_s4.py
+++ b/client/tests/kvm/tests/guest_s4.py
@@ -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))
diff --git a/client/tests/kvm/tests/ksm_overcommit.py b/client/tests/kvm/tests/ksm_overcommit.py
index 129811d..a3c52ef 100644
--- a/client/tests/kvm/tests/ksm_overcommit.py
+++ b/client/tests/kvm/tests/ksm_overcommit.py
@@ -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)
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 10/17] KVM test: add VM.verify_alive() and Monitor.verify_responsive()
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (7 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 09/17] KVM test: use the new VM exceptions Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 11/17] KVM test: use VM.verify_alive() instead of kvm_test_utils.get_living_vm() Michael Goldish
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_monitor.py | 31 +++++++++++++++----------------
client/tests/kvm/kvm_vm.py | 21 ++++++++++++++++-----
2 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py
index 7e6b594..6321fbd 100644
--- a/client/tests/kvm/kvm_monitor.py
+++ b/client/tests/kvm/kvm_monitor.py
@@ -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):
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index dc943cf..d236359 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -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):
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 11/17] KVM test: use VM.verify_alive() instead of kvm_test_utils.get_living_vm()
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (8 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 10/17] KVM test: add VM.verify_alive() and Monitor.verify_responsive() Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 12/17] KVM test: kvm_preprocessing.py: simplify handling of params['migration_mode'] Michael Goldish
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
It looks cleaner even though it's 1 extra line.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
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(-)
diff --git a/client/tests/kvm/tests/autotest.py b/client/tests/kvm/tests/autotest.py
index ec4bd9f..0b97b03 100644
--- a/client/tests/kvm/tests/autotest.py
+++ b/client/tests/kvm/tests/autotest.py
@@ -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)
diff --git a/client/tests/kvm/tests/balloon_check.py b/client/tests/kvm/tests/balloon_check.py
index a9226c3..9ed0a7e 100644
--- a/client/tests/kvm/tests/balloon_check.py
+++ b/client/tests/kvm/tests/balloon_check.py
@@ -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)
diff --git a/client/tests/kvm/tests/boot.py b/client/tests/kvm/tests/boot.py
index 936ce65..54db1c6 100644
--- a/client/tests/kvm/tests/boot.py
+++ b/client/tests/kvm/tests/boot.py
@@ -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)
diff --git a/client/tests/kvm/tests/boot_savevm.py b/client/tests/kvm/tests/boot_savevm.py
index c805816..6acd0a2 100644
--- a/client/tests/kvm/tests/boot_savevm.py
+++ b/client/tests/kvm/tests/boot_savevm.py
@@ -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)
diff --git a/client/tests/kvm/tests/clock_getres.py b/client/tests/kvm/tests/clock_getres.py
index 7c828f2..1a762e5 100644
--- a/client/tests/kvm/tests/clock_getres.py
+++ b/client/tests/kvm/tests/clock_getres.py
@@ -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)
diff --git a/client/tests/kvm/tests/ethtool.py b/client/tests/kvm/tests/ethtool.py
index be8f1d2..011df29 100644
--- a/client/tests/kvm/tests/ethtool.py
+++ b/client/tests/kvm/tests/ethtool.py
@@ -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")
diff --git a/client/tests/kvm/tests/file_transfer.py b/client/tests/kvm/tests/file_transfer.py
index eb856d4..a192f19 100644
--- a/client/tests/kvm/tests/file_transfer.py
+++ b/client/tests/kvm/tests/file_transfer.py
@@ -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)
diff --git a/client/tests/kvm/tests/guest_s4.py b/client/tests/kvm/tests/guest_s4.py
index 72f255d..7f61c33 100644
--- a/client/tests/kvm/tests/guest_s4.py
+++ b/client/tests/kvm/tests/guest_s4.py
@@ -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)
diff --git a/client/tests/kvm/tests/guest_test.py b/client/tests/kvm/tests/guest_test.py
index 54f64ca..cd902df 100644
--- a/client/tests/kvm/tests/guest_test.py
+++ b/client/tests/kvm/tests/guest_test.py
@@ -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:
diff --git a/client/tests/kvm/tests/iofuzz.py b/client/tests/kvm/tests/iofuzz.py
index 0642e79..d995509 100644
--- a/client/tests/kvm/tests/iofuzz.py
+++ b/client/tests/kvm/tests/iofuzz.py
@@ -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:
diff --git a/client/tests/kvm/tests/ioquit.py b/client/tests/kvm/tests/ioquit.py
index ca08b96..80c8221 100644
--- a/client/tests/kvm/tests/ioquit.py
+++ b/client/tests/kvm/tests/ioquit.py
@@ -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)
diff --git a/client/tests/kvm/tests/iozone_windows.py b/client/tests/kvm/tests/iozone_windows.py
index 6171906..15b135e 100644
--- a/client/tests/kvm/tests/iozone_windows.py
+++ b/client/tests/kvm/tests/iozone_windows.py
@@ -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,
diff --git a/client/tests/kvm/tests/jumbo.py b/client/tests/kvm/tests/jumbo.py
index fd9fb3e..e20aa9f 100644
--- a/client/tests/kvm/tests/jumbo.py
+++ b/client/tests/kvm/tests/jumbo.py
@@ -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")
diff --git a/client/tests/kvm/tests/kdump.py b/client/tests/kvm/tests/kdump.py
index 3d9f142..bfcbae1 100644
--- a/client/tests/kvm/tests/kdump.py
+++ b/client/tests/kvm/tests/kdump.py
@@ -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)
diff --git a/client/tests/kvm/tests/linux_s3.py b/client/tests/kvm/tests/linux_s3.py
index 7758d08..ece8676 100644
--- a/client/tests/kvm/tests/linux_s3.py
+++ b/client/tests/kvm/tests/linux_s3.py
@@ -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)
diff --git a/client/tests/kvm/tests/mac_change.py b/client/tests/kvm/tests/mac_change.py
index 4876719..3fd196f 100644
--- a/client/tests/kvm/tests/mac_change.py
+++ b/client/tests/kvm/tests/mac_change.py
@@ -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
diff --git a/client/tests/kvm/tests/migration.py b/client/tests/kvm/tests/migration.py
index 234120c..76cbcfc 100644
--- a/client/tests/kvm/tests/migration.py
+++ b/client/tests/kvm/tests/migration.py
@@ -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)
diff --git a/client/tests/kvm/tests/migration_multi_host.py b/client/tests/kvm/tests/migration_multi_host.py
index 4569531..12d70ef 100644
--- a/client/tests/kvm/tests/migration_multi_host.py
+++ b/client/tests/kvm/tests/migration_multi_host.py
@@ -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")
diff --git a/client/tests/kvm/tests/migration_with_file_transfer.py b/client/tests/kvm/tests/migration_with_file_transfer.py
index f614d63..f641451 100644
--- a/client/tests/kvm/tests/migration_with_file_transfer.py
+++ b/client/tests/kvm/tests/migration_with_file_transfer.py
@@ -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)
diff --git a/client/tests/kvm/tests/migration_with_reboot.py b/client/tests/kvm/tests/migration_with_reboot.py
index 3d7ace8..c96a4d7 100644
--- a/client/tests/kvm/tests/migration_with_reboot.py
+++ b/client/tests/kvm/tests/migration_with_reboot.py
@@ -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)
diff --git a/client/tests/kvm/tests/multicast.py b/client/tests/kvm/tests/multicast.py
index 9b63146..ddb7807 100644
--- a/client/tests/kvm/tests/multicast.py
+++ b/client/tests/kvm/tests/multicast.py
@@ -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):
diff --git a/client/tests/kvm/tests/netperf.py b/client/tests/kvm/tests/netperf.py
index eaa868e..819562a 100644
--- a/client/tests/kvm/tests/netperf.py
+++ b/client/tests/kvm/tests/netperf.py
@@ -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)
diff --git a/client/tests/kvm/tests/nic_bonding.py b/client/tests/kvm/tests/nic_bonding.py
index 222ace2..692978c 100644
--- a/client/tests/kvm/tests/nic_bonding.py
+++ b/client/tests/kvm/tests/nic_bonding.py
@@ -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")
diff --git a/client/tests/kvm/tests/nic_promisc.py b/client/tests/kvm/tests/nic_promisc.py
index abcef25..b9a52ff 100644
--- a/client/tests/kvm/tests/nic_promisc.py
+++ b/client/tests/kvm/tests/nic_promisc.py
@@ -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)
diff --git a/client/tests/kvm/tests/nicdriver_unload.py b/client/tests/kvm/tests/nicdriver_unload.py
index 3c629bf..d4ddfdd 100644
--- a/client/tests/kvm/tests/nicdriver_unload.py
+++ b/client/tests/kvm/tests/nicdriver_unload.py
@@ -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)
diff --git a/client/tests/kvm/tests/pci_hotplug.py b/client/tests/kvm/tests/pci_hotplug.py
index 1270f15..3ce2f87 100644
--- a/client/tests/kvm/tests/pci_hotplug.py
+++ b/client/tests/kvm/tests/pci_hotplug.py
@@ -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)
diff --git a/client/tests/kvm/tests/physical_resources_check.py b/client/tests/kvm/tests/physical_resources_check.py
index 1875f07..b9542b7 100644
--- a/client/tests/kvm/tests/physical_resources_check.py
+++ b/client/tests/kvm/tests/physical_resources_check.py
@@ -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)
diff --git a/client/tests/kvm/tests/ping.py b/client/tests/kvm/tests/ping.py
index d206848..0dbbdf6 100644
--- a/client/tests/kvm/tests/ping.py
+++ b/client/tests/kvm/tests/ping.py
@@ -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)
diff --git a/client/tests/kvm/tests/pxe.py b/client/tests/kvm/tests/pxe.py
index ec9a549..026e397 100644
--- a/client/tests/kvm/tests/pxe.py
+++ b/client/tests/kvm/tests/pxe.py
@@ -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")
diff --git a/client/tests/kvm/tests/qmp_basic.py b/client/tests/kvm/tests/qmp_basic.py
index 985ad15..952da99 100644
--- a/client/tests/kvm/tests/qmp_basic.py
+++ b/client/tests/kvm/tests/qmp_basic.py
@@ -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)
diff --git a/client/tests/kvm/tests/shutdown.py b/client/tests/kvm/tests/shutdown.py
index 1150211..fc0407f 100644
--- a/client/tests/kvm/tests/shutdown.py
+++ b/client/tests/kvm/tests/shutdown.py
@@ -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)
diff --git a/client/tests/kvm/tests/stress_boot.py b/client/tests/kvm/tests/stress_boot.py
index 620d5f0..752bd72 100644
--- a/client/tests/kvm/tests/stress_boot.py
+++ b/client/tests/kvm/tests/stress_boot.py
@@ -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...")
diff --git a/client/tests/kvm/tests/timedrift.py b/client/tests/kvm/tests/timedrift.py
index 1dea364..348efb8 100644
--- a/client/tests/kvm/tests/timedrift.py
+++ b/client/tests/kvm/tests/timedrift.py
@@ -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)
diff --git a/client/tests/kvm/tests/timedrift_with_migration.py b/client/tests/kvm/tests/timedrift_with_migration.py
index 6cb79dc..b8d3e6c 100644
--- a/client/tests/kvm/tests/timedrift_with_migration.py
+++ b/client/tests/kvm/tests/timedrift_with_migration.py
@@ -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)
diff --git a/client/tests/kvm/tests/timedrift_with_reboot.py b/client/tests/kvm/tests/timedrift_with_reboot.py
index 7668bdd..8ec121d 100644
--- a/client/tests/kvm/tests/timedrift_with_reboot.py
+++ b/client/tests/kvm/tests/timedrift_with_reboot.py
@@ -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)
diff --git a/client/tests/kvm/tests/timedrift_with_stop.py b/client/tests/kvm/tests/timedrift_with_stop.py
index 27a1472..cf396cb 100644
--- a/client/tests/kvm/tests/timedrift_with_stop.py
+++ b/client/tests/kvm/tests/timedrift_with_stop.py
@@ -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:
diff --git a/client/tests/kvm/tests/unattended_install.py b/client/tests/kvm/tests/unattended_install.py
index 471ab56..9617603 100644
--- a/client/tests/kvm/tests/unattended_install.py
+++ b/client/tests/kvm/tests/unattended_install.py
@@ -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"):
diff --git a/client/tests/kvm/tests/vlan.py b/client/tests/kvm/tests/vlan.py
index f35e3a7..19a9250 100644
--- a/client/tests/kvm/tests/vlan.py
+++ b/client/tests/kvm/tests/vlan.py
@@ -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))
diff --git a/client/tests/kvm/tests/vmstop.py b/client/tests/kvm/tests/vmstop.py
index c3a4cb5..5bff3b3 100644
--- a/client/tests/kvm/tests/vmstop.py
+++ b/client/tests/kvm/tests/vmstop.py
@@ -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)
diff --git a/client/tests/kvm/tests/whql_client_install.py b/client/tests/kvm/tests/whql_client_install.py
index 589f258..5a2ed4d 100644
--- a/client/tests/kvm/tests/whql_client_install.py
+++ b/client/tests/kvm/tests/whql_client_install.py
@@ -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
diff --git a/client/tests/kvm/tests/whql_submission.py b/client/tests/kvm/tests/whql_submission.py
index 2c0f367..afd613e 100644
--- a/client/tests/kvm/tests/whql_submission.py
+++ b/client/tests/kvm/tests/whql_submission.py
@@ -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
diff --git a/client/tests/kvm/tests/yum_update.py b/client/tests/kvm/tests/yum_update.py
index 62bb4f3..849a67a 100644
--- a/client/tests/kvm/tests/yum_update.py
+++ b/client/tests/kvm/tests/yum_update.py
@@ -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)
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 12/17] KVM test: kvm_preprocessing.py: simplify handling of params['migration_mode']
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (9 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 11/17] KVM test: use VM.verify_alive() instead of kvm_test_utils.get_living_vm() Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 13/17] KVM test: make migrate() a VM method Michael Goldish
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
Also reorder the if statements because if migration_mode is specified it causes
an unconditional VM restart (unlike start_vm).
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_preprocessing.py | 16 ++++++----------
1 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py
index 450cf59..5ce0a3b 100644
--- a/client/tests/kvm/kvm_preprocessing.py
+++ b/client/tests/kvm/kvm_preprocessing.py
@@ -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
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 13/17] KVM test: make migrate() a VM method
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (10 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 12/17] KVM test: kvm_preprocessing.py: simplify handling of params['migration_mode'] Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 14/17] KVM test: simplify migration_with_reboot and migration_with_file_transfer Michael Goldish
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
This 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.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_vm.py | 142 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 142 insertions(+), 0 deletions(-)
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index d236359..d6ca782 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -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.
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 14/17] KVM test: simplify migration_with_reboot and migration_with_file_transfer
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (11 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 13/17] KVM test: make migrate() a VM method Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 15/17] KVM test: use VM.migrate() instead of kvm_test_utils.migrate() Michael Goldish
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
Now that migration can be performed without switching VMs (but rather by
switching states) these tests can be greatly simplified.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
.../kvm/tests/migration_with_file_transfer.py | 53 +++++++-------------
client/tests/kvm/tests/migration_with_reboot.py | 54 ++-----------------
2 files changed, 24 insertions(+), 83 deletions(-)
diff --git a/client/tests/kvm/tests/migration_with_file_transfer.py b/client/tests/kvm/tests/migration_with_file_transfer.py
index f641451..27c1fe1 100644
--- a/client/tests/kvm/tests/migration_with_file_transfer.py
+++ b/client/tests/kvm/tests/migration_with_file_transfer.py
@@ -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):
diff --git a/client/tests/kvm/tests/migration_with_reboot.py b/client/tests/kvm/tests/migration_with_reboot.py
index c96a4d7..a365239 100644
--- a/client/tests/kvm/tests/migration_with_reboot.py
+++ b/client/tests/kvm/tests/migration_with_reboot.py
@@ -19,65 +19,23 @@ def run_migration_with_reboot(test, params, env):
@param params: Dictionary with test parameters.
@param env: Dictionary with the test environment.
"""
- def reboot_test(client, session, address, reboot_command, port, username,
- password, prompt, linesep, log_filename, timeout):
- """
- A version of reboot test which is safe to be called in the background as
- it doesn't need a VM object.
- """
- # Send a reboot command to the guest's shell
- session.sendline(reboot_command)
- logging.info("Reboot command sent. Waiting for guest to go down...")
-
- # Wait for the session to become unresponsive and close it
- if not kvm_utils.wait_for(lambda: not session.is_responsive(timeout=30),
- 120, 0, 1):
- raise error.TestFail("Guest refuses to go down")
- session.close()
-
- # 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_login(client, address, port, username,
- password, prompt, linesep,
- log_filename, timeout)
- logging.info("Guest is up again")
- session.close()
-
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
- timeout = int(params.get("login_timeout", 360))
- session = vm.wait_for_login(timeout=timeout)
-
- # params of reboot
- username = vm.params.get("username", "")
- password = vm.params.get("password", "")
- prompt = vm.params.get("shell_prompt", "[\#\$]")
- linesep = eval("'%s'" % vm.params.get("shell_linesep", r"\n"))
- client = vm.params.get("shell_client")
- address = vm.get_address(0)
- port = vm.get_port(int(params.get("shell_port")))
- log_filename = ("migration-reboot-%s-%s.log" %
- (vm.name, kvm_utils.generate_random_string(4)))
- reboot_command = vm.params.get("reboot_command")
+ 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")
- mig_cancel = bool(params.get("mig_cancel"))
+ mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2
try:
# Reboot the VM in the background
- bg = kvm_utils.Thread(reboot_test, (client, session, address,
- reboot_command, port, username,
- password, prompt, linesep,
- log_filename, timeout))
+ bg = kvm_utils.Thread(kvm_test_utils.reboot, (vm, session))
bg.start()
-
try:
while bg.is_alive():
- vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol)
+ vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay)
finally:
- bg.join()
-
+ session = bg.join()
finally:
session.close()
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 15/17] KVM test: use VM.migrate() instead of kvm_test_utils.migrate()
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (12 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 14/17] KVM test: simplify migration_with_reboot and migration_with_file_transfer Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 16/17] KVM test: reorder kvm_utils.copy_files_from() path parameters Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 17/17] KVM test: rename path parameters in kvm_vm.copy_files_*() Michael Goldish
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm; +Cc: Michael Goldish
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
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(-)
diff --git a/client/tests/kvm/tests/migration.py b/client/tests/kvm/tests/migration.py
index 76cbcfc..d6dc1b0 100644
--- a/client/tests/kvm/tests/migration.py
+++ b/client/tests/kvm/tests/migration.py
@@ -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
diff --git a/client/tests/kvm/tests/migration_multi_host.py b/client/tests/kvm/tests/migration_multi_host.py
index 12d70ef..7647af4 100644
--- a/client/tests/kvm/tests/migration_multi_host.py
+++ b/client/tests/kvm/tests/migration_multi_host.py
@@ -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,
diff --git a/client/tests/kvm/tests/timedrift_with_migration.py b/client/tests/kvm/tests/timedrift_with_migration.py
index b8d3e6c..66e8fde 100644
--- a/client/tests/kvm/tests/timedrift_with_migration.py
+++ b/client/tests/kvm/tests/timedrift_with_migration.py
@@ -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)
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 16/17] KVM test: reorder kvm_utils.copy_files_from() path parameters
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (13 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 15/17] KVM test: use VM.migrate() instead of kvm_test_utils.migrate() Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 17/17] KVM test: rename path parameters in kvm_vm.copy_files_*() Michael Goldish
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
Reorder 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.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_utils.py | 8 ++++----
client/tests/kvm/kvm_vm.py | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index cb79c59..646d4fa 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -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
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index d6ca782..4680577 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -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)
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread* [KVM-AUTOTEST PATCH 17/17] KVM test: rename path parameters in kvm_vm.copy_files_*()
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
` (14 preceding siblings ...)
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 16/17] KVM test: reorder kvm_utils.copy_files_from() path parameters Michael Goldish
@ 2011-01-03 18:27 ` Michael Goldish
15 siblings, 0 replies; 17+ messages in thread
From: Michael Goldish @ 2011-01-03 18:27 UTC (permalink / raw)
To: autotest, kvm
local_path -> host_path
remote_path -> guest_path
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_vm.py | 17 ++++++++---------
1 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 4680577..056416e 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -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):
--
1.7.3.4
^ permalink raw reply related [flat|nested] 17+ messages in thread