blob: 3b53d7ef56119844a3b0a5a9429d01fb47531506 [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])
50 jobs_list = [(dir, os.path.join(topdir, dir)) for dir in os.listdir(topdir)]
mblighbb7b8912006-10-08 03:59:02 +000051
mbligh9ec94852007-10-25 15:24:16 +000052debug = True
53
mbligh74fc0462007-11-05 20:24:17 +000054failcc = ""
55notify_user = None
mblighbb7b8912006-10-08 03:59:02 +000056
mbligh432bad42007-10-09 19:56:07 +000057db = db.db(autocommit=False) # do commits transactionally
mbligh056d0d32006-10-08 22:31:10 +000058
mbligh9ec94852007-10-25 15:24:16 +000059
mbligh74fc0462007-11-05 20:24:17 +000060def mailfailure(jobname, job, mesgtxt):
61 # XXX: Need to insert URL here too (frontend.test.url?)
62 link = "http://" + socket.gethostname() + "/results/" + jobname
63
64 # This looks pretty good on fixed-width-font email reader.
65 message_header = "\n%s\n%s\n\n%-12s %-20s %-12s %-10s %s\n" % ("The following tests FAILED for this job:", link, "Job name", "Kernel", "Test name", "FAIL/WARN", "Failure Reason")
66 message_header += "%-12s %-20s %-12s %-10s %s\n" % ("========", "======", "=========", "=========", "==============")
67
68 subject = "AUTOTEST: FAILED tests from " + " job " + jobname
69 parse.mail(notify_user, job.user, failcc, subject, message_header + mesgtxt)
70
71
mbligh9ec94852007-10-25 15:24:16 +000072def do_parse(jobname, path):
73 if debug:
mbligh74fc0462007-11-05 20:24:17 +000074 print '\nScanning' + path
mbligh9ec94852007-10-25 15:24:16 +000075 if db.find_job(jobname): # Job has already been parsed
mbligh994a23d2007-10-25 15:28:58 +000076 if debug:
mbligh74fc0462007-11-05 20:24:17 +000077 print '! Already processed'
mbligh9ec94852007-10-25 15:24:16 +000078 return
79 job = parse.job(path, 'regression')
mbligh8e1ab172007-09-13 17:29:56 +000080 if not job:
mbligh994a23d2007-10-25 15:28:58 +000081 if debug:
mbligh74fc0462007-11-05 20:24:17 +000082 print '! Not a job'
mbligh9ec94852007-10-25 15:24:16 +000083 return
mbligh74fc0462007-11-05 20:24:17 +000084 print '+ Parsed ' + path
mblighd5c33db2006-10-08 21:34:16 +000085 if not job.kernel:
mbligh994a23d2007-10-25 15:28:58 +000086 if debug:
mbligh74fc0462007-11-05 20:24:17 +000087 print '! Not a job.kernel'
mbligh9ec94852007-10-25 15:24:16 +000088 return
mbligh74fc0462007-11-05 20:24:17 +000089 print '* jobname, kernel version: %s %s' % (jobname, job.kernel.base)
90 mesgtxt = "\n"
mblighe9cf9d42007-08-31 08:56:00 +000091 for test in job.tests:
mbligh74fc0462007-11-05 20:24:17 +000092 if not test.subdir:
93 continue
94 print "* testname, status, reason: %s %s %s" % (test.subdir, test.status, test.reason)
95 if re.match(r'(FAIL|WARN)',test.status):
96 mesgtxt += "%-12s %-20s %-12s %-10s %s" % (jobname, job.kernel.base, test.subdir, test.status, test.reason)
97
98 if len(mesgtxt) > 2 and mailit:
99 print "Sending email report of FAILURES on " + jobname + " to " + job.user
100 mailfailure(jobname, job, mesgtxt)
mbligh9ec94852007-10-25 15:24:16 +0000101 db.insert_job(jobname, job)
mblighbc985702007-11-05 20:52:15 +0000102 print "COMMITING"
mbligh432bad42007-10-09 19:56:07 +0000103 db.commit()
mblighfd6682452007-09-30 22:02:02 +0000104
mbligh9ec94852007-10-25 15:24:16 +0000105
mbligh74fc0462007-11-05 20:24:17 +0000106
mbligh9ec94852007-10-25 15:24:16 +0000107for (jobname, path) in jobs_list:
108 machine_list = os.path.join(path, '.machines')
109 if os.path.exists(machine_list):
110 for m in open(machine_list, 'r').readlines():
111 machine = m.rstrip()
112 if not machine:
113 continue
114 jobpath = os.path.join(path, machine)
115 jobname = os.path.join(os.path.basename(path), machine)
mblighbc985702007-11-05 20:52:15 +0000116 try:
117 do_parse(jobname, jobpath)
118 except:
119 print format_error()
120 continue
mbligh9ec94852007-10-25 15:24:16 +0000121 else:
mblighbc985702007-11-05 20:52:15 +0000122 try:
123 do_parse(jobname, path)
124 except:
125 print format_error()
126 continue
mbligh9ec94852007-10-25 15:24:16 +0000127
128
mblighbc985702007-11-05 20:52:15 +0000129# rows = db.select('distinct hostname', 'machines', {})
130# machines = [row[0] for row in rows]
131#
132# for machine in machines:
133# dir = os.path.dirname(os.path.abspath(sys.argv[0]))
134# vertical_text = os.path.join(dir, 'vertical_text.py')
135# os.system(vertical_text + ' ' + machine)