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