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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This fixes a problem with importing the autotest subtest.
It may be safer than importing tests.<testname> because, according to the
Python documentation, imp.find_module() searches only the given path,
regardless of what's in sys.path.

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/kvm.py |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

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)
-- 
1.5.4.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux