In the virt tests, it is frequently very useful that we
know easily which KVM version was tested. So, in order to
list that in a generic way, allow the user to specify
arbitrary keyvals to be displayed in the results email.

With this and the fact that we can now store version
keyvals for installed software and get them displayed
on the email, similar to:

software_version_qemu: 
git://git.qemu.org/qemu.git:master:a21143486b9c6d7a50b7b62877c02b3c686943cb

Signed-off-by: Lucas Meneghel Rodrigues <l...@redhat.com>
---
 global_config.ini             |    2 ++
 scheduler/scheduler_models.py |   41 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/global_config.ini b/global_config.ini
index 39a212f..6ab7fcc 100644
--- a/global_config.ini
+++ b/global_config.ini
@@ -162,6 +162,8 @@ reverify_max_hosts_at_once: 0
 drone_sets_enabled: False
 # default_drone_set_name: This is required if drone sets are enabled
 default_drone_set_name:
+# Keyval names that you want to see listed on the results email (space/comma 
separated)
+keyval_names_exibit_summary_mail:
 
 [HOSTS]
 # Comma delimited list of processes that must be present to call a host 'up'
diff --git a/scheduler/scheduler_models.py b/scheduler/scheduler_models.py
index 17aa910..6d33afb 100644
--- a/scheduler/scheduler_models.py
+++ b/scheduler/scheduler_models.py
@@ -24,6 +24,8 @@ from autotest.database import database_connection
 from autotest.scheduler import drone_manager, email_manager
 from autotest.scheduler import scheduler_config
 
+GLOBAL_CONFIG = global_config.global_config
+
 _notify_email_statuses = []
 _base_url = None
 
@@ -35,7 +37,7 @@ def initialize():
     _db = database_connection.DatabaseConnection('AUTOTEST_WEB')
     _db.connect(db_type='django')
 
-    notify_statuses_list = global_config.global_config.get_config_value(
+    notify_statuses_list = GLOBAL_CONFIG.get_config_value(
             scheduler_config.CONFIG_SECTION, "notify_email_statuses",
             default='')
     global _notify_email_statuses
@@ -46,14 +48,14 @@ def initialize():
     # AUTOTEST_WEB.base_url is still a supported config option as some people
     # may wish to override the entire url.
     global _base_url
-    config_base_url = global_config.global_config.get_config_value(
+    config_base_url = GLOBAL_CONFIG.get_config_value(
             scheduler_config.CONFIG_SECTION, 'base_url', default='')
     if config_base_url:
         _base_url = config_base_url
     else:
         # For the common case of everything running on a single server you
         # can just set the hostname in a single place in the config file.
-        server_name = global_config.global_config.get_config_value(
+        server_name = GLOBAL_CONFIG.get_config_value(
                 'SERVER', 'hostname')
         if not server_name:
             logging.critical('[SERVER] hostname missing from the config file.')
@@ -629,6 +631,13 @@ class HostQueueEntry(DBObject):
             body += "Host: %s\n" % hostname
         if summary is not None:
             body += "Summary: %s\n" % summary
+
+        keyval_list = self.get_keyval_list()
+        if keyval_list:
+            for kv in keyval_list:
+                if job_stats[kv]:
+                    body += job_stats[kv] + "\n"
+
         body += "Execution time (HH:MM:SS): %s\n" % job_stats['execution_time']
         body += job_stats['fail_detail']
         body += job_stats['warn_detail']
@@ -917,6 +926,20 @@ class Job(DBObject):
                         formatted_row += "\n"
             return formatted_row
 
+
+        def _get_test_keyval(jobid, keyname, db, default=''):
+            idx = db.execute('SELECT job_idx FROM tko_jobs WHERE '
+                             'afe_job_id=%s' % jobid)[-1]
+            test_idx = db.execute('SELECT test_idx FROM tko_tests WHERE '
+                                  'job_idx=%s' % idx)[3]
+            try:
+                return db.execute('SELECT value FROM tko_test_attributes'
+                                  ' WHERE test_idx=%s AND attribute="%s"' %
+                                  (test_idx, keyname))[-1]
+            except:
+                return default
+
+
         stats = {}
 
         rows = _db.execute("""
@@ -975,9 +998,21 @@ class Job(DBObject):
         else:
             stats['execution_time'] = '(none)'
 
+        keyval_list = self.get_keyval_list()
+        if keyval_list:
+            for kv in keyval_list:
+                stats[kv] = _get_test_keyval(self.id, kv, _db)
+
         return stats
 
 
+    def get_keyval_list(self):
+        raw = GLOBAL_CONFIG.get_config_value('SCHEDULER',
+                                             
'keyval_names_exibit_summary_mail',
+                                             default="")
+        return re.split(r'[\s,;:]', raw)
+
+
     def set_status(self, status, update_queues=False):
         self.update_field('status',status)
 
-- 
1.7.10.4

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to