>From 044599e858d57a665b60eb98d936938fb2a26aa7 Mon Sep 17 00:00:00 2001
From: Josef Skladanka <jskladan@redhat.com>
Date: Fri, 9 Jul 2010 15:28:32 +0200
Subject: [PATCH 2/2] tests now use the BaseTest class

---
 lib/python/test.py                 |   45 +++++++++++++++++++--
 tests/conflicts/conflicts.py       |   46 +++++++++++++--------
 tests/initscripts/initscripts.py   |   77 ++++++++++++++++++------------------
 tests/rats_install/rats_install.py |   44 +++++++++++---------
 tests/rats_sanity/rats_sanity.py   |   44 +++++++++++---------
 tests/repoclosure/repoclosure.py   |   38 ++++++++++-------
 tests/rpmguard/rpmguard.py         |   66 ++++++++++++++++--------------
 tests/rpmlint/rpmlint.py           |   60 ++++++++++++++-------------
 8 files changed, 244 insertions(+), 176 deletions(-)

diff --git a/lib/python/test.py b/lib/python/test.py
index ce2640b..a8be13d 100644
--- a/lib/python/test.py
+++ b/lib/python/test.py
@@ -17,7 +17,7 @@
 #
 # Author: Josef Skladanka <jskladan@redhat.com>
 
-from autotest_lib.client.bin import test
+from autotest_lib.client.bin import test, utils
 from autotest_lib.client.bin.test_config import config_loader
 
 from decorators import ExceptionCatcher
@@ -30,25 +30,62 @@ class BaseTest(test.test, object):
     def initialize(self, config, **kwargs):
         self.config = config_loader(config, self.tmpdir)
         self.autotest_url = make_autotest_url(self.config)
+        self.result = None #overall test result ~ "PASSED", "FAILED"...
+        self.summary = "" #used as mail-subject
+        self.highlights = "" #used as first part of mail-body
+        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.run_once_failed")
     def run_once(self, **kwargs):
         pass
 
     def initialize_failed(self):
-        print "Initialize failed"
+        if self.result is None:
+            self.result = "CRASHED"
+        if self.summary == "":
+            self.summary = "%s: Initialize failed" % self.__class__.__name__
         try:
             self.postprocess()
         except:
             pass
 
     def run_once_failed(self):
-        print "Run_once failed"
+        if self.result is None:
+            self.result = "CRASHED"
+        if self.summary == "":
+            self.summary = "%s: Run_once failed" % self.__class__.__name__
         try:
             self.postprocess()
         except:
             pass
 
     def postprocess(self):
-        pass
+        if self.result is None:
+            self.result = "NEEDS_INSPECTION"
+        if self.summary is None or len(self.summary) == 0:
+            self.summary = "%s: %s" % (self.__class__.__name__, self.result)
+
+        # send mail
+        send_to = []
+        result_email = self.config.get('test','result_email')
+        if result_email and isinstance(result_email, str):
+            send_to = result_email.split(',')
+            try:
+                for email in self.mail_to:
+                    if isinstance(email, str) and len(email) > 0:
+                        send_to.append(email)
+            except:
+                pass
+
+        if send_to:
+            mail_body = "Stored logs available at <%s>\n\n" % self.autotest_url 
+            mail_body += "%s\n" % self.highlights
+            mail_body += "-\n"*79
+            mail_body += self.outputs
+            utils.send_email(mail_to=send_to,
+                    mail_from=self.config.get('test','mail_from'),
+                    mail_server=self.config.get('test','smtpserver'),
+                    subject=self.summary,
+                    body = mail_body)
 
diff --git a/tests/conflicts/conflicts.py b/tests/conflicts/conflicts.py
index e82ca06..8a79376 100644
--- a/tests/conflicts/conflicts.py
+++ b/tests/conflicts/conflicts.py
@@ -18,17 +18,27 @@
 # Author: Will Woods <wwoods@redhat.com>
 
 import os
-import autoqa.util
-from autotest_lib.client.bin import test, utils
-from autotest_lib.client.bin.test_config import config_loader
+from autoqa.test import BaseTest
+from autoqa.decorators import ExceptionCatcher
+from autotest_lib.client.bin import utils
 
-class conflicts(test.test):
+class conflicts(BaseTest):
     version = 1
 
