blob: 559f84d09ba8627c7f9be3328e2ec8e346ad259f [file] [log] [blame]
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07001# /usr/bin/env python
2"""
adminbae64d82013-08-01 10:50:15 -07003Created on 07-Jan-2013
Jeremy Songsterae01bba2016-07-11 15:39:17 -07004Modified 2015 by ON.Lab
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 Ronquillo23fb2162017-09-15 14:59:57 -070013 ( 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 Ronquillo23fb2162017-09-15 14:59:57 -070024"""
adminbae64d82013-08-01 10:50:15 -070025import logging
26import datetime
27import re
28import os
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070029
30
adminbae64d82013-08-01 10:50:15 -070031class Logger:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070032
33 """
adminbae64d82013-08-01 10:50:15 -070034 Add continuous logs and reports of the test.
Jon Hall81d3d392015-04-24 14:40:35 -070035
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070036 author:: Raghav Kashyap( raghavkashyap@paxterrasolutions.com )
37 """
38 def _printHeader( self, main ):
39 """
adminbae64d82013-08-01 10:50:15 -070040 Log's header will be append to the Log file
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070041 """
42 logmsg = "\n" + " " * 32 + "+----------------+\n" + "-" * 30 + " { Script And Files } " + "-" * 30 + "\n" + " " * 32 + "+----------------+\n"
adminbae64d82013-08-01 10:50:15 -070043 logmsg = logmsg + "\n\tScript Log File : " + main.LogFileName + ""
44 logmsg = logmsg + "\n\tReport Log File : " + main.ReportFileName + ""
45 for component in main.componentDictionary.keys():
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070046 logmsg = logmsg + "\n\t" + component + " Session Log : " + main.logdir + "/" + component + ".session" + ""
Jon Hall81d3d392015-04-24 14:40:35 -070047
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070048 logmsg = logmsg + "\n\tTest Script :" + path + "Tests/" + main.TEST + ".py" + ""
adminbae64d82013-08-01 10:50:15 -070049 logmsg = logmsg + "\n\tTest Params : " + path + "Tests/" + main.TEST + ".params" + ""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070050 logmsg = logmsg + "\n\tTopology : " + path + "Tests/" + main.TEST + ".topo" + ""
51 logmsg = logmsg + "\n" + " " * 30 + "+" + "-" * 18 + "+" + "\n" + "-" * 27 + " { Script Exec Params } " + "-" * 27 + "\n" + " " * 30 + "+" + "-" * 18 + "+\n"
52 values = "\n\t" + str( main.params )
53 values = re.sub( ",", "\n\t", values )
54 values = re.sub( "{", "\n\t", values )
55 values = re.sub( "}", "\n\t", values )
adminbae64d82013-08-01 10:50:15 -070056 logmsg = logmsg + values
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070057 logmsg = logmsg + "\n\n" + " " * 31 + "+---------------+\n" + "-" * 29 + " { Components Used } " + "-" * 29 + "\n" + " " * 31 + "+---------------+\n"
adminbae64d82013-08-01 10:50:15 -070058 component_list = []
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070059 component_list.append( None )
Jon Hall81d3d392015-04-24 14:40:35 -070060
adminbae64d82013-08-01 10:50:15 -070061 # Listing the components in the order of test_target component should be first.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070062 if isinstance( main.componentDictionary, dict ):
adminbae64d82013-08-01 10:50:15 -070063 for key in main.componentDictionary.keys():
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070064 if main.test_target == key:
65 component_list[ 0 ] = key + "-Test Target"
66 else:
67 component_list.append( key )
Jon Hall81d3d392015-04-24 14:40:35 -070068
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070069 for index in range( len( component_list ) ):
70 if index == 0:
71 if component_list[ index ]:
72 logmsg += "\t" + component_list[ index ] + "\n"
73 elif index > 0:
74 logmsg += "\t" + str( component_list[ index ] ) + "\n"
Jon Hall81d3d392015-04-24 14:40:35 -070075
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070076 logmsg = logmsg + "\n\n" + " " * 30 + "+--------+\n" + "-" * 28 + " { Topology } " + "-" * 28 + "\n" + " " * 30 + "+--------+\n"
77 values = "\n\t" + str( main.topology[ 'COMPONENT' ] )
78 values = re.sub( ",", "\n\t", values )
79 values = re.sub( "{", "\n\t", values )
80 values = re.sub( "}", "\n\t", values )
adminbae64d82013-08-01 10:50:15 -070081 logmsg = logmsg + values
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070082 logmsg = logmsg + "\n" + "-" * 60 + "\n"
Jon Hall81d3d392015-04-24 14:40:35 -070083
adminbae64d82013-08-01 10:50:15 -070084 # enter into log file all headers
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070085 logfile = open( main.LogFileName, "w+" )
86 logfile.write( logmsg )
adminbae64d82013-08-01 10:50:15 -070087 print logmsg
88 main.logHeader = logmsg
adminbae64d82013-08-01 10:50:15 -070089 logfile.close()
Jon Hall81d3d392015-04-24 14:40:35 -070090
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070091 # enter into report file all headers
92 main.reportFile = open( main.ReportFileName, "w+" )
93 main.reportFile.write( logmsg )
adminbae64d82013-08-01 10:50:15 -070094 main.reportFile.close()
Jon Hall81d3d392015-04-24 14:40:35 -070095
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070096 # Sumamry file header
97 currentTime = str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
Jon Hall79bec222015-04-30 16:23:30 -070098 main.summaryFile = open( main.SummaryFileName, "w+" )
99 main.summaryFile.write( main.TEST + " at " + currentTime + "\n" )
100 main.summaryFile.close()
101
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700102 # wiki file header
103 currentTime = str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
Jon Hall81d3d392015-04-24 14:40:35 -0700104 main.wikiFile = open( main.WikiFileName, "w+" )
Jon Hall79bec222015-04-30 16:23:30 -0700105 main.wikiFile.write( main.TEST + " at " + currentTime + "<p></p>\n" )
Jon Hall81d3d392015-04-24 14:40:35 -0700106 main.wikiFile.close()
107
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700108 def initlog( self, main ):
109 """
adminbae64d82013-08-01 10:50:15 -0700110 Initialise all the log handles.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700111 """
adminbae64d82013-08-01 10:50:15 -0700112 main._getTest()
Jon Hall81d3d392015-04-24 14:40:35 -0700113 main.STARTTIME = datetime.datetime.now()
adminbae64d82013-08-01 10:50:15 -0700114
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700115 currentTime = re.sub( "-|\s|:|\.", "_", str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) ) )
adminbae64d82013-08-01 10:50:15 -0700116 if main.logdir:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700117 main.logdir = main.logdir + "/" + main.TEST + "_" + currentTime
adminbae64d82013-08-01 10:50:15 -0700118 else:
119 main.logdir = main.logs_path + main.TEST + "_" + currentTime
Jon Hall81d3d392015-04-24 14:40:35 -0700120
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700121 os.mkdir( main.logdir )
Jon Hall81d3d392015-04-24 14:40:35 -0700122
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700123 main.LogFileName = main.logdir + "/" + main.TEST + "_" + str( currentTime ) + ".log"
124 main.ReportFileName = main.logdir + "/" + main.TEST + "_" + str( currentTime ) + ".rpt"
Jon Hall79bec222015-04-30 16:23:30 -0700125 main.WikiFileName = main.logdir + "/" + main.TEST + "Wiki.txt"
126 main.SummaryFileName = main.logdir + "/" + main.TEST + "Summary.txt"
Jon Hall94fd0472014-12-08 11:52:42 -0800127 main.JenkinsCSV = main.logdir + "/" + main.TEST + ".csv"
Devin Lim90803a82017-08-29 13:41:44 -0700128 main.resultFile = main.logdir + "/" + main.TEST + "Result.txt"
129
Jon Hall25079782015-10-13 13:54:39 -0700130 main.TOTAL_TC_SUCCESS = 0
Jon Hall81d3d392015-04-24 14:40:35 -0700131
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700132 # Add log-level - Report
133 logging.addLevelName( 9, "REPORT" )
134 logging.addLevelName( 7, "EXACT" )
135 logging.addLevelName( 11, "CASE" )
136 logging.addLevelName( 12, "STEP" )
137 main.log = logging.getLogger( main.TEST )
138
139 def report( msg ):
140 """
adminbae64d82013-08-01 10:50:15 -0700141 Will append the report message to the logs.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700142 """
143 main.log._log( 9, msg, "OpenFlowAutoMattion", "OFAutoMation" )
adminbae64d82013-08-01 10:50:15 -0700144 currentTime = datetime.datetime.now()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700145 currentTime = currentTime.strftime( "%d %b %Y %H:%M:%S" )
146 newmsg = "\n[REPORT] " + "[" + str( currentTime ) + "] " + msg
adminbae64d82013-08-01 10:50:15 -0700147 print newmsg
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700148 main.reportFile = open( main.ReportFileName, "a+" )
149 main.reportFile.write( newmsg )
adminbae64d82013-08-01 10:50:15 -0700150 main.reportFile.close()
Jon Hall81d3d392015-04-24 14:40:35 -0700151
152 main.log.report = report
153
Jon Hall79bec222015-04-30 16:23:30 -0700154 def summary( msg ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700155 """
Jon Hall79bec222015-04-30 16:23:30 -0700156 Will append the message to the txt file for the summary.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700157 """
158 main.log._log( 6, msg, "OpenFlowAutoMattion", "OFAutoMation" )
159 main.summaryFile = open( main.SummaryFileName, "a+" )
160 main.summaryFile.write( msg + "\n" )
Jon Hall79bec222015-04-30 16:23:30 -0700161 main.summaryFile.close()
162
163 main.log.summary = summary
164
Jon Hall81d3d392015-04-24 14:40:35 -0700165 def wiki( msg ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700166 """
Jon Hall81d3d392015-04-24 14:40:35 -0700167 Will append the message to the txt file for the wiki.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700168 """
169 main.log._log( 6, msg, "OpenFlowAutoMattion", "OFAutoMation" )
170 main.wikiFile = open( main.WikiFileName, "a+" )
171 main.wikiFile.write( msg + "\n" )
Jon Hall81d3d392015-04-24 14:40:35 -0700172 main.wikiFile.close()
173
174 main.log.wiki = wiki
175
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700176 def exact( exmsg ):
177 """
adminbae64d82013-08-01 10:50:15 -0700178 Will append the raw formatted message to the logs
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700179 """
180 main.log._log( 7, exmsg, "OpenFlowAutoMattion", "OFAutoMation" )
181 main.reportFile = open( main.ReportFileName, "a+" )
182 main.reportFile.write( exmsg )
adminbae64d82013-08-01 10:50:15 -0700183 main.reportFile.close()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700184 logfile = open( main.LogFileName, "a" )
185 logfile.write( "\n" + str( exmsg ) + "\n" )
adminbae64d82013-08-01 10:50:15 -0700186 logfile.close()
187 print exmsg
Jon Hall81d3d392015-04-24 14:40:35 -0700188
189 main.log.exact = exact
190
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700191 def case( msg ):
192 """
adminbae64d82013-08-01 10:50:15 -0700193 Format of the case type log defined here.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700194 """
195 main.log._log( 9, msg, "OpenFlowAutoMattion", "OFAutoMation" )
adminbae64d82013-08-01 10:50:15 -0700196 currentTime = datetime.datetime.now()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700197 newmsg = "[" + str( currentTime ) + "] " + "[" + main.TEST + "] " + "[CASE] " + msg
198 logfile = open( main.LogFileName, "a" )
199 logfile.write( "\n" + str( newmsg ) + "\n" )
adminbae64d82013-08-01 10:50:15 -0700200 logfile.close()
201 print newmsg
Jon Hall81d3d392015-04-24 14:40:35 -0700202
Jon Hall4ba53f02015-07-29 13:07:41 -0700203 main.log.case = case
Jon Hall81d3d392015-04-24 14:40:35 -0700204
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700205 def step( msg ):
206 """
adminbae64d82013-08-01 10:50:15 -0700207 Format of the step type log defined here.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700208 """
209 main.log._log( 9, msg, "OpenFlowAutoMattion", "OFAutoMation" )
adminbae64d82013-08-01 10:50:15 -0700210 currentTime = datetime.datetime.now()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700211 newmsg = "[" + str( currentTime ) + "] " + "[" + main.TEST + "] " + "[STEP] " + msg
212 logfile = open( main.LogFileName, "a" )
213 logfile.write( "\n" + str( newmsg ) + "\n" )
adminbae64d82013-08-01 10:50:15 -0700214 logfile.close()
215 print newmsg
Jon Hall81d3d392015-04-24 14:40:35 -0700216
217 main.log.step = step
218
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700219 main.LogFileHandler = logging.FileHandler( main.LogFileName )
220 self._printHeader( main )
adminbae64d82013-08-01 10:50:15 -0700221
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700222 # initializing logging module and setting log level
223 main.log.setLevel( logging.INFO )
224 main.log.setLevel( logging.DEBUG ) # Temporary
225 main.LogFileHandler.setLevel( logging.INFO )
Jon Hall81d3d392015-04-24 14:40:35 -0700226
adminbae64d82013-08-01 10:50:15 -0700227 # create console handler with a higher log level
228 main.ConsoleHandler = logging.StreamHandler()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700229 main.ConsoleHandler.setLevel( logging.INFO )
230 main.ConsoleHandler.setLevel( logging.DEBUG ) # Temporary
adminbae64d82013-08-01 10:50:15 -0700231 # create formatter and add it to the handlers
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700232 # formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
233
Jon Hall0bde9ba2015-03-19 11:32:57 -0700234 class MyFormatter( logging.Formatter ):
235 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
236 'blue': '\033[94m', 'green': '\033[92m',
237 'yellow': '\033[93m', 'red': '\033[91m',
238 'end': '\033[0m' }
239
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700240 FORMATS = { 'DEFAULT': '%(asctime)s - %(name)s - %(levelname)s - %(message)s' }
Jon Hall0bde9ba2015-03-19 11:32:57 -0700241 if COLORS: # NOTE:colors will only be loaded if command is run from one line
242 # IE: './cli.py run testname'
243 # This is to prevent issues with Jenkins parsing
244 # TODO: Make colors configurable
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700245 levels = { logging.ERROR: colors[ 'red' ] +
246 FORMATS[ 'DEFAULT' ] +
247 colors[ 'end' ],
248 logging.WARN: colors[ 'yellow' ] +
249 FORMATS[ 'DEFAULT' ] +
250 colors[ 'end' ],
251 logging.DEBUG: colors[ 'purple' ] +
252 FORMATS[ 'DEFAULT' ] +
253 colors[ 'end' ] }
Jon Hall0bde9ba2015-03-19 11:32:57 -0700254 FORMATS.update( levels )
255
256 def format( self, record ):
257 self._fmt = self.FORMATS.get( record.levelno,
258 self.FORMATS[ 'DEFAULT' ] )
259 return logging.Formatter.format( self, record )
260 formatter = MyFormatter()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700261 main.ConsoleHandler.setFormatter( formatter )
262 main.LogFileHandler.setFormatter( formatter )
adminbae64d82013-08-01 10:50:15 -0700263
264 # add the handlers to logger
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700265 main.log.addHandler( main.ConsoleHandler )
266 main.log.addHandler( main.LogFileHandler )
Jon Hall81d3d392015-04-24 14:40:35 -0700267
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700268 def testSummary( self, main ):
269 """
adminbae64d82013-08-01 10:50:15 -0700270 testSummary will take care about the Summary of test.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700271 """
adminbae64d82013-08-01 10:50:15 -0700272 main.ENDTIME = datetime.datetime.now()
273 main.EXECTIME = main.ENDTIME - main.STARTTIME
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700274 if ( main.TOTAL_TC_PASS == 0 ):
adminbae64d82013-08-01 10:50:15 -0700275 main.TOTAL_TC_SUCCESS = 0
276 else:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700277 main.TOTAL_TC_SUCCESS = str( ( main.TOTAL_TC_PASS * 100 ) / main.TOTAL_TC_RUN )
278 if ( main.TOTAL_TC_RUN == 0 ):
adminbae64d82013-08-01 10:50:15 -0700279 main.TOTAL_TC_EXECPERCENT = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700280 else:
281 main.TOTAL_TC_EXECPERCENT = str( ( main.TOTAL_TC_RUN * 100 ) / main.TOTAL_TC_PLANNED )
282 testResult = "\n\n" + "*" * 37 + "\n" + "\tTest Execution Summary\n" + "\n" + "*" * 37 + " \n"
283 testResult = testResult + "\n Test Start : " + str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
284 testResult = testResult + "\n Test End : " + str( main.ENDTIME.strftime( "%d %b %Y %H:%M:%S" ) )
285 testResult = testResult + "\n Execution Time : " + str( main.EXECTIME )
286 testResult = testResult + "\n Total tests planned : " + str( main.TOTAL_TC_PLANNED )
287 testResult = testResult + "\n Total tests RUN : " + str( main.TOTAL_TC_RUN )
288 testResult = testResult + "\n Total Pass : " + str( main.TOTAL_TC_PASS )
289 testResult = testResult + "\n Total Fail : " + str( main.TOTAL_TC_FAIL )
290 testResult = testResult + "\n Total No Result : " + str( main.TOTAL_TC_NORESULT )
291 testResult = testResult + "\n Success Percentage : " + str( main.TOTAL_TC_SUCCESS ) + "%"
292 testResult = testResult + "\n Execution Result : " + str( main.TOTAL_TC_EXECPERCENT ) + "%\n"
Devin Limec989792017-08-15 15:57:55 -0700293 if main.failedCase:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700294 testResult = testResult + "\n Case Failed : " + str( main.failedCase )
Devin Limec989792017-08-15 15:57:55 -0700295 if main.noResultCase:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700296 testResult = testResult + "\n Case NoResult : " + str( main.noResultCase )
297 testResult = testResult + "\n Case Executed : " + str( main.executedCase )
298 testResult = testResult + "\n Case Not Executed : " + str( main.leftCase )
299 # main.log.report( testResult )
adminbae64d82013-08-01 10:50:15 -0700300 main.testResult = testResult
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700301 main.log.exact( testResult )
Jon Hall94fd0472014-12-08 11:52:42 -0800302
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700303 # CSV output needed for Jenkins plot plugin
304 # NOTE: the elements were ordered based on the colors assigned to the data
305 logfile = open( main.JenkinsCSV, "w" )
306 logfile.write( ",".join( [ 'Tests Failed', 'Tests Passed', 'Tests Planned' ] ) + "\n" )
307 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 -0800308 logfile.close()
309
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700310 executedStatus = open( main.resultFile, "w" )
Devin Lim90803a82017-08-29 13:41:44 -0700311 if main.TOTAL_TC_FAIL == 0 and main.TOTAL_TC_NORESULT + main.TOTAL_TC_PASS == main.TOTAL_TC_PLANNED:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700312 executedStatus.write( "1\n" )
Devin Lim90803a82017-08-29 13:41:44 -0700313 else:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700314 executedStatus.write( "0\n" )
Devin Lim90803a82017-08-29 13:41:44 -0700315 executedStatus.close()
316
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700317 def updateCaseResults( self, main ):
318 """
adminbae64d82013-08-01 10:50:15 -0700319 Update the case result based on the steps execution and asserting each step in the test-case
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700320 """
321 case = str( main.CurrentTestCaseNumber )
322 currentResult = main.testCaseResult.get( case, 2 )
Jon Hall81d3d392015-04-24 14:40:35 -0700323
Jon Hall79bec222015-04-30 16:23:30 -0700324 if currentResult == 2:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700325 main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
adminbae64d82013-08-01 10:50:15 -0700326 main.TOTAL_TC_NORESULT = main.TOTAL_TC_NORESULT + 1
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700327 main.log.exact( "\n " + "*" * 29 + "\n" + "\n Result: No Assertion Called \n" + "*" * 29 + "\n" )
328 line = "Case " + case + ": " + main.CurrentTestCase + " - No Result"
Jon Hall79bec222015-04-30 16:23:30 -0700329 elif currentResult == 1:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700330 main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
331 main.TOTAL_TC_PASS = main.TOTAL_TC_PASS + 1
332 main.log.exact( "\n" + "*" * 29 + "\n Result: Pass \n" + "*" * 29 + "\n" )
333 line = "Case " + case + ": " + main.CurrentTestCase + " - PASS"
Jon Hall79bec222015-04-30 16:23:30 -0700334 elif currentResult == 0:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700335 main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
adminbae64d82013-08-01 10:50:15 -0700336 main.TOTAL_TC_FAIL = main.TOTAL_TC_FAIL + 1
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700337 main.log.exact( "\n" + "*" * 29 + "\n Result: Failed \n" + "*" * 29 + "\n" )
338 line = "Case " + case + ": " + main.CurrentTestCase + " - FAIL"
Jon Hall79bec222015-04-30 16:23:30 -0700339 else:
340 main.log.error( " Unknown result of case " + case +
341 ". Result was: " + currentResult )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700342 line = "Case " + case + ": " + main.CurrentTestCase + " - ERROR"
Jon Hall79bec222015-04-30 16:23:30 -0700343 main.log.wiki( "<h3>" + line + "</h3>" )
344 main.log.summary( line )