Skip to contentSkip to conversation

KVM test: Add migration server control file

PATCH New Lucas Meneghel Rodrigues 1 participant 2 messages Dec 1, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 3/4 KVM test: Add migration server control file

Introduce the server migration control file, that makes possible to run the multi host migration. It parses the base config file, restricts it with appropriate parameters, generates the test dicts, modify the test_dicts so there's a distinction between the migration roles ('destination' or 'source').

---
 client/tests/kvm/migration_control.srv |  103 ++++++++++++++++++++++++++++++++
 1 files changed, 103 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/migration_control.srv
client/tests/kvm/migration_control.srv new file +103 -0
new file mode 100644
index 0000000..781e820
@@ -0,0 +1,103 @@
+AUTHOR = "Yolkfull Chow <[email protected]>"
+TIME = "SHORT"
+NAME = "Migration across multiple hosts"
+TEST_CATEGORY = "Functional"
+TEST_CLASS = "Virtualization"
+TEST_TYPE = "Server"
+DOC = """
+Migrate KVM guest between two hosts. It parses the base config file, restricts
+it with appropriate parameters, generates the test dicts, modify the test_dicts
+so there's a distinction between the migration roles ('dest' or 'source').
+"""
+
+import sys, os, commands, glob, shutil, logging
+from autotest_lib.server import utils
+
+# Specify the directory of autotest before you start this test
+AUTOTEST_DIR = '/usr/local/autotest'
+
+# Specify the root directory that on client machines
+rootdir = '/tmp/kvm_autotest_root'
+
+# Make possible to import the KVM test APIs
+KVM_DIR = os.path.join(AUTOTEST_DIR, 'client/tests/kvm')
+sys.path.append(KVM_DIR)
+
+import common, kvm_config
+
+def run(pair):
+    logging.info("KVM migration running on source host [%s] and destination "
+                 "host [%s]\n", pair[0], pair[1])
+
+    source = hosts.create_host(pair[0])
+    dest = hosts.create_host(pair[1])
+    source_at = autotest.Autotest(source)
+    dest_at = autotest.Autotest(dest)
+
+    cfg_file = os.path.join(KVM_DIR, "tests_base.cfg")
+
+    if not os.path.exists(cfg_file):
+        raise error.JobError("Config file %s was not found", cfg_file)
+
+    # Get test set (dictionary list) from the configuration file
+    cfg = kvm_config.config()
+    test_variants = """
+image_name(_.*)? ?<= /tmp/kvm_autotest_root/images/
+cdrom(_.*)? ?<= /tmp/kvm_autotest_root/
+floppy ?<= /tmp/kvm_autotest_root/
+Linux:
+    unattended_install:
+        kernel ?<= /tmp/kvm_autotest_root/
+        initrd ?<= /tmp/kvm_autotest_root/
+only qcow2
+only virtio_net
+only virtio_blk
+only smp2
+only no_pci_assignable
+only smallpages
+only Fedora.13.64
+only migrate_multi_host
+nic_mode = tap
+"""
+    cfg.fork_and_parse(cfg_file, test_variants)
+    test_list = cfg.get_list()
+
+    for params in test_list:
+        params['srchost'] = source.ip
+        params['dsthost'] = dest.ip
+        params['rootdir'] = rootdir
+
+        source_params = params.copy()
+        source_params['role'] = "source"
+
+        dest_params = params.copy()
+        dest_params['role'] = "destination"
+        dest_params['migration_mode'] = "tcp"
+
+        # Report the parameters we've received
+        print "Test parameters:"
+        keys = test_dict.keys()
+        keys.sort()
+        for key in keys:
+            logging.debug("    %s = %s", key, test_dict[key])
+
+        source_control_file = "job.run_test('kvm', params=%s)" % source_dict
+        dest_control_file = "job.run_test('kvm', params=%s)" % dest_dict
+
+        dest_command = subcommand(dest_at.run,
+                                  [dest_control_file, dest.hostname])
+
+        source_command = subcommand(source_at.run,
+                                    [source_control_file, source.hostname])
+
+        parallel([dest_command, source_command])
+
+# Grab the pairs (and failures)
+(pairs, failures) = utils.form_ntuples_from_machines(machines, 2)
+
+# Log the failures
+for failure in failures:
+    job.record("FAIL", failure[0], "kvm", failure[1])
+
+# Now run through each pair and run
+job.parallel_simple(run, pairs, log=False)
\ No newline at end of file
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 4/4 KVM test: Modifications on the migrate utility function