-    def initialize(self, config):
-        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)
+    @ExceptionCatcher("self.initialize_failed")
+    def initialize(self, config, **kwargs):
+        super(conflicts, self).__init__(config)
+        # This is where you can look up more info about the package, e.g.:
+        #import autoqa.koji_utils
+        #koji = autoqa.koji_utils.SimpleKojiClientSession()
+        #self.pkgurls = koji.nvr_to_urls(envr)
+        #
+        # Use these variables to store information about the test.
+        # They are published by self.postprocess (see autoqa.test.BaseTest)
+        #self.result = None # result value ("PASSED", "FAILED", ...)
+        #self.summary = ""
+        #self.highlights = ""
+        #self.outputs = ""
 
     def writelog(self, logname, logdata):
         fullname = os.path.join(self.resultsdir, logname)
@@ -36,7 +46,8 @@ class conflicts(test.test):
         f.write(logdata)
         f.close()
 
-    def run_once(self, baseurl, parents, reponame):
+    @ExceptionCatcher("self.run_once_failed")
+    def run_once(self, baseurl, parents, reponame, **kwargs):
         os.chdir(self.bindir)
         cmd = './potential_conflict.py --tempcache --newest'
         cmd += ' --repofrompath=target,%s --repoid=target' % baseurl
@@ -66,14 +77,13 @@ class conflicts(test.test):
         self.write_test_keyval({'file_conflicts_count':len(file_conflicts),
                                 'conflicting_pkgs_count':len(conflicting_pkgs)})
 
-        result_email = self.config.get('test','result_email')
-        if result_email:
-            mail_body = "Stored logs available at <%s>\n\n" % self.autotest_url
-            mail_body += out
-            utils.send_email(mail_to=result_email,
-                             mail_from=self.config.get('test','mail_from'),
-                             mail_server=self.config.get('test','smtpserver'),
-                             subject='conflicts: %u packages with file conflicts in %s' % (len(conflicting_pkgs), reponame),
-                             body = mail_body)
+        if len(conflicting_pkgs) > 0:
+            self.result = "PASSED"
+        else:
+            self.result = "FAILED"
+        self.summary = "conflicts: %u packages with file conflicts in %s" % (len(conflicting_pkgs), reponame)
+        self.highlights = "= Conflicting pkgs =\n%s" % "\n".join(sorted(conflicting_pkgs))
+        self.highlights += "\n\n= File conflicts =\n%s" % "\n".jouin(sorted(file_conflicts))
+        self.outputs = out
 
         # TODO fail test if file conflicts exist?
diff --git a/tests/initscripts/initscripts.py b/tests/initscripts/initscripts.py
index fcef479..0de74d1 100644
--- a/tests/initscripts/initscripts.py
+++ b/tests/initscripts/initscripts.py
@@ -23,19 +23,25 @@ import subprocess
 import re
 import autoqa.koji_utils
 import autoqa.util
+from autoqa.test import BaseTest
+from autoqa.decorators import ExceptionCatcher
 import koji
-from autotest_lib.client.bin import test, utils
-from autotest_lib.client.bin.test_config import config_loader
+from autotest_lib.client.bin import utils
 from autotest_lib.client.common_lib import error
 from autoqa.repoinfo import repoinfo
 
-class initscripts(test.test):
+class initscripts(BaseTest):
     version = 1 # increment if setup() changes
 
-    def initialize(self, envr, name, kojitag, config):
-        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)
+    @ExceptionCatcher("self.initialize_failed")
+    def initialize(self, envr, name, kojitag, config, **kwargs):
+        super(initscripts, self).__init__(config) #FIXME: change classname!
+        # Use these variables to store information about the test.
+        # They are published by self.postprocess (see autoqa.test.BaseTest)
+        #self.result = None # result value ("PASSED", "FAILED", ...)
+        #self.summary = ""
+        #self.highlights = ""
+        #self.outputs = ""
 
     def setup(self):
         """
@@ -48,7 +54,7 @@ class initscripts(test.test):
             f.close()
         utils.system('yum -y install beakerlib') 
 
-    def run_beakerlib_test(self, name, path_to_runtest):
+    def run_beakerlib_test(self, name, path_to_runtest, **kwargs):
         #install required packages
         """
         there are lines like
