blob: 9cb3b8b59775179e1bc5bb3702bfb62ee58611dc [file] [log] [blame]
Jon Hall66a816c2015-01-27 11:13:27 -08001#!/usr/bin/env python
2
3import sys
4import os
5import re
6import datetime
7import time
8import argparse
9import shutil
10
11parser = argparse.ArgumentParser()
12parser.add_argument("-n", "--name", help="Comma Separated string of test names. Ex: --name='test1, test2, test3'")
13parser.add_argument("-w", "--workspace", help="The name of the Jenkin's job/workspace where csv files will be saved'")
14args = parser.parse_args()
15
16#Pass in test names as a comma separated string argument.
17#Example: ./Jenkins_getresult.py "Test1,Test2,Test3,Test4"
18name_list = args.name.split(",")
19result_list = map(lambda x: x.strip(), name_list)
20job = args.workspace
21if job is None:
22 job = ""
23print job
24
25#NOTE: testnames list should be in order in which it is run
26testnames = result_list
27output = ''
28header = ''
29graphs = ''
30testdate = datetime.datetime.now()
31#workspace = "/var/lib/jenkins/workspace/ONOS-HA"
32workspace = "/var/lib/jenkins/workspace/"
33workspace = workspace + job
34
35header +="<p>**************************************</p>"
36header +=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
42if 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
59for 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 Hall21270ac2015-02-16 17:59:55 -0800104 page_name = "Master-HA"
Jon Hallbdc8e5a2015-02-04 15:59:56 -0800105 if "ONOS-HA-Maint" in job:
Jon Hall21270ac2015-02-16 17:59:55 -0800106 #NOTE if page name starts with number it prepends 'id-' to anchor links
107 page_name = "id-1.0-HA"
Jon Hall66a816c2015-01-27 11:13:27 -0800108
Jon Hallae4d1d72015-02-18 13:26:54 -0800109 header += "<li><a href=\'#" + str(page_name) + "-Test" + str(test) + "\'> " + str(test) + " - Results: " + str(passes) + " Passed, " + str(fails) + " Failed</a></li>"
Jon Hall66a816c2015-01-27 11:13:27 -0800110
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)
119output = header + graphs + output
120print output