blob: b69409955d9345bf28bc13f395decea7ab2c12c5 [file] [log] [blame]
mblighc6b01ed2006-10-13 17:03:26 +00001#!/usr/bin/python
mbligh74fc0462007-11-05 20:24:17 +00002import os, re, parse, frontend, db, sys, socket, getopt
mblighbc985702007-11-05 20:52:15 +00003from traceback import format_exception
mbligh74fc0462007-11-05 20:24:17 +00004
5usage = """\
6usage: parse
7 [-m] # Send mail for FAILED tests
8 [-o directory] # Specify results directory directly
9 <top level results directory> # Specify top level results directory
10"""
11
mblighbc985702007-11-05 20:52:15 +000012def format_error():
13 t, o, tb = sys.exc_info()
14 trace = format_exception(t, o, tb)
15 # Clear the backtrace to prevent a circular reference
16 # in the heap -- as per tutorial
17 tb = ''
18
19 return ''.join(trace)
20
21
mbligh74fc0462007-11-05 20:24:17 +000022try:
23 opts, args = getopt.getopt(sys.argv[1:], "hmo:", ["help"])
24except getopt.GetoptError:
25 # print help information and exit:
26 usage()
27 sys.exit(2)
28
29if len(sys.argv) < 2:
30 print usage
31 sys.exit(2)
32
33singledir = None
34mailit = False
35for name, value in opts:
36 if name in ("-h", "--help"):
37 usage()
38 sys.exit()
39 if name == "-m":
40 mailit = True
41 if name in ("-o", "--output"):
42 singledir = value
43
44
45if singledir:
46 dir = os.path.abspath(singledir)
47 jobs_list = [(os.path.basename(dir), dir)]
48else:
49 topdir = os.path.abspath(args[0])
mbligh032c2de2007-11-24 19:20:12 +000050 dirs = os.listdir(topdir)
51 jobs_list = [(dir, os.path.join(topdir, dir)) for dir in dirs]
mblighbb7b8912006-10-08 03:59:02 +000052
mbligh9ec94852007-10-25 15:24:16 +000053debug = True
54
mbligh74fc0462007-11-05 20:24:17 +000055failcc = ""
56notify_user = None
mblighbb7b8912006-10-08 03:59:02 +000057
mbligh432bad42007-10-09 19:56:07 +000058db = db.db(autocommit=False) # do commits transactionally
mbligh056d0d32006-10-08 22:31:10 +000059
mbligh9ec94852007-10-25 15:24:16 +000060
mbligh74fc0462007-11-05 20:24:17 +000061def mailfailure(jobname, job, mesgtxt):
62 # XXX: Need to insert URL here too (frontend.test.url?)
63 link = "http://" + socket.gethostname() + "/results/" + jobname
64
65 # This looks pretty good on fixed-width-font email reader.
mbligh032c2de2007-11-24 19:20:12 +000066 message_header = "\n%s\n%s\n\n%-12s %-20s %-12s %-10s %s\n" % \
67 ("The following tests FAILED for this job:",
68 link, "Job name", "Kernel", "Test name",
69 "FAIL/WARN", "Failure Reason")
70 message_header += "%-12s %-20s %-12s %-10s %s\n" % \
71 ("========", "======", "=========",
72 "=========", "==============")
mbligh74fc0462007-11-05 20:24:17 +000073
74 subject = "AUTOTEST: FAILED tests from " + " job " + jobname
mbligh032c2de2007-11-24 19:20:12 +000075 parse.mail(notify_user, job.user, failcc, subject,
76 message_header + mesgtxt)
mbligh74fc0462007-11-05 20:24:17 +000077
78
mbligh9ec94852007-10-25 15:24:16 +000079def do_parse(jobname, path):
80 if debug:
mbligh74fc0462007-11-05 20:24:17 +000081 print '\nScanning' + path
mbligh9ec94852007-10-25 15:24:16 +000082 if db.find_job(jobname): # Job has already been parsed
mbligh994a23d2007-10-25 15:28:58 +000083 if debug:
mbligh74fc0462007-11-05 20:24:17 +000084 print '! Already processed'
mbligh9ec94852007-10-25 15:24:16 +000085 return
86 job = parse.job(path, 'regression')
mbligh8e1ab172007-09-13 17:29:56 +000087 if not job:
mbligh994a23d2007-10-25 15:28:58 +000088 if debug:
mbligh74fc0462007-11-05 20:24:17 +000089 print '! Not a job'
mbligh9ec94852007-10-25 15:24:16 +000090 return
mbligh74fc0462007-11-05 20:24:17 +000091 print '+ Parsed ' + path
mblighd5c33db2006-10-08 21:34:16 +000092 if not job.kernel:
mbligh994a23d2007-10-25 15:28:58 +000093 if debug:
mbligh74fc0462007-11-05 20:24:17 +000094 print '! Not a job.kernel'
mbligh9ec94852007-10-25 15:24:16 +000095 return
mbligh74fc0462007-11-05 20:24:17 +000096 print '* jobname, kernel version: %s %s' % (jobname, job.kernel.base)
97 mesgtxt = "\n"
mblighe9cf9d42007-08-31 08:56:00 +000098 for test in job.tests:
mbligh74fc0462007-11-05 20:24:17 +000099 if not test.subdir:
100 continue
mbligh4a2c61e2007-11-12 22:13:11 +0000101 print "* testname, status, reason: %s %s %s" % \
102 (test.subdir, test.status, test.reason)
mbligh74fc0462007-11-05 20:24:17 +0000103 if re.match(r'(FAIL|WARN)',test.status):
mbligh4a2c61e2007-11-12 22:13:11 +0000104 mesgtxt += "%-12s %-20s %-12s %-10s %s" % \
105 (jobname, job.kernel.base, test.subdir,
106 test.status, test.reason)
mbligh74fc0462007-11-05 20:24:17 +0000107
108 if len(mesgtxt) > 2 and mailit:
mbligh4a2c61e2007-11-12 22:13:11 +0000109 print "Sending email report of FAILURES on %s to %s" % \
110 (jobname, job.user)
mbligh74fc0462007-11-05 20:24:17 +0000111 mailfailure(jobname, job, mesgtxt)
mbligh9ec94852007-10-25 15:24:16 +0000112 db.insert_job(jobname, job)
mblighbc985702007-11-05 20:52:15 +0000113 print "COMMITING"
mbligh432bad42007-10-09 19:56:07 +0000114 db.commit()
mblighfd6682452007-09-30 22:02:02 +0000115
mbligh9ec94852007-10-25 15:24:16 +0000116
mbligh74fc0462007-11-05 20:24:17 +0000117
mbligh9ec94852007-10-25 15:24:16 +0000118for (jobname, path) in jobs_list:
119 machine_list = os.path.join(path, '.machines')
120 if os.path.exists(machine_list):
121 for m in open(machine_list, 'r').readlines():
122 machine = m.rstrip()
123 if not machine:
124 continue
125 jobpath = os.path.join(path, machine)
126 jobname = os.path.join(os.path.basename(path), machine)
mblighbc985702007-11-05 20:52:15 +0000127 try:
128 do_parse(jobname, jobpath)
129 except:
130 print format_error()
131 continue
mbligh9ec94852007-10-25 15:24:16 +0000132 else:
mblighbc985702007-11-05 20:52:15 +0000133 try:
134 do_parse(jobname, path)
135 except:
136 print format_error()
137 continue
mbligh9ec94852007-10-25 15:24:16 +0000138
139
mblighbc985702007-11-05 20:52:15 +0000140# rows = db.select('distinct hostname', 'machines', {})
141# machines = [row[0] for row in rows]
142#
143# for machine in machines:
144# dir = os.path.dirname(os.path.abspath(sys.argv[0]))
145# vertical_text = os.path.join(dir, 'vertical_text.py')
146# os.system(vertical_text + ' ' + machine)