@@ -77,7 +83,7 @@ class initscripts(test.test):
         #run the test
         cmd = os.path.join(path_to_runtest, "runtest.sh")
         result = utils.run(cmd, ignore_status = True, stdout_tee = utils.TEE_TO_LOGS)
-        self.results += result.stdout
+        self.outputs += result.stdout
 
         #store the log journal created by beakerlib
         """
@@ -86,7 +92,7 @@ class initscripts(test.test):
         :: [15:22:06] ::  JOURNAL TXT: /tmp/beakerlib-CoEg7JM/journal.txt
         extracts paths to these files, ands stores the files in self.resultsdir
         """
-        journal_lines = filter(lambda x: x.find("JOURNAL") > -1, self.results.splitlines())
+        journal_lines = filter(lambda x: x.find("JOURNAL") > -1, self.outputs.splitlines())
         journal_files = map(lambda x: x.split(':')[-1].strip(), journal_lines)
         for fname in journal_files:
             shutil.copy(fname, os.path.join(self.resultsdir, "journal_%s.%s" % (name, fname.split('.')[-1])))
@@ -95,8 +101,8 @@ class initscripts(test.test):
 
 
 
-
-    def run_once(self, envr, name, kojitag):
+    @ExceptionCatcher("self.run_once_failed")
+    def run_once(self, envr, name, kojitag, **kwargs):
         """
         name - name of the package for initscript test
         """
@@ -115,7 +121,9 @@ class initscripts(test.test):
                     test_name = path.replace(os.path.join(self.bindir, "./tests/"), "").replace(os.path.sep, "_")
                     tests.append((test_name, path))
         else:
-            raise error.TestWarn("No initscript checker found for package %s" % name)
+            self.summary = "No initscript checker found for package %s" % name
+            self.result = "FAILED"
+            raise error.TestWarn(self.summary)
 
 
         #install packages from koji (stolen from rpmlint test)
@@ -138,39 +146,32 @@ class initscripts(test.test):
 
         #sort tests alphabetically by test_name
         tests.sort(key = lambda x: x[0])
-        self.results = ""
+        self.outputs = ""
         tests_exit_status = []
         for test in tests:
-            self.results += "RUNNING: %s\n%s\n" % (test[0], "=" * len("RUNNING: %s" % test[0]))
+            self.outputs += "RUNNING: %s\n%s\n" % (test[0], "=" * len("RUNNING: %s" % test[0]))
             tests_exit_status.append((test[0], self.run_beakerlib_test(test[0], test[1])))
-            self.results += "\n"
+            self.outputs += "\n"
 
 
         tests_exit_status_nonzero = filter(lambda x: x[1] != 0, tests_exit_status)
         tests_exit_status_zero = filter(lambda x: x[1] == 0, tests_exit_status)
 
-        #send email with results
-        mail_to = self.config.get('test', 'result_email')
-        mail_from = self.config.get('test', 'mail_from')
-        mail_server = self.config.get('test', 'smtpserver')
-        if (mail_to and mail_from and mail_server):
-            mail_to = mail_to.split(',') 
-            collection_name = repoinfo.getrepo_by_tag(kojitag)['collection_name']
-            if collection_name and autoqa.util.check_opt_in(name, collection_name):
-                #FIXME - hardcoded partial email address here - obviously sub-par
-                mail_to.append('%s-owner@fedoraproject.org' % name)
-
-            msg = "Stored logs available at <%s>\n\n" % self.autotest_url
-            msg += "Following tests returned zero exit code: %s\n" % repr(tests_exit_status_zero)
-            msg += "Following tests returned NON-zero exit code: %s\n" % repr(tests_exit_status_nonzero)
-            msg += "%s\n" % ("#" * 79,)
-
-            print 'Sending email with results to %s ...' %  ', '.join(mail_to)
-            utils.send_email(mail_to = mail_to,
-                             mail_from = mail_from,
-                             mail_server = mail_server,
-                             subject = 'initscripts: %d PASSED, %d FAILED for package %s' % (len(tests_exit_status_zero), len(tests_exit_status_nonzero), envr),
-                             body = msg + self.results)
+        if len(tests_exit_status_nonzero) == 0:
+            self.result = "PASSED"
+        else:
+            self.result = "FAILED"
+        self.summary = "initscripts: %d PASSED, %d FAILED for package %s" % (len(tests_exit_status_zero), len(tests_exit_status_nonzero), envr)
+        self.highlights = "Following tests returned zero exit code: %s\n" % repr(tests_exit_status_zero)
+        self.highlights += "Following tests returned NON-zero exit code: %s\n" % repr(tests_exit_status_nonzero)
+
+
+        #add subscribed package owners to mail-to
+        self.mail_to = []
+        collection_name = repoinfo.getrepo_by_tag(kojitag)['collection_name']
+        if collection_name and autoqa.util.check_opt_in(name, collection_name):
+            #FIXME - hardcoded partial email address here - obviously sub-par
+            self.mail_to.append('%s-owner@fedoraproject.org' % name)
 
         if len(tests_exit_status_nonzero) > 0:
              msg = "Following tests returned non-zero exit code: %s" % repr(tests_exit_status_nonzero)
