diff mbox

[KVM-AUTOTEST] KVM test: use the imp module to import subtest module by filename

Message ID 1259748361-21909-2-git-send-email-mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish Dec. 2, 2009, 10:06 a.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py
index 380fbee..4caa03b 100644
--- a/client/tests/kvm/kvm.py
+++ b/client/tests/kvm/kvm.py
@@ -1,4 +1,4 @@ 
-import sys, os, time, logging
+import sys, os, time, logging, imp
 from autotest_lib.client.bin import test
 from autotest_lib.client.common_lib import error
 import kvm_utils, kvm_preprocessing
@@ -21,8 +21,9 @@  class kvm(test.test):
             (Online doc - Getting started with KVM testing)
     """
     version = 1
+
     def initialize(self):
-        self.subtest_dir = os.path.join(self.bindir, 'tests')
+        pass
 
 
     def run_once(self, params):
@@ -44,13 +45,15 @@  class kvm(test.test):
                 # Get the test routine corresponding to the specified test type
                 t_type = params.get("type")
                 # Verify if we have the correspondent source file for it
-                module_path = os.path.join(self.subtest_dir, '%s.py' % t_type)
+                subtest_dir = os.path.join(self.bindir, "tests")
+                module_path = os.path.join(subtest_dir, "%s.py" % t_type)
                 if not os.path.isfile(module_path):
                     raise error.TestError("No %s.py test file found" % t_type)
                 # Load the test module
-                # (KVM test dir was appended to sys.path in the control file)
-                __import__("tests.%s" % t_type)
-                test_module = sys.modules["tests.%s" % t_type]
+                f, p, d = imp.find_module(t_type, [subtest_dir])
+                test_module = imp.load_module(t_type, f, p, d)
+                f.close()
+
                 # Preprocess
                 kvm_preprocessing.preprocess(self, params, env)
                 kvm_utils.dump_env(env, env_filename)