* Re: [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/
[not found] <346382647.1061041244007938766.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
@ 2009-06-03 5:47 ` Michael Goldish
0 siblings, 0 replies; 4+ messages in thread
From: Michael Goldish @ 2009-06-03 5:47 UTC (permalink / raw)
To: David Huff; +Cc: kvm
Regardless of whether the idea should be implemented, I think the code
can be simplified a bit, to look something like this:
type = params.get("type")
routine_obj = self.test_routines.get(type)
if routine_obj:
module_name = routine_obj.module_name
routine_name = routine_obj.routine_name
else:
module_name = type
routine_name = "run_" + type
try:
module = __import__(module_name)
routine = eval("module." + routine_name)
except:
raise error.TestError("Could not find test routine for type '%s'" % type)
# Preprocess
...
Obviously this means that routine will be used instead of routine_obj.routine
throughout the rest of run_once.
We don't need inspect because if there's anything wrong with <module_name>.<routine_name>,
the test will fail anyway and print the exception info like it does for normal failures.
Also, there's no need to store test_dir as an attribute. Just do:
sys.path.append(os.path.join(self.bindir, "kvm_tests"))
Let me know what you think.
----- Original Message -----
From: "David Huff" <dhuff@redhat.com>
To: kvm@vger.kernel.org
Cc: "David Huff" <dhuff@redhat.com>
Sent: Tuesday, May 26, 2009 7:27:00 PM (GMT+0200) Auto-Detected
Subject: [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/
This will allow for adding of additional tests with out modifying the "code."
One would just add the testname.py file to the test_dir and edit the comfig file.
fixed typo
---
client/tests/kvm_runtest_2/kvm_runtest_2.py | 32 +++++++++++++++++++-------
1 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/client/tests/kvm_runtest_2/kvm_runtest_2.py b/client/tests/kvm_runtest_2/kvm_runtest_2.py
index fda7282..6420191 100644
--- a/client/tests/kvm_runtest_2/kvm_runtest_2.py
+++ b/client/tests/kvm_runtest_2/kvm_runtest_2.py
@@ -2,6 +2,7 @@
import sys
import os
+import inspect
import time
import shelve
import random
@@ -21,26 +22,26 @@ class test_routine:
class kvm_runtest_2(test.test):
version = 1
+
def setup(self):
pass
def initialize(self):
- # Define the test routines corresponding to different values of the 'type' field
+ # directory where to look for tests
+ self.test_dir = os.path.join(self.bindir, "kvm_tests")
+
+ # pre-defined the test routines corresponding to different values of the 'type' field
self.test_routines = {
- # type module name routine
+ # type module name routine name
"steps": test_routine("kvm_guest_wizard", "run_steps"),
"stepmaker": test_routine("stepmaker", "run_stepmaker"),
- "boot": test_routine("kvm_tests", "run_boot"),
- "migration": test_routine("kvm_tests", "run_migration"),
- "yum_update": test_routine("kvm_tests", "run_yum_update"),
- "autotest": test_routine("kvm_tests", "run_autotest"),
"kvm_install": test_routine("kvm_install", "run_kvm_install"),
- "linux_s3": test_routine("kvm_tests", "run_linux_s3"),
}
-
+
# Make it possible to import modules from the test's bindir
sys.path.append(self.bindir)
-
+ sys.path.append(self.test_dir)
+
def run_once(self, params):
import kvm_log
import kvm_utils
@@ -74,6 +75,12 @@ class kvm_runtest_2(test.test):
type = params.get("type")
routine_obj = self.test_routines.get(type)
# If type could not be found in self.test_routines...
+ # look for test in kvm_tests directory, where type = 'testname'
+ # defined in file 'testname'.py and test routine method run_'testname'
+ if os.path.isfile(os.path.join(self.test_dir,type+".py")):
+ module_name = type
+ routine_name = "run_"+module_name
+ routine_obj = test_routine(module_name,routine_name)
if not routine_obj:
message = "Unsupported test type: %s" % type
kvm_log.error(message)
@@ -83,6 +90,13 @@ class kvm_runtest_2(test.test):
# Dynamically import the module
module = __import__(routine_obj.module_name)
# Get the needed routine
+ try:
+ inspect.isfunction(eval("module."+routine_obj.routine_name))
+ except Exception, e:
+ kvm_log.error("Test failed: %s" % e)
+ kvm_log.error("could not load:%s" % eval("module."+routine_obj.routine_name))
+ raise
+
routine_obj.routine = eval("module." + routine_obj.routine_name)
# Preprocess
--
1.6.0.6
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/
2009-04-28 21:48 ` [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/ David Huff
@ 2009-05-27 11:58 ` Uri Lublin
0 siblings, 0 replies; 4+ messages in thread
From: Uri Lublin @ 2009-05-27 11:58 UTC (permalink / raw)
To: David Huff; +Cc: kvm
David Huff wrote:
> This will allow for adding of additional tests with out modifying the "code."
>
> One would just add the testname.py file to the test_dir and edit the comfig file.
> ---
> client/tests/kvm_runtest_2/kvm_runtest_2.py | 32 +++++++++++++++++++-------
> 1 files changed, 23 insertions(+), 9 deletions(-)
>
> diff --git a/client/tests/kvm_runtest_2/kvm_runtest_2.py b/client/tests/kvm_runtest_2/kvm_runtest_2.py
> index fda7282..b6477f5 100644
> --- a/client/tests/kvm_runtest_2/kvm_runtest_2.py
> +++ b/client/tests/kvm_runtest_2/kvm_runtest_2.py
> @@ -2,6 +2,7 @@
>
> import sys
> import os
> +import inspect
> import time
> import shelve
> import random
> @@ -21,26 +22,26 @@ class test_routine:
> class kvm_runtest_2(test.test):
> version = 1
>
> +
> def setup(self):
> pass
>
> def initialize(self):
> - # Define the test routines corresponding to different values of the 'type' field
> + # directory where to look for tests
> + self.test_dir = os.path.join(self.bindir, "kvm_tests")
> +
> + # pre-defined the test routines corresponding to different values of the 'type' field
> self.test_routines = {
> - # type module name routine
> + # type module name routine name
> "steps": test_routine("kvm_guest_wizard", "run_steps"),
> "stepmaker": test_routine("stepmaker", "run_stepmaker"),
> - "boot": test_routine("kvm_tests", "run_boot"),
> - "migration": test_routine("kvm_tests", "run_migration"),
> - "yum_update": test_routine("kvm_tests", "run_yum_update"),
> - "autotest": test_routine("kvm_tests", "run_autotest"),
> "kvm_install": test_routine("kvm_install", "run_kvm_install"),
> - "linux_s3": test_routine("kvm_tests", "run_linux_s3"),
> }
> -
> +
> # Make it possible to import modules from the test's bindir
> sys.path.append(self.bindir)
> -
> + sys.path.append(self.test_dir)
> +
> def run_once(self, params):
> import kvm_log
> import kvm_utils
> @@ -74,6 +75,12 @@ class kvm_runtest_2(test.test):
> type = params.get("type")
> routine_obj = self.test_routines.get(type)
If routine_obj exists, use it, instead of dynamically load according to type.
> # If type could not be found in self.test_routines...
> + # look for test in kvm_tests directory, where type = 'testname'
> + # defined in file 'testname'.py and test routine method run_'testname'
> + if os.path.isfile(os.path.join(self.test_dir,type+".py")):
> + module_name = type
> + routine_name = "run_"+module_name
> + routine_obj = test_routine(moudule_name,routine_name)
1. Nit: Please leave a space after comma.
2. Typo moudule_name.
> if not routine_obj:
> message = "Unsupported test type: %s" % type
> kvm_log.error(message)
> @@ -83,6 +90,13 @@ class kvm_runtest_2(test.test):
> # Dynamically import the module
> module = __import__(routine_obj.module_name)
> # Get the needed routine
> + try:
> + inspect.isfunction(eval("module."+routine_obj.routine_name))
1. Nit: f = eval("module."+routine_obj.routine_name)
inspect.isfunction(f)
...
routing_obj.routing = f
2. If you call inspect.isfunction(), check its return-value. It can return
false. ( If you do not call inspect it would fail later when routine_obj.routine
is called ).
Regards,
Uri.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/
2009-05-26 16:26 [KVM_AUTOTEST] patch set to dynamically load tests David Huff
@ 2009-05-26 16:27 ` David Huff
0 siblings, 0 replies; 4+ messages in thread
From: David Huff @ 2009-05-26 16:27 UTC (permalink / raw)
To: kvm; +Cc: David Huff
This will allow for adding of additional tests with out modifying the "code."
One would just add the testname.py file to the test_dir and edit the comfig file.
fixed typo
---
client/tests/kvm_runtest_2/kvm_runtest_2.py | 32 +++++++++++++++++++-------
1 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/client/tests/kvm_runtest_2/kvm_runtest_2.py b/client/tests/kvm_runtest_2/kvm_runtest_2.py
index fda7282..6420191 100644
--- a/client/tests/kvm_runtest_2/kvm_runtest_2.py
+++ b/client/tests/kvm_runtest_2/kvm_runtest_2.py
@@ -2,6 +2,7 @@
import sys
import os
+import inspect
import time
import shelve
import random
@@ -21,26 +22,26 @@ class test_routine:
class kvm_runtest_2(test.test):
version = 1
+
def setup(self):
pass
def initialize(self):
- # Define the test routines corresponding to different values of the 'type' field
+ # directory where to look for tests
+ self.test_dir = os.path.join(self.bindir, "kvm_tests")
+
+ # pre-defined the test routines corresponding to different values of the 'type' field
self.test_routines = {
- # type module name routine
+ # type module name routine name
"steps": test_routine("kvm_guest_wizard", "run_steps"),
"stepmaker": test_routine("stepmaker", "run_stepmaker"),
- "boot": test_routine("kvm_tests", "run_boot"),
- "migration": test_routine("kvm_tests", "run_migration"),
- "yum_update": test_routine("kvm_tests", "run_yum_update"),
- "autotest": test_routine("kvm_tests", "run_autotest"),
"kvm_install": test_routine("kvm_install", "run_kvm_install"),
- "linux_s3": test_routine("kvm_tests", "run_linux_s3"),
}
-
+
# Make it possible to import modules from the test's bindir
sys.path.append(self.bindir)
-
+ sys.path.append(self.test_dir)
+
def run_once(self, params):
import kvm_log
import kvm_utils
@@ -74,6 +75,12 @@ class kvm_runtest_2(test.test):
type = params.get("type")
routine_obj = self.test_routines.get(type)
# If type could not be found in self.test_routines...
+ # look for test in kvm_tests directory, where type = 'testname'
+ # defined in file 'testname'.py and test routine method run_'testname'
+ if os.path.isfile(os.path.join(self.test_dir,type+".py")):
+ module_name = type
+ routine_name = "run_"+module_name
+ routine_obj = test_routine(module_name,routine_name)
if not routine_obj:
message = "Unsupported test type: %s" % type
kvm_log.error(message)
@@ -83,6 +90,13 @@ class kvm_runtest_2(test.test):
# Dynamically import the module
module = __import__(routine_obj.module_name)
# Get the needed routine
+ try:
+ inspect.isfunction(eval("module."+routine_obj.routine_name))
+ except Exception, e:
+ kvm_log.error("Test failed: %s" % e)
+ kvm_log.error("could not load:%s" % eval("module."+routine_obj.routine_name))
+ raise
+
routine_obj.routine = eval("module." + routine_obj.routine_name)
# Preprocess
--
1.6.0.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/
2009-04-28 21:48 kvm_autotest: dynamically load tests David Huff
@ 2009-04-28 21:48 ` David Huff
2009-05-27 11:58 ` Uri Lublin
0 siblings, 1 reply; 4+ messages in thread
From: David Huff @ 2009-04-28 21:48 UTC (permalink / raw)
To: kvm; +Cc: David Huff
This will allow for adding of additional tests with out modifying the "code."
One would just add the testname.py file to the test_dir and edit the comfig file.
---
client/tests/kvm_runtest_2/kvm_runtest_2.py | 32 +++++++++++++++++++-------
1 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/client/tests/kvm_runtest_2/kvm_runtest_2.py b/client/tests/kvm_runtest_2/kvm_runtest_2.py
index fda7282..b6477f5 100644
--- a/client/tests/kvm_runtest_2/kvm_runtest_2.py
+++ b/client/tests/kvm_runtest_2/kvm_runtest_2.py
@@ -2,6 +2,7 @@
import sys
import os
+import inspect
import time
import shelve
import random
@@ -21,26 +22,26 @@ class test_routine:
class kvm_runtest_2(test.test):
version = 1
+
def setup(self):
pass
def initialize(self):
- # Define the test routines corresponding to different values of the 'type' field
+ # directory where to look for tests
+ self.test_dir = os.path.join(self.bindir, "kvm_tests")
+
+ # pre-defined the test routines corresponding to different values of the 'type' field
self.test_routines = {
- # type module name routine
+ # type module name routine name
"steps": test_routine("kvm_guest_wizard", "run_steps"),
"stepmaker": test_routine("stepmaker", "run_stepmaker"),
- "boot": test_routine("kvm_tests", "run_boot"),
- "migration": test_routine("kvm_tests", "run_migration"),
- "yum_update": test_routine("kvm_tests", "run_yum_update"),
- "autotest": test_routine("kvm_tests", "run_autotest"),
"kvm_install": test_routine("kvm_install", "run_kvm_install"),
- "linux_s3": test_routine("kvm_tests", "run_linux_s3"),
}
-
+
# Make it possible to import modules from the test's bindir
sys.path.append(self.bindir)
-
+ sys.path.append(self.test_dir)
+
def run_once(self, params):
import kvm_log
import kvm_utils
@@ -74,6 +75,12 @@ class kvm_runtest_2(test.test):
type = params.get("type")
routine_obj = self.test_routines.get(type)
# If type could not be found in self.test_routines...
+ # look for test in kvm_tests directory, where type = 'testname'
+ # defined in file 'testname'.py and test routine method run_'testname'
+ if os.path.isfile(os.path.join(self.test_dir,type+".py")):
+ module_name = type
+ routine_name = "run_"+module_name
+ routine_obj = test_routine(moudule_name,routine_name)
if not routine_obj:
message = "Unsupported test type: %s" % type
kvm_log.error(message)
@@ -83,6 +90,13 @@ class kvm_runtest_2(test.test):
# Dynamically import the module
module = __import__(routine_obj.module_name)
# Get the needed routine
+ try:
+ inspect.isfunction(eval("module."+routine_obj.routine_name))
+ except Exception, e:
+ kvm_log.error("Test failed: %s" % e)
+ kvm_log.error("could not load:%s" % eval("module."+routine_obj.routine_name))
+ raise
+
routine_obj.routine = eval("module." + routine_obj.routine_name)
# Preprocess
--
1.6.0.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-06-03 5:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <346382647.1061041244007938766.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
2009-06-03 5:47 ` [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/ Michael Goldish
2009-05-26 16:26 [KVM_AUTOTEST] patch set to dynamically load tests David Huff
2009-05-26 16:27 ` [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/ David Huff
-- strict thread matches above, loose matches on Subject: below --
2009-04-28 21:48 kvm_autotest: dynamically load tests David Huff
2009-04-28 21:48 ` [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/ David Huff
2009-05-27 11:58 ` Uri Lublin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.