diff --git a/tests/rats_install/rats_install.py b/tests/rats_install/rats_install.py
index 7746b0e..d79f82d 100644
--- a/tests/rats_install/rats_install.py
+++ b/tests/rats_install/rats_install.py
@@ -20,19 +20,25 @@
 import os
 import sys
 from autoqa import rats, util
+from autoqa.test import BaseTest
+from autoqa.decorators import ExceptionCatcher
 from autoqa.virtguest import findhostbridge
-from autotest_lib.client.bin import test, utils
+from autotest_lib.client.bin import utils
 from autotest_lib.client.common_lib import error
-from autotest_lib.client.bin.test_config import config_loader
 
-class rats_install(test.test):
+class rats_install(BaseTest):
     version = 1
 
-    def initialize(self, config):
-        self.config = config_loader(config, self.tmpdir)
+    @ExceptionCatcher("self.initialize_failed")
+    def initialize(self, config, **kwargs):
+        super(rats_install, self).__init__(config)
         self.irb_conf = os.path.join(self.bindir, 'irb.cfg')
-        #URL of logs/results stored on autotest-server
-        self.autotest_url = util.make_autotest_url(self.config)
+        # Use these variables to store information about the test.
+        # They are published by self.postprocess (see autoqa.test.BaseTest)
+        #self.result = None # result value ("PASSED", "FAILED", ...)
+        #self.summary = ""
+        #self.highlights = ""
+        #self.outputs = ""
 
     def setup(self):
         if os.path.exists(self.irb_conf):
@@ -49,7 +55,8 @@ class rats_install(test.test):
         #       use the big hammer until we figure out the right thing to do
         utils.system('lokkit --disabled')
 
-    def run_once(self, baseurl, treename, image_url="", boot_args=""):
+    @ExceptionCatcher("self.run_once_failed")
+    def run_once(self, baseurl, treename, image_url="", boot_args="", **kwargs):
         os.chdir(self.bindir)
         cmd = "./install.py -s %s -l %s" % (self.tmpdir, self.resultsdir)
         if image_url != "":
@@ -57,22 +64,19 @@ class rats_install(test.test):
         if boot_args != "":
             cmd += " -x %s" % boot_args
         cmd += " %s" % baseurl
-        result = 'PASS'
+
+        self.result = None
         try:
             out = utils.system_output(cmd + " 2>&1", retain_output=True)
         except error.CmdError, e:
-            result = 'FAIL'
+            self.result = "FAILED"
             out = e.result_obj.stdout
 
-        result_email = self.config.get('test','result_email')
-        if result_email:
-            mail_body = "Stored results available at <%s>\n\n" % self.autotest_url
-            mail_body += out
-            utils.send_email(mail_to=result_email,
-                             mail_from=self.config.get('test','mail_from'),
-                             mail_server=self.config.get('test','smtpserver'),
-                             subject='rats_install %s %s' % (result, treename),
-                             body = mail_body)
+        if self.result is None:
+            self.result = "PASSED"
+        self.summary = "rats_install: %s %s" % (self.result, treename)
+        self.highlights = None
+        self.outputs = out
 
         # grab extra key = val data
         keyvals = util.read_keyvals()
