diff mbox

[Autotest] Server test: Adds support for multi-host migration in afe tool.

Message ID 1355134127-15234-1-git-send-email-jzupka@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jiri Zupka Dec. 10, 2012, 10:08 a.m. UTC
Test name Multi_host migration.

Signed-off-by: Ji?í Župka <jzupka@redhat.com>
---
 multihost_migration/control.srv            |   55 +++++++++++
 multihost_migration/multihost_migration.py |  136 ++++++++++++++++++++++++++++
 2 files changed, 191 insertions(+), 0 deletions(-)
 create mode 100644 multihost_migration/control.srv
 create mode 100644 multihost_migration/multihost_migration.py
diff mbox

Patch

diff --git a/multihost_migration/control.srv b/multihost_migration/control.srv
new file mode 100644
index 0000000..db6c08a
--- /dev/null
+++ b/multihost_migration/control.srv
@@ -0,0 +1,55 @@ 
+AUTHOR = "jzupka@redhat.com (J. Zupka)"
+TIME = "MEDIUM"
+NAME = "Multi_host migration"
+TEST_CATEGORY = "Virtualization"
+TEST_CLASS = 'Multihost Migration'
+TEST_TYPE = "Server"
+SYNC_COUNT = 2
+DOC = """
+Multihost_migration tests multihost migration with different configuration.
+
+List of test are described in /client/tests/virt/cfg/subtest.cfg.sample.
+
+Environment for test:
+Storage:
+  Both quest have to have acces to same shared diskplace vhere are images of
+  migrated guests placed. (NFS, ...)
+Network client hosts:
+  Both machine on which are migration tests started have to be in same network.
+Netowrk client guests:
+  For some test are necessary join guest to same network. (bridge connected
+  directly to network).
+
+EXTRA_PARAMS:
+  adds extra params to client part of autotest. It is possible use this Extra
+  params for closer specific of running test.
+  example:
+  EXTRA_PARAMS = ""\"
+  only pc.migrate_multi_host..ping-pong-stress.cpu_memory..tcp
+  ""\"
+    start migrate_multi_host only ping-pong-stress test wirh
+    cpu and memory load.
+"""
+
+from autotest.server import utils
+
+EXTRA_PARAMS = """
+"""
+
+def run(machines):
+    job.run_test('multihost_migration', machines=machines,
+                 extra_params=EXTRA_PARAMS, cycles=1)
+
+if 'all' in args:
+    # Run test with all machines at once.
+    run(machines)
+else:
+    # 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)
diff --git a/multihost_migration/multihost_migration.py b/multihost_migration/multihost_migration.py
new file mode 100644
index 0000000..8103fb6
--- /dev/null
+++ b/multihost_migration/multihost_migration.py
@@ -0,0 +1,136 @@ 
+import sys, os, commands, logging, random
+from autotest.server import autotest_remote, hosts, subcommand, test
+from autotest.client.shared import error
+from autotest.client.tests.virt.virttest import utils_misc, cartesian_config
+
+
+def generate_mac_address():
+    r = random.SystemRandom()
+    mac = "9a:%02x:%02x:%02x:%02x:%02x" % (r.randint(0x00, 0xff),
+                                           r.randint(0x00, 0xff),
+                                           r.randint(0x00, 0xff),
+                                           r.randint(0x00, 0xff),
+                                           r.randint(0x00, 0xff))
+    return mac
+
+
+class Machines(object):
+        def __init__(self, host):
+            self.host = host
+            self.at = None
+            self.params = None
+            self.control = None
+
+
+class multihost_migration(test.test):
+    version = 2
+
+    def run_once(self, machines, extra_params, cycles):
+        AUTOTEST_DIR = self.job.clientdir
+
+        KVM_DIR = os.path.join(AUTOTEST_DIR, 'tests', 'virt')
+
+        sys.path.insert(0, KVM_DIR)
+
+
+        CONTROL_MAIN_PART = """
+testname = "virt"
+bindir = os.path.join(job.testdir, testname)
+job.install_pkg(testname, 'test', bindir)
+
+kvm_test_dir = os.path.join(os.environ['AUTODIR'],'tests', 'virt')
+sys.path.append(kvm_test_dir)
+"""
+        logging.info("KVM test running on hosts %s\n", machines)
+
+        _hosts = {}
+        for machine in machines:
+            _hosts[machine] = Machines(hosts.create_host(machine))
+
+        for host in _hosts.itervalues():
+            host.at = autotest_remote.Autotest(host.host)
+
+        cfg_file = os.path.join(KVM_DIR, "kvm", "cfg", "multi-host-tests.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
+        parser = cartesian_config.Parser()
+        parser.parse_file(cfg_file)
+        parser.parse_string(extra_params)
+        test_dicts = parser.get_dicts()
+
+        ips = []
+        for machine in machines:
+            host = _hosts[machine]
+            ips.append(host.host.ip)
+
+        logging.info("")
+        for i, params in enumerate(test_dicts):
+            logging.info("Test    %d:  %s" % (i, params.get("shortname")))
+        logging.info("")
+
+        test_dicts = parser.get_dicts()
+
+        test_dicts_ar = [x for x in test_dicts]
+
+        if not test_dicts_ar:
+            error.TestNAError("Impossible start any test with"
+                              "this configuration.")
+
+        for params in test_dicts_ar:
+
+            params['hosts'] = ips
+
+            params['not_preprocess'] = "yes"
+            for vm in params.get("vms").split():
+                for nic in params.get('nics', "").split():
+                    params['mac_%s_%s' % (nic, vm)] = generate_mac_address()
+
+            params['master_images_clone'] = "image1"
+            params['kill_vm'] = "yes"
+
+            s_host = _hosts[machines[0]]
+            s_host.params = params.copy()
+            s_host.params['clone_master'] = "yes"
+            s_host.params['hostid'] = machines[0]
+
+            for machine in machines[1:]:
+                host = _hosts[machine]
+                host.params = params.copy()
+                host.params['clone_master'] = "no"
+                host.params['hostid'] = machine
+
+            # Report the parameters we've received
+            logging.debug("Test parameters:")
+            keys = params.keys()
+            keys.sort()
+            for key in keys:
+                logging.debug("    %s = %s", key, params[key])
+
+            for machine in machines:
+                host = _hosts[machine]
+                host.control = CONTROL_MAIN_PART
+
+            for machine in machines:
+                host = _hosts[machine]
+                host.control += ("job.run_test('virt', tag='%s', params=%s)" %
+                                 (host.params['shortname'], host.params))
+
+            logging.debug('Master control file:\n%s', _hosts[machines[0]].control)
+            for machine in machines[1:]:
+                host = _hosts[machine]
+                logging.debug('Slave control file:\n%s', host.control)
+
+            commands = []
+
+            for machine in machines:
+                host = _hosts[machine]
+                commands.append(subcommand.subcommand(host.at.run,
+                                           [host.control, host.host.hostname]))
+
+            try:
+                subcommand.parallel(commands)
+            except error.AutoservError, e:
+                logging.error(e)