Skip to contentSkip to conversation

KVM test: Change the way subtests are loaded

PATCH In review Lucas Meneghel Rodrigues 3 participants 3 messages Oct 30, 2009 – Nov 25, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM test: Change the way subtests are loaded

Recently autoserv changed its default behavior of rsyncing the whole client directory to the test machine, now it will copy only the needed tests to the client machine.

Also, the way the tests are loaded when running from the server has changed, breaking the KVM test when ran from autoserv.

So change the mechanism to load KVM subtests, in order to cope with the recent autoserv changes.

Thanks to Ryan Harper for having noticed this issue.

---
 client/tests/kvm/kvm.py |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
client/tests/kvm/kvm.py +5 -4
index 204164d..06ef9f5 100644
@@ -22,9 +22,9 @@ class kvm(test.test):
     """
     version = 1
     def initialize(self):
-        # Make it possible to import modules from the test's bindir
-        sys.path.append(self.bindir)
+        # Make it possible to import modules from the subtest dir
         self.subtest_dir = os.path.join(self.bindir, 'tests')
+        sys.path.append(self.subtest_dir)
 
 
     def run_once(self, params):
@@ -51,7 +51,7 @@ class kvm(test.test):
                     raise error.TestError("No %s.py test file found" % type)
                 # Load the tests directory (which was turned into a py module)
                 try:
-                    test_module = __import__("tests.%s" % type)
+                    test_module = __import__(type)
                 except ImportError, e:
                     raise error.TestError("Failed to import test %s: %s" %
                                           (type, e))
@@ -60,7 +60,8 @@ class kvm(test.test):
                 kvm_preprocessing.preprocess(self, params, env)
                 kvm_utils.dump_env(env, env_filename)
                 # Run the test function
-                eval("test_module.%s.run_%s(self, params, env)" % (type, type))
+                run_func = getattr(test_module, "run_%s" % type)
+                run_func(self, params, env)
                 kvm_utils.dump_env(env, env_filename)
 
             except Exception, e:
Signature · 1 line
1.6.2.5
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Lucas Meneghel Rodrigues

Recently autoserv changed its default behavior of rsyncing the whole client directory to the test machine, now it will copy only the needed tests to the client machine.

Also, the way the tests are loaded when running from the server has changed, breaking the KVM test when ran from autoserv.

Quoted 6 lines

So change the mechanism to load KVM subtests, in order to cope with the recent autoserv changes.

Thanks to Ryan Harper for having noticed this issue.

This fixed the issue for me.

Thanks Lucas!

Signature · 4 lines
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
[email protected]
#2 lore raw
In reply to Lucas Meneghel Rodrigues
Quoted 37 lines · Lucas Meneghel Rodrigues

Recently autoserv changed its default behavior of rsyncing the whole client directory to the test machine, now it will copy only the needed tests to the client machine.

Also, the way the tests are loaded when running from the server has changed, breaking the KVM test when ran from autoserv.

So change the mechanism to load KVM subtests, in order to cope with the recent autoserv changes.

Thanks to Ryan Harper for having noticed this issue.

---
 client/tests/kvm/kvm.py |    9 +++++----

 1 files changed, 5 insertions(+), 4 deletions(-)
client/tests/kvm/kvm.py +0 -0
index 204164d..06ef9f5 100644
@@ -22,9 +22,9 @@ class kvm(test.test):

    """
    version = 1
    def initialize(self):
-        # Make it possible to import modules from the test's bindir
-        sys.path.append(self.bindir)
+        # Make it possible to import modules from the subtest dir self.subtest_dir = os.path.join(self.bindir, 'tests')
+        sys.path.append(self.subtest_dir)

    def run_once(self, params):

client/tests/kvm/kvm.py +0 -0
@@ -51,7 +51,7 @@ class kvm(test.test):
                     raise error.TestError("No %s.py test file found" % type)
                 # Load the tests directory (which was turned into a py module)
Quoted 3 lines

                try:
-                    test_module = __import__("tests.%s" % type)
+                    test_module = __import__(type)

This seems to have broken the execution of autotest under kvm guests. I see the following error
'module' object has no attribute 'run_autotest'
Traceback (most recent call last):
File
"/scratch/images/sudhir/devel/autotest/client/common_lib/test.py", line 570, in _call_test_function
return func(*args, **dargs)
File
"/scratch/images/sudhir/devel/autotest/client/common_lib/test.py", line 279, in execute
postprocess_profiled_run, args, dargs)
File
"/scratch/images/sudhir/devel/autotest/client/common_lib/test.py", line 201, in _call_run_once

                      self.run_once(*args, **dargs)
                    File

"/scratch/images/sudhir/devel/autotest/client/tests/kvm/kvm.py", line 63, in run_once
run_func = getattr(test_module, "run_%s" % type)
AttributeError: 'module' object has no attribute
'run_autotest'

A little more debugging prints out that the module 'autotest' has been imported from a wrong place.
<module 'autotest' from
'/scratch/images/sudhir/devel/autotest/client/tests/kvm/autotest/__init__.pyc'> So may be either we need to force to import from specific path or change the name autotest.

I had the test variant as below
only autotest.hackbench
I am unable to run any of the tests under autotest.

Quoted 21 lines

                except ImportError, e:
                    raise error.TestError("Failed to import test %s: %s" % (type, e))

client/tests/kvm/kvm.py +2 -1
@@ -60,7 +60,8 @@ class kvm(test.test):
                 kvm_preprocessing.preprocess(self, params, env)
                 kvm_utils.dump_env(env, env_filename)
                 # Run the test function
-                eval("test_module.%s.run_%s(self, params, env)" % (type, type))
+                run_func = getattr(test_module, "run_%s" % type)
+                run_func(self, params, env)
                 kvm_utils.dump_env(env, env_filename)
 

            except Exception, e:
--
1.6.2.5

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

Signature · 1 line
Sudhir Kumar