In order to accomodate multi-host migration, make migrate accept 2 additional parameters, dest_host and mig_port. Also, handle properly the case where we are doing migration inside the same host.

---
 client/tests/kvm/kvm_test_utils.py |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)
client/tests/kvm/kvm_test_utils.py +21 -10
index 2269cd7..cdad442 100644
@@ -133,7 +133,7 @@ def reboot(vm, session, method="shell", sleep_before_reset=10, nic_index=0,
 
 
 def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
-            mig_cancel=False):
+            mig_cancel=False, dest_host='localhost', mig_port=None):
     """
     Migrate a VM locally and re-register it in the environment.
 
@@ -143,6 +143,8 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
     @param mig_timeout: timeout value for migration.
     @param mig_protocol: migration protocol
     @param mig_cancel: Test migrate_cancel or not when protocol is tcp.
+    @param dest_host: Destination host (defaults to 'localhost').
+    @param mig_port: Port that will be used for migration.
     @return: The post-migration VM.
     """
     def mig_finished():
@@ -181,7 +183,8 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
             raise error.TestFail("Timeout expired while waiting for migration "
                                  "to finish")
 
-    dest_vm = vm.clone()
+    if dest_host == 'localhost':
+        dest_vm = vm.clone()
 
     if mig_protocol == "exec":
         # Exec is a little different from other migrate methods - first we
@@ -196,9 +199,11 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
             vm.monitor.migrate(uri)
             wait_for_migration()
 
-            if not dest_vm.create(migration_mode=mig_protocol,
-                                  migration_exec_cmd=exec_cmd, mac_source=vm):
-                raise error.TestError("Could not create dest VM")
+            if dest_host == 'localhost':
+                if not dest_vm.create(migration_mode=mig_protocol,
+                                      migration_exec_cmd=exec_cmd,
+                                      mac_source=vm):
+                    raise error.TestError("Could not create dest VM")
         finally:
             logging.debug("Removing migration file %s", exec_file)
             try:
@@ -206,11 +211,15 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
             except OSError:
                 pass
     else:
-        if not dest_vm.create(migration_mode=mig_protocol, mac_source=vm):
-            raise error.TestError("Could not create dest VM")
+        if dest_host == 'localhost':
+            if not dest_vm.create(migration_mode=mig_protocol, mac_source=vm):
+                raise error.TestError("Could not create dest VM")
         try:
             if mig_protocol == "tcp":
-                uri = "tcp:localhost:%d" % dest_vm.migration_port
+                if dest_host == 'localhost':
+                    uri = "tcp:localhost:%d" % dest_vm.migration_port
+                else:
+                    uri = 'tcp:%s:%d' % (dest_host, mig_port)
             elif mig_protocol == "unix":
                 uri = "unix:%s" % dest_vm.migration_file
             vm.monitor.migrate(uri)
@@ -222,12 +231,14 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
                                           "Waiting for migration "
                                           "cancellation"):
                     raise error.TestFail("Failed to cancel migration")
-                dest_vm.destroy(gracefully=False)
+                if dest_host == 'localhost':
+                    dest_vm.destroy(gracefully=False)
                 return vm
             else:
                 wait_for_migration()
         except:
-            dest_vm.destroy()
+            if dest_host == 'localhost':
+                dest_vm.destroy()
             raise
 
     # Report migration status
Signature · 1 line
1.7.2.3