blob: 859612d81108d7fb082584e42954998c414c0e26 [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 Hallbdc8e5a2015-02-04 15:59:56 -0800104 page_name = "Master+-+HA"
105 if "ONOS-HA-Maint" in job:
106 page_name = "1.0+-+HA"
Jon Hall66a816c2015-01-27 11:13:27 -0800107
108 header += "<li><a href=\'#" + str(page_name) + str(test) + "\'> " + str(test) + " - Results: " + str(passes) + " Passed, " + str(fails) + " Failed</a></li>"
109
110 #*********************
111 #include any other phrase specific to case you would like to include in wiki here
112 if test == "IntentPerf":
113 output += "URL to Historical Performance results data: <a href='http://10.128.5.54perf.html'>Perf Graph</a>"
114 #*********************
115
116#header_file = open("/tmp/header_ha.txt",'w')
117#header_file.write(header)
118output = header + graphs + output
119print output