blob: 782601704128e84820569b44ebd2ef05e3227ed2 [file] [log] [blame]
Jeremy Ronquillo696f4262017-10-17 10:56:26 -07001# /usr/bin/env python
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002'''
adminbae64d82013-08-01 10:50:15 -07003Created on 07-Jan-2013
Jeremy Ronquillo696f4262017-10-17 10:56:26 -07004Modified 2015 by Open Networking Foundation
Jon Hall81d3d392015-04-24 14:40:35 -07005
Jeremy Songsterae01bba2016-07-11 15:39:17 -07006Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
7the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
8or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
adminbae64d82013-08-01 10:50:15 -07009
10 TestON is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000013 (at your option) any later version.
adminbae64d82013-08-01 10:50:15 -070014
15 TestON is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
Jon Hall81d3d392015-04-24 14:40:35 -070021 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070022
23
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000024'''
25
adminbae64d82013-08-01 10:50:15 -070026import logging
27import datetime
28import re
29import os
Jon Hall43060f62020-06-23 13:13:33 -070030import json
adminbae64d82013-08-01 10:50:15 -070031class Logger:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000032 '''
adminbae64d82013-08-01 10:50:15 -070033 Add continuous logs and reports of the test.
Jon Hall81d3d392015-04-24 14:40:35 -070034
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000035 @author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com)
36 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070037 def _printHeader( self, main ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000038 '''
adminbae64d82013-08-01 10:50:15 -070039 Log's header will be append to the Log file
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000040 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070041 logmsg = "\n" + " " * 32 + "+----------------+\n" + "-" * 30 + " { Script And Files } " + "-" * 30 + "\n" + " " * 32 + "+----------------+\n"
adminbae64d82013-08-01 10:50:15 -070042 logmsg = logmsg + "\n\tScript Log File : " + main.LogFileName + ""
43 logmsg = logmsg + "\n\tReport Log File : " + main.ReportFileName + ""
44 for component in main.componentDictionary.keys():
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070045 logmsg = logmsg + "\n\t" + component + " Session Log : " + main.logdir + "/" + component + ".session" + ""
Jon Hall81d3d392015-04-24 14:40:35 -070046
Jon Halld74d2952018-03-01 13:26:39 -080047 logmsg = logmsg + "\n\tTest Script : " + main.testFile + ""
48 logmsg = logmsg + "\n\tTest Params : " + main.testDir + "/" + main.paramsFile + ""
49 logmsg = logmsg + "\n\tTopology : " + main.testDir + "/" + main.topoFile + ""
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070050 logmsg = logmsg + "\n" + " " * 30 + "+" + "-" * 18 + "+" + "\n" + "-" * 27 + " { Script Exec Params } " + "-" * 27 + "\n" + " " * 30 + "+" + "-" * 18 + "+\n"
Jon Hall43060f62020-06-23 13:13:33 -070051 logmsg += "\n" + json.dumps( main.params, sort_keys=True, indent=4 )
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070052 logmsg = logmsg + "\n\n" + " " * 31 + "+---------------+\n" + "-" * 29 + " { Components Used } " + "-" * 29 + "\n" + " " * 31 + "+---------------+\n"
adminbae64d82013-08-01 10:50:15 -070053 component_list = []
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070054 component_list.append( None )
Jon Hall81d3d392015-04-24 14:40:35 -070055
adminbae64d82013-08-01 10:50:15 -070056 # Listing the components in the order of test_target component should be first.
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070057 if type( main.componentDictionary ) == dict:
adminbae64d82013-08-01 10:50:15 -070058 for key in main.componentDictionary.keys():
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070059 if main.test_target == key:
60 component_list[ 0 ] = key + "-Test Target"
61 else:
62 component_list.append( key )
Jon Hall81d3d392015-04-24 14:40:35 -070063
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070064 for index in range( len( component_list ) ):
65 if index == 0:
66 if component_list[ index ]:
67 logmsg += "\t" + component_list[ index ] + "\n"
68 elif index > 0:
69 logmsg += "\t" + str( component_list[ index ] ) + "\n"
Jon Hall81d3d392015-04-24 14:40:35 -070070
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070071 logmsg = logmsg + "\n\n" + " " * 30 + "+--------+\n" + "-" * 28 + " { Topology } " + "-" * 28 + "\n" + " " * 30 + "+--------+\n"
Jon Hall43060f62020-06-23 13:13:33 -070072 sortedComponents = sorted( main.topology['COMPONENT'].items(), key=lambda (k, v): v[ 'connect_order' ] )
73 logmsg += "\n" + json.dumps( sortedComponents, indent=4 )
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070074 logmsg = logmsg + "\n" + "-" * 60 + "\n"
Jon Hall81d3d392015-04-24 14:40:35 -070075
adminbae64d82013-08-01 10:50:15 -070076 # enter into log file all headers
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070077 logfile = open( main.LogFileName, "w+" )
78 logfile.write( logmsg )
adminbae64d82013-08-01 10:50:15 -070079 print logmsg
80 main.logHeader = logmsg
adminbae64d82013-08-01 10:50:15 -070081 logfile.close()
Jon Hall81d3d392015-04-24 14:40:35 -070082
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070083 # enter into report file all headers
84 main.reportFile = open( main.ReportFileName, "w+" )
85 main.reportFile.write( logmsg )
adminbae64d82013-08-01 10:50:15 -070086 main.reportFile.close()
Jon Hall81d3d392015-04-24 14:40:35 -070087
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070088 # Sumamry file header
89 currentTime = str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
Jon Hall79bec222015-04-30 16:23:30 -070090 main.summaryFile = open( main.SummaryFileName, "w+" )
91 main.summaryFile.write( main.TEST + " at " + currentTime + "\n" )
92 main.summaryFile.close()
93
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070094 # wiki file header
95 currentTime = str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
Jon Hall81d3d392015-04-24 14:40:35 -070096 main.wikiFile = open( main.WikiFileName, "w+" )
Jon Hall79bec222015-04-30 16:23:30 -070097 main.wikiFile.write( main.TEST + " at " + currentTime + "<p></p>\n" )
Jon Hall81d3d392015-04-24 14:40:35 -070098 main.wikiFile.close()
99
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700100 def initlog( self, main ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000101 '''
adminbae64d82013-08-01 10:50:15 -0700102 Initialise all the log handles.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000103 '''
adminbae64d82013-08-01 10:50:15 -0700104 main._getTest()
Jon Hall81d3d392015-04-24 14:40:35 -0700105 main.STARTTIME = datetime.datetime.now()
adminbae64d82013-08-01 10:50:15 -0700106
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700107 currentTime = re.sub( "-|\s|:|\.", "_", str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) ) )
adminbae64d82013-08-01 10:50:15 -0700108 if main.logdir:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700109 main.logdir = main.logdir + "/" + main.TEST + "_" + currentTime
adminbae64d82013-08-01 10:50:15 -0700110 else:
111 main.logdir = main.logs_path + main.TEST + "_" + currentTime
Jon Hall81d3d392015-04-24 14:40:35 -0700112
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700113 os.mkdir( main.logdir )
Jon Hall81d3d392015-04-24 14:40:35 -0700114
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700115 main.LogFileName = main.logdir + "/" + main.TEST + "_" + str( currentTime ) + ".log"
116 main.ReportFileName = main.logdir + "/" + main.TEST + "_" + str( currentTime ) + ".rpt"
Jon Hall79bec222015-04-30 16:23:30 -0700117 main.WikiFileName = main.logdir + "/" + main.TEST + "Wiki.txt"
118 main.SummaryFileName = main.logdir + "/" + main.TEST + "Summary.txt"
Jon Hall94fd0472014-12-08 11:52:42 -0800119 main.JenkinsCSV = main.logdir + "/" + main.TEST + ".csv"
Devin Lim90803a82017-08-29 13:41:44 -0700120 main.resultFile = main.logdir + "/" + main.TEST + "Result.txt"
You Wang28cb8552019-02-19 16:11:52 -0800121 main.alarmFileName = main.logdir + "/" + main.TEST + "Alarm.txt"
Devin Lim90803a82017-08-29 13:41:44 -0700122
You Wangc2e22b22019-02-28 17:11:11 -0800123 main.TOTAL_TC_SUCCESS_PERCENT = 0
Jon Hall81d3d392015-04-24 14:40:35 -0700124
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700125 # Add log-level - Report
126 logging.addLevelName( 9, "REPORT" )
127 logging.addLevelName( 7, "EXACT" )
128 logging.addLevelName( 11, "CASE" )
129 logging.addLevelName( 12, "STEP" )
130 main.log = logging.getLogger( main.TEST )
131
132 def report( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000133 '''
adminbae64d82013-08-01 10:50:15 -0700134 Will append the report message to the logs.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000135 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700136 main.log._log( 9, msg, "OpenFlowAutoMattion", "OFAutoMation" )
adminbae64d82013-08-01 10:50:15 -0700137 currentTime = datetime.datetime.now()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700138 currentTime = currentTime.strftime( "%d %b %Y %H:%M:%S" )
139 newmsg = "\n[REPORT] " + "[" + str( currentTime ) + "] " + msg
adminbae64d82013-08-01 10:50:15 -0700140 print newmsg
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700141 main.reportFile = open( main.ReportFileName, "a+" )
142 main.reportFile.write( newmsg )
adminbae64d82013-08-01 10:50:15 -0700143 main.reportFile.close()
Jon Hall81d3d392015-04-24 14:40:35 -0700144
145 main.log.report = report
146
Jon Hall79bec222015-04-30 16:23:30 -0700147 def summary( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000148 '''
Jon Hall79bec222015-04-30 16:23:30 -0700149 Will append the message to the txt file for the summary.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000150 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700151 main.log._log( 6, msg, "OpenFlowAutoMattion", "OFAutoMation" )
152 main.summaryFile = open( main.SummaryFileName, "a+" )
153 main.summaryFile.write( msg + "\n" )
Jon Hall79bec222015-04-30 16:23:30 -0700154 main.summaryFile.close()
155
156 main.log.summary = summary
157
Jon Hall81d3d392015-04-24 14:40:35 -0700158 def wiki( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000159 '''
Jon Hall81d3d392015-04-24 14:40:35 -0700160 Will append the message to the txt file for the wiki.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000161 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700162 main.log._log( 6, msg, "OpenFlowAutoMattion", "OFAutoMation" )
163 main.wikiFile = open( main.WikiFileName, "a+" )
164 main.wikiFile.write( msg + "\n" )
Jon Hall81d3d392015-04-24 14:40:35 -0700165 main.wikiFile.close()
166
167 main.log.wiki = wiki
168
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700169 def exact( exmsg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000170 '''
adminbae64d82013-08-01 10:50:15 -0700171 Will append the raw formatted message to the logs
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000172 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700173 main.log._log( 7, exmsg, "OpenFlowAutoMattion", "OFAutoMation" )
174 main.reportFile = open( main.ReportFileName, "a+" )
175 main.reportFile.write( exmsg )
adminbae64d82013-08-01 10:50:15 -0700176 main.reportFile.close()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700177 logfile = open( main.LogFileName, "a" )
178 logfile.write( "\n" + str( exmsg ) + "\n" )
adminbae64d82013-08-01 10:50:15 -0700179 logfile.close()
180 print exmsg
Jon Hall81d3d392015-04-24 14:40:35 -0700181
182 main.log.exact = exact
183
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700184 def case( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000185 '''
adminbae64d82013-08-01 10:50:15 -0700186 Format of the case type log defined here.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000187 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700188 main.log._log( 9, msg, "OpenFlowAutoMattion", "OFAutoMation" )
adminbae64d82013-08-01 10:50:15 -0700189 currentTime = datetime.datetime.now()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700190 newmsg = "[" + str( currentTime ) + "] " + "[" + main.TEST + "] " + "[CASE] " + msg
191 logfile = open( main.LogFileName, "a" )
192 logfile.write( "\n" + str( newmsg ) + "\n" )
adminbae64d82013-08-01 10:50:15 -0700193 logfile.close()
194 print newmsg
Jon Hall81d3d392015-04-24 14:40:35 -0700195
Jon Hall4ba53f02015-07-29 13:07:41 -0700196 main.log.case = case
Jon Hall81d3d392015-04-24 14:40:35 -0700197
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700198 def step( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000199 '''
adminbae64d82013-08-01 10:50:15 -0700200 Format of the step type log defined here.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000201 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700202 main.log._log( 9, msg, "OpenFlowAutoMattion", "OFAutoMation" )
adminbae64d82013-08-01 10:50:15 -0700203 currentTime = datetime.datetime.now()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700204 newmsg = "[" + str( currentTime ) + "] " + "[" + main.TEST + "] " + "[STEP] " + msg
205 logfile = open( main.LogFileName, "a" )
206 logfile.write( "\n" + str( newmsg ) + "\n" )
adminbae64d82013-08-01 10:50:15 -0700207 logfile.close()
208 print newmsg
Jon Hall81d3d392015-04-24 14:40:35 -0700209
210 main.log.step = step
211
You Wang28cb8552019-02-19 16:11:52 -0800212 def alarm( msg ):
213 '''
214 Format of the alarm type log defined here.
215 '''
216 main.log._log( 6, msg, "OpenFlowAutoMattion", "OFAutoMation" )
217 main.alarmFile = open( main.alarmFileName, "a+" )
218 main.alarmFile.write( msg + "\n" )
219 main.alarmFile.close()
220
221 main.log.alarm = alarm
222
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700223 main.LogFileHandler = logging.FileHandler( main.LogFileName )
224 self._printHeader( main )
adminbae64d82013-08-01 10:50:15 -0700225
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700226 # initializing logging module and settig log level
227 main.log.setLevel( logging.INFO )
228 main.log.setLevel( logging.DEBUG ) # Temporary
229 main.LogFileHandler.setLevel( logging.INFO )
Jon Hall81d3d392015-04-24 14:40:35 -0700230
adminbae64d82013-08-01 10:50:15 -0700231 # create console handler with a higher log level
232 main.ConsoleHandler = logging.StreamHandler()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700233 main.ConsoleHandler.setLevel( logging.INFO )
234 main.ConsoleHandler.setLevel( logging.DEBUG ) # Temporary
adminbae64d82013-08-01 10:50:15 -0700235 # create formatter and add it to the handlers
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700236 # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
237
Jon Hall0bde9ba2015-03-19 11:32:57 -0700238 class MyFormatter( logging.Formatter ):
239 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
240 'blue': '\033[94m', 'green': '\033[92m',
241 'yellow': '\033[93m', 'red': '\033[91m',
242 'end': '\033[0m' }
243
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700244 FORMATS = { 'DEFAULT': '%(asctime)s - %(name)s - %(levelname)s - %(message)s' }
Jon Hall0bde9ba2015-03-19 11:32:57 -0700245 if COLORS: # NOTE:colors will only be loaded if command is run from one line
246 # IE: './cli.py run testname'
247 # This is to prevent issues with Jenkins parsing
248 # TODO: Make colors configurable
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700249 levels = { logging.ERROR: colors[ 'red' ] +
250 FORMATS[ 'DEFAULT' ] +
251 colors[ 'end' ],
252 logging.WARN: colors[ 'yellow' ] +
253 FORMATS[ 'DEFAULT' ] +
254 colors[ 'end' ],
255 logging.DEBUG: colors[ 'purple' ] +
256 FORMATS[ 'DEFAULT' ] +
257 colors[ 'end' ] }
Jon Hall0bde9ba2015-03-19 11:32:57 -0700258 FORMATS.update( levels )
259
260 def format( self, record ):
261 self._fmt = self.FORMATS.get( record.levelno,
262 self.FORMATS[ 'DEFAULT' ] )
263 return logging.Formatter.format( self, record )
264 formatter = MyFormatter()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700265 main.ConsoleHandler.setFormatter( formatter )
266 main.LogFileHandler.setFormatter( formatter )
adminbae64d82013-08-01 10:50:15 -0700267
268 # add the handlers to logger
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700269 main.log.addHandler( main.ConsoleHandler )
270 main.log.addHandler( main.LogFileHandler )
Jon Hall81d3d392015-04-24 14:40:35 -0700271
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700272 def testSummary( self, main ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000273 '''
adminbae64d82013-08-01 10:50:15 -0700274 testSummary will take care about the Summary of test.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000275 '''
276
adminbae64d82013-08-01 10:50:15 -0700277 main.ENDTIME = datetime.datetime.now()
278 main.EXECTIME = main.ENDTIME - main.STARTTIME
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700279 if ( main.TOTAL_TC_PASS == 0 ):
You Wangc2e22b22019-02-28 17:11:11 -0800280 main.TOTAL_TC_SUCCESS_PERCENT = 0
adminbae64d82013-08-01 10:50:15 -0700281 else:
You Wangc2e22b22019-02-28 17:11:11 -0800282 main.TOTAL_TC_SUCCESS_PERCENT = main.TOTAL_TC_PASS * 100 / main.TOTAL_TC_RUN
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700283 if ( main.TOTAL_TC_RUN == 0 ):
adminbae64d82013-08-01 10:50:15 -0700284 main.TOTAL_TC_EXECPERCENT = 0
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700285 else:
286 main.TOTAL_TC_EXECPERCENT = str( ( main.TOTAL_TC_RUN*100 )/main.TOTAL_TC_PLANNED )
287 testResult = "\n\n" + "*" * 37 + "\n" + "\tTest Execution Summary\n" + "\n" + "*" * 37 + " \n"
288 testResult = testResult + "\n Test Start : " + str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
289 testResult = testResult + "\n Test End : " + str( main.ENDTIME.strftime( "%d %b %Y %H:%M:%S" ) )
290 testResult = testResult + "\n Execution Time : " + str( main.EXECTIME )
You Wangc2e22b22019-02-28 17:11:11 -0800291 testResult = testResult + "\n Total Tests Planned : " + str( main.TOTAL_TC_PLANNED )
292 testResult = testResult + "\n Total Tests Run : " + str( main.TOTAL_TC_RUN )
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700293 testResult = testResult + "\n Total Pass : " + str( main.TOTAL_TC_PASS )
294 testResult = testResult + "\n Total Fail : " + str( main.TOTAL_TC_FAIL )
295 testResult = testResult + "\n Total No Result : " + str( main.TOTAL_TC_NORESULT )
You Wangc2e22b22019-02-28 17:11:11 -0800296 testResult = testResult + "\n Success Percentage : " + str( main.TOTAL_TC_SUCCESS_PERCENT ) + "%"
297 testResult = testResult + "\n Execution Percentage : " + str( main.TOTAL_TC_EXECPERCENT ) + "%\n"
Devin Limec989792017-08-15 15:57:55 -0700298 if main.failedCase:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700299 testResult = testResult + "\n Case Failed : " + str( main.failedCase )
Devin Limec989792017-08-15 15:57:55 -0700300 if main.noResultCase:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700301 testResult = testResult + "\n Case NoResult : " + str( main.noResultCase )
302 testResult = testResult + "\n Case Executed : " + str( main.executedCase )
303 testResult = testResult + "\n Case Not Executed : " + str( main.leftCase )
304 # main.log.report(testResult)
adminbae64d82013-08-01 10:50:15 -0700305 main.testResult = testResult
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700306 main.log.exact( testResult )
Jon Hall94fd0472014-12-08 11:52:42 -0800307
You Wangc2e22b22019-02-28 17:11:11 -0800308 # Write to alarm log if Success Percentage is lower than expected
309 if 'ALARM' in main.params.keys() and 'minPassPercent' in main.params[ 'ALARM' ].keys():
310 minPassPercent = int( main.params[ 'ALARM' ][ 'minPassPercent' ] )
311 if main.TOTAL_TC_SUCCESS_PERCENT < minPassPercent:
312 main.log.alarm( 'Success percentage: {}% < {}%'.format( main.TOTAL_TC_SUCCESS_PERCENT, minPassPercent ) )
313
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700314 # CSV output needed for Jenkin's plot plugin
315 # NOTE: the elements were orded based on the colors assigned to the data
316 logfile = open( main.JenkinsCSV , "w" )
317 logfile.write( ",".join( [ 'Tests Failed', 'Tests Passed', 'Tests Planned' ] ) + "\n" )
318 logfile.write( ",".join( [ str( int( main.TOTAL_TC_FAIL ) ), str( int( main.TOTAL_TC_PASS ) ), str( int( main.TOTAL_TC_PLANNED ) ) ] ) + "\n" )
Jon Hall94fd0472014-12-08 11:52:42 -0800319 logfile.close()
320
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700321 executedStatus = open( main.resultFile, "w" )
Devin Lim90803a82017-08-29 13:41:44 -0700322 if main.TOTAL_TC_FAIL == 0 and main.TOTAL_TC_NORESULT + main.TOTAL_TC_PASS == main.TOTAL_TC_PLANNED:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700323 executedStatus.write( "1\n" )
Devin Lim90803a82017-08-29 13:41:44 -0700324 else:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700325 executedStatus.write( "0\n" )
Devin Lim79af50f2017-10-26 14:26:47 -0700326 executedStatus.write( "[Total]:" + str( main.TOTAL_TC_PLANNED ) + " [Executed]:" + str( main.TOTAL_TC_RUN ) + " [Failed]:" + str( main.TOTAL_TC_FAIL ) + "\n" )
Devin Lim90803a82017-08-29 13:41:44 -0700327 executedStatus.close()
328
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700329 def updateCaseResults( self, main ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000330 '''
adminbae64d82013-08-01 10:50:15 -0700331 Update the case result based on the steps execution and asserting each step in the test-case
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000332 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700333 case = str( main.CurrentTestCaseNumber )
334 currentResult = main.testCaseResult.get( case, 2 )
Jon Hall81d3d392015-04-24 14:40:35 -0700335
Jon Hall79bec222015-04-30 16:23:30 -0700336 if currentResult == 2:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700337 main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
adminbae64d82013-08-01 10:50:15 -0700338 main.TOTAL_TC_NORESULT = main.TOTAL_TC_NORESULT + 1
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700339 main.log.exact( "\n " + "*" * 29 + "\n" + "\n Result: No Assertion Called \n" + "*" * 29 + "\n" )
340 line = "Case " + case + ": " + main.CurrentTestCase + " - No Result"
Jon Hall79bec222015-04-30 16:23:30 -0700341 elif currentResult == 1:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700342 main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
343 main.TOTAL_TC_PASS = main.TOTAL_TC_PASS + 1
344 main.log.exact( "\n" + "*" * 29 + "\n Result: Pass \n" + "*" * 29 + "\n" )
345 line = "Case " + case + ": " + main.CurrentTestCase + " - PASS"
Jon Hall79bec222015-04-30 16:23:30 -0700346 elif currentResult == 0:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700347 main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
adminbae64d82013-08-01 10:50:15 -0700348 main.TOTAL_TC_FAIL = main.TOTAL_TC_FAIL + 1
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700349 main.log.exact( "\n" + "*" * 29 + "\n Result: Failed \n" + "*" * 29 + "\n" )
350 line = "Case " + case + ": " + main.CurrentTestCase + " - FAIL"
Jon Hall79bec222015-04-30 16:23:30 -0700351 else:
352 main.log.error( " Unknown result of case " + case +
353 ". Result was: " + currentResult )
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700354 line = "Case " + case + ": " + main.CurrentTestCase + " - ERROR"
Jon Hall79bec222015-04-30 16:23:30 -0700355 main.log.wiki( "<h3>" + line + "</h3>" )
356 main.log.summary( line )