Home | History | Annotate | Download | only in kvm
      1 AUTHOR = "Yolkfull Chow <yzhou (a] 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 from autotest_lib.client.common_lib import cartesian_config
     16 
     17 # Specify the directory of autotest before you start this test
     18 AUTOTEST_DIR = '/usr/local/autotest'
     19 
     20 # Specify the root directory that on client machines
     21 rootdir = '/tmp/kvm_autotest_root'
     22 
     23 KVM_DIR = os.path.join(AUTOTEST_DIR, 'client/tests/kvm')
     24 
     25 
     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))
     33     return mac
     34 
     35 
     36 def run(pair):
     37     logging.info("KVM migration running on source host [%s] and destination "
     38                  "host [%s]\n", pair[0], pair[1])
     39 
     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)
     44 
     45     cfg_file = os.path.join(KVM_DIR, "tests_base.cfg")
     46 
     47     if not os.path.exists(cfg_file):
     48         raise error.JobError("Config file %s was not found", cfg_file)
     49 
     50     # Get test set (dictionary list) from the configuration file
     51     parser = cartesian_config.Parser()
     52     test_variants = """
     53 image_name(_.*)? ?<= /tmp/kvm_autotest_root/images/
     54 cdrom(_.*)? ?<= /tmp/kvm_autotest_root/
     55 floppy ?<= /tmp/kvm_autotest_root/
     56 Linux:
     57     unattended_install:
     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
     62 only qcow2
     63 only virtio_net
     64 only virtio_blk
     65 only smp2
     66 only no_pci_assignable
     67 only smallpages
     68 only Fedora.14.64
     69 only migrate_multi_host
     70 nic_mode = tap
     71 nic_mac_nic1 = %s
     72 """ % (generate_mac_address())
     73     parser.parse_file(cfg_file)
     74     parser.parse_string(test_variants)
     75     test_dicts = parser.get_dicts()
     76 
     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
     80 """
     81     for params in test_dicts:
     82         params['srchost'] = source.ip
     83         params['dsthost'] = dest.ip
     84         params['rootdir'] = rootdir
     85 
     86         source_params = params.copy()
     87         source_params['role'] = "source"
     88 
     89         dest_params = params.copy()
     90         dest_params['role'] = "destination"
     91         dest_params['migration_mode'] = "tcp"
     92 
     93         # Report the parameters we've received
     94         print "Test parameters:"
     95         keys = params.keys()
     96         keys.sort()
     97         for key in keys:
     98             logging.debug("    %s = %s", key, params[key])
     99 
    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))
    104 
    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])
    109 
    110         source_command = subcommand(source_at.run,
    111                                     [source_control_file, source.hostname])
    112 
    113         parallel([dest_command, source_command])
    114 
    115 # Grab the pairs (and failures)
    116 (pairs, failures) = utils.form_ntuples_from_machines(machines, 2)
    117 
    118 # Log the failures
    119 for failure in failures:
    120     job.record("FAIL", failure[0], "kvm", failure[1])
    121 
    122 # Now run through each pair and run
    123 job.parallel_simple(run, pairs, log=False)
    124