On Wed, 2010-08-25 at 16:50 -0300, Lucas Meneghel Rodrigues wrote: > Sometimes, we just want to have important data about the job > readily available, without having to open the web interface. > > This patch adds important info to the regular status e-mails: > > * Number of tests executed > * Success rate > * Details about test failures > > So people can decide whether they actually want to inspect > the results more carefully. > > Here's how the notification e-mails appear after the test > > Subject: Autotest | Job ID: 27 "Longer test" | Status: 1 Completed | > Success Rate: 40.0 % > > Job ID: 27 > Job Name: Longer test > Status: 1 Completed > Results interface URL: http://autotest/afe/#tab_id=view_job&object_id=27 > Summary: > Host: 192.168.122.198 Status: Completed > Execution Time (HH:MM:SS): 00:01:38 > Tests Executed: 5 > Tests Passed: 2
OOps, pasted the sample e-mail in an incomplete form. Subject: Autotest | Job ID: 27 "Longer test" | Status: 1 Completed | Success Rate: 40.0 % Job ID: 27 Job Name: Longer test Status: 1 Completed Results interface URL: http://autotest/afe/#tab_id=view_job&object_id=27 Summary: Host: 192.168.122.198 Status: Completed Execution Time (HH:MM:SS): 00:01:38 Tests Executed: 5 Tests Passed: 2 Tests Failed: 3 Success Rate: 40.0 % Summary of failed tests: Test Name Status Reason error_test_error ERROR This test always causes an error. error_test_fail FAIL This test always fails. error_test_bug FAIL Unhandled str: Unhandled RuntimeError: Woof Woof, Timmy's trapped in the well! > In the future, we might encapsulate this code and create a way to do site > overrides for different email needs. I consider that what's in this patch is > sufficiently good and interesting for all users, hence I'm sending it. > > Signed-off-by: Lucas Meneghel Rodrigues <[email protected]> > --- > scheduler/scheduler_models.py | 105 > +++++++++++++++++++++++++++++++++++++---- > 1 files changed, 95 insertions(+), 10 deletions(-) > > diff --git a/scheduler/scheduler_models.py b/scheduler/scheduler_models.py > index bafaf5f..6ad8df3 100644 > --- a/scheduler/scheduler_models.py > +++ b/scheduler/scheduler_models.py > @@ -594,11 +594,34 @@ class HostQueueEntry(DBObject): > def _email_on_status(self, status): > hostname = self._get_hostname() > > - subject = 'Autotest: Job ID: %s "%s" Host: %s %s' % ( > - self.job.id, self.job.name, hostname, status) > - body = "Job ID: %s\nJob Name: %s\nHost: %s\nStatus: %s\n%s\n" % ( > - self.job.id, self.job.name, hostname, status, > - self._view_job_url()) > + job_stats = Job(id=self.job.id).get_test_execution_details() > + > + subject = ('Autotest | Job ID: %s "%s" | Host: %s | Status: %s ' > + (self.job.id, self.job.name, hostname, status)) > + > + if status != "Failed": > + subject += '| Success Rate: %s %%' % job_stats['success_rate'] > + > + body = ("Job ID: %s\n" > + "Job Name: %s\n" > + "Host: %s\n" > + "Status: %s\n" > + "Results interface URL: %s\n" > + "Execution Time (HH:MM:SS): %s\n" > + "Tests Executed: %s\n" > + "Tests Passed: %s\n" > + "Tests Failed: %s\n" > + "Success Rate: %s %%\n" > + "Summary of failed tests:\n" % (self.job.id, self.job.name, > + hostname, status, > + self._view_job_url(), > + job_stats['execution_time'], > + job_stats['total_executed'], > + job_stats['total_passed'], > + job_stats['total_failed'], > + job_stats['success_rate'])) > + body += job_stats['failed_rows'] > + > email_manager.manager.send_email(self.job.email_list, subject, body) > > > @@ -619,11 +642,34 @@ class HostQueueEntry(DBObject): > status = ', '.join('%d %s' % (count, status) for status, count > in status_counts.iteritems()) > > - subject = 'Autotest: Job ID: %s "%s" %s' % ( > - self.job.id, self.job.name, status) > - body = "Job ID: %s\nJob Name: %s\nStatus: %s\n%s\nSummary:\n%s" % ( > - self.job.id, self.job.name, status, self._view_job_url(), > - summary_text) > + job_stats = Job(id=self.job.id).get_test_execution_details() > + > + subject = ('Autotest | Job ID: %s "%s" | Status: %s ' % > + (self.job.id, self.job.name, status)) > + > + if status != "Failed": > + subject += '| Success Rate: %s %%' % job_stats['success_rate'] > + > + body = ("Job ID: %s\n" > + "Job Name: %s\n" > + "Status: %s\n" > + "Results interface URL: %s\n" > + "Summary:\n%s\n" > + "Execution Time (HH:MM:SS): %s\n" > + "Tests Executed: %s\n" > + "Tests Passed: %s\n" > + "Tests Failed: %s\n" > + "Success Rate: %s %%\n" > + "Summary of failed tests:\n" % (self.job.id, self.job.name, > + status, > self._view_job_url(), > + summary_text, > + > job_stats['execution_time'], > + > job_stats['total_executed'], > + job_stats['total_passed'], > + job_stats['total_failed'], > + job_stats['success_rate'])) > + body += job_stats['failed_rows'] > + > email_manager.manager.send_email(self.job.email_list, subject, body) > > > @@ -821,6 +867,45 @@ class Job(DBObject): > return entries > > > + def get_test_execution_details(self): > + stats = {} > + rows = _db.execute(""" > + SELECT t.test, s.word, t.reason > + FROM tko_tests AS t, tko_jobs AS j, tko_status AS s > + WHERE t.job_idx = j.job_idx > + AND s.status_idx = t.status > + AND j.afe_job_id = %s > + """ % self.id) > + total_executed = len(rows) > + # We have to discount SERVER_JOB and CLIENT_JOB.0 > + if total_executed > 2: > + total_executed -= 2 > + failed_rows = [r for r in rows if not 'GOOD' in r] > + failed_str = '%-30s %-10s %-40s\n' % ("Test Name", "Status", > "Reason") > + for row in failed_rows: > + failed_str += '%-30s %-10s %-40s\n' % row > + total_failed = len(failed_rows) > + success_rate = 100 - ((total_failed / float(total_executed)) * 100) > + stats['total_executed'] = total_executed > + stats['total_failed'] = total_failed > + stats['total_passed'] = total_executed - total_failed > + stats['success_rate'] = success_rate > + stats['failed_rows'] = failed_str > + > + time_row = _db.execute(""" > + SELECT started_time, finished_time > + FROM tko_jobs > + WHERE afe_job_id = %s; > + """ % self.id) > + t_begin, t_end = time_row[0] > + delta = t_end - t_begin > + minutes, seconds = divmod(delta.seconds, 60) > + hours, minutes = divmod(minutes, 60) > + stats['execution_time'] = "%02d:%02d:%02d" % (hours, minutes, > seconds) > + > + return stats > + > + > def set_status(self, status, update_queues=False): > self.update_field('status',status) > _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
