1 AUTHOR = "Yolkfull Chow <yzhou@redhat.com>"
3 NAME = "Migration across multiple hosts"
4 TEST_CATEGORY = "Functional"
5 TEST_CLASS = "Virtualization"
8 Migrate KVM guest between two hosts. It parses the base config file, restricts
9 it with appropriate parameters, generates the test dicts, modify the test_dicts
10 so there's a distinction between the migration roles ('dest' or 'source').
13 import sys, os, commands, glob, shutil, logging, random
14 from autotest_lib.server import utils
15 from autotest_lib.client.common_lib import cartesian_config
17 # Specify the directory of autotest before you start this test
18 AUTOTEST_DIR = '/usr/local/autotest'
20 # Specify the root directory that on client machines
21 rootdir = '/tmp/kvm_autotest_root'
23 KVM_DIR = os.path.join(AUTOTEST_DIR, 'client/tests/kvm')
26 def generate_mac_address():
27 r = random.SystemRandom()
28 mac = "9a:%02x:%02x:%02x:%02x:%02x" % (r.randint(0x00, 0xff),
29 r.randint(0x00, 0xff),
30 r.randint(0x00, 0xff),
31 r.randint(0x00, 0xff),
32 r.randint(0x00, 0xff))
37 logging.info("KVM migration running on source host [%s] and destination "
38 "host [%s]\n", pair[0], pair[1])
40 source = hosts.create_host(pair[0])
41 dest = hosts.create_host(pair[1])
42 source_at = autotest.Autotest(source)
43 dest_at = autotest.Autotest(dest)
45 cfg_file = os.path.join(KVM_DIR, "tests_base.cfg")
47 if not os.path.exists(cfg_file):
48 raise error.JobError("Config file %s was not found", cfg_file)
50 # Get test set (dictionary list) from the configuration file
51 parser = cartesian_config.Parser()
53 image_name(_.*)? ?<= /tmp/kvm_autotest_root/images/
54 cdrom(_.*)? ?<= /tmp/kvm_autotest_root/
55 floppy ?<= /tmp/kvm_autotest_root/
58 kernel ?<= /tmp/kvm_autotest_root/
59 initrd ?<= /tmp/kvm_autotest_root/
60 qemu_binary = /usr/libexec/qemu-kvm
61 qemu_img_binary = /usr/bin/qemu-img
66 only no_pci_assignable
69 only migrate_multi_host
72 """ % (generate_mac_address())
73 parser.parse_file(cfg_file)
74 parser.parse_string(test_variants)
75 test_dicts = parser.get_dicts()
77 source_control_file = dest_control_file = """
78 kvm_test_dir = os.path.join(os.environ['AUTODIR'],'tests/kvm')
79 sys.path.append(kvm_test_dir)\n
81 for params in test_dicts:
82 params['srchost'] = source.ip
83 params['dsthost'] = dest.ip
84 params['rootdir'] = rootdir
86 source_params = params.copy()
87 source_params['role'] = "source"
89 dest_params = params.copy()
90 dest_params['role'] = "destination"
91 dest_params['migration_mode'] = "tcp"
93 # Report the parameters we've received
94 print "Test parameters:"
98 logging.debug(" %s = %s", key, params[key])
100 source_control_file += ("job.run_test('kvm', tag='%s', params=%s)" %
101 (source_params['shortname'], source_params))
102 dest_control_file += ("job.run_test('kvm', tag='%s', params=%s)" %
103 (dest_params['shortname'], dest_params))
105 logging.info('Source control file:\n%s', source_control_file)
106 logging.info('Destination control file:\n%s', dest_control_file)
107 dest_command = subcommand(dest_at.run,
108 [dest_control_file, dest.hostname])
110 source_command = subcommand(source_at.run,
111 [source_control_file, source.hostname])
113 parallel([dest_command, source_command])
115 # Grab the pairs (and failures)
116 (pairs, failures) = utils.form_ntuples_from_machines(machines, 2)
119 for failure in failures:
120 job.record("FAIL", failure[0], "kvm", failure[1])
122 # Now run through each pair and run
123 job.parallel_simple(run, pairs, log=False)