Exception handling added to FUNCintent where needed
and made related changes to driver and teston functions
Change-Id: I8db4949d7eeabb5067a3b70d238348858d0a445f
diff --git a/TestON/core/teston.py b/TestON/core/teston.py
index eb8c0ba..e798e98 100644
--- a/TestON/core/teston.py
+++ b/TestON/core/teston.py
@@ -350,7 +350,7 @@
                 self.log.error( "\nException in the following section of" +
                                 " code: " + str( testCaseNumber ) + "." +
                                 str( stepNo ) + ": " + stepName )
-                self.log.error( e )
+                self.log.error( str( e.__class__ ) + str( e.message ) )
                 self.stepCount = self.stepCount + 1
                 self.logger.updateCaseResults( self )
                 # WIKI results
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 89e591b..0a1d25f 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -852,7 +852,7 @@
                 response = self.execute( cmd = cmd, prompt="mininet>" ,timeout=10 )
                 print response
                 pattern = "h\d-eth([\w])"
-                ipAddressSearch = re.search( pattern, response )                
+                ipAddressSearch = re.search( pattern, response )
                 print ipAddressSearch.group(1)
                 intf= host + "-eth" + str(ipAddressSearch.group(1))
                 cmd = host + " ip -6 addr add %s dev %s" % ( IP, intf )
@@ -1951,15 +1951,14 @@
                                         timeout )
                 if i == 0:
                     main.log.info( "Exiting mininet..." )
-                response = self.execute(
-                    cmd="exit",
-                    prompt="(.*)",
-                    timeout=120 )
-                main.log.info( self.name + ": Stopped" )
-                self.handle.sendline( "sudo mn -c" )
-                response = main.TRUE
+                    response = self.execute( cmd="exit",
+                                             prompt="(.*)",
+                                             timeout=120 )
+                    main.log.info( self.name + ": Stopped" )
+                    self.handle.sendline( "sudo mn -c" )
+                    response = main.TRUE
 
-                if i == 1:
+                elif i == 1:
                     main.log.info( " Mininet trying to exit while not " +
                                    "in the mininet prompt" )
                 elif i == 2:
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 3c8b2ef..c5ac77e 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -928,20 +928,19 @@
             if jsonFormat:
                 cmdStr += " -j"
             handle = self.sendline( cmdStr )
-            assert "Command not found:" not in handle, handle
-            try:
+            if handle:
+                assert "Command not found:" not in handle, handle
                 # TODO: Maybe make this less hardcoded
                 # ConsistentMap Exceptions
                 assert "org.onosproject.store.service" not in handle
                 # Node not leader
                 assert "java.lang.IllegalStateException" not in handle
-            except AssertionError:
                 main.log.error( "Error in processing '" + cmdStr + "' " +
                                 "command: " + str( handle ) )
-                return None
             return handle
         except AssertionError:
-            main.log.exception( "" )
+            main.log.exception( "Error in processing '" + cmdStr + "' " +
+                            "command: " + str( handle ) )
             return None
         except TypeError:
             main.log.exception( self.name + ": Object not as expected" )
@@ -3198,7 +3197,6 @@
                 return state
         except ( TypeError, ValueError ):
             main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) )
-            main.stop()
             return None
         except pexpect.EOF:
             main.log.error( self.name + ": EOF exception found" )
diff --git a/TestON/tests/FUNC/FUNCintent/FUNCintent.py b/TestON/tests/FUNC/FUNCintent/FUNCintent.py
index 0855dc1..ceb4b2d 100644
--- a/TestON/tests/FUNC/FUNCintent/FUNCintent.py
+++ b/TestON/tests/FUNC/FUNCintent/FUNCintent.py
@@ -135,6 +135,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" )
@@ -208,24 +209,21 @@
         onosIsUp = main.TRUE
 
         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 ] )
+            onosIsUp = main.ONOSbench.isup( 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" )
+                                 onpass="ONOS service is ready on all nodes",
+                                 onfail="ONOS service did not start properly on all nodes" )
 
         main.step( "Start ONOS cli" )
         cliResult = main.TRUE
