AUTHOR = "Jiri Zupka " TIME = "SHORT" NAME = "" TEST_CATEGORY = "Functional" TEST_CLASS = "Virtualization" TEST_TYPE = "Server" DOC = """ KVM tests (multi-host) server control Runs tests across multiple hosts. It uses the config file 'multi-host-tests.cfg' in order to yield the appropriate dicts for the multi host test. """ import sys, os, commands, glob, shutil, logging, random from autotest.server import utils from autotest.client.shared import cartesian_config, error # Specify the directory of autotest before you start this test AUTOTEST_DIR = job.clientdir KVM_DIR = os.path.join(AUTOTEST_DIR, 'tests', 'kvm') CONTROL_MAIN_PART = """ testname = "kvm" bindir = os.path.join(job.testdir, testname) job.install_pkg(testname, 'test', bindir) kvm_test_dir = os.path.join(os.environ['AUTODIR'],'tests', 'kvm') sys.path.append(kvm_test_dir) """ try: import autotest.common except ImportError: import common 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 def run(machines): logging.info("KVM test running on hosts %s\n", machines) class Machines(object): def __init__(self, host): self.host = host self.at = None self.params = None self.control = None _hosts = {} for machine in machines: _hosts[machine] = Machines(hosts.create_host(machine)) ats = [] for host in _hosts.itervalues(): host.at = autotest_remote.Autotest(host.host) cfg_file = os.path.join(KVM_DIR, "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) test_dicts = parser.get_dicts() ips = [] for machine in machines: host = _hosts[machine] ips.append(host.host.ip) for params in test_dicts: 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('kvm', 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(host.at.run, [host.control, host.host.hostname])) try: parallel(commands) except error.AutoservError as e: logging.error(e) 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)