blob: 181e1a960d5f04387017ac3ce6f6d8cea8728997 [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
Jon Hall390696c2015-05-05 17:13:41 -07009import glob
Jon Hall66a816c2015-01-27 11:13:27 -080010import shutil
11
12parser = argparse.ArgumentParser()
13parser.add_argument("-n", "--name", help="Comma Separated string of test names. Ex: --name='test1, test2, test3'")
14parser.add_argument("-w", "--workspace", help="The name of the Jenkin's job/workspace where csv files will be saved'")
15args = parser.parse_args()
16
17#Pass in test names as a comma separated string argument.
18#Example: ./Jenkins_getresult.py "Test1,Test2,Test3,Test4"
19name_list = args.name.split(",")
20result_list = map(lambda x: x.strip(), name_list)
21job = args.workspace
22if job is None:
23 job = ""
24print job
25
26#NOTE: testnames list should be in order in which it is run
27testnames = result_list
28output = ''
29header = ''
30graphs = ''
31testdate = datetime.datetime.now()
32#workspace = "/var/lib/jenkins/workspace/ONOS-HA"
33workspace = "/var/lib/jenkins/workspace/"
34workspace = workspace + job
35
36header +="<p>**************************************</p>"
37header +=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
43if 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 Hall390696c2015-05-05 17:13:41 -070047 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 Hall66a816c2015-01-27 11:13:27 -080051 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
60for 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 Hall390696c2015-05-05 17:13:41 -070067 for csvFile in glob.glob( path + '*.csv' ):
68 shutil.copy( csvFile, workspace )
Jon Hall66a816c2015-01-27 11:13:27 -080069 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 Hall5cfd23c2015-03-19 11:40:57 -070075 #Open the latest log folder
Jon Hall66a816c2015-01-27 11:13:27 -080076 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 Hall21270ac2015-02-16 17:59:55 -0800106 page_name = "Master-HA"
Jon Hall5cfd23c2015-03-19 11:40:57 -0700107 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 Hall21270ac2015-02-16 17:59:55 -0800112 page_name = "id-1.0-HA"
Jon Hall66a816c2015-01-27 11:13:27 -0800113
Jon Hallae4d1d72015-02-18 13:26:54 -0800114 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 -0800115
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)
124output = header + graphs + output
125print output