KVM test: Renaming some test files
PATCH 1/2 KVM test: Renaming some test files
Move kvm_guest_wizard.py to steps.py and kvm_install.py to build.py. Made the necessary arrangements in the subtest loading code.
Signed-off-by Lucas Meneghel Rodrigues <[email protected]>
--- client/tests/kvm/build.py | 333 ++++++++++++++++++++++++++++++++++ client/tests/kvm/control | 6 +- client/tests/kvm/kvm.py | 4 +- client/tests/kvm/kvm_guest_wizard.py | 249 ------------------------- client/tests/kvm/kvm_install.py | 333 ---------------------------------- client/tests/kvm/steps.py | 249 +++++++++++++++++++++++++ 6 files changed, 587 insertions(+), 587 deletions(-) create mode 100755 client/tests/kvm/build.py delete mode 100644 client/tests/kvm/kvm_guest_wizard.py delete mode 100755 client/tests/kvm/kvm_install.py create mode 100644 client/tests/kvm/steps.py
client/tests/kvm/build.py new file +333 -0
@@ -0,0 +1,333 @@ +import time, os, sys, urllib, re, signal, logging, datetime +from autotest_lib.client.bin import utils, test +from autotest_lib.client.common_lib import error +import kvm_utils + + +def load_kvm_modules(module_dir): + """ + Unload previously loaded kvm modules, then load modules present on any + sub directory of module_dir. Function will walk through module_dir until + it finds the modules. + + @param module_dir: Directory where the KVM modules are located. + """ + vendor = "intel" + if os.system("grep vmx /proc/cpuinfo 1>/dev/null") != 0: + vendor = "amd" + logging.debug("Detected CPU vendor as '%s'" %(vendor)) + + logging.debug("Killing any qemu processes that might be left behind") + utils.system("pkill qemu", ignore_status=True) + + logging.info("Unloading previously loaded KVM modules") + kvm_utils.unload_module("kvm") + if utils.module_is_loaded("kvm"): + message = "Failed to remove old KVM modules" + logging.error(message) + raise error.TestError(message) + + logging.info("Loading new KVM modules...") + kvm_module_path = None + kvm_vendor_module_path = None + # Search for the built KVM modules + for folder, subdirs, files in os.walk(module_dir): + if "kvm.ko" in files: + kvm_module_path = os.path.join(folder, "kvm.ko") + kvm_vendor_module_path = os.path.join(folder, "kvm-%s.ko" % vendor) + abort = False + if not kvm_module_path: + logging.error("Need a directory containing both kernel module and " + "userspace sources.") + logging.error("If you are trying to build only KVM userspace and use " + "the KVM modules you have already loaded, put " + "'load_modules': 'no' on the control file 'params' " + "dictionary.") + raise error.TestError("Could not find a built kvm.ko module on the " + "source dir.") + elif not os.path.isfile(kvm_vendor_module_path): + logging.error("Could not find KVM (%s) module that was supposed to be" + " built on the source dir", vendor) + abort = True + if abort: + raise error.TestError("Could not load KVM modules.") + utils.system("/sbin/insmod %s" % kvm_module_path) + time.sleep(1) + utils.system("/sbin/insmod %s" % kvm_vendor_module_path) + + if not utils.module_is_loaded("kvm"): + message = "Failed to load the KVM modules built for the test" + logging.error(message) + raise error.TestError(message) + + +def create_symlinks(test_bindir, prefix): + """ + Create symbolic links for the appropriate qemu and qemu-img commands on + the kvm test bindir. + + @param test_bindir: KVM test bindir + @param prefix: KVM prefix path + """ + qemu_path = os.path.join(test_bindir, "qemu") + qemu_img_path = os.path.join(test_bindir, "qemu-img") + if os.path.lexists(qemu_path): + os.unlink(qemu_path) + if os.path.lexists(qemu_img_path): + os.unlink(qemu_img_path) + kvm_qemu = os.path.join(prefix, "bin", "qemu-system-x86_64") + if not os.path.isfile(kvm_qemu): + raise error.TestError('Invalid qemu path') + kvm_qemu_img = os.path.join(prefix, "bin", "qemu-img") + if not os.path.isfile(kvm_qemu_img): + raise error.TestError('Invalid qemu-img path') + os.symlink(kvm_qemu, qemu_path) + os.symlink(kvm_qemu_img, qemu_img_path) + + +class SourceDirInstaller: + """ + Class that handles building/installing KVM directly from a tarball or + a single source code dir. + """ + def __init__(self, test, params): + """ + Initializes class attributes, and retrieves KVM code. + + @param test: kvm test object + @param params: Dictionary with test arguments + """ + install_mode = params["mode"] + srcdir = params.get("srcdir") + # KVM build prefix + self.test_bindir = test.bindir + prefix = os.path.join(test.bindir, 'build') + self.prefix = os.path.abspath(prefix) + # Are we going to load modules? + load_modules = params.get('load_modules') + if not load_modules: + self.load_modules = True + elif load_modules == 'yes': + self.load_modules = True + elif load_modules == 'no': + self.load_modules = False + + if install_mode == 'localsrc': + if not srcdir: + raise error.TestError("Install from source directory specified" + "but no source directory provided on the" + "control file.") + else: + self.srcdir = srcdir + self.repo_type = kvm_utils.check_kvm_source_dir(self.srcdir) + return + else: + srcdir = test.srcdir + if not os.path.isdir(srcdir): + os.makedirs(srcdir) + + if install_mode == 'release': + release_tag = params.get("release_tag") + release_dir = params.get("release_dir") + logging.info("Installing KVM from release tarball") + if not release_tag: + release_tag = kvm_utils.get_latest_kvm_release_tag(release_dir) + tarball = os.path.join(release_dir, "kvm-%s.tar.gz" % release_tag) + logging.info("Retrieving release kvm-%s" % release_tag) + tarball = utils.unmap_url("/", tarball, "/tmp") + + elif install_mode == 'snapshot': + logging.info("Installing KVM from snapshot") + snapshot_dir = params.get("snapshot_dir") + if not snapshot_dir: + raise error.TestError("Snapshot dir not provided") + snapshot_date = params.get("snapshot_date") + if not snapshot_date: + # Take yesterday's snapshot + d = (datetime.date.today() - + datetime.timedelta(1)).strftime("%Y%m%d") + else: + d = snapshot_date + tarball = os.path.join(snapshot_dir, "kvm-snapshot-%s.tar.gz" % d) + logging.info("Retrieving kvm-snapshot-%s" % d) + tarball = utils.unmap_url("/", tarball, "/tmp") + + elif install_mode == 'localtar': + tarball = params.get("tarball") + if not tarball: + raise error.TestError("KVM Tarball install specified but no" + " tarball provided on control file.") + logging.info("Installing KVM from a local tarball") + logging.info("Using tarball %s") + tarball = utils.unmap_url("/", params.get("tarball"), "/tmp") + + os.chdir(srcdir) + self.srcdir = os.path.join(srcdir, utils.extract_tarball(tarball)) + self.repo_type = kvm_utils.check_kvm_source_dir(self.srcdir) + + + def __build(self): + os.chdir(self.srcdir) + # For testing purposes, it's better to build qemu binaries with + # debugging symbols, so we can extract more meaningful stack traces. + cfg = "./configure --disable-strip --prefix=%s" % self.prefix + steps = [cfg, "make clean", "make -j %s" % (utils.count_cpus() + 1)] + logging.info("Building KVM") + for step in steps: + utils.system(step) + + + def __install(self): + os.chdir(self.srcdir) + logging.info("Installing KVM userspace") + if self.repo_type == 1: + utils.system("make -C qemu install") + elif self.repo_type == 2: + utils.system("make install") + create_symlinks(self.test_bindir, self.prefix) + + + def __load_modules(self): + load_kvm_modules(self.srcdir) + + + def install(self): + self.__build() + self.__install() + if self.load_modules: + self.__load_modules() + + +class GitInstaller: + def __init__(self, test, params): + """ + Initialize class parameters and retrieves code from git repositories. + + @param test: kvm test object. + @param params: Dictionary with test parameters. + """ + install_mode = params["mode"] + srcdir = params.get("srcdir", test.bindir) + if not srcdir: + os.makedirs(srcdir) + self.srcdir = srcdir + # KVM build prefix + self.test_bindir = test.bindir + prefix = os.path.join(test.bindir, 'build') + self.prefix = os.path.abspath(prefix) + # Are we going to load modules? + load_modules = params.get('load_modules') + if not load_modules: + self.load_modules = True + elif load_modules == 'yes': + self.load_modules = True + elif load_modules == 'no': + self.load_modules = False + + kernel_repo = params.get("git_repo") + user_repo = params.get("user_git_repo") + kmod_repo = params.get("kmod_repo") + + branch = params.get("git_branch", "master") + lbranch = params.get("lbranch") + + tag = params.get("git_tag", "HEAD") + user_tag = params.get("user_git_tag", "HEAD") + kmod_tag = params.get("kmod_git_tag", "HEAD") + + if not kernel_repo: + message = "KVM git repository path not specified" + logging.error(message) + raise error.TestError(message) + if not user_repo: + message = "KVM user git repository path not specified" + logging.error(message) + raise error.TestError(message) + + kernel_srcdir = os.path.join(srcdir, "kvm") + kvm_utils.get_git_branch(kernel_repo, branch, kernel_srcdir, tag, + lbranch) + self.kernel_srcdir = kernel_srcdir + + userspace_srcdir = os.path.join(srcdir, "kvm_userspace") + kvm_utils.get_git_branch(user_repo, branch, userspace_srcdir, user_tag, + lbranch) + self.userspace_srcdir = userspace_srcdir + + if kmod_repo: + kmod_srcdir = os.path.join (srcdir, "kvm_kmod") + kvm_utils.get_git_branch(kmod_repo, branch, kmod_srcdir, user_tag, + lbranch) + self.kmod_srcdir = kmod_srcdir + + + def __build(self): + if self.kmod_srcdir: + logging.info('Building KVM modules') + os.chdir(self.kmod_srcdir) + utils.system('./configure') + utils.system('make clean') + utils.system('make sync LINUX=%s' % self.kernel_srcdir) + utils.system('make -j %s' % utils.count_cpus()) + logging.info('Building KVM userspace code') + os.chdir(self.userspace_srcdir) + utils.system('./configure --disable-strip --prefix=%s' % + self.prefix) + utils.system('make clean') + utils.system('make -j %s' % utils.count_cpus()) + else: + os.chdir(self.userspace_srcdir) + utils.system('./configure --disable-strip --prefix=%s' % + self.prefix) + logging.info('Building KVM modules') + utils.system('make clean') + utils.system('make -C kernel LINUX=%s sync' % self.kernel_srcdir) + logging.info('Building KVM userspace code') + utils.system('make -j %s' % utils.count_cpus()) + + + def __install(self): + os.chdir(self.userspace_srcdir) + utils.system('make install') + create_symlinks(self.test_bindir, self.prefix) + + + def __load_modules(self): + if self.kmod_srcdir: + load_kvm_modules(self.kmod_srcdir) + else: + load_kvm_modules(self.userspace_srcdir) + + + def install(self): + self.__build() + self.__install() + if self.load_modules: + self.__load_modules() + + +def run_build(test, params, env): + """ + Installs KVM using the selected install mode. Most install methods will + take kvm source code, build it and install it to a given location. + + @param test: kvm test object. + @param params: Dictionary with test parameters. + @param env: Test environment. + """ + install_mode = params.get("mode") + srcdir = params.get("srcdir", test.srcdir) + params["srcdir"] = srcdir + + if install_mode == 'noinstall': + logging.info("Skipping installation") + return + elif install_mode in ['localsrc', 'localtar', 'release', 'snapshot']: + installer = SourceDirInstaller(test, params) + elif install_mode == 'git': + installer = GitInstaller(test, params) + else: + raise error.TestError('Invalid or unsupported' + ' install mode: %s' % install_mode) + + installer.install()
client/tests/kvm/control +3 -3
@@ -72,9 +72,9 @@ link_if_not_exist(pwd, qemu_img, 'qemu-img') # Params that will be passed to the KVM install/build test # -------------------------------------------------------- params = { - "name": "kvm_install", - "shortname": "kvm_install", - "type": "kvm_install", + "name": "build", + "shortname": "build", + "type": "build", "mode": "release", #"mode": "snapshot", #"mode": "localtar",
client/tests/kvm/kvm.py +2 -2
@@ -48,14 +48,14 @@ class kvm(test.test): # of the 'type' field self.test_routines = { # type module name routine - "steps": test_routine("kvm_guest_wizard", "run_steps"), + "build": test_routine("build", "run_build"), + "steps": test_routine("steps", "run_steps"), "stepmaker": test_routine("stepmaker", "run_stepmaker"), "boot": test_routine("kvm_tests", "run_boot"), "shutdown": test_routine("kvm_tests", "run_shutdown"), "migration": test_routine("kvm_tests", "run_migration"), "yum_update": test_routine("kvm_tests", "run_yum_update"), "autotest": test_routine("kvm_tests", "run_autotest"), - "kvm_install": test_routine("kvm_install", "run_kvm_install"), "linux_s3": test_routine("kvm_tests", "run_linux_s3"), "stress_boot": test_routine("kvm_tests", "run_stress_boot"), "timedrift": test_routine("kvm_tests", "run_timedrift"),
client/tests/kvm/kvm_guest_wizard.py deleted +0 -249
249 lines not on this page · raw message
client/tests/kvm/kvm_install.py deleted +0 -333
333 lines not on this page · raw message
client/tests/kvm/steps.py new file +249 -0
249 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 2/2 KVM test: Fixing KVM release tag detection
Sourceforge changes again their URL schema so it's time to fix it.
Signed-off-by Lucas Meneghel Rodrigues <[email protected]>
--- client/tests/kvm/build.py | 4 +++- client/tests/kvm/control | 4 +++- client/tests/kvm/kvm_utils.py | 13 ++++++------- 3 files changed, 12 insertions(+), 9 deletions(-)
client/tests/kvm/build.py +3 -1
@@ -129,9 +129,11 @@ class SourceDirInstaller: if install_mode == 'release': release_tag = params.get("release_tag") release_dir = params.get("release_dir") + release_listing = params.get("release_listing") logging.info("Installing KVM from release tarball") if not release_tag: - release_tag = kvm_utils.get_latest_kvm_release_tag(release_dir) + release_tag = kvm_utils.get_latest_kvm_release_tag( + release_listing) tarball = os.path.join(release_dir, "kvm-%s.tar.gz" % release_tag) logging.info("Retrieving release kvm-%s" % release_tag) tarball = utils.unmap_url("/", tarball, "/tmp")
client/tests/kvm/control +3 -1
@@ -93,7 +93,9 @@ params = { ## specify a release tag. If you omit it, the test will get the latest ## release tag available. #"release_tag": '84', - "release_dir": 'http://downloads.sourceforge.net/kvm/', + "release_dir": 'http://downloads.sourceforge.net/project/kvm/', + # This is the place that contains the sourceforge project list of files + "release_listing": 'http://sourceforge.net/projects/kvm/files/', ## Install from a kvm snapshot location ("mode": "snapshot"). You can ## optionally specify a snapshot date. If you omit it, the test will get
client/tests/kvm/kvm_utils.py +6 -7
@@ -282,18 +282,17 @@ def kill_process_tree(pid, sig=signal.SIGKILL): safe_kill(pid, signal.SIGCONT) -def get_latest_kvm_release_tag(release_dir): +def get_latest_kvm_release_tag(release_listing): """ Fetches the latest release tag for KVM. - @param release_dir: KVM source forge download location. + @param release_listing: URL that contains a list of the Source Forge + KVM project files. """ try: - page_url = os.path.join(release_dir, "showfiles.php") - local_web_page = utils.unmap_url("/", page_url, "/tmp") - f = open(local_web_page, "r") - data = f.read() - f.close() + release_page = utils.urlopen(release_listing) + data = release_page.read() + release_page.close() rx = re.compile("kvm-(\d+).tar.gz", re.IGNORECASE) matches = rx.findall(data) # In all regexp matches to something that looks like a release tag,
Signature · 1 line
1.6.2.5