@@ -237,6 +235,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 ] )
@@ -366,6 +366,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" )
@@ -383,15 +386,19 @@
                                  actual=stepResult,
                                  onpass="Successfully loaded topology",
                                  onfail="Failed to load topology" )
-        # Exit if topology did not load properly
+
+        # Set flag to test cases if topology did not load properly
         if not topoResult:
-            main.cleanup()
-            main.exit()
+            main.initialized = main.FALSE
+            main.skipCase()
 
     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" )
@@ -409,10 +416,9 @@
                                  actual=stepResult,
                                  onpass="Successfully loaded topology",
                                  onfail="Failed to load topology" )
-        # Exit if topology did not load properly
+        # Set flag to skip test cases if topology did not load properly
         if not topoResult:
-            main.cleanup()
-            main.exit()
+            main.initialized = main.FALSE
 
     def CASE12( self, main ):
         """
@@ -420,6 +426,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 +\
@@ -440,8 +449,9 @@
                                                          ip=tempONOSip,
                                                          port='6653' )
         if not assignResult:
-            main.cleanup()
-            main.exit()
+            main.log.error( "Problem assigning mastership of switches" )
+            main.initialized = main.FALSE
+            main.skipCase()
 
         for i in range( 1, ( main.numSwitch + 1 ) ):
             response = main.Mininet1.getSwController( "s" + str( i ) )
@@ -457,11 +467,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
@@ -484,11 +499,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 with fwd and pingall and store its data in 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" )
         main.step( "Pingall hosts and confirm ONOS discovery" )
         utilities.retry( f=main.intentFunction.fwdPingall, retValue=main.FALSE, args=[ main ] )
@@ -499,6 +519,9 @@
                                  actual=stepResult,
                                  onpass="Successfully discovered hosts",
                                  onfail="Failed to discover hosts" )
+        if not stepResult:
+            main.initialized = main.FALSE
+            main.skipCase()
 
         main.step( "Populate hostsData" )
         stepResult = main.intentFunction.populateHostData( main )
@@ -506,17 +529,23 @@
                                  actual=stepResult,
                                  onpass="Successfully populated hostsData",
                                  onfail="Failed to populate hostsData" )
+        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
@@ -530,6 +559,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 )
@@ -537,11 +569,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" )
 
@@ -552,11 +589,16 @@
                                  actual=balanceResult,
                                  onpass="Successfully balanced mastership of switches",
                                  onfail="Failed to balance mastership of switches" )
+        if not balanceResult:
+            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" )
 
@@ -571,6 +613,8 @@
                                  actual=stepResult,
                                  onpass="Successfully activated Flow Objectives",
                                  onfail="Failed to activate Flow Objectives" )
+        if not balanceResult:
+            main.initialized = main.FALSE
 
     def CASE18( self, main ):
         """