@@ -89,5 +93,5 @@ class rats_install(test.test):
             except Exception, e:
                 print "Failed to send results to irb: %s" % str(e)
 
-        if result == 'FAIL':
+        if self.result == 'FAILED':
             raise error.TestFail
diff --git a/tests/rats_sanity/rats_sanity.py b/tests/rats_sanity/rats_sanity.py
index 65ea2a4..d009b4b 100644
--- a/tests/rats_sanity/rats_sanity.py
+++ b/tests/rats_sanity/rats_sanity.py
@@ -19,43 +19,47 @@
 
 import os
 from autoqa import rats, util
-from autotest_lib.client.bin import test, utils
+from autoqa.test import BaseTest
+from autoqa.decorators import ExceptionCatcher
+from autotest_lib.client.bin import utils
 from autotest_lib.client.common_lib import error
-from autotest_lib.client.bin.test_config import config_loader
 
-class rats_sanity(test.test):
+class rats_sanity(BaseTest):
     version = 1
 
-    def initialize(self, config):
-        self.config = config_loader(config, self.tmpdir)
+    @ExceptionCatcher("self.initialize_failed")
+    def initialize(self, config, **kwargs):
+        super(rats_sanity, self).__install__(config)
         self.irb_conf = os.path.join(self.bindir, 'irb.cfg')
-        #URL of logs/results stored on autotest-server
-        self.autotest_url = util.make_autotest_url(self.config)
+        # Use these variables to store information about the test.
+        # They are published by self.postprocess (see autoqa.test.BaseTest)
+        #self.result = None # result value ("PASSED", "FAILED", ...)
+        #self.summary = ""
+        #self.highlights = ""
+        #self.outputs = ""
 
     def setup(self):
         if os.path.exists(self.irb_conf):
             utils.system('yum -y install python-fedora')
 
-    def run_once(self, baseurl, parents, reponame):
+    @ExceptionCatcher("self.run_once_failed")
+    def run_once(self, baseurl, parents, reponame, **kwargs):
         os.chdir(self.bindir)
         cmd = "./sanity.py -s %s -l %s" % (self.tmpdir, self.resultsdir)
         cmd += " %s" % baseurl
-        result = 'PASS'
+        self.result = None
         try:
             out = utils.system_output(cmd + " 2>&1", retain_output=True)
         except error.CmdError, e:
-            result = 'FAIL'
+            self.result = 'FAILED'
             out = e.result_obj.stdout
 
-        result_email = self.config.get('test','result_email')
-        if result_email:
-            mail_body = "Stored logs available at <%s>\n\n" % self.autotest_url
-            mail_body += out
-            utils.send_email(mail_to=result_email,
-                             mail_from=self.config.get('test','mail_from'),
-                             mail_server=self.config.get('test','smtpserver'),
-                             subject='rats_sanity %s %s' % (result, reponame),
-                             body = mail_body)
+        if self.result is None:
+            self.result = "PASSED"
+        self.summary = "rats_sanity: %s %s" % (self.result, reponame)
+        self.highlights = None
+        self.outputs = out
+
 
         # grab extra key = val data
         keyvals = util.read_keyvals()
@@ -72,5 +76,5 @@ class rats_sanity(test.test):
             except Exception, e:
                 print "Failed to send results to irb: %s" % str(e)
 
-        if result == 'FAIL':
+        if self.result == 'FAILED':
             raise error.TestFail
diff --git a/tests/repoclosure/repoclosure.py b/tests/repoclosure/repoclosure.py
index 0a8638c..4f6767a 100644
--- a/tests/repoclosure/repoclosure.py
+++ b/tests/repoclosure/repoclosure.py
@@ -18,22 +18,30 @@
 # Author: Will Woods <wwoods@redhat.com>
 
 import autoqa.util
-from autotest_lib.client.bin import test, utils
+from autoqa.test import BaseTest
+from autoqa.decorators import ExceptionCatcher
+from autotest_lib.client.bin import utils
 from autotest_lib.client.common_lib import error
 from autotest_lib.client.bin.test_config import config_loader
 
-class repoclosure(test.test):
+class repoclosure(BaseTest):
     version = 1
 
