OLD | NEW |
| (Empty) |
1 AUTHOR = "Yolkfull Chow <yzhou@redhat.com>" | |
2 TIME = "SHORT" | |
3 NAME = "Migration across multiple hosts" | |
4 TEST_CATEGORY = "Functional" | |
5 TEST_CLASS = "Virtualization" | |
6 TEST_TYPE = "Server" | |
7 DOC = """ | |
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'). | |
11 """ | |
12 | |
13 import sys, os, commands, glob, shutil, logging, random | |
14 from autotest_lib.server import utils | |
15 | |
16 # Specify the directory of autotest before you start this test | |
17 AUTOTEST_DIR = '/usr/local/autotest' | |
18 | |
19 # Specify the root directory that on client machines | |
20 rootdir = '/tmp/kvm_autotest_root' | |
21 | |
22 # Make possible to import the KVM test APIs | |
23 KVM_DIR = os.path.join(AUTOTEST_DIR, 'client/tests/kvm') | |
24 sys.path.append(KVM_DIR) | |
25 | |
26 import common, kvm_config | |
27 | |
28 def 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 | |
38 def 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 = """ | |
55 image_name(_.*)? ?<= /tmp/kvm_autotest_root/images/ | |
56 cdrom(_.*)? ?<= /tmp/kvm_autotest_root/ | |
57 floppy ?<= /tmp/kvm_autotest_root/ | |
58 Linux: | |
59 unattended_install: | |
60 kernel ?<= /tmp/kvm_autotest_root/ | |
61 initrd ?<= /tmp/kvm_autotest_root/ | |
62 qemu_binary = /usr/libexec/qemu-kvm | |
63 qemu_img_binary = /usr/bin/qemu-img | |
64 only qcow2 | |
65 only virtio_net | |
66 only virtio_blk | |
67 only smp2 | |
68 only no_pci_assignable | |
69 only smallpages | |
70 only Fedora.13.64 | |
71 only migrate_multi_host | |
72 nic_mode = tap | |
73 nic_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 = """ | |
79 kvm_test_dir = os.path.join(os.environ['AUTODIR'],'tests/kvm') | |
80 sys.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)" % (sou
rce_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 | |
118 for failure in failures: | |
119 job.record("FAIL", failure[0], "kvm", failure[1]) | |
120 | |
121 # Now run through each pair and run | |
122 job.parallel_simple(run, pairs, log=False) | |
OLD | NEW |