blob: 16ada361d07102b0afc3684d2e2423e4feca617a [file] [log] [blame]
Eric Li7edb3042011-01-06 17:57:17 -08001AUTHOR = "Yolkfull Chow <yzhou@redhat.com>"
2TIME = "SHORT"
3NAME = "Migration across multiple hosts"
4TEST_CATEGORY = "Functional"
5TEST_CLASS = "Virtualization"
6TEST_TYPE = "Server"
7DOC = """
8Migrate KVM guest between two hosts. It parses the base config file, restricts
9it with appropriate parameters, generates the test dicts, modify the test_dicts
10so there's a distinction between the migration roles ('dest' or 'source').
11"""
12
13import sys, os, commands, glob, shutil, logging, random
14from autotest_lib.server import utils
15
16# Specify the directory of autotest before you start this test
17AUTOTEST_DIR = '/usr/local/autotest'
18
19# Specify the root directory that on client machines
20rootdir = '/tmp/kvm_autotest_root'
21
22# Make possible to import the KVM test APIs
23KVM_DIR = os.path.join(AUTOTEST_DIR, 'client/tests/kvm')
24sys.path.append(KVM_DIR)
25
26import common, kvm_config
27
28def generate_mac_address():
29 r = random.SystemRandom()
30 mac = "9a:%02x:%02x:%02x:%02x:%02x" % (r.randint(0x00, 0xff),
31 r.randint(0x00, 0xff),
32 r.randint(0x00, 0xff),
33 r.randint(0x00, 0xff),
34 r.randint(0x00, 0xff))
35 return mac
36
37
38def run(pair):
39 logging.info("KVM migration running on source host [%s] and destination "
40 "host [%s]\n", pair[0], pair[1])
41
42 source = hosts.create_host(pair[0])
43 dest = hosts.create_host(pair[1])
44 source_at = autotest.Autotest(source)
45 dest_at = autotest.Autotest(dest)
46
47 cfg_file = os.path.join(KVM_DIR, "tests_base.cfg")
48
49 if not os.path.exists(cfg_file):
50 raise error.JobError("Config file %s was not found", cfg_file)
51
52 # Get test set (dictionary list) from the configuration file
53 cfg = kvm_config.config()
54 test_variants = """
55image_name(_.*)? ?<= /tmp/kvm_autotest_root/images/
56cdrom(_.*)? ?<= /tmp/kvm_autotest_root/
57floppy ?<= /tmp/kvm_autotest_root/
58Linux:
59 unattended_install:
60 kernel ?<= /tmp/kvm_autotest_root/
61 initrd ?<= /tmp/kvm_autotest_root/
62qemu_binary = /usr/libexec/qemu-kvm
63qemu_img_binary = /usr/bin/qemu-img
64only qcow2
65only virtio_net
66only virtio_blk
67only smp2
68only no_pci_assignable
69only smallpages
70only Fedora.13.64
71only migrate_multi_host
72nic_mode = tap
73nic_mac_nic1 = %s
74""" % (generate_mac_address())
75 cfg.fork_and_parse(cfg_file, test_variants)
76 test_dicts = cfg.get_list()
77
78 source_control_file = dest_control_file = """
79kvm_test_dir = os.path.join(os.environ['AUTODIR'],'tests/kvm')
80sys.path.append(kvm_test_dir)\n
81"""
82 for params in test_dicts:
83 params['srchost'] = source.ip
84 params['dsthost'] = dest.ip
85 params['rootdir'] = rootdir
86
87 source_params = params.copy()
88 source_params['role'] = "source"
89
90 dest_params = params.copy()
91 dest_params['role'] = "destination"
92 dest_params['migration_mode'] = "tcp"
93
94 # Report the parameters we've received
95 print "Test parameters:"
96 keys = params.keys()
97 keys.sort()
98 for key in keys:
99 logging.debug(" %s = %s", key, params[key])
100
101 source_control_file += "job.run_test('kvm', tag='%s', params=%s)" % (source_params['shortname'], source_params)
102 dest_control_file += "job.run_test('kvm', tag='%s', params=%s)" % (dest_params['shortname'], dest_params)
103
104 logging.info('Source control file:\n%s', source_control_file)
105 logging.info('Destination control file:\n%s', dest_control_file)
106 dest_command = subcommand(dest_at.run,
107 [dest_control_file, dest.hostname])
108
109 source_command = subcommand(source_at.run,
110 [source_control_file, source.hostname])
111
112 parallel([dest_command, source_command])
113
114# Grab the pairs (and failures)
115(pairs, failures) = utils.form_ntuples_from_machines(machines, 2)
116
117# Log the failures
118for failure in failures:
119 job.record("FAIL", failure[0], "kvm", failure[1])
120
121# Now run through each pair and run
122job.parallel_simple(run, pairs, log=False)