Add a server-side test - kvm_migration
PATCH v3 1/2 Add a server-side test - kvm_migration
This patch will add a server-side test namely kvm_migration. Currently, it will use existing KVM client test framework and add a new file kvm_migration.py to help judge executing routine: source machine or dest machine.
Improvement based on Version #2:
* Log into migrated guest from source client machine because the previous session got before migration should be still responsive.
* Compare the output of `migration_test_command' before and after migration.
* Add checking status of migrated guest via monitor command 'info status'.
* As suggested by Sudhir, rename 'rem_port' to 'mig_port'. I also rename 'rem_host' to be 'dest_host'.
--- client/tests/kvm/kvm_migration.py | 170 ++++++++++++++++++++++++++++++++ client/tests/kvm/kvm_test_utils.py | 27 +++--- client/tests/kvm/kvm_tests.cfg.sample | 2 + client/tests/kvm_migration | 1 + server/tests/kvm/migration_control.srv | 139 ++++++++++++++++++++++++++ 5 files changed, 327 insertions(+), 12 deletions(-) create mode 100644 client/tests/kvm/kvm_migration.py create mode 120000 client/tests/kvm_migration create mode 100644 server/tests/kvm/migration_control.srv
client/tests/kvm/kvm_migration.py new file +170 -0
@@ -0,0 +1,170 @@ +import sys, os, time, logging, commands, socket +from autotest_lib.client.bin import test +from autotest_lib.client.common_lib import error +import kvm_utils, kvm_preprocessing, common, kvm_vm, kvm_test_utils + + +class kvm_migration(test.test): + """ + KVM migration test. + + @copyright: Red Hat 2008-2009 + @see: http://www.linux-kvm.org/page/KVM-Autotest/Client_Install + (Online doc - Getting started with KVM testing) + + Migration execution progress: + + source host dest host + ------------------------------------------------------------------ + log into guest + ------------------------------------------------------------------ + start socket server + + ---- wait 30 secs -------------- wait login_timeout+30 secs------- + + accept connection connect to socket server,send mig_port + ------------------------------------------------------------------ + start migration + + ---- wait 30 secs -------------- wait mig_timeout+30 secs--------- + + try to log into migrated guest check VM's status via monitor cmd + ------------------------------------------------------------------ + + """ + version = 1 + def initialize(self): + pass + + + def run_once(self, params): + """ + Setup remote machine and then execute migration. + """ + # Check whether remote machine is ready + dsthost = params.get("dsthost") + srchost = params.get("srchost") + image_path = os.path.join(self.bindir, "images") + + rootdir = params.get("rootdir") + iso = os.path.join(rootdir, 'iso') + images = os.path.join(rootdir, 'images') + qemu = os.path.join(rootdir, 'qemu') + qemu_img = os.path.join(rootdir, 'qemu-img') + + def link_if_not_exist(ldir, target, link_name): + t = target + l = os.path.join(ldir, link_name) + if not os.path.exists(l): + os.symlink(t,l) + link_if_not_exist(self.bindir, '../../', 'autotest') + link_if_not_exist(self.bindir, iso, 'isos') + link_if_not_exist(self.bindir, images, 'images') + link_if_not_exist(self.bindir, qemu, 'qemu') + link_if_not_exist(self.bindir, qemu_img, 'qemu-img') + + # Report the parameters we've received and write them as keyvals + logging.debug("Test parameters:") + keys = params.keys() + keys.sort() + for key in keys: + logging.debug(" %s = %s", key, params[key]) + self.write_test_keyval({key: params[key]}) + + # Open the environment file + env_filename = os.path.join(self.bindir, params.get("env", "env")) + env = kvm_utils.load_env(env_filename, {}) + logging.debug("Contents of environment: %s" % str(env)) + + # Preprocess + kvm_preprocessing.preprocess(self, params, env) + kvm_utils.dump_env(env, env_filename) + + try: + try: + # Get the living VM + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + migration_test_command = params.get("migration_test_command") + login_timeout = int(params.get("login_timeout")) + mig_timeout = int(params.get("mig_timeout")) + source_addr = (srchost, 50006) + all = [srchost, dsthost] + + # Check whether migration is supported + s, o = vm.send_monitor_cmd("help info") + if not "info migrate" in o: + raise error.TestError("Migration is not supported") + + if params.get("role") == "source": + + session = kvm_test_utils.wait_for_login(vm, + timeout=login_timeout) + ref_output = session.get_command_output(migration_test_command) + + # Listen on a port to get the migration port received from + # dest machine + s = socket.socket() + s.bind(source_addr) + s.listen(1) + + # Wait 30 seconds for source and dest to reach this point + self.job.barrier(srchost,'socket_started',30).rendezvous(*all) + + conn, addr = s.accept() + mig_port = int(conn.recv(6)) + s.close() + + logging.info("Start migrating now...") + kvm_test_utils.migrate(vm, dsthost, mig_port, env) + + # Wait up to 30 seconds for dest to reach this point + self.job.barrier(srchost,'mig_finished',30).rendezvous(*all) + + output = session.get_command_output(migration_test_command) + if output != ref_output: + msg = "Output of migration_test_command mismatch!" + logging.error(msg) + logging.error("Before migration: \n%s" % ref_output) + logging.error("After migration: \n%s" % output) + raise error.TestFail(msg) + + session.close() + + elif params.get("role") == "dest": + + # Wait up to login_timeout+30 seconds for the source to + # reach this point + self.job.barrier(dsthost, 'socket_started', + login_timeout+30).rendezvous(*all) + + s = socket.socket() + s.connect(source_addr) + s.send("%d" % vm.migration_port) + s.close() + + # Wait up to mig_timeout+30 seconds for the source to + # reach this point: migration finished + self.job.barrier(dsthost, 'mig_finished', + mig_timeout+30).rendezvous(*all) + + s, o = vm.send_monitor_cmd('info status') + if s or not 'VM status: running' in o: + raise error.TestFail( + "Check migrated guest's status failed") + logging.info("Migrated guest is running") + + else: + raise error.TestError('Invalid role specified') + + except Exception, e: + logging.error("Test failed: %s", e) + logging.debug("Postprocessing on error...") + kvm_preprocessing.postprocess_on_error(self, params, env) + kvm_utils.dump_env(env, env_filename) + raise + + finally: + # Postprocess + kvm_preprocessing.postprocess(self, params, env) + logging.debug("Contents of environment: %s", str(env)) + kvm_utils.dump_env(env, env_filename)
client/tests/kvm/kvm_test_utils.py +15 -12
@@ -106,7 +106,7 @@ def reboot(vm, session, method="shell", sleep_before_reset=10, nic_index=0, return session -def migrate(vm, env=None): +def migrate(vm, dest_host, mig_port, env=None, mig_timeout=90): """ Migrate a VM locally and re-register it in the environment.
@@ -133,13 +133,14 @@ def migrate(vm, env=None): if not "info migrate" in o: raise error.TestError("Migration is not supported") - # Clone the source VM and ask the clone to wait for incoming migration - dest_vm = vm.clone() - dest_vm.create(for_migration=True) + if dest_host == "localhost": + # Clone the source VM and ask the clone to wait for incoming migration + dest_vm = vm.clone() + dest_vm.create(for_migration=True) try: # Define the migration command - cmd = "migrate -d tcp:localhost:%d" % dest_vm.migration_port + cmd = "migrate -d tcp:%s:%d" % (dest_host, mig_port) logging.debug("Migrating with command: %s" % cmd) # Migrate
@@ -150,7 +151,7 @@ def migrate(vm, env=None): raise error.TestFail("Migration command failed") # Wait for migration to finish - if not kvm_utils.wait_for(mig_finished, 90, 2, 2, + if not kvm_utils.wait_for(mig_finished, mig_timeout, 2, 2, "Waiting for migration to finish..."): raise error.TestFail("Timeout elapsed while waiting for migration " "to finish")
@@ -166,15 +167,17 @@ def migrate(vm, env=None): # Kill the source VM vm.destroy(gracefully=False) - # Replace the source VM with the new cloned VM - if env is not None: - kvm_utils.env_register_vm(env, vm.name, dest_vm) + if dest_host == "localhost": + # Replace the source VM with the new cloned VM + if env is not None: + kvm_utils.env_register_vm(env, vm.name, dest_vm) - # Return the new cloned VM - return dest_vm + # Return the new cloned VM + return dest_vm except: - dest_vm.destroy() + if dest_host == "localhost": + dest_vm.destroy() raise
client/tests/kvm/kvm_tests.cfg.sample +2 -0
@@ -81,6 +81,8 @@ variants: migration_bg_command = "cd /tmp; nohup tcpdump -q -t ip host localhost" migration_bg_check_command = pgrep tcpdump migration_bg_kill_command = pkill tcpdump + mig_timeout = 90 + login_timeout = 240 kill_vm_on_error = yes iterations = 2 used_mem = 1024
client/tests/kvm_migration new file +1 -0
@@ -0,0 +1 @@ +kvm
server/tests/kvm/migration_control.srv new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
1.6.5.2
PATCH 2/2 KVM test: subtest migration: Add rem_host and rem_port for migrate()
Since kvm_test_utils.migrate() adds two arguments to adopt server-side migration. This client side test also needs update.
--- client/tests/kvm/tests/migration.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
client/tests/kvm/tests/migration.py +2 -1
@@ -43,7 +43,8 @@ def run_migration(test, params, env): session2.close() # Migrate the VM - dest_vm = kvm_test_utils.migrate(vm, env) + dest_vm = kvm_test_utils.migrate(vm, "localhost", + dest_vm.migration_port, env) # Log into the guest again logging.info("Logging into guest after migration...")
Signature · 1 line
1.6.5.2