Index: client/virt/kvm_installer.py |
diff --git a/client/tests/kvm/installer.py b/client/virt/kvm_installer.py |
similarity index 86% |
rename from client/tests/kvm/installer.py |
rename to client/virt/kvm_installer.py |
index 8026d6ddbd92c5a409c23e666afd5291bb9b07cd..dc1ffcec50406a5b40e7cceadc88e354cc295693 100644 |
--- a/client/tests/kvm/installer.py |
+++ b/client/virt/kvm_installer.py |
@@ -1,29 +1,7 @@ |
-import os, logging, datetime, glob |
-import shutil |
+import os, logging, datetime, glob, shutil |
from autotest_lib.client.bin import utils, os_dep |
from autotest_lib.client.common_lib import error |
-import kvm_utils |
- |
- |
-def check_configure_options(script_path): |
- """ |
- Return the list of available options (flags) of a given kvm configure build |
- script. |
- |
- @param script: Path to the configure script |
- """ |
- abspath = os.path.abspath(script_path) |
- help_raw = utils.system_output('%s --help' % abspath, ignore_status=True) |
- help_output = help_raw.split("\n") |
- option_list = [] |
- for line in help_output: |
- cleaned_line = line.lstrip() |
- if cleaned_line.startswith("--"): |
- option = cleaned_line.split()[0] |
- option = option.split("=")[0] |
- option_list.append(option) |
- |
- return option_list |
+import virt_utils, virt_installer |
def kill_qemu_processes(): |
@@ -37,14 +15,6 @@ def kill_qemu_processes(): |
utils.system("fuser -k /dev/kvm", ignore_status=True) |
-def cpu_vendor(): |
- vendor = "intel" |
- if os.system("grep vmx /proc/cpuinfo 1>/dev/null") != 0: |
- vendor = "amd" |
- logging.debug("Detected CPU vendor as '%s'", vendor) |
- return vendor |
- |
- |
def _unload_kvm_modules(mod_list): |
logging.info("Unloading previously loaded KVM modules") |
for module in reversed(mod_list): |
@@ -160,15 +130,6 @@ def install_roms(rom_dir, prefix): |
shutil.copy(rom_src, rom_dst) |
-def save_build(build_dir, dest_dir): |
- logging.debug('Saving the result of the build on %s', dest_dir) |
- base_name = os.path.basename(build_dir) |
- tarball_name = base_name + '.tar.bz2' |
- os.chdir(os.path.dirname(build_dir)) |
- utils.system('tar -cjf %s %s' % (tarball_name, base_name)) |
- shutil.move(tarball_name, os.path.join(dest_dir, tarball_name)) |
- |
- |
class KvmInstallException(Exception): |
pass |
@@ -200,7 +161,7 @@ class BaseInstaller(object): |
self.extra_modules = eval(params.get("extra_modules", |
default_extra_modules)) |
- self.cpu_vendor = cpu_vendor() |
+ self.cpu_vendor = virt_installer.cpu_vendor() |
self.srcdir = test.srcdir |
if not os.path.isdir(self.srcdir): |
@@ -240,7 +201,7 @@ class BaseInstaller(object): |
if test_repo: |
test_srcdir = os.path.join(self.srcdir, "kvm-unit-tests") |
- kvm_utils.get_git_branch(test_repo, test_branch, test_srcdir, |
+ virt_utils.get_git_branch(test_repo, test_branch, test_srcdir, |
test_commit, test_lbranch) |
unittest_cfg = os.path.join(test_srcdir, 'x86', |
'unittests.cfg') |
@@ -386,15 +347,13 @@ class YumInstaller(BaseInstaller): |
unittest=self.unittest_prefix) |
self.reload_modules_if_needed() |
if self.save_results: |
- save_build(self.srcdir, self.results_dir) |
+ virt_installer.save_build(self.srcdir, self.results_dir) |
class KojiInstaller(YumInstaller): |
""" |
Class that handles installing KVM from the fedora build service, koji. |
- |
- It uses yum to install and remove packages. Packages are specified |
- according to the syntax defined in the PkgSpec class. |
+ It uses yum to install and remove packages. |
""" |
load_stock_modules = True |
def set_install_params(self, test, params): |
@@ -405,73 +364,34 @@ class KojiInstaller(YumInstaller): |
@param params: Dictionary with test arguments |
""" |
super(KojiInstaller, self).set_install_params(test, params) |
+ default_koji_cmd = '/usr/bin/koji' |
+ default_src_pkg = 'qemu' |
+ self.src_pkg = params.get("src_pkg", default_src_pkg) |
self.tag = params.get("koji_tag", None) |
- self.koji_cmd = params.get("koji_cmd", None) |
- if self.tag is not None: |
- kvm_utils.set_default_koji_tag(self.tag) |
- self.koji_pkgs = eval(params.get("koji_pkgs", "[]")) |
+ self.build = params.get("koji_build", None) |
+ self.koji_cmd = params.get("koji_cmd", default_koji_cmd) |
def _get_packages(self): |
""" |
Downloads the specific arch RPMs for the specific build name. |
""" |
- koji_client = kvm_utils.KojiClient(cmd=self.koji_cmd) |
- for pkg_text in self.koji_pkgs: |
- pkg = kvm_utils.KojiPkgSpec(pkg_text) |
- if pkg.is_valid(): |
- koji_client.get_pkgs(pkg, dst_dir=self.srcdir) |
- else: |
- logging.error('Package specification (%s) is invalid: %s', pkg, |
- pkg.describe_invalid()) |
- |
- |
- def _clean_previous_installs(self): |
- kill_qemu_processes() |
- removable_packages = " ".join(self._get_rpm_names()) |
- utils.system("yum -y remove %s" % removable_packages) |
+ downloader = virt_utils.KojiDownloader(cmd=self.koji_cmd) |
+ downloader.get(src_package=self.src_pkg, tag=self.tag, |
+ build=self.build, dst_dir=self.srcdir) |
def install(self): |
- self._clean_previous_installs() |
+ super(KojiInstaller, self)._clean_previous_installs() |
self._get_packages() |
- self._install_packages() |
+ super(KojiInstaller, self)._install_packages() |
self.install_unittests() |
create_symlinks(test_bindir=self.test_bindir, |
bin_list=self.qemu_bin_paths, |
unittest=self.unittest_prefix) |
self.reload_modules_if_needed() |
if self.save_results: |
- save_build(self.srcdir, self.results_dir) |
- |
- |
- def _get_rpm_names(self): |
- all_rpm_names = [] |
- koji_client = kvm_utils.KojiClient(cmd=self.koji_cmd) |
- for pkg_text in self.koji_pkgs: |
- pkg = kvm_utils.KojiPkgSpec(pkg_text) |
- rpm_names = koji_client.get_pkg_rpm_names(pkg) |
- all_rpm_names += rpm_names |
- return all_rpm_names |
- |
- |
- def _get_rpm_file_names(self): |
- all_rpm_file_names = [] |
- koji_client = kvm_utils.KojiClient(cmd=self.koji_cmd) |
- for pkg_text in self.koji_pkgs: |
- pkg = kvm_utils.KojiPkgSpec(pkg_text) |
- rpm_file_names = koji_client.get_pkg_rpm_file_names(pkg) |
- all_rpm_file_names += rpm_file_names |
- return all_rpm_file_names |
- |
- |
- def _install_packages(self): |
- """ |
- Install all downloaded packages. |
- """ |
- os.chdir(self.srcdir) |
- rpm_file_names = " ".join(self._get_rpm_file_names()) |
- utils.system("yum --nogpgcheck -y localinstall %s" % rpm_file_names) |
+ virt_installer.save_build(self.srcdir, self.results_dir) |
class SourceDirInstaller(BaseInstaller): |
@@ -509,7 +429,7 @@ class SourceDirInstaller(BaseInstaller): |
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_tag = virt_utils.get_latest_kvm_release_tag( |
release_listing) |
tarball = os.path.join(release_dir, 'kvm', release_tag, |
"kvm-%s.tar.gz" % release_tag) |
@@ -545,9 +465,9 @@ class SourceDirInstaller(BaseInstaller): |
utils.extract_tarball_to_dir(tarball, self.srcdir) |
if self.install_mode in ['release', 'snapshot', 'localtar', 'srcdir']: |
- self.repo_type = kvm_utils.check_kvm_source_dir(self.srcdir) |
- configure_script = os.path.join(self.srcdir, 'configure') |
- self.configure_options = check_configure_options(configure_script) |
+ self.repo_type = virt_utils.check_kvm_source_dir(self.srcdir) |
+ p = os.path.join(self.srcdir, 'configure') |
+ self.configure_options = virt_installer.check_configure_options(p) |
def _build(self): |
@@ -635,7 +555,7 @@ class SourceDirInstaller(BaseInstaller): |
self._install() |
self.reload_modules_if_needed() |
if self.save_results: |
- save_build(self.srcdir, self.results_dir) |
+ virt_installer.save_build(self.srcdir, self.results_dir) |
class GitInstaller(SourceDirInstaller): |
@@ -671,7 +591,7 @@ class GitInstaller(SourceDirInstaller): |
raise error.TestError(message) |
userspace_srcdir = os.path.join(self.srcdir, "kvm_userspace") |
- kvm_utils.get_git_branch(user_repo, user_branch, userspace_srcdir, |
+ virt_utils.get_git_branch(user_repo, user_branch, userspace_srcdir, |
user_commit, user_lbranch) |
self.userspace_srcdir = userspace_srcdir |
@@ -684,7 +604,7 @@ class GitInstaller(SourceDirInstaller): |
if kernel_repo: |
kernel_srcdir = os.path.join(self.srcdir, "kvm") |
- kvm_utils.get_git_branch(kernel_repo, kernel_branch, kernel_srcdir, |
+ virt_utils.get_git_branch(kernel_repo, kernel_branch, kernel_srcdir, |
kernel_commit, kernel_lbranch) |
self.kernel_srcdir = kernel_srcdir |
if kernel_patches: |
@@ -698,7 +618,7 @@ class GitInstaller(SourceDirInstaller): |
if kmod_repo: |
kmod_srcdir = os.path.join (self.srcdir, "kvm_kmod") |
- kvm_utils.get_git_branch(kmod_repo, kmod_branch, kmod_srcdir, |
+ virt_utils.get_git_branch(kmod_repo, kmod_branch, kmod_srcdir, |
kmod_commit, kmod_lbranch) |
self.kmod_srcdir = kmod_srcdir |
if kmod_patches: |
@@ -710,8 +630,8 @@ class GitInstaller(SourceDirInstaller): |
else: |
self.kmod_srcdir = None |
- configure_script = os.path.join(self.userspace_srcdir, 'configure') |
- self.configure_options = check_configure_options(configure_script) |
+ p = os.path.join(self.userspace_srcdir, 'configure') |
+ self.configure_options = virt_installer.check_configure_options(p) |
def _build(self): |
@@ -784,7 +704,7 @@ class GitInstaller(SourceDirInstaller): |
self._install() |
self.reload_modules_if_needed() |
if self.save_results: |
- save_build(self.srcdir, self.results_dir) |
+ virt_installer.save_build(self.srcdir, self.results_dir) |
class PreInstalledKvm(BaseInstaller): |