Exception handling for FUNCintentRest
Change-Id: Iddbdeb1983fa3598ae6ed2972817cf4bf8c66da7
diff --git a/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.py b/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.py
index 8c6c8d5..f48ae3b 100644
--- a/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.py
+++ b/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.py
@@ -155,6 +155,7 @@
# main.scale[ 0 ] determines the current number of ONOS controller
main.numCtrls = int( main.scale[ 0 ] )
main.flowCompiler = "Flow Rules"
+ main.initialized = main.TRUE
main.case( "Starting up " + str( main.numCtrls ) +
" node(s) ONOS cluster" )
@@ -233,22 +234,22 @@
for i in range( main.numCtrls ):
onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
- if onosIsUp == main.TRUE:
- main.log.report( "ONOS instance is up and ready" )
- else:
- main.log.report( "ONOS instance may not be up, stop and " +
- "start ONOS again " )
- for i in range( main.numCtrls ):
- stopResult = stopResult and \
- main.ONOSbench.onosStop( main.ONOSip[ i ] )
- for i in range( main.numCtrls ):
- startResult = startResult and \
- main.ONOSbench.onosStart( main.ONOSip[ i ] )
+ if onosIsUp == main.TRUE:
+ main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
+ else:
+ main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
+ "start ONOS again " )
+ stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
+ startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
+ if not startResult or stopResult:
+ main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1 ) )
stepResult = onosIsUp and stopResult and startResult
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="ONOS service is ready",
onfail="ONOS service did not start properly" )
+ if not stepResult:
+ main.initialized = main.FALSE
# Start an ONOS cli to provide functionality that is not currently
# supported by the Rest API remove this when Leader Checking is supported
@@ -264,6 +265,8 @@
actual=stepResult,
onpass="Successfully start ONOS cli",
onfail="Failed to start ONOS cli" )
+ if not stepResult:
+ main.initialized = main.FALSE
# Remove the first element in main.scale list
main.scale.remove( main.scale[ 0 ] )
@@ -477,6 +480,9 @@
"""
Start Mininet topology with OF 1.0 switches
"""
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
main.OFProtocol = "1.0"
main.log.report( "Start Mininet topology with OF 1.0 switches" )
main.case( "Start Mininet topology with OF 1.0 switches" )
@@ -496,13 +502,15 @@
onfail="Failed to load topology" )
# Exit if topology did not load properly
if not topoResult:
- main.cleanup()
- main.exit()
+ main.initialized = main.FALSE
def CASE11( self, main ):
"""
Start Mininet topology with OF 1.3 switches
"""
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
main.OFProtocol = "1.3"
main.log.report( "Start Mininet topology with OF 1.3 switches" )
main.case( "Start Mininet topology with OF 1.3 switches" )
@@ -522,8 +530,7 @@
onfail="Failed to load topology" )
# Exit if topology did not load properly
if not topoResult:
- main.cleanup()
- main.exit()
+ main.initialized = main.FALSE
def CASE12( self, main ):
"""
@@ -531,6 +538,9 @@
"""
import re
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
main.case( "Assign switches to controllers" )
main.step( "Assigning switches to controllers" )
main.caseExplanation = "Assign OF " + main.OFProtocol +\
@@ -551,8 +561,9 @@
ip=tempONOSip,
port='6653' )
if not assignResult:
- main.cleanup()
- main.exit()
+ main.log.error( "Problem assigning mastership of switches, skipping further test cases" )
+ main.initialized = main.FALSE
+ main.skipCase()
for i in range( 1, ( main.numSwitch + 1 ) ):
response = main.Mininet1.getSwController( "s" + str( i ) )
@@ -568,11 +579,16 @@
"to controller",
onfail="Failed to assign switches to " +
"controller" )
+ if not stepResult:
+ main.initialized = main.FALSE
def CASE13( self,main ):
"""
Create Scapy components
"""
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
main.case( "Create scapy components" )
main.step( "Create scapy components" )
import json
@@ -595,11 +611,16 @@
actual=scapyResult,
onpass="Successfully created Scapy Components",
onfail="Failed to discover Scapy Components" )
+ if not scapyResult:
+ main.initialized = main.FALSE
def CASE14( self, main ):
"""
Discover all hosts and store its data to a dictionary
"""
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
main.case( "Discover all hosts" )
stepResult = main.TRUE
@@ -623,17 +644,23 @@
actual=stepResult,
onpass="Successfully discovered hosts",
onfail="Failed to discover hosts" )
+ if not stepResult:
+ main.initialized = main.FALSE
def CASE15( self, main ):
"""
Discover all hosts with scapy arp packets and store its data to a dictionary
"""
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
main.case( "Discover all hosts using scapy" )
main.step( "Send packets from each host to the first host and confirm onos discovery" )
import collections
if len( main.scapyHosts ) < 1:
main.log.error( "No scapy hosts have been created" )
+ main.initialized = main.FALSE
main.skipCase()
# Send ARP packets from each scapy host component
@@ -647,6 +674,9 @@
actual=stepResult,
onpass="ONOS correctly discovered all hosts",
onfail="ONOS incorrectly discovered hosts" )
+ if not stepResult:
+ main.initialized = main.FALSE
+ main.skipCase()
main.step( "Populate hostsData" )
stepResult = main.intentFunction.populateHostData( main )
@@ -654,11 +684,16 @@
actual=stepResult,
onpass="Successfully populated hostsData",
onfail="Failed to populate hostsData" )
+ if not stepResult:
+ main.initialized = main.FALSE
def CASE16( self, main ):
"""
Balance Masters
"""
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
main.case( "Balance mastership of switches" )
main.step( "Balancing mastership of switches" )
@@ -669,11 +704,16 @@
actual=stepResult,
onpass="Successfully balanced mastership of switches",
onfail="Failed to balance mastership of switches" )
+ if not stepResult:
+ main.initialized = main.FALSE
def CASE17( self, main ):
"""
Use Flow Objectives
"""
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
main.case( "Enable intent compilation using Flow Objectives" )
main.step( "Enabling Flow Objectives" )
@@ -688,6 +728,8 @@
actual=stepResult,
onpass="Successfully activated Flow Objectives",
onfail="Failed to activate Flow Objectives" )
+ if not stepResult:
+ main.initialized = main.FALSE
def CASE18( self, main ):
"""
@@ -750,14 +792,31 @@
import time
import json
import re
-
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
# Assert variables - These variable's name|format must be followed
# if you want to use the wrapper function
assert main, "There is no main"
- assert main.CLIs, "There is no main.CLIs"
- assert main.Mininet1, "Mininet handle should be named Mininet1"
- assert main.numSwitch, "Placed the total number of switch topology in \
- main.numSwitch"
+ try:
+ assert main.CLIs
+ except AssertionError:
+ main.log.error( "There is no main.CLIs, skipping test cases" )
+ main.initialized = main.FALSE
+ main.skipCase()
+ try:
+ assert main.Mininet1
+ except AssertionError:
+ main.log.error( "Mininet handle should be named Mininet1, skipping test cases" )
+ main.initialized = main.FALSE
+ main.skipCase()
+ try:
+ assert main.numSwitch
+ except AssertionError:
+ main.log.error( "Place the total number of switch topology in \
+ main.numSwitch" )
+ main.initialized = main.FALSE
+ main.skipCase()
# Save leader candidates
intentLeadersOld = main.CLIs2[ 0 ].leaderCandidates()
@@ -971,14 +1030,31 @@
import time
import json
import re
-
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
# Assert variables - These variable's name|format must be followed
# if you want to use the wrapper function
assert main, "There is no main"
- assert main.CLIs, "There is no main.CLIs"
- assert main.Mininet1, "Mininet handle should be named Mininet1"
- assert main.numSwitch, "Placed the total number of switch topology in \
- main.numSwitch"
+ try:
+ assert main.CLIs
+ except AssertionError:
+ main.log.error( "There is no main.CLIs, skipping test cases" )
+ main.initialized = main.FALSE
+ main.skipCase()
+ try:
+ assert main.Mininet1
+ except AssertionError:
+ main.log.error( "Mininet handle should be named Mininet1, skipping test cases" )
+ main.initialized = main.FALSE
+ main.skipCase()
+ try:
+ assert main.numSwitch
+ except AssertionError:
+ main.log.error( "Place the total number of switch topology in \
+ main.numSwitch" )
+ main.initialized = main.FALSE
+ main.skipCase()
main.case( "Point Intents Test - " + str( main.numCtrls ) +
" NODE(S) - OF " + main.OFProtocol + " - Using " + main.flowCompiler )
@@ -1532,58 +1608,35 @@
" to single point intents" )
def CASE5000( self, main ):
- # """
- # Will add description in next patch set
- # """
- # assert main, "There is no main"
- # assert main.CLIs, "There is no main.CLIs"
- # assert main.Mininet1, "Mininet handle should be named Mininet1"
- # assert main.numSwitch, "Placed the total number of switch topology in \
- # main.numSwitch"
- # main.case( "Test host mobility with host intents " )
- # main.step( " Testing host mobility by moving h1 from s5 to s6" )
- # h1PreMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
-
- # main.log.info( "Moving h1 from s5 to s6")
-
- # main.Mininet1.moveHost( "h1","s5","s6" )
-
- # main.intentFunction.getHostsData( main )
- # h1PostMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
-
- # utilities.assert_equals( expect="of:0000000000000006",
- # actual=h1PostMove,
- # onpass="Mobility: Successfully moved h1 to s6",
- # onfail="Mobility: Failed to moved h1 to s6" +
- # " to single point intents" +
- # " with IPV4 type and MAC addresses" +
- # " in the same VLAN" )
-
- # main.step( "IPV4: Add host intents between h1 and h9" )
- # stepResult = main.TRUE
- # stepResult = main.intentFunction.hostIntent( main,
- # onosNode='0',
- # name='IPV4',
- # host1='h1',
- # host2='h9',
- # host1Id='00:00:00:00:00:01/-1',
- # host2Id='00:00:00:00:00:09/-1' )
-
- # utilities.assert_equals( expect=main.TRUE,
- # actual=stepResult,
- # onpass="IPV4: Host intent test successful " +
- # "between two IPV4 hosts",
- # onfail="IPV4: Host intent test failed " +
- # "between two IPV4 hosts")
"""
Tests Host Mobility
Modifies the topology location of h1
"""
+ if main.initialized == main.FALSE:
+ main.log.error( "Test components did not start correctly, skipping further tests" )
+ main.skipCase()
+ # Assert variables - These variable's name|format must be followed
+ # if you want to use the wrapper function
assert main, "There is no main"
- assert main.CLIs, "There is no main.CLIs"
- assert main.Mininet1, "Mininet handle should be named Mininet1"
- assert main.numSwitch, "Placed the total number of switch topology in \
- main.numSwitch"
+ try:
+ assert main.CLIs
+ except AssertionError:
+ main.log.error( "There is no main.CLIs, skipping test cases" )
+ main.initialized = main.FALSE
+ main.skipCase()
+ try:
+ assert main.Mininet1
+ except AssertionError:
+ main.log.error( "Mininet handle should be named Mininet1, skipping test cases" )
+ main.initialized = main.FALSE
+ main.skipCase()
+ try:
+ assert main.numSwitch
+ except AssertionError:
+ main.log.error( "Place the total number of switch topology in \
+ main.numSwitch" )
+ main.initialized = main.FALSE
+ main.skipCase()
main.case( "Test host mobility with host intents " )
main.step( "Testing host mobility by moving h1 from s5 to s6" )
h1PreMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
diff --git a/TestON/tests/FUNC/FUNCintentRest/dependencies/FuncIntentFunction.py b/TestON/tests/FUNC/FUNCintentRest/dependencies/FuncIntentFunction.py
index 900abd5..8a48a13 100644
--- a/TestON/tests/FUNC/FUNCintentRest/dependencies/FuncIntentFunction.py
+++ b/TestON/tests/FUNC/FUNCintentRest/dependencies/FuncIntentFunction.py
@@ -66,24 +66,31 @@
main.log.info( itemName + ": Adding single point to multi point intents" )
- if not host1.get( "id" ):
- main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
- main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
- host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
+ try:
+ if not host1.get( "id" ):
+ main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
+ main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
+ host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
- if not host2.get( "id" ):
- main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
- host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
+ if not host2.get( "id" ):
+ main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
+ host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
- # Adding host intents
- main.log.info( itemName + ": Adding host intents" )
+ # Adding host intents
+ main.log.info( itemName + ": Adding host intents" )
- intent1 = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
- hostIdTwo=host2.get( "id" ) )
+ intent1 = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
+ hostIdTwo=host2.get( "id" ) )
- # Get all intents ID in the system, time delay right after intents are added
- time.sleep( main.addIntentSleep )
- intentsId = main.CLIs[ 0 ].getIntentsId()
+ # Get all intents ID in the system, time delay right after intents are added
+ time.sleep( main.addIntentSleep )
+ intentsId = main.CLIs[ 0 ].getIntentsId()
+ except (KeyError, TypeError):
+ errorMsg = "There was a problem loading the hosts data."
+ if intentsId:
+ errorMsg += " There was a problem installing host to host intent."
+ main.log.error( errorMsg )
+ return main.FALSE
if utilities.retry ( f=checkIntentState, retValue=main.FALSE,
args = (main, intentsId ), sleep=main.checkIntentSleep ):
@@ -157,16 +164,20 @@
main.log.info( itemName + ": Testing Host Intent" )
- if not host1.get( "id" ):
- main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
- host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
+ try:
+ if not host1.get( "id" ):
+ main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
+ host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
- if not host2.get( "id" ):
- main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
- host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
+ if not host2.get( "id" ):
+ main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
+ host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
- senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
- recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
+ senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
+ recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
+ except ( KeyError, TypeError ):
+ main.log.error( "There was a problem loading the hosts data." )
+ return main.FALSE
testResult = main.TRUE
main.log.info( itemName + ": Adding single point to multi point intents" )
@@ -336,50 +347,58 @@
main.log.info( itemName + ": Adding single to single point intents" )
- for sender in senders:
- if not sender.get( "device" ):
- main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
- sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
+ try:
+ for sender in senders:
+ if not sender.get( "device" ):
+ main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
+ sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
- for recipient in recipients:
- if not recipient.get( "device" ):
- main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
- recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
+ for recipient in recipients:
+ if not recipient.get( "device" ):
+ main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
+ recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
- ingressDevice = senders[ 0 ].get( "device" )
- egressDevice = recipients[ 0 ].get( "device" )
+ ingressDevice = senders[ 0 ].get( "device" )
+ egressDevice = recipients[ 0 ].get( "device" )
- portIngress = senders[ 0 ].get( "port", "" )
- portEgress = recipients[ 0 ].get( "port", "" )
- main.log.debug( ingressDevice )
- main.log.debug( egressDevice )
+ portIngress = senders[ 0 ].get( "port", "" )
+ portEgress = recipients[ 0 ].get( "port", "" )
+ main.log.debug( ingressDevice )
+ main.log.debug( egressDevice )
- srcMac = senders[ 0 ].get( "mac" )
- dstMac = recipients[ 0 ].get( "mac" )
+ srcMac = senders[ 0 ].get( "mac" )
+ dstMac = recipients[ 0 ].get( "mac" )
- ipSrc = senders[ 0 ].get( "ip" )
- ipDst = recipients[ 0 ].get( "ip" )
+ ipSrc = senders[ 0 ].get( "ip" )
+ ipDst = recipients[ 0 ].get( "ip" )
- intent1 = main.CLIs[ onosNode ].addPointIntent(
- ingressDevice=ingressDevice,
- egressDevice=egressDevice,
- ingressPort=portIngress,
- egressPort=portEgress,
- ethType=ethType,
- ethSrc=srcMac,
- ethDst=dstMac,
- bandwidth=bandwidth,
- lambdaAlloc=lambdaAlloc,
- ipProto=ipProto,
- ipSrc=ipSrc,
- ipDst=ipDst,
- tcpSrc=tcpSrc,
- tcpDst=tcpDst )
+ intent1 = main.CLIs[ onosNode ].addPointIntent(
+ ingressDevice=ingressDevice,
+ egressDevice=egressDevice,
+ ingressPort=portIngress,
+ egressPort=portEgress,
+ ethType=ethType,
+ ethSrc=srcMac,
+ ethDst=dstMac,
+ bandwidth=bandwidth,
+ lambdaAlloc=lambdaAlloc,
+ ipProto=ipProto,
+ ipSrc=ipSrc,
+ ipDst=ipDst,
+ tcpSrc=tcpSrc,
+ tcpDst=tcpDst )
- time.sleep( main.addIntentSleep )
- intentsId = main.CLIs[ 0 ].getIntentsId()
+ time.sleep( main.addIntentSleep )
+ intentsId = main.CLIs[ 0 ].getIntentsId()
+ except (KeyError, TypeError):
+ errorMsg = "There was a problem loading the hosts data."
+ if intentId:
+ errorMsg += " There was a problem installing Point to Point intent."
+ main.log.error( errorMsg )
+ return main.FALSE
+ # Check intent state
if utilities.retry ( f=checkIntentState, retValue=main.FALSE,
args = (main, intentsId ), sleep=main.checkIntentSleep ):
return intentsId
@@ -387,13 +406,6 @@
main.log.error( "Single to Single point intent did not install correctly" )
return main.FALSE
- # Check intents state
- if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, intentsId ), sleep=main.checkIntentSleep ):
- return intentsId
- else:
- main.log.error( "Point Intent did not install correctly" )
- return main.FALSE
-
def testPointIntent( main,
name,
intentId,
@@ -472,21 +484,25 @@
main.log.info( itemName + ": Testing Point Intent" )
- # Names for scapy
- senderNames = [ x.get( "name" ) for x in senders ]
- recipientNames = [ x.get( "name" ) for x in recipients ]
- badSenderNames = [ x.get( "name" ) for x in badSenders ]
- badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
+ try:
+ # Names for scapy
+ senderNames = [ x.get( "name" ) for x in senders ]
+ recipientNames = [ x.get( "name" ) for x in recipients ]
+ badSenderNames = [ x.get( "name" ) for x in badSenders ]
+ badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
- for sender in senders:
- if not sender.get( "device" ):
- main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
- sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
+ for sender in senders:
+ if not sender.get( "device" ):
+ main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
+ sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
- for recipient in recipients:
- if not recipient.get( "device" ):
- main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
- recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
+ for recipient in recipients:
+ if not recipient.get( "device" ):
+ main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
+ recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
+ except (KeyError, TypeError):
+ main.log.error( "There was a problem loading the hosts data." )
+ return main.FALSE
testResult = main.TRUE
main.log.info( itemName + ": Testing point intents" )
@@ -1534,22 +1550,30 @@
controllerStr = str( controller + 1 ) # ONOS node number
# Compare Hosts
# Load hosts data for controller node
- if hosts[ controller ] and "Error" not in hosts[ controller ]:
- try:
- hostData = json.loads( hosts[ controller ] )
- except ( TypeError, ValueError ):
- main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
- hostFails.append( controllerStr )
+ try:
+ if hosts[ controller ]:
+ main.log.info( "Hosts discovered" )
else:
- onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
- for x in hostData
- if len( x.get( "ipAddresses" ) ) > 0 ]
- if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
- main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
+ main.log.error( "Problem discovering hosts" )
+ if hosts[ controller ] and "Error" not in hosts[ controller ]:
+ try:
+ hostData = json.loads( hosts[ controller ] )
+ except ( TypeError, ValueError ):
+ main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
hostFails.append( controllerStr )
- else:
- main.log.error( "Hosts returned nothing or an error." )
- hostFails.append( controllerStr )
+ else:
+ onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
+ for x in hostData
+ if len( x.get( "ipAddresses" ) ) > 0 ]
+ if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
+ main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
+ hostFails.append( controllerStr )
+ else:
+ main.log.error( "Hosts returned nothing or an error." )
+ hostFails.append( controllerStr )
+ except IndexError:
+ main.log.error( "Hosts returned nothing, Failed to discover hosts." )
+ return main.FALSE
if hostFails:
main.log.error( "List of failed ONOS Nodes:" + ', '.join(map(str, hostFails )) )
@@ -1579,9 +1603,18 @@
hostj[ 'location' ][ 'port' ]
main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
return main.TRUE
+ except ValueError:
+ main.log.error( "ValueError while populating hostsData" )
+ return main.FALSE
except KeyError:
main.log.error( "KeyError while populating hostsData")
return main.FALSE
+ except IndexError:
+ main.log.error( "IndexError while populating hostsData" )
+ return main.FALSE
+ except TypeError:
+ main.log.error( "TypeError while populating hostsData" )
+ return main.FALSE
def scapyCheckConnection( main, senders, recipients, packet=None, packetFilter=None, expectFailure=False ):
"""