mbligh | c6b01ed | 2006-10-13 17:03:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 2 | import os, re, parse, frontend, db, sys, socket, getopt |
| 3 | |
| 4 | usage = """\ |
| 5 | usage: 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 | |
| 11 | try: |
| 12 | opts, args = getopt.getopt(sys.argv[1:], "hmo:", ["help"]) |
| 13 | except getopt.GetoptError: |
| 14 | # print help information and exit: |
| 15 | usage() |
| 16 | sys.exit(2) |
| 17 | |
| 18 | if len(sys.argv) < 2: |
| 19 | print usage |
| 20 | sys.exit(2) |
| 21 | |
| 22 | singledir = None |
| 23 | mailit = False |
| 24 | for 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 | |
| 34 | if singledir: |
| 35 | dir = os.path.abspath(singledir) |
| 36 | jobs_list = [(os.path.basename(dir), dir)] |
| 37 | else: |
| 38 | topdir = os.path.abspath(args[0]) |
| 39 | jobs_list = [(dir, os.path.join(topdir, dir)) for dir in os.listdir(topdir)] |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 40 | |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 41 | debug = True |
| 42 | |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 43 | failcc = "" |
| 44 | notify_user = None |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 45 | |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 46 | db = db.db(autocommit=False) # do commits transactionally |
mbligh | 056d0d3 | 2006-10-08 22:31:10 +0000 | [diff] [blame] | 47 | |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 48 | |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 49 | def 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 | |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 61 | def do_parse(jobname, path): |
| 62 | if debug: |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 63 | print '\nScanning' + path |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 64 | if db.find_job(jobname): # Job has already been parsed |
mbligh | 994a23d | 2007-10-25 15:28:58 +0000 | [diff] [blame] | 65 | if debug: |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 66 | print '! Already processed' |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 67 | return |
| 68 | job = parse.job(path, 'regression') |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 69 | if not job: |
mbligh | 994a23d | 2007-10-25 15:28:58 +0000 | [diff] [blame] | 70 | if debug: |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 71 | print '! Not a job' |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 72 | return |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 73 | print '+ Parsed ' + path |
mbligh | d5c33db | 2006-10-08 21:34:16 +0000 | [diff] [blame] | 74 | if not job.kernel: |
mbligh | 994a23d | 2007-10-25 15:28:58 +0000 | [diff] [blame] | 75 | if debug: |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 76 | print '! Not a job.kernel' |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 77 | return |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 78 | print '* jobname, kernel version: %s %s' % (jobname, job.kernel.base) |
| 79 | mesgtxt = "\n" |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 80 | for test in job.tests: |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 81 | 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) |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 90 | db.insert_job(jobname, job) |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 91 | db.commit() |
mbligh | fd668245 | 2007-09-30 22:02:02 +0000 | [diff] [blame] | 92 | |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 93 | |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame^] | 94 | |
mbligh | 9ec9485 | 2007-10-25 15:24:16 +0000 | [diff] [blame] | 95 | for (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 | |
mbligh | 2aaeb67 | 2007-10-01 14:54:18 +0000 | [diff] [blame] | 109 | rows = db.select('distinct hostname', 'machines', {}) |
mbligh | fd668245 | 2007-09-30 22:02:02 +0000 | [diff] [blame] | 110 | machines = [row[0] for row in rows] |
| 111 | |
| 112 | for 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) |