Refactored IpOpticalMulti test
diff --git a/TestON/core/logger.py b/TestON/core/logger.py
index 1dfe6bf..a2c5aa7 100644
--- a/TestON/core/logger.py
+++ b/TestON/core/logger.py
@@ -1,7 +1,7 @@
#/usr/bin/env python
'''
Created on 07-Jan-2013
-
+
@author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com)
TestON is free software: you can redistribute it and/or modify
@@ -15,7 +15,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with TestON. If not, see <http://www.gnu.org/licenses/>.
+ along with TestON. If not, see <http://www.gnu.org/licenses/>.
'''
@@ -27,7 +27,7 @@
class Logger:
'''
Add continuous logs and reports of the test.
-
+
@author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com)
'''
def _printHeader(self,main) :
@@ -39,7 +39,7 @@
logmsg = logmsg + "\n\tReport Log File : " + main.ReportFileName + ""
for component in main.componentDictionary.keys():
logmsg = logmsg + "\n\t"+component+" Session Log : " + main.logdir+"/"+component+".session" + ""
-
+
logmsg = logmsg + "\n\tTest Script :" + path + "Tests/" + main.TEST + ".py"+ ""
logmsg = logmsg + "\n\tTest Params : " + path + "Tests/" + main.TEST + ".params" + ""
logmsg = logmsg + "\n\tTopology : " + path + "Tests/" +main.TEST + ".topo" + ""
@@ -49,11 +49,10 @@
values = re.sub("{", "\n\t", values)
values = re.sub("}", "\n\t", values)
logmsg = logmsg + values
-
logmsg = logmsg + "\n\n"+" " * 31+"+---------------+\n" +"-" * 29+" { Components Used } " +"-" * 29+"\n"+" " * 31+"+---------------+\n"
component_list = []
component_list.append(None)
-
+
# Listing the components in the order of test_target component should be first.
if type(main.componentDictionary) == dict:
for key in main.componentDictionary.keys():
@@ -61,64 +60,67 @@
component_list[0] = key+"-Test Target"
else :
component_list.append(key)
-
+
for index in range(len(component_list)) :
if index==0:
if component_list[index]:
logmsg+="\t"+component_list[index]+"\n"
elif index > 0 :
logmsg+="\t"+str(component_list[index])+"\n"
-
-
-
+
logmsg = logmsg + "\n\n"+" " * 30+"+--------+\n" +"-" * 28+" { Topology } "+"-" * 28 +"\n" +" " * 30+"+--------+\n"
values = "\n\t" + str(main.topology['COMPONENT'])
values = re.sub(",", "\n\t", values)
values = re.sub("{", "\n\t", values)
values = re.sub("}", "\n\t", values)
logmsg = logmsg + values
-
logmsg = logmsg + "\n"+"-" * 60+"\n"
-
+
# enter into log file all headers
logfile = open(main.LogFileName,"w+")
logfile.write (logmsg)
print logmsg
main.logHeader = logmsg
-
logfile.close()
-
+
#enter into report file all headers
main.reportFile = open(main.ReportFileName,"w+")
main.reportFile.write(logmsg)
main.reportFile.close()
-
+
+ #wiki file header
+ currentTime = str( main.STARTTIME.strftime("%d %b %Y %H:%M:%S") )
+ main.wikiFile = open( main.WikiFileName, "w+" )
+ main.wikiFile.write( main.TEST + " at " + currentTime + "\n" )
+ main.wikiFile.close()
+
def initlog(self,main):
'''
Initialise all the log handles.
'''
main._getTest()
- main.STARTTIME = datetime.datetime.now()
+ main.STARTTIME = datetime.datetime.now()
currentTime = re.sub("-|\s|:|\.", "_", str(main.STARTTIME.strftime("%d %b %Y %H:%M:%S")))
if main.logdir:
main.logdir = main.logdir+ "/"+main.TEST + "_" + currentTime
else:
main.logdir = main.logs_path + main.TEST + "_" + currentTime
-
+
os.mkdir(main.logdir)
-
+
main.LogFileName = main.logdir + "/" + main.TEST + "_" +str(currentTime) + ".log"
main.ReportFileName = main.logdir + "/" + main.TEST + "_" + str(currentTime) + ".rpt"
+ main.WikiFileName = main.logdir + "/" + main.TEST + ".txt"
main.JenkinsCSV = main.logdir + "/" + main.TEST + ".csv"
-
+
#### Add log-level - Report
logging.addLevelName(9, "REPORT")
logging.addLevelName(7, "EXACT")
logging.addLevelName(11, "CASE")
logging.addLevelName(12, "STEP")
main.log = logging.getLogger(main.TEST)
- def report (msg):
+ def report(msg):
'''
Will append the report message to the logs.
'''
@@ -130,11 +132,21 @@
main.reportFile = open(main.ReportFileName,"a+")
main.reportFile.write(newmsg)
main.reportFile.close()
-
-
- main.log.report = report
-
- def exact (exmsg):
+
+ main.log.report = report
+
+ def wiki( msg ):
+ '''
+ Will append the message to the txt file for the wiki.
+ '''
+ main.log._log(6,msg,"OpenFlowAutoMattion","OFAutoMation")
+ main.wikiFile = open(main.WikiFileName,"a+")
+ main.wikiFile.write(msg+"\n")
+ main.wikiFile.close()
+
+ main.log.wiki = wiki
+
+ def exact(exmsg):
'''
Will append the raw formatted message to the logs
'''
@@ -146,10 +158,9 @@
logfile.write("\n"+ str(exmsg) +"\n")
logfile.close()
print exmsg
-
- main.log.exact = exact
-
-
+
+ main.log.exact = exact
+
def case(msg):
'''
Format of the case type log defined here.
@@ -161,10 +172,10 @@
logfile.write("\n"+ str(newmsg) +"\n")
logfile.close()
print newmsg
-
+
main.log.case = case
-
- def step (msg):
+
+ def step(msg):
'''
Format of the step type log defined here.
'''
@@ -175,9 +186,9 @@
logfile.write("\n"+ str(newmsg) +"\n")
logfile.close()
print newmsg
-
- main.log.step = step
-
+
+ main.log.step = step
+
main.LogFileHandler = logging.FileHandler(main.LogFileName)
self._printHeader(main)
@@ -185,7 +196,7 @@
main.log.setLevel(logging.INFO)
main.log.setLevel(logging.DEBUG) # Temporary
main.LogFileHandler.setLevel(logging.INFO)
-
+
# create console handler with a higher log level
main.ConsoleHandler = logging.StreamHandler()
main.ConsoleHandler.setLevel(logging.INFO)
@@ -225,7 +236,7 @@
# add the handlers to logger
main.log.addHandler(main.ConsoleHandler)
main.log.addHandler(main.LogFileHandler)
-
+
def testSummary(self,main):
'''
testSummary will take care about the Summary of test.
@@ -237,12 +248,10 @@
main.TOTAL_TC_SUCCESS = 0
else:
main.TOTAL_TC_SUCCESS = str((main.TOTAL_TC_PASS*100)/main.TOTAL_TC_RUN)
-
if (main.TOTAL_TC_RUN == 0) :
main.TOTAL_TC_EXECPERCENT = 0
else :
main.TOTAL_TC_EXECPERCENT = str((main.TOTAL_TC_RUN*100)/main.TOTAL_TC_PLANNED)
-
testResult = "\n\n"+"*" * 37+"\n" + "\tTest Execution Summary\n" + "\n"+"*" * 37+" \n"
testResult = testResult + "\n Test Start : " + str(main.STARTTIME.strftime("%d %b %Y %H:%M:%S"))
testResult = testResult + "\n Test End : " + str(main.ENDTIME.strftime("%d %b %Y %H:%M:%S"))
@@ -254,7 +263,7 @@
testResult = testResult + "\n Total No Result : " + str(main.TOTAL_TC_NORESULT)
testResult = testResult + "\n Success Percentage : " + str(main.TOTAL_TC_SUCCESS) + "%"
testResult = testResult + "\n Execution Result : " + str(main.TOTAL_TC_EXECPERCENT) + "%"
-
+
#main.log.report(testResult)
main.testResult = testResult
main.log.exact(testResult)
@@ -266,24 +275,25 @@
logfile.write(",".join( [str(int(main.TOTAL_TC_FAIL)), str(int(main.TOTAL_TC_PASS)), str(int(main.TOTAL_TC_PLANNED))] ))
logfile.close()
-
-
-
def updateCaseResults(self,main):
'''
Update the case result based on the steps execution and asserting each step in the test-case
'''
case = str(main.CurrentTestCaseNumber)
-
+
if main.testCaseResult[case] == 2:
main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
main.TOTAL_TC_NORESULT = main.TOTAL_TC_NORESULT + 1
main.log.exact("\n "+"*" * 29+"\n" + "\n Result: No Assertion Called \n"+"*" * 29+"\n")
+ main.log.wiki("Case "+case+": "+main.CurrentTestCase+" - No Result")
elif main.testCaseResult[case] == 1:
main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
main.TOTAL_TC_PASS = main.TOTAL_TC_PASS + 1
main.log.exact("\n"+"*" * 29+"\n Result: Pass \n"+"*" * 29+"\n")
+ main.log.wiki("Case "+case+": "+main.CurrentTestCase+" - PASSED")
elif main.testCaseResult[case] == 0:
main.TOTAL_TC_RUN = main.TOTAL_TC_RUN + 1
main.TOTAL_TC_FAIL = main.TOTAL_TC_FAIL + 1
main.log.exact("\n"+"*" * 29+"\n Result: Failed \n"+"*" * 29+"\n")
+ main.log.wiki("Case "+case+": "+main.CurrentTestCase+" - FAILED")
+