Home | History | Annotate | Download | only in kvm
      1 AUTHOR = """
      2 uril (a] redhat.com (Uri Lublin)
      3 drusso (a] redhat.com (Dror Russo)
      4 mgoldish (a] redhat.com (Michael Goldish)
      5 dhuff (a] redhat.com (David Huff)
      6 aeromenk (a] redhat.com (Alexey Eromenko)
      7 mburns (a] redhat.com (Mike Burns)
      8 """
      9 TIME = 'SHORT'
     10 NAME = 'KVM test'
     11 TEST_TYPE = 'client'
     12 TEST_CLASS = 'Virtualization'
     13 TEST_CATEGORY = 'Functional'
     14 
     15 DOC = """
     16 Executes the KVM test framework on a given host. This module is separated in
     17 minor functions, that execute different tests for doing Quality Assurance on
     18 KVM (both kernelspace and userspace) code.
     19 """
     20 
     21 
     22 import sys, os, commands, re
     23 
     24 #-----------------------------------------------------------------------------
     25 # set English environment (command output might be localized, need to be safe)
     26 #-----------------------------------------------------------------------------
     27 os.environ['LANG'] = 'en_US.UTF-8'
     28 
     29 #---------------------------------------------------------
     30 # Enable modules import from current directory (tests/kvm)
     31 #---------------------------------------------------------
     32 pwd = os.path.join(os.environ['AUTODIR'],'tests/kvm')
     33 sys.path.append(pwd)
     34 
     35 # ------------------------
     36 # create required symlinks
     37 # ------------------------
     38 # When dispatching tests from autotest-server the links we need do not exist on
     39 # the host (the client). The following lines create those symlinks. Change
     40 # 'rootdir' here and/or mount appropriate directories in it.
     41 #
     42 # When dispatching tests on local host (client mode) one can either setup kvm
     43 # links, or same as server mode use rootdir and set all appropriate links and
     44 # mount-points there. For example, guest installation tests need to know where
     45 # to find the iso-files.
     46 #
     47 # We create the links only if not already exist, so if one already set up the
     48 # links for client/local run we do not touch the links.
     49 rootdir='/tmp/kvm_autotest_root'
     50 iso=os.path.join(rootdir, 'iso')
     51 images=os.path.join(rootdir, 'images')
     52 qemu=os.path.join(rootdir, 'qemu')
     53 qemu_img=os.path.join(rootdir, 'qemu-img')
     54 
     55 
     56 def link_if_not_exist(ldir, target, link_name):
     57     t = target
     58     l = os.path.join(ldir, link_name)
     59     if not os.path.exists(l):
     60         os.system('ln -s %s %s' % (t, l))
     61 
     62 # Create links only if not already exist
     63 link_if_not_exist(pwd, '../../', 'autotest')
     64 link_if_not_exist(pwd, iso, 'isos')
     65 link_if_not_exist(pwd, images, 'images')
     66 link_if_not_exist(pwd, qemu, 'qemu')
     67 link_if_not_exist(pwd, qemu_img, 'qemu-img')
     68 
     69 # --------------------------------------------------------
     70 # Params that will be passed to the KVM install/build test
     71 # --------------------------------------------------------
     72 params = {
     73     "name": "build",
     74     "shortname": "build",
     75     "type": "build",
     76     #"mode": "release",
     77     #"mode": "snapshot",
     78     #"mode": "localtar",
     79     #"mode": "localsrc",
     80     #"mode": "git",
     81     "mode": "noinstall",
     82     #"mode": "koji",
     83 
     84     ## Are we going to load modules built by this test?
     85     ## Defaults to 'yes', so if you are going to provide only userspace code to
     86     ## be built by this test, please set load_modules to 'no', and make sure
     87     ## the kvm and kvm-[vendor] module is already loaded by the time you start
     88     ## it.
     89     #"load_modules": "no",
     90 
     91     ## Install from a kvm release ("mode": "release"). You can optionally
     92     ## specify a release tag. If you omit it, the test will get the latest
     93     ## release tag available.
     94     #"release_tag": '84',
     95     #"release_dir": 'http://downloads.sourceforge.net/project/kvm/',
     96     # This is the place that contains the sourceforge project list of files
     97     #"release_listing": 'http://sourceforge.net/projects/kvm/files/',
     98 
     99     ## Install from a kvm snapshot location ("mode": "snapshot"). You can
    100     ## optionally specify a snapshot date. If you omit it, the test will get
    101     ## yesterday's snapshot.
    102     #"snapshot_date": '20090712'
    103     #"snapshot_dir": 'http://foo.org/kvm-snapshots/',
    104 
    105     ## Install from a tarball ("mode": "localtar")
    106     #"tarball": "/tmp/kvm-84.tar.gz",
    107 
    108     ## Install from a local source code dir ("mode": "localsrc")
    109     #"srcdir": "/path/to/source-dir"
    110 
    111     ## Install from koji build server ("mode": "koji")
    112     ## Koji is the Fedora Project buildserver. It is possible to install
    113     ## packages right from Koji if you provide a release tag or a build.
    114     ## Tag (if available)
    115     #"koji_tag": 'dist-f11',
    116     ## Build (if available, is going to override tag).
    117     #"koji_build": 'qemu-0.10-16.fc11',
    118     ## Command to interact with the build server
    119     #"koji_cmd": '/usr/bin/koji',
    120     ## The name of the source package that's being built
    121     #"src_pkg": 'qemu',
    122     ## Name of the rpms we need installed
    123     #"pkg_list": ['qemu-kvm', 'qemu-kvm-tools', 'qemu-system-x86', 'qemu-common', 'qemu-img'],
    124     ## Paths of the qemu relevant executables that should be checked
    125     #"qemu_bin_paths": ['/usr/bin/qemu-kvm', '/usr/bin/qemu-img'],
    126 
    127     ## Install from git ("mode": "git")
    128     ## If you provide only "git_repo" and "user_git_repo", the build test
    129     ## will assume it will perform all build from the userspace dir, building
    130     ## modules trough make -C kernel LINUX=%s sync. As of today (07-13-2009)
    131     ## we need 3 git repos, "git_repo" (linux sources), "user_git_repo" and 
    132     ## "kmod_repo" to build KVM userspace + kernel modules.
    133     #"git_repo": 'git://git.kernel.org/pub/scm/linux/kernel/git/avi/kvm.git',
    134     #"kernel_branch": 'kernel_branch_name',
    135     #"kernel_lbranch": 'kernel_lbranch_name',
    136     #"kernel_tag": 'kernel_tag_name',
    137     #"user_git_repo": 'git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git',
    138     #"user_branch": 'user_branch_name',
    139     #"user_lbranch": 'user_lbranch_name',
    140     #"user_tag": 'user_tag_name',
    141     #"kmod_repo": 'git://git.kernel.org/pub/scm/virt/kvm/kvm-kmod.git',
    142     #"kmod_branch": 'kmod_branch_name',
    143     #"kmod_lbranch": 'kmod_lbranch_name',
    144     #"kmod_tag": 'kmod_tag_name',
    145 }
    146 
    147 # If you don't want to execute the build stage, just use 'noinstall' as the
    148 # install type. If you run the tests from autotest-server, make sure that
    149 # /tmp/kvm-autotest-root/qemu is a link to your existing executable. Note that
    150 # if kvm_install is chose to run, it overwrites existing qemu and qemu-img
    151 # links to point to the newly built executables.
    152 
    153 if not params.get("mode") == "noinstall":
    154     if not job.run_test("kvm", params=params, tag=params.get("shortname")):
    155         print 'kvm_installation failed ... exiting'
    156         sys.exit(1)
    157 
    158 # ----------------------------------------------------------
    159 # Get test set (dictionary list) from the configuration file
    160 # ----------------------------------------------------------
    161 from autotest_lib.client.common_lib import cartesian_config
    162 
    163 str = """
    164 # This string will be parsed after tests.cfg.  Make any desired changes to the
    165 # test configuration here.  For example:
    166 #install, setup: timeout_multiplier = 3
    167 #display = sdl
    168 """
    169 
    170 parser = cartesian_config.Parser()
    171 parser.parse_file(os.path.join(pwd, "tests.cfg"))
    172 parser.parse_string(str)
    173 
    174 tests = list(parser.get_dicts())
    175 
    176 # -------------
    177 # Run the tests
    178 # -------------
    179 from autotest_lib.client.virt import virt_scheduler
    180 from autotest_lib.client.bin import utils
    181 
    182 # total_cpus defaults to the number of CPUs reported by /proc/cpuinfo
    183 total_cpus = utils.count_cpus()
    184 # total_mem defaults to 3/4 of the total memory reported by 'free'
    185 total_mem = int(commands.getoutput("free -m").splitlines()[1].split()[1]) * 3/4
    186 # We probably won't need more workers than CPUs
    187 num_workers = total_cpus
    188 
    189 # Start the scheduler and workers
    190 s = virt_scheduler.scheduler(tests, num_workers, total_cpus, total_mem, pwd)
    191 job.parallel([s.scheduler],
    192              *[(s.worker, i, job.run_test) for i in range(num_workers)])
    193 
    194 # create the html report in result dir
    195 reporter = os.path.join(pwd, 'make_html_report.py')
    196 html_file = os.path.join(job.resultdir,'results.html')
    197 os.system('%s -r %s -f %s -R'%(reporter, job.resultdir, html_file))
    198