andrewonlab | 5cbb3cd | 2014-11-18 14:25:40 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | import re |
| 6 | import datetime |
| 7 | import time |
| 8 | import argparse |
| 9 | |
| 10 | parser = argparse.ArgumentParser() |
| 11 | parser.add_argument("-n", "--name", help="Comma Separated string of test names. Ex: --name='test1, test2, test3'") |
| 12 | args = parser.parse_args() |
| 13 | |
| 14 | #Pass in test names as a comma separated string argument. |
| 15 | #Example: ./Jenkins_getresult.py "Test1,Test2,Test3,Test4" |
| 16 | name_list = args.name.split(",") |
| 17 | result_list = map(lambda x: x.strip(), name_list) |
| 18 | |
| 19 | #NOTE: testnames list should be in order in which it is run |
| 20 | testnames = result_list |
| 21 | output = '' |
| 22 | testdate = datetime.datetime.now() |
| 23 | |
| 24 | output +="<p>**************************************</p>" |
| 25 | output +=testdate.strftime('Jenkins test result for %H:%M on %b %d, %Y. %Z') |
| 26 | |
| 27 | #TestON reporting |
| 28 | for test in testnames: |
| 29 | name = os.popen("ls /home/admin/ONLabTest/TestON/logs/ -rt | grep %s | tail -1" % test).read().split()[0] |
| 30 | path = "/home/admin/ONLabTest/TestON/logs/" + name + "/" |
| 31 | output +="<p></p>" |
| 32 | #output +=" Date: %s, %s %s" % (name.split("_")[2], name.split("_")[1], name.split("_")[3]) + "<br>*******************<br>" |
| 33 | #Open the latest log folder |
| 34 | output += "<h2>Test "+str(test)+"</h2><p>************************************</p>" |
| 35 | |
| 36 | f = open(path + name + ".rpt") |
| 37 | |
| 38 | #Parse through each line of logs and look for specific strings to output to wiki. |
| 39 | #NOTE: with current implementation, you must specify which output to output to wiki by using |
| 40 | #main.log.report("") since it is looking for the [REPORT] tag in the logs |
| 41 | for line in f: |
| 42 | if re.search("Result summary for Testcase", line): |
| 43 | output += "<h3>"+str(line)+"</h3>" |
| 44 | #output += "<br>" |
| 45 | if re.search("\[REPORT\]", line): |
| 46 | line_split = line.split("] ") |
| 47 | #line string is split by bracket, and first two items (log tags) in list are omitted from output |
| 48 | #join is used to convert list to string |
| 49 | line_str = ''.join(line_split[2:]) |
| 50 | output += "<p>" |
| 51 | output += line_str |
| 52 | output += "</p>" |
| 53 | if re.search("Result:", line): |
| 54 | output += "<p>" |
| 55 | output += line |
| 56 | output += "</p>" |
| 57 | f.close() |
| 58 | |
| 59 | #********************* |
| 60 | #include any other phrase specific to case you would like to include in wiki here |
| 61 | if test == "IntentPerf": |
| 62 | output += "URL to Historical Performance results data: <a href='http://10.128.5.54/perf.html'>Perf Graph</a>" |
| 63 | #********************* |
| 64 | print output |