-    def initialize(self, config):
-        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)
+    @ExceptionCatcher("self.initialize_failed")
+    def initialize(self, config, **kwargs):
+        super(repoclosure, self).__init__(config)
+        # Use these variables to store information about the test.
+        # They are published by self.postprocess (see autoqa.test.BaseTest)
+        #self.result = None # result value ("PASSED", "FAILED", ...)
+        #self.summary = ""
+        #self.highlights = ""
+        #self.outputs = ""
 
     def setup(self):
         utils.system('yum -y install yum-utils')
 
-    def run_once(self, baseurl, parents='', reponame=''):
+    @ExceptionCatcher("self.run_once_failed")
+    def run_once(self, baseurl, parents='', reponame='', **kwargs):
         # build the repoclosure commandline
         cmd = 'repoclosure --tempcache --newest'
         cmd += ' --repofrompath=target,%s --repoid=target' % baseurl
@@ -48,15 +56,13 @@ class repoclosure(test.test):
         unresolved_count = out.count('unresolved deps:')
         self.write_test_keyval({'unresolved_dep_count':unresolved_count})
 
-        result_email = self.config.get('test','result_email')
-        if result_email:
-            mail_body = "Stored logs available at <%s>\n\n" % self.autotest_url
-            mail_body += out
-            utils.send_email(mail_to=result_email,
-                             mail_from=self.config.get('test','mail_from'),
-                             mail_server=self.config.get('test','smtpserver'),
-                             subject='repoclosure: %u packages with unresolved deps in %s' % (unresolved_count, reponame),
-                             body = mail_body)
+        if unresolved_count:
+            self.result = "FAILED"
+        else:
+            self.result = "PASSED"
+        self.summary = 'repoclosure: %u packages with unresolved deps in %s' % (unresolved_count, reponame)
+        self.highlights = None
+        self.outputs = out
 
         if unresolved_count:
             raise error.TestFail, "%u packages with unresolved deps" % unresolved_count
diff --git a/tests/rpmguard/rpmguard.py b/tests/rpmguard/rpmguard.py
index 50245b9..6c88747 100644
--- a/tests/rpmguard/rpmguard.py
+++ b/tests/rpmguard/rpmguard.py
@@ -18,8 +18,9 @@
 #
 # Author: Kamil Paral <kparal@redhat.com>
 
-from autotest_lib.client.bin import test, utils
-from autotest_lib.client.bin.test_config import config_loader
+from autoqa.test import BaseTest
+from autoqa.decorators import ExceptionCatcher
+from autotest_lib.client.bin import utils
 from autotest_lib.client.common_lib import error
 import autoqa.koji_utils
 import autoqa.util
@@ -27,7 +28,7 @@ from autoqa.repoinfo import repoinfo
 import os
 import rpmUtils.miscutils
 
-class rpmguard(test.test):
+class rpmguard(BaseTest):
     version = 1 # increment if setup() changes
 
     def setup(self):
@@ -41,8 +42,9 @@ rpmlint | cut -d ' ' -f 1", retain_output=True)
             % (self.tmpdir, rpmlint))
 
 
-    def initialize(self, envr, name, kojitag, config):
-        self.config = config_loader(config, self.tmpdir)
+    @ExceptionCatcher("self.initialize_failed")
+    def initialize(self, envr, name, kojitag, config, **kwargs):
+        super(rpmguard, self).__init__(config)
         # we have several results (comparing different architectures), let's
         # store it separately
         self.results = []
@@ -51,11 +53,17 @@ rpmlint | cut -d ' ' -f 1", retain_output=True)
         self.rpmguard = os.path.join(self.bindir, 'rpmguard')
         self.rpmdir = os.path.join(self.tmpdir, 'rpms')
         #URL of logs/results stored on autotest-server
-        self.autotest_url = autoqa.util.make_autotest_url(self.config)
         os.makedirs(self.rpmdir)
+        # Use these variables to store information about the test.
+        # They are published by self.postprocess (see autoqa.test.BaseTest)
+        #self.result = None # result value ("PASSED", "FAILED", ...)
+        #self.summary = ""
+        #self.highlights = ""
+        #self.outputs = ""
 
 
-    def run_once(self, envr, name, kojitag):
+    @ExceptionCatcher("self.run_once_failed")
+    def run_once(self, envr, name, kojitag, **kwargs):
         # where to log output
         out = open(os.path.join(self.resultsdir,'rpmguard.log'),'wb')
 
