Skip to contentSkip to conversation

KVM test: step file tests: apply timeout_multiplier to 'sleep' as well as barriers

PATCH New Michael Goldish 1 participant 2 messages Dec 2, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM test: step file tests: apply timeout_multiplier to 'sleep' as well as barriers

---
 client/tests/kvm/tests/steps.py |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
client/tests/kvm/tests/steps.py +2 -1
index 11b2ae1..456fb44 100644
@@ -225,7 +225,8 @@ def run_steps(test, params, env):
         elif skip_current_step:
             continue
         elif words[0] == "sleep":
-            time.sleep(float(words[1]))
+            timeout_multiplier = float(params.get("timeout_multiplier") or 1)
+            time.sleep(float(words[1]) * timeout_multiplier)
         elif words[0] == "key":
             vm.send_key(words[1])
         elif words[0] == "var":
Signature · 1 line
1.5.4.1
#1 lore raw

PATCH 1/1 KVM test: use the imp module to import subtest module by filename

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.

---
 client/tests/kvm/kvm.py |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
client/tests/kvm/kvm.py +9 -6
index 380fbee..4caa03b 100644
@@ -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)
Signature · 1 line
1.5.4.1