@@ -632,14 +676,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.CLIs[ 0 ].leaderCandidates()
@@ -866,14 +927,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.testName = "Point Intents"
         main.case( main.testName + " Test - " + str( main.numCtrls ) +
@@ -1191,11 +1269,29 @@
                     - Ping hosts
                 - Remove intents
         """
+        if main.initialized == main.FALSE:
+            main.log.error( "Test components did not start correctly, skipping further tests" )
+            main.skipCase()
         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.testName = "Single to Multi Point Intents"
         main.case( main.testName + " Test - " + str( main.numCtrls ) +
@@ -1397,11 +1493,29 @@
                     - Ping hosts
              - Remove intents
         """
+        if main.initialized == main.FALSE:
+            main.log.error( "Test components did not start correctly, skipping further tests" )
+            main.skipCase()
         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.testName = "Multi To Single Point Intents"
         main.case( main.testName + " Test - " + str( main.numCtrls ) +
@@ -1589,11 +1703,29 @@
         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 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 ]
@@ -1657,11 +1789,29 @@
         """
         Tests Multi to Single Point Intent and Single to Multi Point Intent End Point Failure
         """
+        if main.initialized == main.FALSE:
+            main.log.error( "Test components did not start correctly, skipping further tests" )
+            main.skipCase()
         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 Multi to Single End Point Failure" )
         main.step( "Installing Multi to Single Point intents" )
 
diff --git a/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py b/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
index 976838c..dbafffa 100644
--- a/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
+++ b/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
@@ -64,19 +64,25 @@
     onosNode = int( onosNode )
 
     main.log.info( itemName + ": Adding single point to multi point intents" )
+    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 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.h ostData".format( host2.get( "name" ) ) )
-        host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
-
-    # Adding point intent
-    intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
-                                                    hostIdTwo=host2.get( "id" ) )
+        # Adding point intent
+        intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
+                                                        hostIdTwo=host2.get( "id" ) )
+    except (KeyError, TypeError):
+        errorMsg = "There was a problem loading the hosts data."
+        if intentId:
+            errorMsg += "  There was a problem installing host to host intent."
+        main.log.error( errorMsg )
+        return main.FALSE
 
     # Check intents state
     if utilities.retry( f=checkIntentState, retValue=main.FALSE,
@@ -151,19 +157,24 @@
 
     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" ) ]
 
-    testResult = main.TRUE
-    main.log.info( itemName + ": Adding single point to multi point intents" )
+        testResult = main.TRUE
+    except (KeyError, TypeError):
+        main.log.error( "There was a problem loading the hosts data." )
+        return main.FALSE
+
+    main.log.info( itemName + ": Testing Host to Host intents" )
 
     # Check intent state
     if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
@@ -330,43 +341,50 @@
 
     main.log.info( itemName + ": Adding point to 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", "" )
+        portIngress = senders[ 0 ].get( "port", "" )
+        portEgress = recipients[ 0 ].get( "port", "" )
 
-    dstMac = recipients[ 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" )
 
-    # Adding point intent
-    intentId = main.CLIs[ onosNode ].addPointIntent(
-                                        ingressDevice=ingressDevice,
-                                        egressDevice=egressDevice,
-                                        portIngress=portIngress,
-                                        portEgress=portEgress,
-                                        ethType=ethType,
-                                        ethDst=dstMac,
-                                        bandwidth=bandwidth,
-                                        lambdaAlloc=lambdaAlloc,
-                                        ipProto=ipProto,
-                                        ipSrc=ipSrc,
-                                        ipDst=ipDst,
-                                        tcpSrc=tcpSrc,
-                                        tcpDst=tcpDst )
+        # Adding point intent
+        intentId = main.CLIs[ onosNode ].addPointIntent(
+                                            ingressDevice=ingressDevice,
+                                            egressDevice=egressDevice,
+                                            portIngress=portIngress,
+                                            portEgress=portEgress,
+                                            ethType=ethType,
+                                            ethDst=dstMac,
+                                            bandwidth=bandwidth,
+                                            lambdaAlloc=lambdaAlloc,
+                                            ipProto=ipProto,
+                                            ipSrc=ipSrc,
+                                            ipDst=ipDst,
+                                            tcpSrc=tcpSrc,
+                                            tcpDst=tcpDst )
+    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 intents state
     if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
@@ -719,42 +737,49 @@
 
     main.log.info( itemName + ": Adding single point to multi 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" )
-    egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
+        ingressDevice = senders[ 0 ].get( "device" )
+        egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
 
-    portIngress = senders[ 0 ].get( "port", "" )
-    portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
-    if not portEgressList:
-        portEgressList = None
+        portIngress = senders[ 0 ].get( "port", "" )
+        portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
+        if not portEgressList:
+            portEgressList = None
 
-    srcMac = senders[ 0 ].get( "mac" )
+        srcMac = senders[ 0 ].get( "mac" )
 
-    # Adding point intent
-    intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
-                                        ingressDevice=ingressDevice,
-                                        egressDeviceList=egressDeviceList,
-                                        portIngress=portIngress,
-                                        portEgressList=portEgressList,
-                                        ethType=ethType,
-                                        ethSrc=srcMac,
-                                        bandwidth=bandwidth,
-                                        lambdaAlloc=lambdaAlloc,
-                                        ipProto=ipProto,
-                                        ipSrc="",
-                                        ipDst="",
-                                        tcpSrc="",
-                                        tcpDst="" )
+        # Adding point intent
+        intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
+                                            ingressDevice=ingressDevice,
+                                            egressDeviceList=egressDeviceList,
+                                            portIngress=portIngress,
+                                            portEgressList=portEgressList,
+                                            ethType=ethType,
+                                            ethSrc=srcMac,
+                                            bandwidth=bandwidth,
+                                            lambdaAlloc=lambdaAlloc,
+                                            ipProto=ipProto,
+                                            ipSrc="",
+                                            ipDst="",
+                                            tcpSrc="",
+                                            tcpDst="" )
+    except (KeyError, TypeError):
+        errorMsg = "There was a problem loading the hosts data."
+        if intentId:
+            errorMsg += "  There was a problem installing Singlepoint to Multipoint intent."
+        main.log.error( errorMsg )
+        return main.FALSE
 
     # Check intents state
     if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