@@ -70,6 +78,8 @@ rpmlint | cut -d ' ' -f 1", retain_output=True)
             warn = "N: There is no previous build of %s in parents of \
 %s tag." % (envr, kojitag)
             print warn
+            self.result = "PASSED"
+            self.summary = "rpmguard: %s" % warn
             out.write(warn + '\n')
             out.close()
             return
@@ -81,6 +91,7 @@ rpmlint | cut -d ' ' -f 1", retain_output=True)
         # (old one, new one)
         rpm_to_match = []
 
+        self.highlighs = ""
         # traverse all RPMs in the newer build
         for new_rpm in new_rpms:
             # find the matching older RPM, there should be exactly one
@@ -95,6 +106,7 @@ rpmlint | cut -d ' ' -f 1", retain_output=True)
                         (new_rpm['nvr'], new_rpm['arch'])
                 print err
                 out.write(err + '\n')
+                self.highlighs += "%s\n" % err
                 continue
             # there certainly should be more than 1 matching older RPM, but
             # let's check as a precaution
@@ -103,6 +115,7 @@ rpmlint | cut -d ' ' -f 1", retain_output=True)
                         (len(old_rpm), new_rpm['nvr'], new_rpm['arch'])
                 print err
                 out.write(err + '\n')
+                self.highlighs += "%s\n" % err
                 continue
 
             # now there is certainly one older RPM matching the newer one
@@ -115,10 +128,11 @@ rpmlint | cut -d ' ' -f 1", retain_output=True)
                 err = 'N: There is no new RPM to match older NVRA: \
 %s.%s' % (old_rpm['nvr'], old_rpm['arch'])
                 print err
+                self.highlighs += "%s\n" % err
                 out.write(err + '\n')
 
         # let's remember if any of invoked command failed
-        test_result = 'PASS'
+        test_result = 'PASSED'
 
         # let's compare the packages finally
         for old_rpm, new_rpm in rpm_to_match:
@@ -149,7 +163,7 @@ rpmlint | cut -d ' ' -f 1", retain_output=True)
                 archs[old_rpm['arch']] = result.stdout
             # if command failed
             else:
-                test_result = 'FAIL'
+                test_result = 'FAILED'
                 self.results.append(info + '\n' + result.stdout + '\n' + \
                     result.stderr + '\nN: ----')
             print 'N: ----'
@@ -178,29 +192,19 @@ rpmlint | cut -d ' ' -f 1", retain_output=True)
         out.write(log)
         out.close()
 
+        warning_count = len([line for line in log.splitlines() if line.startswith('W: ')])
+
+        self.result = test_result
+        self.summary = 'rpmguard: %u warnings for package %s' % (warning_count, envr)
+        self.outputs = log
+
         # email results to mailing list and to pkg owner if they optin
-        send_to = []
-        result_email = self.config.get('test','result_email')
-        if result_email and isinstance(result_email, str):
-            send_to = result_email.split(',')
-            collection_name = repoinfo.getrepo_by_tag(kojitag)['collection_name']
-            if collection_name and autoqa.util.check_opt_in(name, collection_name):
-                #FIXME - hardcoded partial email address here - obviously sub-par
-                send_to.append('%s-owner@fedoraproject.org' % name)
-
-        if send_to:
-            warning_count = len([line for line in log.splitlines() \
-                            if line.startswith('W: ')])
-            print 'Sending email with results to %s ...' % result_email
-            mail_body = "Stored logs available at <%s>\n\n" % self.autotest_url
-            mail_body += log
-            utils.send_email(mail_to=send_to,
-                mail_from=self.config.get('test','mail_from'),
-                mail_server=self.config.get('test','smtpserver'),
-                subject='rpmguard: %u warnings for package %s' % \
-                    (warning_count, envr),
-                body = mail_body)
+        self.mail_to = []
+        collection_name = repoinfo.getrepo_by_tag(kojitag)['collection_name']
+        if collection_name and autoqa.util.check_opt_in(name, collection_name):
+            #FIXME - hardcoded partial email address here - obviously sub-par
+            self.mail_to.append('%s-owner@fedoraproject.org' % name)
 
         # if some command failed, make this test fail
