From 3a8ded3caa1c7e5c01d9e6226956600322e50ac3 Mon Sep 17 00:00:00 2001 From: eric eckstrand Date: Thu, 4 Feb 2016 14:42:12 -0800 Subject: [PATCH] add script to make morning failure report. --- scripts/mr_unit_failure_report.py | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 scripts/mr_unit_failure_report.py diff --git a/scripts/mr_unit_failure_report.py b/scripts/mr_unit_failure_report.py new file mode 100644 index 000000000000..27a8586981f9 --- /dev/null +++ b/scripts/mr_unit_failure_report.py @@ -0,0 +1,58 @@ +import sys +import MySQLdb +import traceback +import time + +def failure_report(args): + mr_unit = MySQLdb.connect(host='172.16.2.178', user='root', passwd=args[1], db='mr_unit') + mr_unit.autocommit(False) + cursor = mr_unit.cursor() + + # the jenkins job is scheduled to run every morning at 8 am (local). By default, we report the failures starting from + # 8 pm (local) of the previous day. + try: + start_time = args[2] + except IndexError: + yesterday = time.localtime(time.time() - 24 * 60 * 60) + start_time = time.mktime(yesterday) - yesterday.tm_hour*60*60 - yesterday.tm_min*60 - yesterday.tm_sec + 20*60*60 + + try: + end_time = args[3] + except IndexError: + end_time = time.time() + + try: + cursor.execute('select * from perf where (`start_time` > {0} and `end_time` < {1} and ' + '`pass` = 0);'.format(start_time, end_time)) + failures = cursor.fetchall() + except: + cursor.close() + traceback.print_exc() + print "Failed to retrieve failures from the perf table in mr_unit database for the period from {0} to {1}"\ + .format(time.strftime('%Y-%m-%d:%H:%M:%S', time.localtime(start_time)), + time.strftime('%Y-%m-%d:%H:%M:%S', time.localtime(end_time))) + raise + cursor.close() + + print "***********************************************************************" + print "Failures for the period from {0} to {1}".format(time.strftime('%Y-%m-%d:%H:%M:%S', time.localtime(start_time)), + time.strftime('%Y-%m-%d:%H:%M:%S', time.localtime(end_time))) + print "***********************************************************************\n" + + for idx, failure in enumerate(failures): + print '\nFAILURE {0}'.format(idx+1) + print '------------------------------------------------------------------------------' + print 'git branch: {0}'.format(failure[3]) + print 'git hash: {0}'.format(failure[2]) + print 'job name: {0}'.format(failure[11]) + print 'build id: {0}'.format(failure[1]) + print 'test name: {0}'.format(failure[5]) + print 'duration (seconds): {0}'.format(failure[7] - failure[6]) + print 'machine ip: {0}'.format(failure[4]) + print 'operating system: {0}'.format(failure[10]) + print 'number of cpus: {0}'.format(failure[9]) + print 'datetime (%Y-%m-%d:%H:%M:%S): {0}'.format(time.strftime('%Y-%m-%d:%H:%M:%S', time.localtime(failure[6]))) + print '------------------------------------------------------------------------------\n' + +if __name__ == '__main__': + failure_report(sys.argv) \ No newline at end of file