Jon Hall | 66a816c | 2015-01-27 11:13:27 -0800 | [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 | import shutil |
| 10 | |
| 11 | parser = argparse.ArgumentParser() |
| 12 | parser.add_argument("-n", "--name", help="Comma Separated string of test names. Ex: --name='test1, test2, test3'") |
| 13 | parser.add_argument("-w", "--workspace", help="The name of the Jenkin's job/workspace where csv files will be saved'") |
| 14 | args = parser.parse_args() |
| 15 | |
| 16 | #Pass in test names as a comma separated string argument. |
| 17 | #Example: ./Jenkins_getresult.py "Test1,Test2,Test3,Test4" |
| 18 | name_list = args.name.split(",") |
| 19 | result_list = map(lambda x: x.strip(), name_list) |
| 20 | job = args.workspace |
| 21 | if job is None: |
| 22 | job = "" |
| 23 | print job |
| 24 | |
| 25 | #NOTE: testnames list should be in order in which it is run |
| 26 | testnames = result_list |
| 27 | output = '' |
| 28 | header = '' |
| 29 | graphs = '' |
| 30 | testdate = datetime.datetime.now() |
| 31 | #workspace = "/var/lib/jenkins/workspace/ONOS-HA" |
| 32 | workspace = "/var/lib/jenkins/workspace/" |
| 33 | workspace = workspace + job |
| 34 | |
| 35 | header +="<p>**************************************</p>" |
| 36 | header +=testdate.strftime('Jenkins test result for %H:%M on %b %d, %Y. %Z') |
| 37 | |
| 38 | |
| 39 | #NOTE: CASE SPECIFIC THINGS |
| 40 | |
| 41 | #THIS LINE IS LOUSY FIXME |
| 42 | if any("HA" in s for s in testnames): |
| 43 | ##Graphs |
| 44 | graphs += '<ac:structured-macro ac:name="html">\n' |
| 45 | graphs += '<ac:plain-text-body><![CDATA[\n' |
| 46 | graphs += '<iframe src="https://onos-jenkins.onlab.us/job/'+job+'/plot/getPlot?index=2&width=500&height=300" noborder="0" width="500" height="300" scrolling="yes" seamless="seamless"></iframe>\n' |
| 47 | graphs += '<iframe src="https://onos-jenkins.onlab.us/job/'+job+'/plot/getPlot?index=1&width=500&height=300" noborder="0" width="500" height="300" scrolling="yes" seamless="seamless"></iframe>\n' |
| 48 | graphs += '<iframe src="https://onos-jenkins.onlab.us/job/'+job+'/plot/getPlot?index=0&width=500&height=300" noborder="0" width="500" height="300" scrolling="yes" seamless="seamless"></iframe>\n' |
| 49 | graphs += '<iframe src="https://onos-jenkins.onlab.us/job/'+job+'/plot/getPlot?index=3&width=500&height=300" noborder="0" width="500" height="300" scrolling="yes" seamless="seamless"></iframe>\n' |
| 50 | graphs += ']]></ac:plain-text-body>\n' |
| 51 | graphs += '</ac:structured-macro>\n' |
| 52 | header +="<p> <a href='https://wiki.onosproject.org/display/OST/Test+Plan+-+HA'>Test Plan for HA Test Cases</a></p>" |
| 53 | |
| 54 | |
| 55 | # *** |
| 56 | |
| 57 | |
| 58 | #TestON reporting |
| 59 | for test in testnames: |
| 60 | passes = 0 |
| 61 | fails = 0 |
| 62 | name = os.popen("ls /home/admin/ONLabTest/TestON/logs/ -rt | grep %s_ | tail -1" % test).read().split()[0] |
| 63 | path = "/home/admin/ONLabTest/TestON/logs/" + name + "/" |
| 64 | try: |
| 65 | #IF exists, move the csv file to the workspace |
| 66 | shutil.copy(path + test + ".csv", workspace) |
| 67 | except IOError: |
| 68 | #File probably doesn't exist |
| 69 | pass |
| 70 | |
| 71 | output +="<p></p>" |
| 72 | #output +=" Date: %s, %s %s" % (name.split("_")[2], name.split("_")[1], name.split("_")[3]) + "<p>*******************<p>" |
| 73 | #Open the latest log folder |
| 74 | output += "<h2>Test "+str(test)+"</h2><p>************************************</p>" |
| 75 | |
| 76 | f = open(path + name + ".rpt") |
| 77 | |
| 78 | #Parse through each line of logs and look for specific strings to output to wiki. |
| 79 | #NOTE: with current implementation, you must specify which output to output to wiki by using |
| 80 | #main.log.report("") since it is looking for the [REPORT] tag in the logs |
| 81 | for line in f: |
| 82 | if re.search("Result summary for Testcase", line): |
| 83 | output += "<h3>"+str(line)+"</h3>" |
| 84 | #output += "<br>" |
| 85 | if re.search("\[REPORT\]", line): |
| 86 | line_split = line.split("] ") |
| 87 | #line string is split by bracket, and first two items (log tags) in list are omitted from output |
| 88 | #join is used to convert list to string |
| 89 | line_str = ''.join(line_split[2:]) |
| 90 | output += "<p>" |
| 91 | output += line_str |
| 92 | output += "</p>" |
| 93 | if re.search("Result:", line): |
| 94 | output += "<p>" |
| 95 | output += line |
| 96 | output += "</p>" |
| 97 | if re.search("Pass", line): |
| 98 | passes = passes + 1 |
| 99 | elif re.search("Fail", line): |
| 100 | fails = fails + 1 |
| 101 | f.close() |
| 102 | #https://wiki.onosproject.org/display/OST/Test+Results+-+HA#Test+Results+-+HA |
| 103 | #Example anchor on new wiki: #TestResults-HA-TestHATestSanity |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 104 | page_name = "Master-HA" |
Jon Hall | bdc8e5a | 2015-02-04 15:59:56 -0800 | [diff] [blame] | 105 | if "ONOS-HA-Maint" in job: |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 106 | #NOTE if page name starts with number it prepends 'id-' to anchor links |
| 107 | page_name = "id-1.0-HA" |
Jon Hall | 66a816c | 2015-01-27 11:13:27 -0800 | [diff] [blame] | 108 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 109 | header += "<li><a href=\'#" + str(page_name) + "-" + str(test) + "\'> " + str(test) + " - Results: " + str(passes) + " Passed, " + str(fails) + " Failed</a></li>" |
Jon Hall | 66a816c | 2015-01-27 11:13:27 -0800 | [diff] [blame] | 110 | |
| 111 | #********************* |
| 112 | #include any other phrase specific to case you would like to include in wiki here |
| 113 | if test == "IntentPerf": |
| 114 | output += "URL to Historical Performance results data: <a href='http://10.128.5.54perf.html'>Perf Graph</a>" |
| 115 | #********************* |
| 116 | |
| 117 | #header_file = open("/tmp/header_ha.txt",'w') |
| 118 | #header_file.write(header) |
| 119 | output = header + graphs + output |
| 120 | print output |