-        if test_result == 'FAIL':
+        if test_result == 'FAILED':
             raise error.TestFail
diff --git a/tests/rpmlint/rpmlint.py b/tests/rpmlint/rpmlint.py
index bbb7460..cb18898 100644
--- a/tests/rpmlint/rpmlint.py
+++ b/tests/rpmlint/rpmlint.py
@@ -17,25 +17,33 @@
 #
 # Author: Will Woods <wwoods@redhat.com>
 
-from autotest_lib.client.bin import test, utils
-from autotest_lib.client.bin.test_config import config_loader
+from autoqa.test import BaseTest
+from autoqa.decorators import ExceptionCatcher
+from autotest_lib.client.bin import utils
 from autotest_lib.client.common_lib import error
 import autoqa.koji_utils, autoqa.util
 import os
 from autoqa.repoinfo import repoinfo
 
-class rpmlint(test.test):
+class rpmlint(BaseTest):
     version = 1 # increment if setup() changes
 
-    def initialize(self, envr, config):
-        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)
+    @ExceptionCatcher("self.initialize_failed")
+    def initialize(self, envr, config, **kwargs):
+        super(rpmlint, self).__init__(config)
+        # Use these variables to store information about the test.
+        # They are published by self.postprocess (see autoqa.test.BaseTest)
+        #self.result = None # result value ("PASSED", "FAILED", ...)
+        #self.summary = ""
+        #self.highlights = ""
+        #self.outputs = ""
+
 
     def setup(self):
         utils.system('yum -y install rpmlint')
 
-    def run_once(self, envr, name, kojitag):
+    @ExceptionCatcher("self.run_once_failed")
+    def run_once(self, envr, name, kojitag, **kwargs):
         koji = autoqa.koji_utils.SimpleKojiClientSession()
         pkgurls = koji.nvr_to_urls(envr)
         rpmdir = os.path.join(self.tmpdir, 'rpms')
@@ -51,6 +59,7 @@ class rpmlint(test.test):
         try:
             self.results = utils.system_output(cmd+" 2>&1", retain_output=True)
         except error.CmdError, e:
+            self.result = "FAILED"
             result = 'FAIL'
             self.results = e.result_obj.stdout
 
@@ -62,29 +71,22 @@ class rpmlint(test.test):
         out.write(self.results)
         out.close()
 
-        # email results to mailing list and to pkg owner if they optin
-        send_to = []
-        result_email = self.config.get('test','result_email')
-        if result_email and isinstance(result_email, str):
-            send_to = result_email.split(',')
-            collection_name = repoinfo.getrepo_by_tag(kojitag)['collection_name']
-            if collection_name and autoqa.util.check_opt_in(name, collection_name):
-                #FIXME - hardcoded partial email address here - obviously sub-par
-                send_to.append('%s-owner@fedoraproject.org' % name)
+        summary = ((self.results.splitlines()[-1]).split(';')[-1])[1:-1]
 
-        if send_to:
-            # parse last line for summary ('N errors, N warnings')
-            summary = ((self.results.splitlines()[-1]).split(';')[-1])[1:-1]
+        if result == 'PASS':
+            self.result = "PASSED"
+        else:
+            self.result = "FAILED"
+        self.summary = 'rpmlint: %s for package %s' % (summary, envr)
+        self.highlights = None
+        self.outputs = out
 
-            print 'Sending email with results to %s ...' %  ', '.join(send_to)
-            mail_body = "Stored logs available at <%s>\n\n" % self.autotest_url
-            mail_body += self.results
-            utils.send_email(mail_to=send_to,
-                mail_from=self.config.get('test','mail_from'),
-                mail_server=self.config.get('test','smtpserver'),
-                subject='rpmlint: %s for package %s' % \
-                    (summary, envr),
-                body = mail_body)
+        # email results to mailing list and to pkg owner if they optin
+        self.mail_to = []
+        collection_name = repoinfo.getrepo_by_tag(kojitag)['collection_name']
+        if collection_name and autoqa.util.check_opt_in(name, collection_name):
+            #FIXME - hardcoded partial email address here - obviously sub-par
+            self.mail_to.append('%s-owner@fedoraproject.org' % name)
 
         # if some command failed, make this test fail
         if result == 'FAIL':
-- 
1.6.6.1

