blob: d02596c736ea23b4ea37a1248373587ab22e385a [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
3
4usage = """\
5usage: parse
6 [-m] # Send mail for FAILED tests
7 [-o directory] # Specify results directory directly
8 <top level results directory> # Specify top level results directory
9"""
10
11try:
12 opts, args = getopt.getopt(sys.argv[1:], "hmo:", ["help"])
13except getopt.GetoptError:
14 # print help information and exit:
15 usage()
16 sys.exit(2)
17
18if len(sys.argv) < 2:
19 print usage
20 sys.exit(2)
21
22singledir = None
23mailit = False
24for name, value in opts:
25 if name in ("-h", "--help"):
26 usage()
27 sys.exit()
28 if name == "-m":
29 mailit = True
30 if name in ("-o", "--output"):
31 singledir = value
32
33
34if singledir:
35 dir = os.path.abspath(singledir)
36 jobs_list = [(os.path.basename(dir), dir)]
37else:
38 topdir = os.path.abspath(args[0])
39 jobs_list = [(dir, os.path.join(topdir, dir)) for dir in os.listdir(topdir)]
mblighbb7b8912006-10-08 03:59:02 +000040
mbligh9ec94852007-10-25 15:24:16 +000041debug = True
42
mbligh74fc0462007-11-05 20:24:17 +000043failcc = ""
44notify_user = None
mblighbb7b8912006-10-08 03:59:02 +000045
mbligh432bad42007-10-09 19:56:07 +000046db = db.db(autocommit=False) # do commits transactionally
mbligh056d0d32006-10-08 22:31:10 +000047
mbligh9ec94852007-10-25 15:24:16 +000048
mbligh74fc0462007-11-05 20:24:17 +000049def mailfailure(jobname, job, mesgtxt):
50 # XXX: Need to insert URL here too (frontend.test.url?)
51 link = "http://" + socket.gethostname() + "/results/" + jobname
52
53 # This looks pretty good on fixed-width-font email reader.
54 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")
55 message_header += "%-12s %-20s %-12s %-10s %s\n" % ("========", "======", "=========", "=========", "==============")
56
57 subject = "AUTOTEST: FAILED tests from " + " job " + jobname
58 parse.mail(notify_user, job.user, failcc, subject, message_header + mesgtxt)
59
60
mbligh9ec94852007-10-25 15:24:16 +000061def do_parse(jobname, path):
62 if debug:
mbligh74fc0462007-11-05 20:24:17 +000063 print '\nScanning' + path
mbligh9ec94852007-10-25 15:24:16 +000064 if db.find_job(jobname): # Job has already been parsed
mbligh994a23d2007-10-25 15:28:58 +000065 if debug:
mbligh74fc0462007-11-05 20:24:17 +000066 print '! Already processed'
mbligh9ec94852007-10-25 15:24:16 +000067 return
68 job = parse.job(path, 'regression')
mbligh8e1ab172007-09-13 17:29:56 +000069 if not job:
mbligh994a23d2007-10-25 15:28:58 +000070 if debug:
mbligh74fc0462007-11-05 20:24:17 +000071 print '! Not a job'
mbligh9ec94852007-10-25 15:24:16 +000072 return
mbligh74fc0462007-11-05 20:24:17 +000073 print '+ Parsed ' + path
mblighd5c33db2006-10-08 21:34:16 +000074 if not job.kernel:
mbligh994a23d2007-10-25 15:28:58 +000075 if debug:
mbligh74fc0462007-11-05 20:24:17 +000076 print '! Not a job.kernel'
mbligh9ec94852007-10-25 15:24:16 +000077 return
mbligh74fc0462007-11-05 20:24:17 +000078 print '* jobname, kernel version: %s %s' % (jobname, job.kernel.base)
79 mesgtxt = "\n"
mblighe9cf9d42007-08-31 08:56:00 +000080 for test in job.tests:
mbligh74fc0462007-11-05 20:24:17 +000081 if not test.subdir:
82 continue
83 print "* testname, status, reason: %s %s %s" % (test.subdir, test.status, test.reason)
84 if re.match(r'(FAIL|WARN)',test.status):
85 mesgtxt += "%-12s %-20s %-12s %-10s %s" % (jobname, job.kernel.base, test.subdir, test.status, test.reason)
86
87 if len(mesgtxt) > 2 and mailit:
88 print "Sending email report of FAILURES on " + jobname + " to " + job.user
89 mailfailure(jobname, job, mesgtxt)
mbligh9ec94852007-10-25 15:24:16 +000090 db.insert_job(jobname, job)
mbligh432bad42007-10-09 19:56:07 +000091 db.commit()
mblighfd6682452007-09-30 22:02:02 +000092
mbligh9ec94852007-10-25 15:24:16 +000093
mbligh74fc0462007-11-05 20:24:17 +000094
mbligh9ec94852007-10-25 15:24:16 +000095for (jobname, path) in jobs_list:
96 machine_list = os.path.join(path, '.machines')
97 if os.path.exists(machine_list):
98 for m in open(machine_list, 'r').readlines():
99 machine = m.rstrip()
100 if not machine:
101 continue
102 jobpath = os.path.join(path, machine)
103 jobname = os.path.join(os.path.basename(path), machine)
104 do_parse(jobname, jobpath)
105 else:
106 do_parse(jobname, path)
107
108
mbligh2aaeb672007-10-01 14:54:18 +0000109rows = db.select('distinct hostname', 'machines', {})
mblighfd6682452007-09-30 22:02:02 +0000110machines = [row[0] for row in rows]
111
112for machine in machines:
113 dir = os.path.dirname(os.path.abspath(sys.argv[0]))
114 vertical_text = os.path.join(dir, 'vertical_text.py')
115 os.system(vertical_text + ' ' + machine)