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")
+
diff --git a/TestON/core/teston.py b/TestON/core/teston.py
index 961e824..0da4cee 100644
--- a/TestON/core/teston.py
+++ b/TestON/core/teston.py
@@ -52,21 +52,17 @@
class TestON:
'''
-
- TestON will initiate the specified test.
- The main tasks are :
- * Initiate the required Component handles for the test.
+ TestON will initiate the specified test.
+ The main tasks are :
+ * Initiate the required Component handles for the test.
* Create Log file Handles.
-
'''
def __init__(self,options):
'''
Initialise the component handles specified in the topology file of the specified test.
-
'''
# Initialization of the variables.
__builtin__.main = self
-
__builtin__.path = path
__builtin__.utilities = Utilities()
self.TRUE = 1
@@ -77,7 +73,10 @@
self.CASERESULT = self.TRUE
self.init_result = self.TRUE
self.testResult = "Summary"
- self.stepName =""
+ self.stepName = ""
+ self.wikiCache = ""
+ # make this into two lists? one for step names, one for results?
+ # this way, the case result could be a true AND of these results
self.EXPERIMENTAL_MODE = False
self.test_target = None
self.lastcommand = None
@@ -127,7 +126,6 @@
#Ordering components based on the connect order.
ordered_component_list =sorted(components_connect_order, key=lambda key: components_connect_order[key])
print ordered_component_list
-
for component in ordered_component_list:
self.componentInit(component)
@@ -143,7 +141,7 @@
return self.configDict
except Exception:
print "There is no such file to parse " + self.configFile
-
+
def componentInit(self,component):
'''
This method will initialize specified component
@@ -157,12 +155,12 @@
driver_options['name']=component
driverName = self.componentDictionary[component]['type']
driver_options ['type'] = driverName
-
+
classPath = self.getDriverPath(driverName.lower())
driverModule = importlib.import_module(classPath)
driverClass = getattr(driverModule, driverName)
driverObject = driverClass()
-
+
connect_result = driverObject.connect(user_name = self.componentDictionary[component]['user'] if ('user' in self.componentDictionary[component].keys()) else getpass.getuser(),
ip_address= self.componentDictionary[component]['host'] if ('host' in self.componentDictionary[component].keys()) else 'localhost',
pwd = self.componentDictionary[component]['password'] if ('password' in self.componentDictionary[component].keys()) else 'changeme',
@@ -171,17 +169,16 @@
if not connect_result:
self.log.error("Exiting form the test execution because the connecting to the "+component+" component failed.")
self.exit()
-
+
vars(self)[component] = driverObject
-
+
def run(self):
'''
- The Execution of the test script's cases listed in the Test params file will be done here.
- And Update each test case result.
- This method will return TRUE if it executed all the test cases successfully,
+ The Execution of the test script's cases listed in the Test params file will be done here.
+ And Update each test case result.
+ This method will return TRUE if it executed all the test cases successfully,
else will retun FALSE
'''
-
self.testCaseResult = {}
self.TOTAL_TC = 0
self.TOTAL_TC_RUN = 0
@@ -192,7 +189,7 @@
self.TEST_ITERATION = 0
self.stepCount = 0
self.CASERESULT = self.TRUE
-
+
import testparser
testFile = self.tests_path + "/"+self.TEST + "/"+self.TEST + ".py"
test = testparser.TestParser(testFile)
@@ -200,16 +197,18 @@
self.code = test.getStepCode()
repeat= int(self.params['repeat']) if ('repeat' in self.params) else 1
self.TOTAL_TC_PLANNED = len(self.testcases_list)*repeat
-
+
result = self.TRUE
while(repeat):
for self.CurrentTestCaseNumber in self.testcases_list:
result = self.runCase(self.CurrentTestCaseNumber)
repeat-=1
return result
-
+
def runCase(self,testCaseNumber):
self.CurrentTestCaseNumber = testCaseNumber
+ self.CurrentTestCase = ""
+ self.stepName = ""
result = self.TRUE
self.stepCount = 0
self.EXPERIMENTAL_MODE = self.FALSE
@@ -221,7 +220,7 @@
except KeyError:
self.log.error("There is no Test-Case "+ self.testCaseNumber)
return self.FALSE
-
+
self.stepCount = 0
while self.stepCount < len(self.code[self.testCaseNumber].keys()):
result = self.runStep(self.stepList,self.code,self.testCaseNumber)
@@ -229,18 +228,39 @@
break
elif result == self.TRUE:
continue
-
if not stopped :
self.testCaseResult[str(self.CurrentTestCaseNumber)] = self.CASERESULT
self.logger.updateCaseResults(self)
+ self.log.wiki(self.wikiCache)
+ self.wikiCache = ""
return result
-
+
def runStep(self,stepList,code,testCaseNumber):
if not cli.pause:
try :
step = stepList[self.stepCount]
exec code[testCaseNumber][step] in module.__dict__
self.stepCount = self.stepCount + 1
+ if step > 0: # FIXME: step 0 is from previous case - Why is it doing this?
+ #FIXME are we losing results because of this?
+ # Maybe we should be updating stepName sooner?
+ self.wikiCache += "\t"+str(testCaseNumber)+"."+str(step)+" "+self.stepName+" - "
+ if self.CASERESULT == self.TRUE:
+ self.wikiCache += "PASSED\n"
+ elif self.CASERESULT == self.FALSE:
+ self.wikiCache += "FAILED\n"
+ else:
+ self.wikiCache += "No Result\n"
+ '''
+ else: # FIXME : DEBUG
+ self.wikiCache += "DEBUG\t"+str(testCaseNumber)+"."+str(step)+" "+self.stepName+" - "
+ if self.CASERESULT == self.TRUE:
+ self.wikiCache += "PASSED\n"
+ elif self.CASERESULT == self.FALSE:
+ self.wikiCache += "FAILED\n"
+ else:
+ self.wikiCache += "No Result\n"
+ '''
except TypeError,e:
print "Exception in the following section of code: Test Step " +\
str(testCaseNumber) + "." + str(step) + " ):"
@@ -250,7 +270,6 @@
self.cleanup()
self.exit()
return main.TRUE
-
if cli.stop:
cli.stop = False
stopped = True
@@ -259,21 +278,21 @@
self.logger.updateCaseResults(self)
result = self.cleanup()
return main.FALSE
-
+
def addCaseHeader(self):
caseHeader = "\n"+"*" * 30+"\n Result summary for Testcase"+str(self.CurrentTestCaseNumber)+"\n"+"*" * 30+"\n"
self.log.exact(caseHeader)
caseHeader = "\n"+"*" * 40 +"\nStart of Test Case"+str(self.CurrentTestCaseNumber)+" : "
for driver in self.componentDictionary.keys():
vars(self)[driver+'log'].info(caseHeader)
-
+
def addCaseFooter(self):
if self.stepCount-1 > 0 :
previousStep = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount-1)+": "+ str(self.stepName) + ""
stepHeader = "\n"+"*" * 40+"\nEnd of Step "+previousStep+"\n"+"*" * 40+"\n"
-
+
caseFooter = "\n"+"*" * 40+"\nEnd of Test case "+str(self.CurrentTestCaseNumber)+"\n"+"*" * 40+"\n"
-
+
for driver in self.driversList:
vars(self)[driver].write(stepHeader+"\n"+caseFooter)
@@ -289,7 +308,6 @@
#self.reportFile.close()
-
#utilities.send_mail()
for component in self.componentDictionary.keys():
try :
@@ -314,12 +332,11 @@
This function will pause the test's execution, and will continue after user provide 'resume' command.
'''
__builtin__.testthread.pause()
-
+
def onfail(self,*components):
'''
- When test step failed, calling all the components onfail.
+ When test step failed, calling all the components onfail.
'''
-
if not components:
try :
for component in self.componentDictionary.keys():
@@ -328,7 +345,6 @@
except(Exception),e:
print str(e)
result = self.FALSE
-
else:
try :
for component in components:
@@ -337,8 +353,7 @@
except(Exception),e:
print str(e)
result = self.FALSE
-
-
+
def getDriverPath(self,driverName):
'''
Based on the component 'type' specified in the params , this method will find the absolute path ,
@@ -348,23 +363,22 @@
cmd = "find "+drivers_path+" -name "+driverName+".py"
result = commands.getoutput(cmd)
-
+
result_array = str(result).split('\n')
result_count = 0
-
+
for drivers_list in result_array:
result_count = result_count+1
if result_count > 1 :
print "found "+driverName+" "+ str(result_count) + " times"+str(result_array)
self.exit()
-
+
result = re.sub("(.*)drivers","",result)
result = re.sub("\.py","",result)
result = re.sub("\.pyc","",result)
result = re.sub("\/",".",result)
result = "drivers"+result
return result
-
def step(self,stepDesc):
'''
@@ -379,16 +393,16 @@
stepName = " INIT : Initializing the test case :"+self.CurrentTestCase
except AttributeError:
stepName = " INIT : Initializing the test case :"+str(self.CurrentTestCaseNumber)
-
+
self.log.step(stepName)
stepHeader = ""
if self.stepCount > 1 :
stepHeader = "\n"+"-"*45+"\nEnd of Step "+previousStep+"\n"+"-"*45+"\n"
-
+
stepHeader += "\n"+"-"*45+"\nStart of Step"+stepName+"\n"+"-"*45+"\n"
for driver in self.componentDictionary.keys():
vars(self)[driver+'log'].info(stepHeader)
-
+
def case(self,testCaseName):
'''
Test's each test-case information will append to the logs.
@@ -399,14 +413,14 @@
caseHeader = testCaseName+"\n"+"*" * 40+"\n"
for driver in self.componentDictionary.keys():
vars(self)[driver+'log'].info(caseHeader)
-
+
def testDesc(self,description):
'''
Test description will append to the logs.
'''
description = "Test Description : " + str (description) + ""
self.log.info(description)
-
+
def _getTest(self):
'''
This method will parse the test script to find required test information.
@@ -422,17 +436,15 @@
if lineMatch:
counter = counter + 1
self.TC_PLANNED = len(self.testcases_list)
-
-
+
def response_parser(self,response, return_format):
''' It will load the default response parser '''
response_dict = {}
response_dict = self.response_to_dict(response, return_format)
return_format_string = self.dict_to_return_format(response,return_format,response_dict)
return return_format_string
-
+
def response_to_dict(self,response,return_format):
-
response_dict = {}
json_match = re.search('^\s*{', response)
xml_match = re.search('^\s*\<', response)
@@ -440,12 +452,10 @@
if json_match :
self.log.info(" Response is in 'JSON' format and Converting to '"+return_format+"' format")
# Formatting the json string
-
response = re.sub(r"{\s*'?(\w)", r'{"\1', response)
response = re.sub(r",\s*'?(\w)", r',"\1', response)
response = re.sub(r"(\w)'?\s*:", r'\1":', response)
response = re.sub(r":\s*'(\w)'\s*([,}])", r':"\1"\2', response)
-
try :
import json
response_dict = json.loads(response)
@@ -453,7 +463,6 @@
self.log.exception( e )
self.log.error("Json Parser is unable to parse the string")
return response_dict
-
elif ini_match :
self.log.info(" Response is in 'INI' format and Converting to '"+return_format+"' format")
from configobj import ConfigObj
@@ -462,7 +471,6 @@
response_file.close()
response_dict = ConfigObj("respnse_file.temp")
return response_dict
-
elif xml_match :
self.log.info(" Response is in 'XML' format and Converting to '"+return_format+"' format")
try :
@@ -470,16 +478,15 @@
except Exception, e:
self.log.exception( e )
return response_dict
-
+
def dict_to_return_format(self,response,return_format,response_dict):
-
if return_format =='table' :
''' Will return in table format'''
to_do = "Call the table output formatter"
global response_table
response_table = '\n'
response_table = response_table +'\t'.join(response_dict)+"\n"
-
+
def get_table(value_to_convert):
''' This will parse the dictionary recusrsively and print as table format'''
table_data = ""
@@ -490,16 +497,12 @@
else :
table_data = table_data + str(value_to_convert) +"\t"
return table_data
-
+
for value in response_dict.values() :
response_table = response_table + get_table(value)
-
-
-
# response_table = response_table + '\t'.join(response_dict.values())
-
return response_table
-
+
elif return_format =='config':
''' Will return in config format'''
to_do = 'Call dict to config coverter'
@@ -511,24 +514,22 @@
response_config = re.sub("}", "\n", response_config)
response_config = re.sub(":", " =", response_config)
return "[response]\n\t "+response_config
-
elif return_format == 'xml':
''' Will return in xml format'''
response_xml = xmldict.dict_to_xml(response_dict)
response_xml = re.sub(">\s*<", ">\n<", response_xml)
return "\n"+response_xml
-
elif return_format == 'json':
''' Will return in json format'''
to_do = 'Call dict to xml coverter'
import json
response_json = json.dumps(response_dict)
return response_json
-
+
def get_random(self):
self.random_order = self.random_order + 1
return self.random_order
-
+
def exit(self):
__builtin__.testthread = None
sys.exit()
@@ -567,14 +568,14 @@
main.testDir = path+'/examples/'
main.tests_path = path+"/examples/"
main.classPath = "examples."+main.TEST+"."+main.TEST
-
+
def verifyLogdir(options):
# Verifying Log directory option
if options.logdir:
main.logdir = options.logdir
else :
main.logdir = main.FALSE
-
+
def verifyMail(options):
# Checking the mailing list
if options.mail:
@@ -611,7 +612,7 @@
else :
print "testcases not specifed in params, please provide in params file or 'testcases' commandline argument"
sys.exit()
-
+
def verifyTestScript(options):
'''
Verifyies test script.
@@ -627,7 +628,6 @@
print "\nThere is no :\""+main.TEST+"\" test, Please Provide OpenSpeak Script/ test script"
__builtin__.testthread = None
main.exit()
-
try :
testModule = __import__(main.classPath, globals(), locals(), [main.TEST], -1)
except(ImportError):
@@ -639,20 +639,19 @@
load_parser()
main.params = main.parser.parseParams(main.classPath)
main.topology = main.parser.parseTopology(main.classPath)
-
+
def verifyParams():
try :
main.params = main.params['PARAMS']
except(KeyError):
print "Error with the params file: Either the file not specified or the format is not correct"
main.exit()
-
try :
main.topology = main.topology['TOPOLOGY']
except(KeyError):
print "Error with the Topology file: Either the file not specified or the format is not correct"
main.exit()
-
+
def load_parser() :
'''
It facilitates the loading customised parser for topology and params file.
@@ -674,11 +673,9 @@
main.parser = parsingClass()
#hashobj = main.parser.parseParams(main.classPath)
if hasattr(main.parser,"parseParams") and hasattr(main.parser,"parseTopology") and hasattr(main.parser,"parse") :
-
pass
else:
main.exit()
-
except ImportError:
print sys.exc_info()[1]
main.exit()
@@ -709,7 +706,6 @@
except ImportError:
print sys.exc_info()[1]
-
def load_logger() :
'''
It facilitates the loading customised parser for topology and params file.
@@ -773,8 +769,5 @@
print sys.exc_info()[1]
main.exit()
-
-
-
def _echo(self):
print "THIS IS ECHO"
diff --git a/TestON/tests/IpOptical/IpOptical.py b/TestON/tests/IpOptical/IpOptical.py
index c290ac9..af88686 100644
--- a/TestON/tests/IpOptical/IpOptical.py
+++ b/TestON/tests/IpOptical/IpOptical.py
@@ -555,7 +555,7 @@
flows = main.ONOS2.flows()
main.log.info( flows )
- case10Result = step1Result
+ case10Result = step1Result
utilities.assert_equals(
expect=main.TRUE,
actual=case10Result,
@@ -571,7 +571,7 @@
main.log.report( "Adding host intents between 2 optical layer host" )
main.case( "Test add host intents between optical layer host" )
- main.log.step( "Discover host using arping" )
+ main.step( "Discover host using arping" )
step1Result = main.TRUE
main.hostMACs = []
main.hostId = []
@@ -597,7 +597,7 @@
onpass="Hosts discovered",
onfail="Failed to discover hosts")
- main.log.step( "Adding host intents to h1 and h2" )
+ main.step( "Adding host intents to h1 and h2" )
step2Result = main.TRUE
intentsId = []
intent1 = main.ONOS3.addHostIntent( hostIdOne = host1,
@@ -622,19 +622,40 @@
"INSTALLED state " )
# pinging h1 to h2 and then ping h2 to h1
- main.log.step( "Pinging h1 and h2" )
+ main.step( "Pinging h1 and h2" )
step3Result = main.TRUE
pingResult = main.TRUE
pingResult = main.LincOE2.pingHostOptical( src="h1", target="h2" )
pingResult = pingResult and main.LincOE2.pingHostOptical( src="h2",
target="h1" )
- step2Result = pingResult
+ step3Result = pingResult
utilities.assert_equals( expect=main.TRUE,
- actual=step2Result,
+ actual=step3Result,
onpass="Pinged successfully between h1 and h2",
onfail="Pinged failed between h1 and h2" )
-
- case25Result = step1Result and step2Result and step3Result
- utilities.assert_equals( expect=main.TRUE, actual=case25Result,
+ # Removed all added host intents
+ main.step( "Removing host intents" )
+ step4Result = main.TRUE
+ removeResult = main.TRUE
+ # Check remaining intents
+ intentsJson = json.loads( main.ONOS3.intents() )
+ main.ONOS3.removeIntent( intentId=intent1, purge=True )
+ main.ONOS3.removeIntent( intentId=intent2, purge=True )
+ for intents in intentsJson:
+ main.ONOS3.removeIntent( intentId=intents.get( 'id' ),
+ app='org.onosproject.optical',
+ purge=True )
+ print json.loads( main.ONOS3.intents() )
+ if len( json.loads( main.ONOS3.intents() ) ):
+ removeResult = main.FALSE
+ step4Result = removeResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=step4Result,
+ onpass="Successfully removed host intents",
+ onfail="Failed to remove host intents" )
+ case25Result = step1Result and step2Result and step3Result and \
+ step4Result
+ utilities.assert_equals( expect=main.TRUE,
+ actual=case25Result,
onpass="Add host intent successful",
onfail="Add host intent failed" )
diff --git a/TestON/tests/IpOpticalMulti/IpOpticalMulti.params b/TestON/tests/IpOpticalMulti/IpOpticalMulti.params
index f3fa343..2aa477d 100755
--- a/TestON/tests/IpOpticalMulti/IpOpticalMulti.params
+++ b/TestON/tests/IpOpticalMulti/IpOpticalMulti.params
@@ -1,6 +1,6 @@
<PARAMS>
- <testcases>1,21,22,25,10,23,24</testcases>
+ <testcases>20,21,22,25,10,23,24</testcases>
#Environment variables
<ENV>
<cellName>multi_test</cellName>
diff --git a/TestON/tests/IpOpticalMulti/IpOpticalMulti.py b/TestON/tests/IpOpticalMulti/IpOpticalMulti.py
index d00410f..31a4cfb 100644
--- a/TestON/tests/IpOpticalMulti/IpOpticalMulti.py
+++ b/TestON/tests/IpOpticalMulti/IpOpticalMulti.py
@@ -113,39 +113,12 @@
onpass="Test startup successful",
onfail="Test startup NOT successful" )
- def CASE10( self ):
- import time
- main.log.report(
- "This testcase uninstalls the reactive forwarding app" )
- main.log.report( "__________________________________" )
- main.case( "Uninstalling reactive forwarding app" )
- # Unistall onos-app-fwd app to disable reactive forwarding
- appInstallResult = main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
- appCheck = main.ONOScli1.appToIDCheck()
- if appCheck != main.TRUE:
- main.log.warn( main.ONOScli1.apps() )
- main.log.warn( main.ONOScli1.appIDs() )
- main.log.info( "onos-app-fwd uninstalled" )
-
- # After reactive forwarding is disabled,
- # the reactive flows on switches timeout in 10-15s
- # So sleep for 15s
- time.sleep( 15 )
-
- hosts = main.ONOScli1.hosts()
- main.log.info( hosts )
- case10Result = appInstallResult
- utilities.assertEquals(
- expect=main.TRUE,
- actual=case10Result,
- onpass="Reactive forwarding app uninstallation successful",
- onfail="Reactive forwarding app uninstallation failed" )
-
def CASE20( self ):
"""
Exit from mininet cli
reinstall ONOS
"""
+ import time
cellName = main.params[ 'ENV' ][ 'cellName' ]
ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
@@ -154,23 +127,61 @@
ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
+
main.log.report( "This testcase exits the mininet cli and reinstalls" +
"ONOS to switch over to Packet Optical topology" )
main.log.report( "_____________________________________________" )
main.case( "Disconnecting mininet and restarting ONOS" )
+
main.step( "Disconnecting mininet and restarting ONOS" )
+ step1Result = main.TRUE
mininetDisconnect = main.Mininet1.disconnect()
print "mininetDisconnect = ", mininetDisconnect
-
- main.step( "Removing raft logs before a clen installation of ONOS" )
- main.ONOSbench.onosRemoveRaftLogs()
-
+ step1Result = mininetDisconnect
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Mininet disconnect successfully",
+ onfail="Mininet failed to disconnect")
+ """
+ main.step( "Removing raft logs before a clean installation of ONOS" )
+ step2Result = main.TRUE
+ removeRaftLogsResult = main.ONOSbench.onosRemoveRaftLogs()
+ step2Result = removeRaftLogsResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step2Result,
+ onpass="Raft logs removed successfully",
+ onfail="Failed to remove raft logs")
+ """
main.step( "Applying cell variable to environment" )
- cellResult = main.ONOSbench.setCell( cellName )
- verifyResult = main.ONOSbench.verifyCell()
+ step3Result = main.TRUE
+ setCellResult = main.ONOSbench.setCell( cellName )
+ verifyCellResult = main.ONOSbench.verifyCell()
+ step3Result = setCellResult and verifyCellResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step3Result,
+ onpass="Cell applied successfully",
+ onfail="Failed to apply cell")
+ main.step( "Uninstalling ONOS package" )
+ step4Result = main.TRUE
+ onos1UninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOS1Ip)
+ onos2UninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOS2Ip)
+ onos3UninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOS3Ip)
+ onosUninstallResult = onos1UninstallResult and onos2UninstallResult \
+ and onos3UninstallResult
+ step4Result = onosUninstallResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step4Result,
+ onpass="Successfully uninstalled ONOS",
+ onfail="Failed to uninstall ONOS")
+ time.sleep( 5 )
main.step( "Installing ONOS package" )
+ step5Result = main.TRUE
onos1InstallResult = main.ONOSbench.onosInstall(
options="-f",
node=ONOS1Ip )
@@ -182,32 +193,48 @@
node=ONOS3Ip )
onosInstallResult = onos1InstallResult and onos2InstallResult and\
onos3InstallResult
- if onosInstallResult == main.TRUE:
- main.log.report( "Installing ONOS package successful" )
- else:
- main.log.report( "Installing ONOS package failed" )
onos1Isup = main.ONOSbench.isup( ONOS1Ip )
onos2Isup = main.ONOSbench.isup( ONOS2Ip )
onos3Isup = main.ONOSbench.isup( ONOS3Ip )
- onosIsup = onos1Isup and onos2Isup and onos3Isup
- if onosIsup == main.TRUE:
+ onosIsUp = onos1Isup and onos2Isup and onos3Isup
+ if onosIsUp == main.TRUE:
main.log.report( "ONOS instances are up and ready" )
else:
main.log.report( "ONOS instances may not be up" )
+ step5Result = onosInstallResult and onosIsUp
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step5Result,
+ onpass="Successfully installed ONOS",
+ onfail="Failed to install ONOS")
main.step( "Starting ONOS service" )
- startResult = main.TRUE
- # startResult = main.ONOSbench.onosStart( ONOS1Ip )
+ step6Result = main.TRUE
+ startResult = main.ONOSbench.onosStart( ONOS1Ip )
+ step6Result = startResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step6Result,
+ onpass="Successfully started ONOS",
+ onfail="Failed to start ONOS")
+
+ main.step( "Starting ONOS cli" )
+ step7Result = main.TRUE
startcli1 = main.ONOScli1.startOnosCli( ONOSIp=ONOS1Ip )
startcli2 = main.ONOScli2.startOnosCli( ONOSIp=ONOS2Ip )
startcli3 = main.ONOScli3.startOnosCli( ONOSIp=ONOS3Ip )
startResult = startcli1 and startcli2 and startcli3
- if startResult == main.TRUE:
- main.log.report( "ONOS cli starts properly" )
- case20Result = mininetDisconnect and cellResult and verifyResult \
- and onosInstallResult and onosIsup and startResult
+ step7Result = startResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step7Result,
+ onpass="Successfully started ONOS cli",
+ onfail="Failed to start ONOS cli")
+ case20Result = step1Result and step3Result and\
+ step4Result and step5Result and step6Result and\
+ step7Result
utilities.assert_equals(
expect=main.TRUE,
actual=case20Result,
@@ -219,32 +246,46 @@
def CASE21( self, main ):
"""
On ONOS bench, run this command:
- sudo -E python ~/onos/tools/test/topos/opticalTest.py -OC1 <Ctrls>
+ sudo -E python ~/onos/tools/test/topos/opticalTest.py -OC1
which spawns packet optical topology and copies the links
json file to the onos instance.
Note that in case of Packet Optical, the links are not learnt
from the topology, instead the links are learnt
from the json config file
"""
+ import time
main.log.report(
"This testcase starts the packet layer topology and REST" )
main.log.report( "_____________________________________________" )
main.case( "Starting LINC-OE and other components" )
- main.step( "Starting LINC-OE and other components" )
- main.log.info( "Activate optical app" )
- appInstallResult = main.ONOScli1.activateApp( "org.onosproject.optical" )
- appCheck = main.ONOScli1.appToIDCheck()
- appCheck = appCheck and main.ONOScli2.appToIDCheck()
- appCheck = appCheck and main.ONOScli3.appToIDCheck()
- if appCheck != main.TRUE:
- main.log.warn( "Checking ONOS application unsuccesful" )
- ctrllerIP = []
- ctrllerIP.append( main.params[ 'CTRL' ][ 'ip1' ] )
- #ctrllerIP.append( main.params[ 'CTRL' ][ 'ip2' ] )
- #ctrllerIP.append( main.params[ 'CTRL' ][ 'ip3' ] )
- opticalMnScript = main.LincOE2.runOpticalMnScript( ctrllerIP = ctrllerIP )
- case21Result = opticalMnScript and appInstallResult
+ main.step( "Activate optical app" )
+ step1Result = main.TRUE
+ activateOpticalResult = main.ONOScli2.activateApp( "org.onosproject.optical" )
+ step1Result = activateOpticalResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully activated optical app",
+ onfail="Failed to activate optical app")
+
+ appCheck = main.ONOScli2.appToIDCheck()
+ if appCheck != main.TRUE:
+ main.log.warn( main.ONOScli2.apps() )
+ main.log.warn( main.ONOScli2.appIDs() )
+
+ main.step( "Starting mininet and LINC-OE" )
+ step2Result = main.TRUE
+ time.sleep( 10 )
+ opticalMnScript = main.LincOE2.runOpticalMnScript(ctrllerIP = main.params[ 'CTRL' ][ 'ip1' ])
+ step2Result = opticalMnScript
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step2Result,
+ onpass="Started the topology successfully ",
+ onfail="Failed to start the topology")
+
+ case21Result = step1Result and step2Result
utilities.assert_equals(
expect=main.TRUE,
actual=case21Result,
@@ -261,14 +302,27 @@
All this is hardcoded in the testcase. If the topology changes,
these hardcoded values need to be changed
"""
+ import time
main.log.report(
"This testcase compares the optical+packet topology against what" +
" is expected" )
main.case( "Topology comparision" )
- main.step( "Topology comparision" )
- devicesResult = main.ONOScli3.devices( jsonFormat=False )
- print "devices_result = ", devicesResult
+ main.step( "Starts new ONOS cli" )
+ step1Result = main.TRUE
+ cliResult = main.ONOScli1.startOnosCli( ONOSIp=main.params[ 'CTRL' ]\
+ [ 'ip1' ] )
+ step1Result = cliResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully starts a new cli",
+ onfail="Failed to start new cli" )
+
+ main.step( "Compare topology" )
+ step2Result = main.TRUE
+ devicesResult = main.ONOScli1.devices( jsonFormat=False )
+ print "devices_result :\n", devicesResult
devicesLinewise = devicesResult.split( "\n" )
roadmCount = 0
packetLayerSWCount = 0
@@ -295,7 +349,6 @@
str( roadmCount ) +
" and is wrong" )
opticalSWResult = main.FALSE
-
if packetLayerSWCount == 6:
print "Number of Packet layer or mininet Switches = %d "\
% packetLayerSWCount + "and is correctly detected"
@@ -312,12 +365,13 @@
str( packetLayerSWCount ) +
" and is wrong" )
packetSWResult = main.FALSE
+ # sleeps for sometime so the state of the switches will be active
+ time.sleep( 30 )
print "_________________________________"
-
- linksResult = main.ONOScli3.links( jsonFormat=False )
+ linksResult = main.ONOScli1.links( jsonFormat=False )
print "links_result = ", linksResult
print "_________________________________"
- linkActiveCount = linksResult.count("state=ACTIVE")
+ linkActiveCount = linksResult.count("state=ACTIVE")
main.log.info( "linkActiveCount = " + str( linkActiveCount ))
if linkActiveCount == 42:
linkActiveResult = main.TRUE
@@ -327,11 +381,18 @@
linkActiveResult = main.FALSE
main.log.info(
"Number of links in ACTIVE state are wrong")
-
- case22Result = opticalSWResult and packetSWResult and \
+ step2Result = opticalSWResult and packetSWResult and \
linkActiveResult
utilities.assert_equals(
expect=main.TRUE,
+ actual=step2Result,
+ onpass="Successfully loaded packet optical topology",
+ onfail="Failed to load packet optical topology" )
+
+ case22Result = step1Result and step2Result
+
+ utilities.assert_equals(
+ expect=main.TRUE,
actual=case22Result,
onpass="Packet optical topology discovery successful",
onfail="Packet optical topology discovery failed" )
@@ -346,83 +407,65 @@
main.log.report(
"This testcase adds bidirectional point intents between 2 " +
"packet layer( mininet ) devices and ping mininet hosts" )
- main.case( "Topology comparision" )
+ main.case( "Install point intents between 2 packet layer device and " +
+ "ping the hosts" )
+
main.step( "Adding point intents" )
- ptpIntentResult = main.ONOScli1.addPointIntent(
+ step1Result = main.TRUE
+ intentsId = []
+ pIntent1 = main.ONOScli1.addPointIntent(
"of:0000ffffffff0001/1",
"of:0000ffffffff0005/1" )
- if ptpIntentResult == main.TRUE:
- main.ONOScli1.intents( jsonFormat=False )
- main.log.info( "Point to point intent install successful" )
-
- ptpIntentResult = main.ONOScli1.addPointIntent(
+ pIntent2 = main.ONOScli1.addPointIntent(
"of:0000ffffffff0005/1",
"of:0000ffffffff0001/1" )
- if ptpIntentResult == main.TRUE:
- main.ONOScli1.intents( jsonFormat=False )
- main.log.info( "Point to point intent install successful" )
-
+ intentsId.append( pIntent1 )
+ intentsId.append( pIntent2 )
+ main.log.info( "Checking intents state")
+ checkStateResult = main.ONOScli1.checkIntentState( intentsId = intentsId )
time.sleep( 30 )
- flowHandle = main.ONOScli1.flows()
- main.log.info( "flows :" + flowHandle )
-
+ main.log.info( "Checking flows state")
+ checkFlowResult = main.ONOScli1.checkFlowsState()
# Sleep for 30 seconds to provide time for the intent state to change
- time.sleep( 60 )
- intentHandle = main.ONOScli1.intents( jsonFormat=False )
- main.log.info( "intents :" + intentHandle )
+ time.sleep( 30 )
+ main.log.info( "Checking intents state one more time")
+ checkStateResult = main.ONOScli1.checkIntentState( intentsId = intentsId )
+ step1Result = checkStateResult and checkFlowResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully added point intents",
+ onfail="Failed to add point intents")
- PingResult = main.TRUE
- count = 1
+ main.step( "Ping h1 and h5" )
+ step2Result = main.TRUE
main.log.info( "\n\nh1 is Pinging h5" )
- ping = main.LincOE2.pingHostOptical( src="h1", target="h5" )
- # ping = main.LincOE2.pinghost()
- if ping == main.FALSE and count < 5:
- count += 1
- PingResult = main.FALSE
- main.log.info(
- "Ping between h1 and h5 failed. Making attempt number " +
- str( count ) +
- " in 2 seconds" )
- time.sleep( 2 )
- elif ping == main.FALSE:
- main.log.info( "All ping attempts between h1 and h5 have failed" )
- PingResult = main.FALSE
- elif ping == main.TRUE:
- main.log.info( "Ping test between h1 and h5 passed!" )
- PingResult = main.TRUE
- else:
- main.log.info( "Unknown error" )
- PingResult = main.ERROR
+ pingResult = main.LincOE2.pingHostOptical( src="h1", target="h5" )
+ step2Result = pingResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step2Result,
+ onpass="Successfully pinged h1 and h5",
+ onfail="Failed to ping between h1 and h5")
- if PingResult == main.FALSE:
- main.log.report(
- "Point intents for packet optical have not ben installed" +
- " correctly. Cleaning up" )
- if PingResult == main.TRUE:
- main.log.report(
- "Point Intents for packet optical have been " +
- "installed correctly" )
-
- case23Result = PingResult
+ case23Result = step1Result and step2Result
utilities.assert_equals(
expect=main.TRUE,
actual=case23Result,
- onpass= "Point intents addition for packet optical and" +
- "Pingall Test successful",
- onfail= "Point intents addition for packet optical and" +
- "Pingall Test NOT successful" )
+ onpass="Point intents are installed properly",
+ onfail="Failed to install point intents" )
def CASE24( self, main ):
import time
import json
"""
LINC uses its own switch IDs. You can use the following
- command on the LINC console to find the mapping between
+ command on the LINC console to find the mapping between
DPIDs and LINC IDs.
rp(application:get_all_key(linc)).
-
+
Test Rerouting of Packet Optical by bringing a port down
- ( port 20 ) of a switch( switchID=1, or LincOE switchID =9 ),
+ ( port 20 ) of a switch( switchID=1, or LincOE switchID =9 ),
so that link
( between switch1 port20 - switch5 port50 ) is inactive
and do a ping test. If rerouting is successful,
@@ -431,16 +474,23 @@
main.log.report(
"This testcase tests rerouting and pings mininet hosts" )
main.case( "Test rerouting and pings mininet hosts" )
+
main.step( "Attach to the Linc-OE session" )
+ step1Result = main.TRUE
attachConsole = main.LincOE1.attachLincOESession()
- print "attachConsole = ", attachConsole
+ step1Result = attachConsole
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully attached Linc-OE session",
+ onfail="Failed to attached Linc-OE session")
main.step( "Bring a port down and verify the link state" )
+ step2Result = main.TRUE
main.LincOE1.portDown( swId="9", ptId="20" )
- linksNonjson = main.ONOScli3.links( jsonFormat=False )
+ linksNonjson = main.ONOScli1.links( jsonFormat=False )
main.log.info( "links = " + linksNonjson )
-
- linkInactiveCount = linksNonjson.count("state=INACTIVE")
+ linkInactiveCount = linksNonjson.count( "state=INACTIVE" )
main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
if linkInactiveCount == 2:
main.log.info(
@@ -448,10 +498,8 @@
else:
main.log.info(
"Number of links in INACTIVE state are wrong")
-
- links = main.ONOScli3.links()
+ links = main.ONOScli1.links()
main.log.info( "links = " + links )
-
linksResult = json.loads( links )
linksStateResult = main.FALSE
for item in linksResult:
@@ -475,53 +523,98 @@
main.log.report(
"Links state is not inactive as expected" )
linksStateResult = main.FALSE
-
- print "links_state_result = ", linksStateResult
time.sleep( 10 )
- flowHandle = main.ONOScli3.flows()
- main.log.info( "flows :" + flowHandle )
+ checkFlowsState = main.ONOScli1.checkFlowsState()
+ step2Result = linksStateResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step2Result,
+ onpass="Successfuly brought down a link",
+ onfail="Failed to bring down a link")
main.step( "Verify Rerouting by a ping test" )
- PingResult = main.TRUE
- count = 1
+ step3Result = main.TRUE
main.log.info( "\n\nh1 is Pinging h5" )
- ping = main.LincOE2.pingHostOptical( src="h1", target="h5" )
- # ping = main.LincOE2.pinghost()
- if ping == main.FALSE and count < 5:
- count += 1
- PingResult = main.FALSE
+ pingResult = main.LincOE2.pingHostOptical( src="h1", target="h5" )
+ step3Result = pingResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step3Result,
+ onpass="Successfully pinged h1 and h5",
+ onfail="Failed to ping between h1 and h5")
+
+ main.step( "Bring the downed port up and verify the link state" )
+ step4Result = main.TRUE
+ main.LincOE1.portUp( swId="9", ptId="20" )
+ linksNonjson = main.ONOScli1.links( jsonFormat=False )
+ main.log.info( "links = " + linksNonjson )
+ linkInactiveCount = linksNonjson.count( "state=INACTIVE" )
+ main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
+ if linkInactiveCount == 0:
main.log.info(
- "Ping between h1 and h5 failed. Making attempt number " +
- str( count ) +
- " in 2 seconds" )
- time.sleep( 2 )
- elif ping == main.FALSE:
- main.log.info( "All ping attempts between h1 and h5 have failed" )
- PingResult = main.FALSE
- elif ping == main.TRUE:
- main.log.info( "Ping test between h1 and h5 passed!" )
- PingResult = main.TRUE
+ "Number of links in INACTIVE state are correct")
else:
- main.log.info( "Unknown error" )
- PingResult = main.ERROR
+ main.log.info(
+ "Number of links in INACTIVE state are wrong")
+ step4Result = main.FALSE
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step4Result,
+ onpass="Successfully brought the port up",
+ onfail="Failed to bring the port up")
- if PingResult == main.TRUE:
- main.log.report( "Ping test successful " )
- if PingResult == main.FALSE:
- main.log.report( "Ping test failed" )
-
- case24Result = PingResult and linksStateResult
- utilities.assert_equals( expect=main.TRUE, actual=case24Result,
+ case24Result = step1Result and step2Result and step3Result \
+ and step4Result
+ utilities.assert_equals( expect=main.TRUE,
+ actual=case24Result,
onpass="Packet optical rerouting successful",
onfail="Packet optical rerouting failed" )
+ def CASE10( self ):
+ main.log.report(
+ "This testcase uninstalls the reactive forwarding app" )
+ main.log.report( "__________________________________" )
+ main.case( "Uninstalling reactive forwarding app" )
+ main.step( "Uninstalling reactive forwarding app" )
+ step1Result = main.TRUE
+ # Unistall onos-app-fwd app to disable reactive forwarding
+ main.log.info( "deactivate reactive forwarding app" )
+ appUninstallResult = main.ONOScli2.deactivateApp( "org.onosproject.fwd" )
+ appCheck = main.ONOScli2.appToIDCheck()
+ if appCheck != main.TRUE:
+ main.log.warn( main.ONOScli2.apps() )
+ main.log.warn( main.ONOScli2.appIDs() )
+ step1Result = appUninstallResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully deactivate reactive forwarding app",
+ onfail="Failed to deactivate reactive forwarding app")
+ # After reactive forwarding is disabled, the reactive flows on
+ # switches timeout in 10-15s
+ # So sleep for 15s
+ time.sleep( 15 )
+ flows = main.ONOScli2.flows()
+ main.log.info( flows )
+
+ case10Result = step1Result
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case10Result,
+ onpass="Reactive forwarding app uninstallation successful",
+ onfail="Reactive forwarding app uninstallation failed" )
+
def CASE25( self ):
"""
Add host intents between 2 packet layer host
"""
import time
import json
- main.log.report( "Adding host intents between 2 packet layer host" )
+ main.log.report( "Adding host intents between 2 optical layer host" )
+ main.case( "Test add host intents between optical layer host" )
+
+ main.step( "Discover host using arping" )
+ step1Result = main.TRUE
main.hostMACs = []
main.hostId = []
#Listing host MAC addresses
@@ -530,15 +623,25 @@
str( hex( i )[ 2: ] ).zfill( 2 ).upper() )
for macs in main.hostMACs:
main.hostId.append( macs + "/-1" )
-
host1 = main.hostId[ 0 ]
host2 = main.hostId[ 1 ]
- intentsId = []
# Use arping to discover the hosts
main.LincOE2.arping( host = "h1" )
main.LincOE2.arping( host = "h2" )
+ time.sleep( 5 )
+ hostsDict = main.ONOScli1.hosts()
+ if not len( hostsDict ):
+ step1Result = main.FALSE
# Adding host intent
- main.log.step( "Adding host intents to h1 and h2" )
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Hosts discovered",
+ onfail="Failed to discover hosts")
+
+ main.step( "Adding host intents to h1 and h2" )
+ step2Result = main.TRUE
+ intentsId = []
intent1 = main.ONOScli1.addHostIntent( hostIdOne = host1,
hostIdTwo = host2 )
intentsId.append( intent1 )
@@ -547,26 +650,54 @@
hostIdTwo = host1 )
intentsId.append( intent2 )
# Checking intents state before pinging
- main.log.step( "Checking intents state" )
- time.sleep( 10 )
+ main.log.info( "Checking intents state" )
+ time.sleep( 30 )
intentResult = main.ONOScli1.checkIntentState( intentsId = intentsId )
- utilities.assert_equals( expect=main.TRUE, actual=intentResult,
+ #check intent state again if intents are not in installed state
+ if not intentResult:
+ intentResult = main.ONOScli1.checkIntentState( intentsId = intentsId )
+ step2Result = intentResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=step2Result,
onpass="All intents are in INSTALLED state ",
onfail="Some of the intents are not in " +
"INSTALLED state " )
# pinging h1 to h2 and then ping h2 to h1
- main.log.step( "Pinging h1 and h2" )
+ main.step( "Pinging h1 and h2" )
+ step3Result = main.TRUE
pingResult = main.TRUE
pingResult = main.LincOE2.pingHostOptical( src="h1", target="h2" )
pingResult = pingResult and main.LincOE2.pingHostOptical( src="h2",
target="h1" )
-
- utilities.assert_equals( expect=main.TRUE, actual=pingResult,
+ step3Result = pingResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=step3Result,
onpass="Pinged successfully between h1 and h2",
onfail="Pinged failed between h1 and h2" )
-
- case25Result = pingResult
- utilities.assert_equals( expect=main.TRUE, actual=case25Result,
+ # Removed all added host intents
+ main.step( "Removing host intents" )
+ step4Result = main.TRUE
+ removeResult = main.TRUE
+ # Check remaining intents
+ intentsJson = json.loads( main.ONOScli1.intents() )
+ main.ONOScli1.removeIntent( intentId=intent1, purge=True )
+ main.ONOScli1.removeIntent( intentId=intent2, purge=True )
+ for intents in intentsJson:
+ main.ONOScli1.removeIntent( intentId=intents.get( 'id' ),
+ app='org.onosproject.optical',
+ purge=True )
+ print json.loads( main.ONOScli1.intents() )
+ if len( json.loads( main.ONOScli1.intents() ) ):
+ removeResult = main.FALSE
+ step4Result = removeResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=step4Result,
+ onpass="Successfully removed host intents",
+ onfail="Failed to remove host intents" )
+ case25Result = step1Result and step2Result and step3Result and \
+ step4Result
+ utilities.assert_equals( expect=main.TRUE,
+ actual=case25Result,
onpass="Add host intent successful",
onfail="Add host intent failed" )
diff --git a/TestON/tests/IpOpticalMulti/IpOpticalMultiOld.py b/TestON/tests/IpOpticalMulti/IpOpticalMultiOld.py
new file mode 100644
index 0000000..d00410f
--- /dev/null
+++ b/TestON/tests/IpOpticalMulti/IpOpticalMultiOld.py
@@ -0,0 +1,572 @@
+
+# Testing the basic functionality of ONOS Next
+# For sanity and driver functionality excercises only.
+
+import time
+import sys
+import os
+import re
+import time
+import json
+
+time.sleep( 1 )
+
+class IpOpticalMulti:
+
+ def __init__( self ):
+ self.default = ''
+
+ def CASE1( self, main ):
+ """
+ Startup sequence:
+ cell <name>
+ onos-verify-cell
+ onos-remove-raft-logs
+ git pull
+ mvn clean install
+ onos-package
+ onos-install -f
+ onos-wait-for-start
+ """
+ cellName = main.params[ 'ENV' ][ 'cellName' ]
+ ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
+ ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
+ ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
+ ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
+ ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
+ ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
+
+ main.case( "Setting up test environment" )
+ main.log.report(
+ "This testcase is testing setting up test environment" )
+ main.log.report( "__________________________________" )
+
+ main.step( "Applying cell variable to environment" )
+ cellResult1 = main.ONOSbench.setCell( cellName )
+ # cellResult2 = main.ONOScli1.setCell( cellName )
+ # cellResult3 = main.ONOScli2.setCell( cellName )
+ # cellResult4 = main.ONOScli3.setCell( cellName )
+ verifyResult = main.ONOSbench.verifyCell()
+ cellResult = cellResult1
+
+ main.step( "Removing raft logs before a clen installation of ONOS" )
+ removeLogResult = main.ONOSbench.onosRemoveRaftLogs()
+
+ main.step( "Git checkout, pull and get version" )
+ #main.ONOSbench.gitCheckout( "master" )
+ gitPullResult = main.ONOSbench.gitPull()
+ main.log.info( "git_pull_result = " + str( gitPullResult ))
+ versionResult = main.ONOSbench.getVersion( report=True )
+
+ if gitPullResult == 1:
+ main.step( "Using mvn clean & install" )
+ cleanInstallResult = main.ONOSbench.cleanInstall()
+ # cleanInstallResult = main.TRUE
+
+ main.step( "Creating ONOS package" )
+ packageResult = main.ONOSbench.onosPackage()
+
+ # main.step( "Creating a cell" )
+ # cellCreateResult = main.ONOSbench.createCellFile( **************
+ # )
+
+ main.step( "Installing ONOS package" )
+ onos1InstallResult = main.ONOSbench.onosInstall(
+ options="-f",
+ node=ONOS1Ip )
+ onos2InstallResult = main.ONOSbench.onosInstall(
+ options="-f",
+ node=ONOS2Ip )
+ onos3InstallResult = main.ONOSbench.onosInstall(
+ options="-f",
+ node=ONOS3Ip )
+ onosInstallResult = onos1InstallResult and onos2InstallResult and\
+ onos3InstallResult
+ if onosInstallResult == main.TRUE:
+ main.log.report( "Installing ONOS package successful" )
+ else:
+ main.log.report( "Installing ONOS package failed" )
+
+ onos1Isup = main.ONOSbench.isup( ONOS1Ip )
+ onos2Isup = main.ONOSbench.isup( ONOS2Ip )
+ onos3Isup = main.ONOSbench.isup( ONOS3Ip )
+ onosIsup = onos1Isup and onos2Isup and onos3Isup
+ if onosIsup == main.TRUE:
+ main.log.report( "ONOS instances are up and ready" )
+ else:
+ main.log.report( "ONOS instances may not be up" )
+
+ main.step( "Starting ONOS service" )
+ startResult = main.TRUE
+ # startResult = main.ONOSbench.onosStart( ONOS1Ip )
+ startcli1 = main.ONOScli1.startOnosCli( ONOSIp=ONOS1Ip )
+ startcli2 = main.ONOScli2.startOnosCli( ONOSIp=ONOS2Ip )
+ startcli3 = main.ONOScli3.startOnosCli( ONOSIp=ONOS3Ip )
+ print startcli1
+ print startcli2
+ print startcli3
+
+ case1Result = ( packageResult and
+ cellResult and verifyResult and onosInstallResult and
+ onosIsup and startResult )
+ utilities.assertEquals( expect=main.TRUE, actual=case1Result,
+ onpass="Test startup successful",
+ onfail="Test startup NOT successful" )
+
+ def CASE10( self ):
+ import time
+ main.log.report(
+ "This testcase uninstalls the reactive forwarding app" )
+ main.log.report( "__________________________________" )
+ main.case( "Uninstalling reactive forwarding app" )
+ # Unistall onos-app-fwd app to disable reactive forwarding
+ appInstallResult = main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
+ appCheck = main.ONOScli1.appToIDCheck()
+ if appCheck != main.TRUE:
+ main.log.warn( main.ONOScli1.apps() )
+ main.log.warn( main.ONOScli1.appIDs() )
+ main.log.info( "onos-app-fwd uninstalled" )
+
+ # After reactive forwarding is disabled,
+ # the reactive flows on switches timeout in 10-15s
+ # So sleep for 15s
+ time.sleep( 15 )
+
+ hosts = main.ONOScli1.hosts()
+ main.log.info( hosts )
+ case10Result = appInstallResult
+ utilities.assertEquals(
+ expect=main.TRUE,
+ actual=case10Result,
+ onpass="Reactive forwarding app uninstallation successful",
+ onfail="Reactive forwarding app uninstallation failed" )
+
+ def CASE20( self ):
+ """
+ Exit from mininet cli
+ reinstall ONOS
+ """
+ cellName = main.params[ 'ENV' ][ 'cellName' ]
+ ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
+ ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
+ ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
+ ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
+ ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
+ ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
+
+ main.log.report( "This testcase exits the mininet cli and reinstalls" +
+ "ONOS to switch over to Packet Optical topology" )
+ main.log.report( "_____________________________________________" )
+ main.case( "Disconnecting mininet and restarting ONOS" )
+ main.step( "Disconnecting mininet and restarting ONOS" )
+ mininetDisconnect = main.Mininet1.disconnect()
+ print "mininetDisconnect = ", mininetDisconnect
+
+ main.step( "Removing raft logs before a clen installation of ONOS" )
+ main.ONOSbench.onosRemoveRaftLogs()
+
+ main.step( "Applying cell variable to environment" )
+ cellResult = main.ONOSbench.setCell( cellName )
+ verifyResult = main.ONOSbench.verifyCell()
+
+
+ main.step( "Installing ONOS package" )
+ onos1InstallResult = main.ONOSbench.onosInstall(
+ options="-f",
+ node=ONOS1Ip )
+ onos2InstallResult = main.ONOSbench.onosInstall(
+ options="-f",
+ node=ONOS2Ip )
+ onos3InstallResult = main.ONOSbench.onosInstall(
+ options="-f",
+ node=ONOS3Ip )
+ onosInstallResult = onos1InstallResult and onos2InstallResult and\
+ onos3InstallResult
+ if onosInstallResult == main.TRUE:
+ main.log.report( "Installing ONOS package successful" )
+ else:
+ main.log.report( "Installing ONOS package failed" )
+
+ onos1Isup = main.ONOSbench.isup( ONOS1Ip )
+ onos2Isup = main.ONOSbench.isup( ONOS2Ip )
+ onos3Isup = main.ONOSbench.isup( ONOS3Ip )
+ onosIsup = onos1Isup and onos2Isup and onos3Isup
+ if onosIsup == main.TRUE:
+ main.log.report( "ONOS instances are up and ready" )
+ else:
+ main.log.report( "ONOS instances may not be up" )
+
+ main.step( "Starting ONOS service" )
+ startResult = main.TRUE
+ # startResult = main.ONOSbench.onosStart( ONOS1Ip )
+ startcli1 = main.ONOScli1.startOnosCli( ONOSIp=ONOS1Ip )
+ startcli2 = main.ONOScli2.startOnosCli( ONOSIp=ONOS2Ip )
+ startcli3 = main.ONOScli3.startOnosCli( ONOSIp=ONOS3Ip )
+ startResult = startcli1 and startcli2 and startcli3
+ if startResult == main.TRUE:
+ main.log.report( "ONOS cli starts properly" )
+ case20Result = mininetDisconnect and cellResult and verifyResult \
+ and onosInstallResult and onosIsup and startResult
+
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case20Result,
+ onpass= "Exiting functionality mininet topology and reinstalling" +
+ " ONOS successful",
+ onfail= "Exiting functionality mininet topology and reinstalling" +
+ " ONOS failed" )
+
+ def CASE21( self, main ):
+ """
+ On ONOS bench, run this command:
+ sudo -E python ~/onos/tools/test/topos/opticalTest.py -OC1 <Ctrls>
+ which spawns packet optical topology and copies the links
+ json file to the onos instance.
+ Note that in case of Packet Optical, the links are not learnt
+ from the topology, instead the links are learnt
+ from the json config file
+ """
+ main.log.report(
+ "This testcase starts the packet layer topology and REST" )
+ main.log.report( "_____________________________________________" )
+ main.case( "Starting LINC-OE and other components" )
+ main.step( "Starting LINC-OE and other components" )
+ main.log.info( "Activate optical app" )
+ appInstallResult = main.ONOScli1.activateApp( "org.onosproject.optical" )
+ appCheck = main.ONOScli1.appToIDCheck()
+ appCheck = appCheck and main.ONOScli2.appToIDCheck()
+ appCheck = appCheck and main.ONOScli3.appToIDCheck()
+ if appCheck != main.TRUE:
+ main.log.warn( "Checking ONOS application unsuccesful" )
+
+ ctrllerIP = []
+ ctrllerIP.append( main.params[ 'CTRL' ][ 'ip1' ] )
+ #ctrllerIP.append( main.params[ 'CTRL' ][ 'ip2' ] )
+ #ctrllerIP.append( main.params[ 'CTRL' ][ 'ip3' ] )
+ opticalMnScript = main.LincOE2.runOpticalMnScript( ctrllerIP = ctrllerIP )
+ case21Result = opticalMnScript and appInstallResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case21Result,
+ onpass="Packet optical topology spawned successsfully",
+ onfail="Packet optical topology spawning failed" )
+
+ def CASE22( self, main ):
+ """
+ Curretly we use, 10 optical switches(ROADM's) and
+ 6 packet layer mininet switches each with one host.
+ Therefore, the roadmCount variable = 10,
+ packetLayerSWCount variable = 6, hostCount=6 and
+ links=42.
+ All this is hardcoded in the testcase. If the topology changes,
+ these hardcoded values need to be changed
+ """
+ main.log.report(
+ "This testcase compares the optical+packet topology against what" +
+ " is expected" )
+ main.case( "Topology comparision" )
+ main.step( "Topology comparision" )
+ devicesResult = main.ONOScli3.devices( jsonFormat=False )
+
+ print "devices_result = ", devicesResult
+ devicesLinewise = devicesResult.split( "\n" )
+ roadmCount = 0
+ packetLayerSWCount = 0
+ for line in devicesLinewise:
+ components = line.split( "," )
+ availability = components[ 1 ].split( "=" )[ 1 ]
+ type = components[ 3 ].split( "=" )[ 1 ]
+ if availability == 'true' and type == 'ROADM':
+ roadmCount += 1
+ elif availability == 'true' and type == 'SWITCH':
+ packetLayerSWCount += 1
+ if roadmCount == 10:
+ print "Number of Optical Switches = %d and is" % roadmCount +\
+ " correctly detected"
+ main.log.info(
+ "Number of Optical Switches = " +
+ str( roadmCount ) +
+ " and is correctly detected" )
+ opticalSWResult = main.TRUE
+ else:
+ print "Number of Optical Switches = %d and is wrong" % roadmCount
+ main.log.info(
+ "Number of Optical Switches = " +
+ str( roadmCount ) +
+ " and is wrong" )
+ opticalSWResult = main.FALSE
+
+ if packetLayerSWCount == 6:
+ print "Number of Packet layer or mininet Switches = %d "\
+ % packetLayerSWCount + "and is correctly detected"
+ main.log.info(
+ "Number of Packet layer or mininet Switches = " +
+ str( packetLayerSWCount ) +
+ " and is correctly detected" )
+ packetSWResult = main.TRUE
+ else:
+ print "Number of Packet layer or mininet Switches = %d and"\
+ % packetLayerSWCount + " is wrong"
+ main.log.info(
+ "Number of Packet layer or mininet Switches = " +
+ str( packetLayerSWCount ) +
+ " and is wrong" )
+ packetSWResult = main.FALSE
+ print "_________________________________"
+
+ linksResult = main.ONOScli3.links( jsonFormat=False )
+ print "links_result = ", linksResult
+ print "_________________________________"
+ linkActiveCount = linksResult.count("state=ACTIVE")
+ main.log.info( "linkActiveCount = " + str( linkActiveCount ))
+ if linkActiveCount == 42:
+ linkActiveResult = main.TRUE
+ main.log.info(
+ "Number of links in ACTIVE state are correct")
+ else:
+ linkActiveResult = main.FALSE
+ main.log.info(
+ "Number of links in ACTIVE state are wrong")
+
+ case22Result = opticalSWResult and packetSWResult and \
+ linkActiveResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case22Result,
+ onpass="Packet optical topology discovery successful",
+ onfail="Packet optical topology discovery failed" )
+
+ def CASE23( self, main ):
+ import time
+ """
+ Add bidirectional point intents between 2 packet layer( mininet )
+ devices and
+ ping mininet hosts
+ """
+ main.log.report(
+ "This testcase adds bidirectional point intents between 2 " +
+ "packet layer( mininet ) devices and ping mininet hosts" )
+ main.case( "Topology comparision" )
+ main.step( "Adding point intents" )
+ ptpIntentResult = main.ONOScli1.addPointIntent(
+ "of:0000ffffffff0001/1",
+ "of:0000ffffffff0005/1" )
+ if ptpIntentResult == main.TRUE:
+ main.ONOScli1.intents( jsonFormat=False )
+ main.log.info( "Point to point intent install successful" )
+
+ ptpIntentResult = main.ONOScli1.addPointIntent(
+ "of:0000ffffffff0005/1",
+ "of:0000ffffffff0001/1" )
+ if ptpIntentResult == main.TRUE:
+ main.ONOScli1.intents( jsonFormat=False )
+ main.log.info( "Point to point intent install successful" )
+
+ time.sleep( 30 )
+ flowHandle = main.ONOScli1.flows()
+ main.log.info( "flows :" + flowHandle )
+
+ # Sleep for 30 seconds to provide time for the intent state to change
+ time.sleep( 60 )
+ intentHandle = main.ONOScli1.intents( jsonFormat=False )
+ main.log.info( "intents :" + intentHandle )
+
+ PingResult = main.TRUE
+ count = 1
+ main.log.info( "\n\nh1 is Pinging h5" )
+ ping = main.LincOE2.pingHostOptical( src="h1", target="h5" )
+ # ping = main.LincOE2.pinghost()
+ if ping == main.FALSE and count < 5:
+ count += 1
+ PingResult = main.FALSE
+ main.log.info(
+ "Ping between h1 and h5 failed. Making attempt number " +
+ str( count ) +
+ " in 2 seconds" )
+ time.sleep( 2 )
+ elif ping == main.FALSE:
+ main.log.info( "All ping attempts between h1 and h5 have failed" )
+ PingResult = main.FALSE
+ elif ping == main.TRUE:
+ main.log.info( "Ping test between h1 and h5 passed!" )
+ PingResult = main.TRUE
+ else:
+ main.log.info( "Unknown error" )
+ PingResult = main.ERROR
+
+ if PingResult == main.FALSE:
+ main.log.report(
+ "Point intents for packet optical have not ben installed" +
+ " correctly. Cleaning up" )
+ if PingResult == main.TRUE:
+ main.log.report(
+ "Point Intents for packet optical have been " +
+ "installed correctly" )
+
+ case23Result = PingResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case23Result,
+ onpass= "Point intents addition for packet optical and" +
+ "Pingall Test successful",
+ onfail= "Point intents addition for packet optical and" +
+ "Pingall Test NOT successful" )
+
+ def CASE24( self, main ):
+ import time
+ import json
+ """
+ LINC uses its own switch IDs. You can use the following
+ command on the LINC console to find the mapping between
+ DPIDs and LINC IDs.
+ rp(application:get_all_key(linc)).
+
+ Test Rerouting of Packet Optical by bringing a port down
+ ( port 20 ) of a switch( switchID=1, or LincOE switchID =9 ),
+ so that link
+ ( between switch1 port20 - switch5 port50 ) is inactive
+ and do a ping test. If rerouting is successful,
+ ping should pass. also check the flows
+ """
+ main.log.report(
+ "This testcase tests rerouting and pings mininet hosts" )
+ main.case( "Test rerouting and pings mininet hosts" )
+ main.step( "Attach to the Linc-OE session" )
+ attachConsole = main.LincOE1.attachLincOESession()
+ print "attachConsole = ", attachConsole
+
+ main.step( "Bring a port down and verify the link state" )
+ main.LincOE1.portDown( swId="9", ptId="20" )
+ linksNonjson = main.ONOScli3.links( jsonFormat=False )
+ main.log.info( "links = " + linksNonjson )
+
+ linkInactiveCount = linksNonjson.count("state=INACTIVE")
+ main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
+ if linkInactiveCount == 2:
+ main.log.info(
+ "Number of links in INACTIVE state are correct")
+ else:
+ main.log.info(
+ "Number of links in INACTIVE state are wrong")
+
+ links = main.ONOScli3.links()
+ main.log.info( "links = " + links )
+
+ linksResult = json.loads( links )
+ linksStateResult = main.FALSE
+ for item in linksResult:
+ if item[ 'src' ][ 'device' ] == "of:0000ffffffffff01" and item[
+ 'src' ][ 'port' ] == "20":
+ if item[ 'dst' ][ 'device' ] == "of:0000ffffffffff05" and item[
+ 'dst' ][ 'port' ] == "50":
+ linksState = item[ 'state' ]
+ if linksState == "INACTIVE":
+ main.log.info(
+ "Links state is inactive as expected due to one" +
+ " of the ports being down" )
+ main.log.report(
+ "Links state is inactive as expected due to one" +
+ " of the ports being down" )
+ linksStateResult = main.TRUE
+ break
+ else:
+ main.log.info(
+ "Links state is not inactive as expected" )
+ main.log.report(
+ "Links state is not inactive as expected" )
+ linksStateResult = main.FALSE
+
+ print "links_state_result = ", linksStateResult
+ time.sleep( 10 )
+ flowHandle = main.ONOScli3.flows()
+ main.log.info( "flows :" + flowHandle )
+
+ main.step( "Verify Rerouting by a ping test" )
+ PingResult = main.TRUE
+ count = 1
+ main.log.info( "\n\nh1 is Pinging h5" )
+ ping = main.LincOE2.pingHostOptical( src="h1", target="h5" )
+ # ping = main.LincOE2.pinghost()
+ if ping == main.FALSE and count < 5:
+ count += 1
+ PingResult = main.FALSE
+ main.log.info(
+ "Ping between h1 and h5 failed. Making attempt number " +
+ str( count ) +
+ " in 2 seconds" )
+ time.sleep( 2 )
+ elif ping == main.FALSE:
+ main.log.info( "All ping attempts between h1 and h5 have failed" )
+ PingResult = main.FALSE
+ elif ping == main.TRUE:
+ main.log.info( "Ping test between h1 and h5 passed!" )
+ PingResult = main.TRUE
+ else:
+ main.log.info( "Unknown error" )
+ PingResult = main.ERROR
+
+ if PingResult == main.TRUE:
+ main.log.report( "Ping test successful " )
+ if PingResult == main.FALSE:
+ main.log.report( "Ping test failed" )
+
+ case24Result = PingResult and linksStateResult
+ utilities.assert_equals( expect=main.TRUE, actual=case24Result,
+ onpass="Packet optical rerouting successful",
+ onfail="Packet optical rerouting failed" )
+
+ def CASE25( self ):
+ """
+ Add host intents between 2 packet layer host
+ """
+ import time
+ import json
+ main.log.report( "Adding host intents between 2 packet layer host" )
+ main.hostMACs = []
+ main.hostId = []
+ #Listing host MAC addresses
+ for i in range( 1 , 7 ):
+ main.hostMACs.append( "00:00:00:00:00:" +
+ str( hex( i )[ 2: ] ).zfill( 2 ).upper() )
+ for macs in main.hostMACs:
+ main.hostId.append( macs + "/-1" )
+
+ host1 = main.hostId[ 0 ]
+ host2 = main.hostId[ 1 ]
+ intentsId = []
+ # Use arping to discover the hosts
+ main.LincOE2.arping( host = "h1" )
+ main.LincOE2.arping( host = "h2" )
+ # Adding host intent
+ main.log.step( "Adding host intents to h1 and h2" )
+ intent1 = main.ONOScli1.addHostIntent( hostIdOne = host1,
+ hostIdTwo = host2 )
+ intentsId.append( intent1 )
+ time.sleep( 5 )
+ intent2 = main.ONOScli1.addHostIntent( hostIdOne = host2,
+ hostIdTwo = host1 )
+ intentsId.append( intent2 )
+ # Checking intents state before pinging
+ main.log.step( "Checking intents state" )
+ time.sleep( 10 )
+ intentResult = main.ONOScli1.checkIntentState( intentsId = intentsId )
+ utilities.assert_equals( expect=main.TRUE, actual=intentResult,
+ onpass="All intents are in INSTALLED state ",
+ onfail="Some of the intents are not in " +
+ "INSTALLED state " )
+
+ # pinging h1 to h2 and then ping h2 to h1
+ main.log.step( "Pinging h1 and h2" )
+ pingResult = main.TRUE
+ pingResult = main.LincOE2.pingHostOptical( src="h1", target="h2" )
+ pingResult = pingResult and main.LincOE2.pingHostOptical( src="h2",
+ target="h1" )
+
+ utilities.assert_equals( expect=main.TRUE, actual=pingResult,
+ onpass="Pinged successfully between h1 and h2",
+ onfail="Pinged failed between h1 and h2" )
+
+ case25Result = pingResult
+ utilities.assert_equals( expect=main.TRUE, actual=case25Result,
+ onpass="Add host intent successful",
+ onfail="Add host intent failed" )