On Mon, 2010-10-04 at 15:16 +0200, Kamil Páral wrote:
Not only run_once() and initialize(), but setup() is now also
guarded
with ExceptionCatcher (and therefore we will receive email if some test
crashed in setup() phase).
Seems like a really useful thing to capture exceptions from those other
methods. I don't think I have anything useful to offer for this patch,
it looks good.
An aside, is there anything specific each of the ExceptionCatcher()
methods do (e.g. initialize_failed, run_once_failed etc...)? I do see
the string used to identify the method that failed, but wonder if that
information could be captured using the exc object itself.
The only reason I ask, is that it seems like each of the *_failed()
methods is similar and the @ExceptionCatcher() stuff seems like more
advanced python that most new python users wouldn't be inherently
familiar with. If were are able to make it even more generic, when it
comes to calling it, I wonder if that would reduce the number of
duplicate *_failed() methods, and make it less cryptic for new test
developers?
Looking at lib/python/decorators.py, I don't know if we only need to
supply a default value:
def __call__(self,f=some_default_func)
This still allows to provide a different decorator function, but
provides an acceptable default. Now if we can figure out the name of
the method that originally failed from the traceback object? Is this
crazy?
Thanks,
James
---
doc/test_class.py.template | 3 ++-
lib/python/test.py | 15 +++++++++++++++
tests/helloworld/helloworld.py | 3 ---
tests/initscripts/initscripts.py | 3 ++-
tests/rats_install/rats_install.py | 3 ++-
tests/rats_sanity/rats_sanity.py | 3 ++-
tests/repoclosure/repoclosure.py | 3 ++-
tests/rpmguard/rpmguard.py | 3 ++-
tests/rpmlint/rpmlint.py | 3 ++-
tests/upgradepath/upgradepath.py | 6 ++----
10 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/doc/test_class.py.template b/doc/test_class.py.template
index b064e2e..00aef9d 100644
--- a/doc/test_class.py.template
+++ b/doc/test_class.py.template
@@ -43,7 +43,8 @@ class testclassname(AutoQATest): # <-- UPDATE Classname
# This is where you make sure that any required packages are installed,
# services are started, your test code is compiled, and so on. This is
# an optional method.
- #def setup(self, some_params):
+ #(a)ExceptionCatcher("self.setup_failed")
+ #def setup(self, some_params, **kwargs):
# utils.system('yum -y install yum-utils')
# This does any pre-test initialization that needs to happen. AutoQA tests
diff --git a/lib/python/test.py b/lib/python/test.py
index ea788f4..a658f53 100644
--- a/lib/python/test.py
+++ b/lib/python/test.py
@@ -35,6 +35,10 @@ class AutoQATest(test.test, object):
self.outputs = "" #second part of mail_body
self.mail_to = [] #list of emails to send results to. Mail is always sent to
results list
+ @ExceptionCatcher("self.setup_failed")
+ def setup(self, **kwargs):
+ pass
+
@ExceptionCatcher("self.initialize_failed")
def initialize(self, config, **kwargs):
self.config = config_loader(config, self.tmpdir)
@@ -44,6 +48,17 @@ class AutoQATest(test.test, object):
def run_once(self, **kwargs):
pass
+ def setup_failed(self, exc = None):
+ self.result = "CRASHED"
+ if exc is not None:
+ self.summary = "Setup failed: %s: %s" % (exc.__class__.__name__,
exc)
+ else:
+ self.summary = "Setup failed: Exception: Unknown exception"
+ try:
+ self.postprocess_iteration()
+ except Exception, e:
+ traceback.print_exc(file=sys.stderr)
+
def initialize_failed(self, exc = None):
self.result = "CRASHED"
if exc is not None:
diff --git a/tests/helloworld/helloworld.py b/tests/helloworld/helloworld.py
index 7644019..9f6ac50 100644
--- a/tests/helloworld/helloworld.py
+++ b/tests/helloworld/helloworld.py
@@ -25,9 +25,6 @@ from autoqa.decorators import ExceptionCatcher
class helloworld(AutoQATest):
version = 1 # increment if setup() changes
- def setup(self):
- pass
-
@ExceptionCatcher("self.run_once_failed")
def run_once(self, *args, **kwargs):
self.summary = 'Hello, World!'
diff --git a/tests/initscripts/initscripts.py b/tests/initscripts/initscripts.py
index 2d10cbf..133d058 100644
--- a/tests/initscripts/initscripts.py
+++ b/tests/initscripts/initscripts.py
@@ -33,7 +33,8 @@ from autoqa.decorators import ExceptionCatcher
class initscripts(AutoQATest):
version = 1 # increment if setup() changes
- def setup(self):
+ @ExceptionCatcher("self.setup_failed")
+ def setup(self, **kwargs):
"""
adds beakerlib repository and installs beakerlib
"""
diff --git a/tests/rats_install/rats_install.py b/tests/rats_install/rats_install.py
index 4896149..360be3f 100644
--- a/tests/rats_install/rats_install.py
+++ b/tests/rats_install/rats_install.py
@@ -35,7 +35,8 @@ class rats_install(AutoQATest):
super(rats_install, self).initialize(config)
self.irb_conf = os.path.join(self.bindir, 'irb.cfg')
- def setup(self):
+ @ExceptionCatcher("self.setup_failed")
+ def setup(self, **kwargs):
if os.path.exists(self.irb_conf):
utils.system('yum -y install python-fedora')
# XXX maybe just install @virtualization + pax?
diff --git a/tests/rats_sanity/rats_sanity.py b/tests/rats_sanity/rats_sanity.py
index a5248a5..5a2a4f1 100644
--- a/tests/rats_sanity/rats_sanity.py
+++ b/tests/rats_sanity/rats_sanity.py
@@ -33,7 +33,8 @@ class rats_sanity(AutoQATest):
super(rats_sanity, self).initialize(config)
self.irb_conf = os.path.join(self.bindir, 'irb.cfg')
- def setup(self):
+ @ExceptionCatcher("self.setup_failed")
+ def setup(self, **kwargs):
if os.path.exists(self.irb_conf):
utils.system('yum -y install python-fedora')
diff --git a/tests/repoclosure/repoclosure.py b/tests/repoclosure/repoclosure.py
index 26f5ac5..5c8752e 100644
--- a/tests/repoclosure/repoclosure.py
+++ b/tests/repoclosure/repoclosure.py
@@ -25,7 +25,8 @@ from autoqa.decorators import ExceptionCatcher
class repoclosure(AutoQATest):
version = 1
- def setup(self):
+ @ExceptionCatcher("self.setup_failed")
+ def setup(self, **kwargs):
utils.system('yum -y install yum-utils')
@ExceptionCatcher("self.run_once_failed")
diff --git a/tests/rpmguard/rpmguard.py b/tests/rpmguard/rpmguard.py
index efd9626..4e4ee04 100644
--- a/tests/rpmguard/rpmguard.py
+++ b/tests/rpmguard/rpmguard.py
@@ -30,7 +30,8 @@ from autoqa.decorators import ExceptionCatcher
class rpmguard(AutoQATest):
version = 1 # increment if setup() changes
- def setup(self):
+ @ExceptionCatcher("self.setup_failed")
+ def setup(self, **kwargs):
utils.system('yum -y install rpmlint')
@ExceptionCatcher("self.initialize_failed")
diff --git a/tests/rpmlint/rpmlint.py b/tests/rpmlint/rpmlint.py
index bd67766..ce92a1d 100644
--- a/tests/rpmlint/rpmlint.py
+++ b/tests/rpmlint/rpmlint.py
@@ -30,7 +30,8 @@ from autoqa.decorators import ExceptionCatcher
class rpmlint(AutoQATest):
version = 1 # increment if setup() changes
- def setup(self):
+ @ExceptionCatcher("self.setup_failed")
+ def setup(self, **kwargs):
utils.system('yum -y install rpmlint')
@ExceptionCatcher("self.initialize_failed")
diff --git a/tests/upgradepath/upgradepath.py b/tests/upgradepath/upgradepath.py
index 46c6632..4f298b1 100755
--- a/tests/upgradepath/upgradepath.py
+++ b/tests/upgradepath/upgradepath.py
@@ -37,7 +37,8 @@ from autotest_lib.client.bin.test_config import config_loader
class upgradepath(AutoQATest):
version = 1 # increment if setup() changes
- def initialize(self, config):
+ @ExceptionCatcher("self.initialize_failed")
+ def initialize(self, config, **kwargs):
self.config = config_loader(config, self.tmpdir)
#URL of logs/results stored on autotest-server
self.autotest_url = autoqa.util.make_autotest_url(self.config)
@@ -49,9 +50,6 @@ class upgradepath(AutoQATest):
self.outputs = []
self.highlights = []
- def setup(self):
- pass
-
def compare(self, matching_build, tags, op, opstr):
koji = autoqa.koji_utils.SimpleKojiClientSession()
result = 'PASSED'