@@ -824,42 +849,48 @@
 
     main.log.info( itemName + ": Adding mutli 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" )
 
+        ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
+        egressDevice = recipients[ 0 ].get( "device" )
 
-    ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
-    egressDevice = recipients[ 0 ].get( "device" )
+        portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
+        portEgress = recipients[ 0 ].get( "port", "" )
+        if not portIngressList:
+            portIngressList = None
 
-    portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
-    portEgress = recipients[ 0 ].get( "port", "" )
-    if not portIngressList:
-        portIngressList = None
+        dstMac = recipients[ 0 ].get( "mac" )
 
-    dstMac = recipients[ 0 ].get( "mac" )
-
-    # Adding point intent
-    intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
-                                        ingressDeviceList=ingressDeviceList,
-                                        egressDevice=egressDevice,
-                                        portIngressList=portIngressList,
-                                        portEgress=portEgress,
-                                        ethType=ethType,
-                                        ethDst=dstMac,
-                                        bandwidth=bandwidth,
-                                        lambdaAlloc=lambdaAlloc,
-                                        ipProto=ipProto,
-                                        ipSrc="",
-                                        ipDst="",
-                                        tcpSrc="",
-                                        tcpDst="" )
+        # Adding point intent
+        intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
+                                            ingressDeviceList=ingressDeviceList,
+                                            egressDevice=egressDevice,
+                                            portIngressList=portIngressList,
+                                            portEgress=portEgress,
+                                            ethType=ethType,
+                                            ethDst=dstMac,
+                                            bandwidth=bandwidth,
+                                            lambdaAlloc=lambdaAlloc,
+                                            ipProto=ipProto,
+                                            ipSrc="",
+                                            ipDst="",
+                                            tcpSrc="",
+                                            tcpDst="" )
+    except (KeyError, TypeError):
+        errorMsg = "There was a problem loading the hosts data."
+        if intentId:
+            errorMsg += "  There was a problem installing Multipoint to Singlepoint intent."
+        main.log.error( errorMsg )
+        return main.FALSE
 
     # Check intents state
     if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
@@ -946,21 +977,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 + ": Adding single point to multi point intents" )
@@ -1124,24 +1159,28 @@
 
     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 ]
-    isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
-    isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
-    connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
-    connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
+    try:
+        # Names for scapy
+        senderNames = [ x.get( "name" ) for x in senders ]
+        recipientNames = [ x.get( "name" ) for x in recipients ]
+        isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
+        isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
+        connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
+        connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
 
-    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 + ": Adding multi point to single point intents" )
@@ -1398,22 +1437,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 )) )
@@ -1463,9 +1510,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 checkTopology( main, expectedLink ):
     statusResult = main.TRUE