Merge "Add exception handling for parseFlowTable in MininetCliDriver"
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 8165d3a..3eb5577 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -2174,71 +2174,80 @@
returns: A list of flows in json format
'''
jsonFlowTable = []
- for flow in flowTable:
- jsonFlow = {}
- # split up the fields of the flow
- parsedFlow = flow.split(", ")
- # get rid of any spaces in front of the field
- for i in range( len(parsedFlow) ):
- item = parsedFlow[i]
- if item[0] == " ":
- parsedFlow[i] = item[1:]
- # grab the selector and treatment from the parsed flow
- # the last element is the selector and the treatment
- temp = parsedFlow.pop(-1)
- # split up the selector and the treatment
- temp = temp.split(" ")
- index = 0
- # parse the flags
- # NOTE: This only parses one flag
- flag = {}
- if version == "1.3":
- flag = {"flag":[temp[index]]}
+ try:
+ for flow in flowTable:
+ jsonFlow = {}
+ # split up the fields of the flow
+ parsedFlow = flow.split(", ")
+ # get rid of any spaces in front of the field
+ for i in range( len(parsedFlow) ):
+ item = parsedFlow[i]
+ if item[0] == " ":
+ parsedFlow[i] = item[1:]
+ # grab the selector and treatment from the parsed flow
+ # the last element is the selector and the treatment
+ temp = parsedFlow.pop(-1)
+ # split up the selector and the treatment
+ temp = temp.split(" ")
+ index = 0
+ # parse the flags
+ # NOTE: This only parses one flag
+ flag = {}
+ if version == "1.3":
+ flag = {"flag":[temp[index]]}
+ index += 1
+ # the first element is the selector and split it up
+ sel = temp[index]
index += 1
- # the first element is the selector and split it up
- sel = temp[index]
- index += 1
- sel = sel.split(",")
- # the priority is stuck in the selecter so put it back
- # in the flow
- parsedFlow.append(sel.pop(0))
- # parse selector
- criteria = []
- for item in sel:
- # this is the type of the packet e.g. "arp"
- if "=" not in item:
- criteria.append( {"type":item} )
- else:
+ sel = sel.split(",")
+ # the priority is stuck in the selecter so put it back
+ # in the flow
+ parsedFlow.append(sel.pop(0))
+ # parse selector
+ criteria = []
+ for item in sel:
+ # this is the type of the packet e.g. "arp"
+ if "=" not in item:
+ criteria.append( {"type":item} )
+ else:
+ field = item.split("=")
+ criteria.append( {field[0]:field[1]} )
+ selector = {"selector": {"criteria":sorted(criteria)} }
+ treat = temp[index]
+ # get rid of the action part e.g. "action=output:2"
+ # we will add it back later
+ treat = treat.split("=")
+ treat.pop(0)
+ # parse treatment
+ action = []
+ for item in treat:
+ field = item.split(":")
+ action.append( {field[0]:field[1]} )
+ # create the treatment field and add the actions
+ treatment = {"treatment": {"action":sorted(action)} }
+ # parse the rest of the flow
+ for item in parsedFlow:
field = item.split("=")
- criteria.append( {field[0]:field[1]} )
- selector = {"selector": {"criteria":sorted(criteria)} }
- treat = temp[index]
- # get rid of the action part e.g. "action=output:2"
- # we will add it back later
- treat = treat.split("=")
- treat.pop(0)
- # parse treatment
- action = []
- for item in treat:
- field = item.split(":")
- action.append( {field[0]:field[1]} )
- # create the treatment field and add the actions
- treatment = {"treatment": {"action":sorted(action)} }
- # parse the rest of the flow
- for item in parsedFlow:
- field = item.split("=")
- jsonFlow.update( {field[0]:field[1]} )
- # add the treatment and the selector to the json flow
- jsonFlow.update( selector )
- jsonFlow.update( treatment )
- jsonFlow.update( flag )
+ jsonFlow.update( {field[0]:field[1]} )
+ # add the treatment and the selector to the json flow
+ jsonFlow.update( selector )
+ jsonFlow.update( treatment )
+ jsonFlow.update( flag )
- if debug: main.log.debug( "\033[94mJson flow:\033[0m\n{}\n".format(jsonFlow) )
+ if debug: main.log.debug( "\033[94mJson flow:\033[0m\n{}\n".format(jsonFlow) )
- # add the json flow to the json flow table
- jsonFlowTable.append( jsonFlow )
+ # add the json flow to the json flow table
+ jsonFlowTable.append( jsonFlow )
- return jsonFlowTable
+ return jsonFlowTable
+
+ except IndexError:
+ main.log.exception( self.name + ": IndexError found" )
+ return None
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanup()
+ main.exit()
def getFlowTable( self, sw, version="", debug=False):
'''