blob: 263e95baf602d6ca8ea0013ddf60a06fcfb264d7 [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
30class Logger:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000031 '''
adminbae64d82013-08-01 10:50:15 -070032 Add continuous logs and reports of the test.
Jon Hall81d3d392015-04-24 14:40:35 -070033
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000034 @author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com)
35 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070036 def _printHeader( self, main ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000037 '''
adminbae64d82013-08-01 10:50:15 -070038 Log's header will be append to the Log file
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000039 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070040 logmsg = "\n" + " " * 32 + "+----------------+\n" + "-" * 30 + " { Script And Files } " + "-" * 30 + "\n" + " " * 32 + "+----------------+\n"
adminbae64d82013-08-01 10:50:15 -070041 logmsg = logmsg + "\n\tScript Log File : " + main.LogFileName + ""
42 logmsg = logmsg + "\n\tReport Log File : " + main.ReportFileName + ""
43 for component in main.componentDictionary.keys():
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070044 logmsg = logmsg + "\n\t" + component + " Session Log : " + main.logdir + "/" + component + ".session" + ""
Jon Hall81d3d392015-04-24 14:40:35 -070045
Jon Halld74d2952018-03-01 13:26:39 -080046 logmsg = logmsg + "\n\tTest Script : " + main.testFile + ""
47 logmsg = logmsg + "\n\tTest Params : " + main.testDir + "/" + main.paramsFile + ""
48 logmsg = logmsg + "\n\tTopology : " + main.testDir + "/" + main.topoFile + ""
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070049 logmsg = logmsg + "\n" + " " * 30 + "+" + "-" * 18 + "+" + "\n" + "-" * 27 + " { Script Exec Params } " + "-" * 27 + "\n" + " " * 30 + "+" + "-" * 18 + "+\n"
50 values = "\n\t" + str( main.params )
51 values = re.sub( ",", "\n\t", values )
52 values = re.sub( "{", "\n\t", values )
53 values = re.sub( "}", "\n\t", values )
adminbae64d82013-08-01 10:50:15 -070054 logmsg = logmsg + values
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070055 logmsg = logmsg + "\n\n" + " " * 31 + "+---------------+\n" + "-" * 29 + " { Components Used } " + "-" * 29 + "\n" + " " * 31 + "+---------------+\n"
adminbae64d82013-08-01 10:50:15 -070056 component_list = []
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070057 component_list.append( None )
Jon Hall81d3d392015-04-24 14:40:35 -070058
adminbae64d82013-08-01 10:50:15 -070059 # Listing the components in the order of test_target component should be first.
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070060 if type( main.componentDictionary ) == dict:
adminbae64d82013-08-01 10:50:15 -070061 for key in main.componentDictionary.keys():
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070062 if main.test_target == key:
63 component_list[ 0 ] = key + "-Test Target"
64 else:
65 component_list.append( key )
Jon Hall81d3d392015-04-24 14:40:35 -070066
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070067 for index in range( len( component_list ) ):
68 if index == 0:
69 if component_list[ index ]:
70 logmsg += "\t" + component_list[ index ] + "\n"
71 elif index > 0:
72 logmsg += "\t" + str( component_list[ index ] ) + "\n"
Jon Hall81d3d392015-04-24 14:40:35 -070073
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070074 logmsg = logmsg + "\n\n" + " " * 30 + "+--------+\n" + "-" * 28 + " { Topology } " + "-" * 28 + "\n" + " " * 30 + "+--------+\n"
75 values = "\n\t" + str( main.topology[ 'COMPONENT' ] )
76 values = re.sub( ",", "\n\t", values )
77 values = re.sub( "{", "\n\t", values )
78 values = re.sub( "}", "\n\t", values )
adminbae64d82013-08-01 10:50:15 -070079 logmsg = logmsg + values
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070080 logmsg = logmsg + "\n" + "-" * 60 + "\n"
Jon Hall81d3d392015-04-24 14:40:35 -070081
adminbae64d82013-08-01 10:50:15 -070082 # enter into log file all headers
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070083 logfile = open( main.LogFileName, "w+" )
84 logfile.write( logmsg )
adminbae64d82013-08-01 10:50:15 -070085 print logmsg
86 main.logHeader = logmsg
adminbae64d82013-08-01 10:50:15 -070087 logfile.close()
Jon Hall81d3d392015-04-24 14:40:35 -070088
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070089 # enter into report file all headers
90 main.reportFile = open( main.ReportFileName, "w+" )
91 main.reportFile.write( logmsg )
adminbae64d82013-08-01 10:50:15 -070092 main.reportFile.close()
Jon Hall81d3d392015-04-24 14:40:35 -070093
Jeremy Ronquillo696f4262017-10-17 10:56:26 -070094 # Sumamry file header
95 currentTime = str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
Jon Hall79bec222015-04-30 16:23:30 -070096 main.summaryFile = open( main.SummaryFileName, "w+" )
97 main.summaryFile.write( main.TEST + " at " + currentTime + "\n" )
98 main.summaryFile.close()
99
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700100 # wiki file header
101 currentTime = str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
Jon Hall81d3d392015-04-24 14:40:35 -0700102 main.wikiFile = open( main.WikiFileName, "w+" )
Jon Hall79bec222015-04-30 16:23:30 -0700103 main.wikiFile.write( main.TEST + " at " + currentTime + "<p></p>\n" )
Jon Hall81d3d392015-04-24 14:40:35 -0700104 main.wikiFile.close()
105
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700106 def initlog( self, main ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000107 '''
adminbae64d82013-08-01 10:50:15 -0700108 Initialise all the log handles.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000109 '''
adminbae64d82013-08-01 10:50:15 -0700110 main._getTest()
Jon Hall81d3d392015-04-24 14:40:35 -0700111 main.STARTTIME = datetime.datetime.now()
adminbae64d82013-08-01 10:50:15 -0700112
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700113 currentTime = re.sub( "-|\s|:|\.", "_", str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) ) )
adminbae64d82013-08-01 10:50:15 -0700114 if main.logdir:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700115 main.logdir = main.logdir + "/" + main.TEST + "_" + currentTime
adminbae64d82013-08-01 10:50:15 -0700116 else:
117 main.logdir = main.logs_path + main.TEST + "_" + currentTime
Jon Hall81d3d392015-04-24 14:40:35 -0700118
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700119 os.mkdir( main.logdir )
Jon Hall81d3d392015-04-24 14:40:35 -0700120
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700121 main.LogFileName = main.logdir + "/" + main.TEST + "_" + str( currentTime ) + ".log"
122 main.ReportFileName = main.logdir + "/" + main.TEST + "_" + str( currentTime ) + ".rpt"
Jon Hall79bec222015-04-30 16:23:30 -0700123 main.WikiFileName = main.logdir + "/" + main.TEST + "Wiki.txt"
124 main.SummaryFileName = main.logdir + "/" + main.TEST + "Summary.txt"
Jon Hall94fd0472014-12-08 11:52:42 -0800125 main.JenkinsCSV = main.logdir + "/" + main.TEST + ".csv"
Devin Lim90803a82017-08-29 13:41:44 -0700126 main.resultFile = main.logdir + "/" + main.TEST + "Result.txt"
You Wang28cb8552019-02-19 16:11:52 -0800127 main.alarmFileName = main.logdir + "/" + main.TEST + "Alarm.txt"
Devin Lim90803a82017-08-29 13:41:44 -0700128
You Wangc2e22b22019-02-28 17:11:11 -0800129 main.TOTAL_TC_SUCCESS_PERCENT = 0
Jon Hall81d3d392015-04-24 14:40:35 -0700130
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700131 # Add log-level - Report
132 logging.addLevelName( 9, "REPORT" )
133 logging.addLevelName( 7, "EXACT" )
134 logging.addLevelName( 11, "CASE" )
135 logging.addLevelName( 12, "STEP" )
136 main.log = logging.getLogger( main.TEST )
137
138 def report( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000139 '''
adminbae64d82013-08-01 10:50:15 -0700140 Will append the report message to the logs.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000141 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700142 main.log._log( 9, msg, "OpenFlowAutoMattion", "OFAutoMation" )
adminbae64d82013-08-01 10:50:15 -0700143 currentTime = datetime.datetime.now()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700144 currentTime = currentTime.strftime( "%d %b %Y %H:%M:%S" )
145 newmsg = "\n[REPORT] " + "[" + str( currentTime ) + "] " + msg
adminbae64d82013-08-01 10:50:15 -0700146 print newmsg
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700147 main.reportFile = open( main.ReportFileName, "a+" )
148 main.reportFile.write( newmsg )
adminbae64d82013-08-01 10:50:15 -0700149 main.reportFile.close()
Jon Hall81d3d392015-04-24 14:40:35 -0700150
151 main.log.report = report
152
Jon Hall79bec222015-04-30 16:23:30 -0700153 def summary( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000154 '''
Jon Hall79bec222015-04-30 16:23:30 -0700155 Will append the message to the txt file for the summary.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000156 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700157 main.log._log( 6, msg, "OpenFlowAutoMattion", "OFAutoMation" )
158 main.summaryFile = open( main.SummaryFileName, "a+" )
159 main.summaryFile.write( msg + "\n" )
Jon Hall79bec222015-04-30 16:23:30 -0700160 main.summaryFile.close()
161
162 main.log.summary = summary
163
Jon Hall81d3d392015-04-24 14:40:35 -0700164 def wiki( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000165 '''
Jon Hall81d3d392015-04-24 14:40:35 -0700166 Will append the message to the txt file for the wiki.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000167 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700168 main.log._log( 6, msg, "OpenFlowAutoMattion", "OFAutoMation" )
169 main.wikiFile = open( main.WikiFileName, "a+" )
170 main.wikiFile.write( msg + "\n" )
Jon Hall81d3d392015-04-24 14:40:35 -0700171 main.wikiFile.close()
172
173 main.log.wiki = wiki
174
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700175 def exact( exmsg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000176 '''
adminbae64d82013-08-01 10:50:15 -0700177 Will append the raw formatted message to the logs
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000178 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700179 main.log._log( 7, exmsg, "OpenFlowAutoMattion", "OFAutoMation" )
180 main.reportFile = open( main.ReportFileName, "a+" )
181 main.reportFile.write( exmsg )
adminbae64d82013-08-01 10:50:15 -0700182 main.reportFile.close()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700183 logfile = open( main.LogFileName, "a" )
184 logfile.write( "\n" + str( exmsg ) + "\n" )
adminbae64d82013-08-01 10:50:15 -0700185 logfile.close()
186 print exmsg
Jon Hall81d3d392015-04-24 14:40:35 -0700187
188 main.log.exact = exact
189
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700190 def case( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000191 '''
adminbae64d82013-08-01 10:50:15 -0700192 Format of the case type log defined here.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000193 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700194 main.log._log( 9, msg, "OpenFlowAutoMattion", "OFAutoMation" )
adminbae64d82013-08-01 10:50:15 -0700195 currentTime = datetime.datetime.now()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700196 newmsg = "[" + str( currentTime ) + "] " + "[" + main.TEST + "] " + "[CASE] " + msg
197 logfile = open( main.LogFileName, "a" )
198 logfile.write( "\n" + str( newmsg ) + "\n" )
adminbae64d82013-08-01 10:50:15 -0700199 logfile.close()
200 print newmsg
Jon Hall81d3d392015-04-24 14:40:35 -0700201
Jon Hall4ba53f02015-07-29 13:07:41 -0700202 main.log.case = case
Jon Hall81d3d392015-04-24 14:40:35 -0700203
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700204 def step( msg ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000205 '''
adminbae64d82013-08-01 10:50:15 -0700206 Format of the step type log defined here.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000207 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700208 main.log._log( 9, msg, "OpenFlowAutoMattion", "OFAutoMation" )
adminbae64d82013-08-01 10:50:15 -0700209 currentTime = datetime.datetime.now()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700210 newmsg = "[" + str( currentTime ) + "] " + "[" + main.TEST + "] " + "[STEP] " + msg
211 logfile = open( main.LogFileName, "a" )
212 logfile.write( "\n" + str( newmsg ) + "\n" )
adminbae64d82013-08-01 10:50:15 -0700213 logfile.close()
214 print newmsg
Jon Hall81d3d392015-04-24 14:40:35 -0700215
216 main.log.step = step
217
You Wang28cb8552019-02-19 16:11:52 -0800218 def alarm( msg ):
219 '''
220 Format of the alarm type log defined here.
221 '''
222 main.log._log( 6, msg, "OpenFlowAutoMattion", "OFAutoMation" )
223 main.alarmFile = open( main.alarmFileName, "a+" )
224 main.alarmFile.write( msg + "\n" )
225 main.alarmFile.close()
226
227 main.log.alarm = alarm
228
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700229 main.LogFileHandler = logging.FileHandler( main.LogFileName )
230 self._printHeader( main )
adminbae64d82013-08-01 10:50:15 -0700231
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700232 # initializing logging module and settig log level
233 main.log.setLevel( logging.INFO )
234 main.log.setLevel( logging.DEBUG ) # Temporary
235 main.LogFileHandler.setLevel( logging.INFO )
Jon Hall81d3d392015-04-24 14:40:35 -0700236
adminbae64d82013-08-01 10:50:15 -0700237 # create console handler with a higher log level
238 main.ConsoleHandler = logging.StreamHandler()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700239 main.ConsoleHandler.setLevel( logging.INFO )
240 main.ConsoleHandler.setLevel( logging.DEBUG ) # Temporary
adminbae64d82013-08-01 10:50:15 -0700241 # create formatter and add it to the handlers
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700242 # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
243
Jon Hall0bde9ba2015-03-19 11:32:57 -0700244 class MyFormatter( logging.Formatter ):
245 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
246 'blue': '\033[94m', 'green': '\033[92m',
247 'yellow': '\033[93m', 'red': '\033[91m',
248 'end': '\033[0m' }
249
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700250 FORMATS = { 'DEFAULT': '%(asctime)s - %(name)s - %(levelname)s - %(message)s' }
Jon Hall0bde9ba2015-03-19 11:32:57 -0700251 if COLORS: # NOTE:colors will only be loaded if command is run from one line
252 # IE: './cli.py run testname'
253 # This is to prevent issues with Jenkins parsing
254 # TODO: Make colors configurable
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700255 levels = { logging.ERROR: colors[ 'red' ] +
256 FORMATS[ 'DEFAULT' ] +
257 colors[ 'end' ],
258 logging.WARN: colors[ 'yellow' ] +
259 FORMATS[ 'DEFAULT' ] +
260 colors[ 'end' ],
261 logging.DEBUG: colors[ 'purple' ] +
262 FORMATS[ 'DEFAULT' ] +
263 colors[ 'end' ] }
Jon Hall0bde9ba2015-03-19 11:32:57 -0700264 FORMATS.update( levels )
265
266 def format( self, record ):
267 self._fmt = self.FORMATS.get( record.levelno,
268 self.FORMATS[ 'DEFAULT' ] )
269 return logging.Formatter.format( self, record )
270 formatter = MyFormatter()
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700271 main.ConsoleHandler.setFormatter( formatter )
272 main.LogFileHandler.setFormatter( formatter )
adminbae64d82013-08-01 10:50:15 -0700273
274 # add the handlers to logger
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700275 main.log.addHandler( main.ConsoleHandler )
276 main.log.addHandler( main.LogFileHandler )
Jon Hall81d3d392015-04-24 14:40:35 -0700277
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700278 def testSummary( self, main ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000279 '''
adminbae64d82013-08-01 10:50:15 -0700280 testSummary will take care about the Summary of test.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000281 '''
282
adminbae64d82013-08-01 10:50:15 -0700283 main.ENDTIME = datetime.datetime.now()
284 main.EXECTIME = main.ENDTIME - main.STARTTIME
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700285 if ( main.TOTAL_TC_PASS == 0 ):
You Wangc2e22b22019-02-28 17:11:11 -0800286 main.TOTAL_TC_SUCCESS_PERCENT = 0
adminbae64d82013-08-01 10:50:15 -0700287 else:
You Wangc2e22b22019-02-28 17:11:11 -0800288 main.TOTAL_TC_SUCCESS_PERCENT = main.TOTAL_TC_PASS * 100 / main.TOTAL_TC_RUN
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700289 if ( main.TOTAL_TC_RUN == 0 ):
adminbae64d82013-08-01 10:50:15 -0700290 main.TOTAL_TC_EXECPERCENT = 0
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700291 else:
292 main.TOTAL_TC_EXECPERCENT = str( ( main.TOTAL_TC_RUN*100 )/main.TOTAL_TC_PLANNED )
293 testResult = "\n\n" + "*" * 37 + "\n" + "\tTest Execution Summary\n" + "\n" + "*" * 37 + " \n"
294 testResult = testResult + "\n Test Start : " + str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
295 testResult = testResult + "\n Test End : " + str( main.ENDTIME.strftime( "%d %b %Y %H:%M:%S" ) )
296 testResult = testResult + "\n Execution Time : " + str( main.EXECTIME )
You Wangc2e22b22019-02-28 17:11:11 -0800297 testResult = testResult + "\n Total Tests Planned : " + str( main.TOTAL_TC_PLANNED )
298 testResult = testResult + "\n Total Tests Run : " + str( main.TOTAL_TC_RUN )
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700299 testResult = testResult + "\n Total Pass : " + str( main.TOTAL_TC_PASS )
300 testResult = testResult + "\n Total Fail : " + str( main.TOTAL_TC_FAIL )
301 testResult = testResult + "\n Total No Result : " + str( main.TOTAL_TC_NORESULT )
You Wangc2e22b22019-02-28 17:11:11 -0800302 testResult = testResult + "\n Success Percentage : " + str( main.TOTAL_TC_SUCCESS_PERCENT ) + "%"
303 testResult = testResult + "\n Execution Percentage : " + str( main.TOTAL_TC_EXECPERCENT ) + "%\n"
Devin Limec989792017-08-15 15:57:55 -0700304 if main.failedCase:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700305 testResult = testResult + "\n Case Failed : " + str( main.failedCase )
Devin Limec989792017-08-15 15:57:55 -0700306 if main.noResultCase:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700307 testResult = testResult + "\n Case NoResult : " + str( main.noResultCase )
308 testResult = testResult + "\n Case Executed : " + str( main.executedCase )
309 testResult = testResult + "\n Case Not Executed : " + str( main.leftCase )
310 # main.log.report(testResult)
adminbae64d82013-08-01 10:50:15 -0700311 main.testResult = testResult
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700312 main.log.exact( testResult )
Jon Hall94fd0472014-12-08 11:52:42 -0800313
You Wangc2e22b22019-02-28 17:11:11 -0800314 # Write to alarm log if Success Percentage is lower than expected
315 if 'ALARM' in main.params.keys() and 'minPassPercent' in main.params[ 'ALARM' ].keys():
316 minPassPercent = int( main.params[ 'ALARM' ][ 'minPassPercent' ] )
317 if main.TOTAL_TC_SUCCESS_PERCENT < minPassPercent:
318 main.log.alarm( 'Success percentage: {}% < {}%'.format( main.TOTAL_TC_SUCCESS_PERCENT, minPassPercent ) )
319
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700320 # CSV output needed for Jenkin's plot plugin
321 # NOTE: the elements were orded based on the colors assigned to the data
322 logfile = open( main.JenkinsCSV , "w" )
323 logfile.write( ",".join( [ 'Tests Failed', 'Tests Passed', 'Tests Planned' ] ) + "\n" )
324 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 -0800325 logfile.close()
326
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700327 executedStatus = open( main.resultFile, "w" )
Devin Lim90803a82017-08-29 13:41:44 -0700328 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 -0700329 executedStatus.write( "1\n" )
Devin Lim90803a82017-08-29 13:41:44 -0700330 else:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700331 executedStatus.write( "0\n" )
Devin Lim79af50f2017-10-26 14:26:47 -0700332 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 -0700333 executedStatus.close()
334
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700335 def updateCaseResults( self, main ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000336 '''
adminbae64d82013-08-01 10:50:15 -0700337 Update the case result based on the steps execution and asserting each step in the test-case
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000338 '''
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700339 case = str( main.CurrentTestCaseNumber )
340 currentResult = main.testCaseResult.get( case, 2 )
Jon Hall81d3d392015-04-24 14:40:35 -0700341
Jon Hall79bec222015-04-30 16:23:30 -0700342 if currentResult == 2:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700343 main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
adminbae64d82013-08-01 10:50:15 -0700344 main.TOTAL_TC_NORESULT = main.TOTAL_TC_NORESULT + 1
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700345 main.log.exact( "\n " + "*" * 29 + "\n" + "\n Result: No Assertion Called \n" + "*" * 29 + "\n" )
346 line = "Case " + case + ": " + main.CurrentTestCase + " - No Result"
Jon Hall79bec222015-04-30 16:23:30 -0700347 elif currentResult == 1:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700348 main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
349 main.TOTAL_TC_PASS = main.TOTAL_TC_PASS + 1
350 main.log.exact( "\n" + "*" * 29 + "\n Result: Pass \n" + "*" * 29 + "\n" )
351 line = "Case " + case + ": " + main.CurrentTestCase + " - PASS"
Jon Hall79bec222015-04-30 16:23:30 -0700352 elif currentResult == 0:
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700353 main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
adminbae64d82013-08-01 10:50:15 -0700354 main.TOTAL_TC_FAIL = main.TOTAL_TC_FAIL + 1
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700355 main.log.exact( "\n" + "*" * 29 + "\n Result: Failed \n" + "*" * 29 + "\n" )
356 line = "Case " + case + ": " + main.CurrentTestCase + " - FAIL"
Jon Hall79bec222015-04-30 16:23:30 -0700357 else:
358 main.log.error( " Unknown result of case " + case +
359 ". Result was: " + currentResult )
Jeremy Ronquillo696f4262017-10-17 10:56:26 -0700360 line = "Case " + case + ": " + main.CurrentTestCase + " - ERROR"
Jon Hall79bec222015-04-30 16:23:30 -0700361 main.log.wiki( "<h3>" + line + "</h3>" )
362 main.log.summary( line )