No test code should ever hit this if the depdencies are set correctly on
the .cfg file. But in case the KVM build failed and dependencies are not
correctly set, we don't want any test that depends on the KVM install
information to incorrectly succeed as the modules aren't really
available.

Signed-off-by: Eduardo Habkost <[email protected]>
---
 client/tests/kvm/kvm/installer.py |   22 +++++++++++++++++++++-
 client/tests/kvm/tests/build.py   |   15 +++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/client/tests/kvm/kvm/installer.py 
b/client/tests/kvm/kvm/installer.py
index 7b6fafc..8e48ee0 100644
--- a/client/tests/kvm/kvm/installer.py
+++ b/client/tests/kvm/kvm/installer.py
@@ -4,7 +4,6 @@ from autotest_lib.client.bin import utils, test, 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
@@ -164,6 +163,15 @@ def save_build(build_dir, dest_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
+
+class FailedKvmInstall(KvmInstallException):
+    pass
+
+class KvmNotInstalled(KvmInstallException):
+    pass
+
 
 class BaseInstaller(object):
     def __init__(self, mode=None):
@@ -708,6 +716,18 @@ class PreInstalledKvm(BaseInstaller):
     # load_modules() will use the stock modules:
     load_stock_modules = True
 
+class FailedInstaller:
+    """Class used to be returned instead of the installer if a installation 
fails
+
+    Useful to make sure no installer object is used if KVM installation fails.
+    """
+    def __init__(self, msg="KVM install failed"):
+        self._msg = msg
+
+    def load_modules(self):
+        """Will refuse to load the KVM modules as install failed"""
+        raise FailedKvmInstall("KVM modules not available. reason: %s" % 
(self._msg))
+
 installer_classes = {
     'localsrc':SourceDirInstaller,
     'localtar':SourceDirInstaller,
diff --git a/client/tests/kvm/tests/build.py b/client/tests/kvm/tests/build.py
index 20ad5b6..8115982 100644
--- a/client/tests/kvm/tests/build.py
+++ b/client/tests/kvm/tests/build.py
@@ -12,7 +12,14 @@ def run_build(test, params, env):
     srcdir = params.get("srcdir", test.srcdir)
     params["srcdir"] = srcdir
 
-    installer = kvm.installer.make_installer(params)
-    installer.set_install_params(test, params)
-    installer.install()
-    env.register_installer(installer)
+    try:
+        installer = kvm.installer.make_installer(params)
+        installer.set_install_params(test, params)
+        installer.install()
+        env.register_installer(installer)
+    except Exception,e:
+        # if the build/install fails, don't allow other tests
+        # to get a installer.
+        msg = "KVM install failed: %s" % (e)
+        env.register_installer(kvm.installer.FailedInstaller(msg))
+        raise
-- 
1.7.3.2

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to