Cleaning up SDNIP tests a bit

Change-Id: Ied2fc6f8b33903a4879c756df360bae4021e9bb0
diff --git a/TestON/tests/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py b/TestON/tests/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py
index 7d97c10..42b4bc8 100644
--- a/TestON/tests/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py
+++ b/TestON/tests/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py
@@ -17,11 +17,11 @@
 
         main.step( "Starting Mininet Topology" )
         topology = main.dependencyPath + main.topology
-        topoResult = main.Mininet.startNet( topoFile = topology )
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = topoResult,
-                                 onpass = "Successfully loaded topology",
-                                 onfail = "Failed to load topology" )
+        topoResult = main.Mininet.startNet( topoFile=topology )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=topoResult,
+                                 onpass="Successfully loaded topology",
+                                 onfail="Failed to load topology" )
         # Exit if topology did not load properly
         if not topoResult:
             main.cleanup()
@@ -35,10 +35,10 @@
             swResult = swResult and main.Mininet.assignSwController( sw,
                                                  [ONOS1Ip, ONOS2Ip, ONOS3Ip] )
 
-        utilities.assert_equals( expect = main.TRUE,
-                             actual = swResult,
-                             onpass = "Successfully connect all switches to ONOS",
-                             onfail = "Failed to connect all switches to ONOS" )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=swResult,
+                                 onpass="Successfully connect all switches to ONOS",
+                                 onfail="Failed to connect all switches to ONOS" )
         if not swResult:
             main.cleanup()
             main.exit()
@@ -68,6 +68,7 @@
         ONOS1Ip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
         ONOS2Ip = os.getenv( main.params[ 'CTRL' ][ 'ip2' ] )
         ONOS3Ip = os.getenv( main.params[ 'CTRL' ][ 'ip3' ] )
+        ipList = [ ONOS1Ip, ONOS2Ip, ONOS3Ip ]
 
         global peer64514
         global peer64515
@@ -76,18 +77,24 @@
         peer64515 = main.params['config']['peer64515']
         peer64516 = main.params['config']['peer64516']
 
+        main.step( "Create cell file" )
+        cellAppString = main.params[ 'ENV' ][ 'appString' ]
+        main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
+                                       main.Mininet.ip_address,
+                                       cellAppString, ipList )
+
         main.step( "Applying cell variable to environment" )
         cellResult = main.ONOSbench.setCell( cellName )
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = cellResult,
-                                 onpass = "Set cell succeeded",
-                                 onfail = "Set cell failed" )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=cellResult,
+                                 onpass="Set cell succeeded",
+                                 onfail="Set cell failed" )
 
         verifyResult = main.ONOSbench.verifyCell()
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = verifyResult,
-                                 onpass = "Verify cell succeeded",
-                                 onfail = "Verify cell failed" )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=verifyResult,
+                                 onpass="Verify cell succeeded",
+                                 onfail="Verify cell failed" )
 
         branchName = main.ONOSbench.getBranchName()
         main.log.report( "ONOS is on branch: " + branchName )
@@ -96,92 +103,105 @@
         uninstallResult = main.ONOSbench.onosUninstall( ONOS1Ip ) \
                           and main.ONOSbench.onosUninstall( ONOS2Ip ) \
                           and main.ONOSbench.onosUninstall( ONOS3Ip )
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = uninstallResult,
-                                 onpass = "Uninstall ONOS from nodes succeeded",
-                                 onfail = "Uninstall ONOS form nodes failed" )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=uninstallResult,
+                                 onpass="Uninstall ONOS from nodes succeeded",
+                                 onfail="Uninstall ONOS form nodes failed" )
 
-        main.ONOSbench.getVersion( report = True )
+        main.ONOSbench.getVersion( report=True )
 
         main.step( "Creating ONOS package" )
-        packageResult = main.ONOSbench.onosPackage( opTimeout = 500 )
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = packageResult,
-                                 onpass = "Package ONOS succeeded",
-                                 onfail = "Package ONOS failed" )
+        packageResult = main.ONOSbench.onosPackage( opTimeout=500 )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=packageResult,
+                                 onpass="Package ONOS succeeded",
+                                 onfail="Package ONOS failed" )
 
         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 )
+        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
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = onosInstallResult,
-                                 onpass = "Install ONOS to nodes succeeded",
-                                 onfail = "Install ONOS to nodes failed" )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=onosInstallResult,
+                                 onpass="Install ONOS to nodes succeeded",
+                                 onfail="Install ONOS to nodes failed" )
 
         main.step( "Checking if ONOS is up yet" )
-        onos1UpResult = main.ONOSbench.isup( ONOS1Ip, timeout = 420 )
-        onos2UpResult = main.ONOSbench.isup( ONOS2Ip, timeout = 420 )
-        onos3UpResult = main.ONOSbench.isup( ONOS3Ip, timeout = 420 )
+        onos1UpResult = main.ONOSbench.isup( ONOS1Ip, timeout=420 )
+        onos2UpResult = main.ONOSbench.isup( ONOS2Ip, timeout=420 )
+        onos3UpResult = main.ONOSbench.isup( ONOS3Ip, timeout=420 )
         onosUpResult = onos1UpResult and onos2UpResult and onos3UpResult
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = onos1UpResult and onosUpResult,
-                                 onpass = "ONOS nodes are up",
-                                 onfail = "ONOS nodes are NOT up" )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=onosUpResult,
+                                 onpass="ONOS nodes are up",
+                                 onfail="ONOS nodes are NOT up" )
 
         main.step( "Checking if ONOS CLI is ready" )
+        main.CLIs = []
         cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip,
-                commandlineTimeout = 100, onosStartTimeout = 600 )
+                commandlineTimeout=100, onosStartTimeout=600 )
+        main.CLIs.append( main.ONOScli1 )
         cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip,
-                commandlineTimeout = 100, onosStartTimeout = 600 )
-        cliResult = cliResult1 and cliResult2
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = cliResult,
-                                 onpass = "ONOS CLI (on node1) is ready",
-                                 onfail = "ONOS CLI (on node1) ready" )
+                commandlineTimeout=100, onosStartTimeout=600 )
+        main.CLIs.append( main.ONOScli2 )
+        cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip,
+                commandlineTimeout=100, onosStartTimeout=600 )
+        main.CLIs.append( main.ONOScli3 )
+        cliResult = cliResult1 and cliResult2 and cliResult3
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=cliResult,
+                                 onpass="ONOS CLIs are ready",
+                                 onfail="ONOS CLIs are not ready" )
 
-        caseResult = ( cellResult and verifyResult and
-                       packageResult and
-                       onosInstallResult and onosUpResult and cliResult )
+        for i in range( 10 ):
+            ready = True
+            for cli in main.CLIs:
+                output = cli.summary()
+                if not output:
+                    ready = False
+            if ready:
+                break
+            time.sleep( 30 )
+        utilities.assert_equals( expect=True, actual=ready,
+                                 onpass="ONOS summary command succeded",
+                                 onfail="ONOS summary command failed" )
 
-        utilities.assert_equals( expect = main.TRUE, actual = caseResult,
-                                 onpass = "ONOS startup successful",
-                                 onfail = "ONOS startup NOT successful" )
-
-        if caseResult == main.FALSE:
+        if not ready:
             main.log.error( "ONOS startup failed!" )
             main.cleanup()
             main.exit()
 
-
     def CASE200( self, main ):
         main.case( "Activate sdn-ip application" )
         main.log.info( "waiting link discovery......" )
-        time.sleep( int ( main.params['timers']['TopoDiscovery'] ) )
+        time.sleep( int( main.params['timers']['TopoDiscovery'] ) )
 
         main.log.info( "Get links in the network" )
         summaryResult = main.ONOScli1.summary()
         linkNum = json.loads( summaryResult )[ "links" ]
-        listResult = main.ONOScli1.links( jsonFormat = False )
+        listResult = main.ONOScli1.links( jsonFormat=False )
         main.log.info( listResult )
-
         if linkNum < 100:
             main.log.error( "Link number is wrong!" )
+            time.sleep( int( main.params['timers']['TopoDiscovery'] ) )
+            listResult = main.ONOScli1.links( jsonFormat=False )
+            main.log.info( listResult )
             main.cleanup()
             main.exit()
 
         main.step( "Activate sdn-ip application" )
         activeSDNIPresult = main.ONOScli1.activateApp( "org.onosproject.sdnip" )
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = activeSDNIPresult,
-                                 onpass = "Activate SDN-IP succeeded",
-                                 onfail = "Activate SDN-IP failed" )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=activeSDNIPresult,
+                                 onpass="Activate SDN-IP succeeded",
+                                 onfail="Activate SDN-IP failed" )
         if not activeSDNIPresult:
+            main.log.info( "Activate SDN-IP failed!" )
             main.cleanup()
             main.exit()
 
@@ -211,18 +231,6 @@
         main.log.info( "Wait Quagga to finish delivery all routes to each \
         other and to sdn-ip, plus finish installing all intents..." )
         time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
-        # TODO
-        # time.sleep( int( main.params[ 'timers' ][ 'PathAvailable' ] ) )
-
-        '''
-        # TODO: use for together with wrapperFile1
-        wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
-        main.USECASE_SdnipI2MN_Cluster = imp.load_source( wrapperFile2,
-                                                         main.dependencyPath +
-                                                         wrapperFile2 +
-                                                         ".py" )
-        '''
-
 
     def CASE1( self, main ):
         '''
@@ -230,42 +238,47 @@
         '''
 
         main.case( "Ping tests between BGP peers and speakers" )
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker1"],
-                       peers = ["peer64514", "peer64515", "peer64516"],
-                       expectAllSuccess = True )
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker2"],
-                       peers = [peer64514, peer64515, peer64516],
-                       expectAllSuccess = True )
-
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker1"],
+                       peers=["peer64514", "peer64515", "peer64516"],
+                       expectAllSuccess=True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker2"],
+                       peers=[peer64514, peer64515, peer64516],
+                       expectAllSuccess=True )
 
     def CASE2( self, main ):
         '''
         point-to-point intents test for each BGP peer and BGP speaker pair
         '''
+        import time
         main.case( "Check point-to-point intents" )
         main.log.info( "There are %s BGP peers in total "
                        % main.params[ 'config' ][ 'peerNum' ] )
         main.step( "Check P2P intents number from ONOS CLI" )
 
-        getIntentsResult = main.ONOScli1.intents( jsonFormat = True )
+        getIntentsResult = main.ONOScli1.intents( jsonFormat=True )
         bgpIntentsActualNum = \
             main.QuaggaCliSpeaker1.extractActualBgpIntentNum( getIntentsResult )
         bgpIntentsExpectedNum = int( main.params[ 'config' ][ 'peerNum' ] ) * 6 * 2
+        if bgpIntentsActualNum != bgpIntentsExpectedNum:
+            time.sleep( int( main.params['timers']['RouteDelivery'] ) )
+            bgpIntentsActualNum = \
+                main.QuaggaCliSpeaker1.extractActualBgpIntentNum( getIntentsResult )
         main.log.info( "bgpIntentsExpected num is:" )
         main.log.info( bgpIntentsExpectedNum )
         main.log.info( "bgpIntentsActual num is:" )
         main.log.info( bgpIntentsActualNum )
         utilities.assertEquals( \
-            expect = True,
-            actual = eq( bgpIntentsExpectedNum, bgpIntentsActualNum ),
-            onpass = "PointToPointIntent Intent Num is correct!",
-            onfail = "PointToPointIntent Intent Num is wrong!" )
+            expect=True,
+            actual=eq( bgpIntentsExpectedNum, bgpIntentsActualNum ),
+            onpass="PointToPointIntent Intent Num is correct!",
+            onfail="PointToPointIntent Intent Num is wrong!" )
 
 
     def CASE3( self, main ):
         '''
         routes and intents check to all BGP peers
         '''
+        import time
         main.case( "Check routes and M2S intents to all BGP peers" )
 
         allRoutesExpected = []
@@ -273,11 +286,16 @@
         allRoutesExpected.append( "5.0.0.0/24" + "/" + "10.0.5.1" )
         allRoutesExpected.append( "6.0.0.0/24" + "/" + "10.0.6.1" )
 
-        getRoutesResult = main.ONOScli1.routes( jsonFormat = True )
+        getRoutesResult = main.ONOScli1.routes( jsonFormat=True )
         allRoutesActual = \
             main.QuaggaCliSpeaker1.extractActualRoutesMaster( getRoutesResult )
         allRoutesStrExpected = str( sorted( allRoutesExpected ) )
         allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
+        if allRoutesStrActual != allRoutesStrExpected:
+            time.sleep( int( main.params['timers']['RouteDelivery'] ) )
+            allRoutesActual = \
+                main.QuaggaCliSpeaker1.extractActualRoutesMaster( getRoutesResult )
+            allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
 
         main.step( "Check routes installed" )
         main.log.info( "Routes expected:" )
@@ -285,32 +303,40 @@
         main.log.info( "Routes get from ONOS CLI:" )
         main.log.info( allRoutesStrActual )
         utilities.assertEquals( \
-            expect = allRoutesStrExpected, actual = allRoutesStrActual,
-            onpass = "Routes are correct!",
-            onfail = "Routes are wrong!" )
+            expect=allRoutesStrExpected, actual=allRoutesStrActual,
+            onpass="Routes are correct!",
+            onfail="Routes are wrong!" )
 
         main.step( "Check M2S intents installed" )
-        getIntentsResult = main.ONOScli1.intents( jsonFormat = True )
+        getIntentsResult = main.ONOScli1.intents( jsonFormat=True )
         routeIntentsActualNum = \
             main.QuaggaCliSpeaker1.extractActualRouteIntentNum( getIntentsResult )
         routeIntentsExpectedNum = 3
+        if routeIntentsActualNum != routeIntentsExpectedNum:
+            time.sleep( int( main.params['timers']['RouteDelivery'] ) )
+            routeIntentsActualNum = \
+                main.QuaggaCliSpeaker1.extractActualRouteIntentNum( getIntentsResult )
 
         main.log.info( "MultiPointToSinglePoint Intent Num expected is:" )
         main.log.info( routeIntentsExpectedNum )
         main.log.info( "MultiPointToSinglePoint Intent NUM Actual is:" )
         main.log.info( routeIntentsActualNum )
         utilities.assertEquals( \
-            expect = True,
-            actual = eq( routeIntentsExpectedNum, routeIntentsActualNum ),
-            onpass = "MultiPointToSinglePoint Intent Num is correct!",
-            onfail = "MultiPointToSinglePoint Intent Num is wrong!" )
+            expect=routeIntentsExpectedNum,
+            actual=routeIntentsActualNum,
+            onpass="MultiPointToSinglePoint Intent Num is correct!",
+            onfail="MultiPointToSinglePoint Intent Num is wrong!" )
 
         main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                     main.FALSE,
+                                     kwargs={'isPENDING':False},
+                                     attempts=10 )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-            onpass = "Flow status is correct!",
-            onfail = "Flow status is wrong!" )
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
 
 
     def CASE4( self, main ):
@@ -319,8 +345,8 @@
         '''
         main.case( "Ping test for each route, all hosts behind BGP peers" )
         main.Functions.pingHostToHost( main,
-                        hosts = ["host64514", "host64515", "host64516"],
-                        expectAllSuccess = True )
+                        hosts=["host64514", "host64515", "host64516"],
+                        expectAllSuccess=True )
 
 
     def CASE5( self, main ):
@@ -330,12 +356,12 @@
         import time
         main.case( "Bring down links and check routes/intents" )
         main.step( "Bring down the link between sw32 and peer64514" )
-        linkResult1 = main.Mininet.link( END1 = "sw32", END2 = "peer64514",
-                                         OPTION = "down" )
-        utilities.assertEquals( expect = main.TRUE,
-                                actual = linkResult1,
-                                onpass = "Bring down link succeeded!",
-                                onfail = "Bring down link failed!" )
+        linkResult1 = main.Mininet.link( END1="sw32", END2="peer64514",
+                                         OPTION="down" )
+        utilities.assertEquals( expect=main.TRUE,
+                                actual=linkResult1,
+                                onpass="Bring down link succeeded!",
+                                onfail="Bring down link failed!" )
 
         if linkResult1 == main.TRUE:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
@@ -347,12 +373,12 @@
             main.exit()
 
         main.step( "Bring down the link between sw8 and peer64515" )
-        linkResult2 = main.Mininet.link( END1 = "sw8", END2 = "peer64515",
-                                         OPTION = "down" )
-        utilities.assertEquals( expect = main.TRUE,
-                                actual = linkResult2,
-                                onpass = "Bring down link succeeded!",
-                                onfail = "Bring down link failed!" )
+        linkResult2 = main.Mininet.link( END1="sw8", END2="peer64515",
+                                         OPTION="down" )
+        utilities.assertEquals( expect=main.TRUE,
+                                actual=linkResult2,
+                                onpass="Bring down link succeeded!",
+                                onfail="Bring down link failed!" )
         if linkResult2 == main.TRUE:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
             main.Functions.checkRouteNum( main, 1 )
@@ -363,12 +389,12 @@
             main.exit()
 
         main.step( "Bring down the link between sw28 and peer64516" )
-        linkResult3 = main.Mininet.link( END1 = "sw28", END2 = "peer64516",
-                                         OPTION = "down" )
-        utilities.assertEquals( expect = main.TRUE,
-                                actual = linkResult3,
-                                onpass = "Bring down link succeeded!",
-                                onfail = "Bring down link failed!" )
+        linkResult3 = main.Mininet.link( END1="sw28", END2="peer64516",
+                                         OPTION="down" )
+        utilities.assertEquals( expect=main.TRUE,
+                                actual=linkResult3,
+                                onpass="Bring down link succeeded!",
+                                onfail="Bring down link failed!" )
         if linkResult3 == main.TRUE:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
             main.Functions.checkRouteNum( main, 0 )
@@ -379,19 +405,23 @@
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                     main.FALSE,
+                                     kwargs={'isPENDING':False},
+                                     attempts=10 )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-            onpass = "Flow status is correct!",
-            onfail = "Flow status is wrong!" )
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
 
         # Ping test
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker1"],
-                       peers = ["peer64514", "peer64515", "peer64516"],
-                       expectAllSuccess = False )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker1"],
+                       peers=["peer64514", "peer64515", "peer64516"],
+                       expectAllSuccess=False )
         main.Functions.pingHostToHost( main,
-                        hosts = ["host64514", "host64515", "host64516"],
-                        expectAllSuccess = False )
+                        hosts=["host64514", "host64515", "host64516"],
+                        expectAllSuccess=False )
 
 
     def CASE6( self, main ):
@@ -401,12 +431,12 @@
         import time
         main.case( "Bring up links and check routes/intents" )
         main.step( "Bring up the link between sw32 and peer64514" )
-        linkResult1 = main.Mininet.link( END1 = "sw32", END2 = "peer64514",
-                                         OPTION = "up" )
-        utilities.assertEquals( expect = main.TRUE,
-                                actual = linkResult1,
-                                onpass = "Bring up link succeeded!",
-                                onfail = "Bring up link failed!" )
+        linkResult1 = main.Mininet.link( END1="sw32", END2="peer64514",
+                                         OPTION="up" )
+        utilities.assertEquals( expect=main.TRUE,
+                                actual=linkResult1,
+                                onpass="Bring up link succeeded!",
+                                onfail="Bring up link failed!" )
         if linkResult1 == main.TRUE:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
             main.Functions.checkRouteNum( main, 1 )
@@ -417,12 +447,12 @@
             main.exit()
 
         main.step( "Bring up the link between sw8 and peer64515" )
-        linkResult2 = main.Mininet.link( END1 = "sw8", END2 = "peer64515",
-                                         OPTION = "up" )
-        utilities.assertEquals( expect = main.TRUE,
-                                actual = linkResult2,
-                                onpass = "Bring up link succeeded!",
-                                onfail = "Bring up link failed!" )
+        linkResult2 = main.Mininet.link( END1="sw8", END2="peer64515",
+                                         OPTION="up" )
+        utilities.assertEquals( expect=main.TRUE,
+                                actual=linkResult2,
+                                onpass="Bring up link succeeded!",
+                                onfail="Bring up link failed!" )
         if linkResult2 == main.TRUE:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
             main.Functions.checkRouteNum( main, 2 )
@@ -433,12 +463,12 @@
             main.exit()
 
         main.step( "Bring up the link between sw28 and peer64516" )
-        linkResult3 = main.Mininet.link( END1 = "sw28", END2 = "peer64516",
-                                         OPTION = "up" )
-        utilities.assertEquals( expect = main.TRUE,
-                                actual = linkResult3,
-                                onpass = "Bring up link succeeded!",
-                                onfail = "Bring up link failed!" )
+        linkResult3 = main.Mininet.link( END1="sw28", END2="peer64516",
+                                         OPTION="up" )
+        utilities.assertEquals( expect=main.TRUE,
+                                actual=linkResult3,
+                                onpass="Bring up link succeeded!",
+                                onfail="Bring up link failed!" )
         if linkResult3 == main.TRUE:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
             main.Functions.checkRouteNum( main, 3 )
@@ -449,19 +479,23 @@
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                     main.FALSE,
+                                     kwargs={'isPENDING':False},
+                                     attempts=10 )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-            onpass = "Flow status is correct!",
-            onfail = "Flow status is wrong!" )
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
 
         # Ping test
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker1"],
-                       peers = ["peer64514", "peer64515", "peer64516"],
-                       expectAllSuccess = True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker1"],
+                       peers=["peer64514", "peer64515", "peer64516"],
+                       expectAllSuccess=True )
         main.Functions.pingHostToHost( main,
-                        hosts = ["host64514", "host64515", "host64516"],
-                        expectAllSuccess = True )
+                        hosts=["host64514", "host64515", "host64516"],
+                        expectAllSuccess=True )
 
 
     def CASE7( self, main ):
@@ -471,10 +505,10 @@
         import time
         main.case( "Stop edge sw32,check P-2-P and M-2-S intents, ping test" )
         main.step( "Stop sw32" )
-        result = main.Mininet.switch( SW = "sw32", OPTION = "stop" )
-        utilities.assertEquals( expect = main.TRUE, actual = result,
-                                onpass = "Stopping switch succeeded!",
-                                onfail = "Stopping switch failed!" )
+        result = main.Mininet.switch( SW="sw32", OPTION="stop" )
+        utilities.assertEquals( expect=main.TRUE, actual=result,
+                                onpass="Stopping switch succeeded!",
+                                onfail="Stopping switch failed!" )
 
         if result == main.TRUE:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
@@ -487,30 +521,30 @@
             main.exit()
 
         main.step( "Check ping between hosts behind BGP peers" )
-        result1 = main.Mininet.pingHost( src = "host64514", target = "host64515" )
-        result2 = main.Mininet.pingHost( src = "host64515", target = "host64516" )
-        result3 = main.Mininet.pingHost( src = "host64514", target = "host64516" )
+        result1 = main.Mininet.pingHost( src="host64514", target="host64515" )
+        result2 = main.Mininet.pingHost( src="host64515", target="host64516" )
+        result3 = main.Mininet.pingHost( src="host64514", target="host64516" )
 
         pingResult1 = ( result1 == main.FALSE ) and ( result2 == main.TRUE ) \
                       and ( result3 == main.FALSE )
-        utilities.assert_equals( expect = True, actual = pingResult1,
-                                 onpass = "Ping test result is correct",
-                                 onfail = "Ping test result is wrong" )
+        utilities.assert_equals( expect=True, actual=pingResult1,
+                                 onpass="Ping test result is correct",
+                                 onfail="Ping test result is wrong" )
 
         if pingResult1 == False:
             main.cleanup()
             main.exit()
 
         main.step( "Check ping between BGP peers and speaker1" )
-        result4 = main.Mininet.pingHost( src = "speaker1", target = "peer64514" )
-        result5 = main.Mininet.pingHost( src = "speaker1", target = "peer64515" )
-        result6 = main.Mininet.pingHost( src = "speaker1", target = "peer64516" )
+        result4 = main.Mininet.pingHost( src="speaker1", target="peer64514" )
+        result5 = main.Mininet.pingHost( src="speaker1", target="peer64515" )
+        result6 = main.Mininet.pingHost( src="speaker1", target="peer64516" )
 
         pingResult2 = ( result4 == main.FALSE ) and ( result5 == main.TRUE ) \
                       and ( result6 == main.TRUE )
-        utilities.assert_equals( expect = True, actual = pingResult2,
-                                 onpass = "Speaker1 ping peers successful",
-                                 onfail = "Speaker1 ping peers NOT successful" )
+        utilities.assert_equals( expect=True, actual=pingResult2,
+                                 onpass="Speaker1 ping peers successful",
+                                 onfail="Speaker1 ping peers NOT successful" )
 
         if pingResult2 == False:
             main.cleanup()
@@ -518,26 +552,30 @@
 
         main.step( "Check ping between BGP peers and speaker2" )
         # TODO
-        result7 = main.Mininet.pingHost( src = "speaker2", target = peer64514 )
-        result8 = main.Mininet.pingHost( src = "speaker2", target = peer64515 )
-        result9 = main.Mininet.pingHost( src = "speaker2", target = peer64516 )
+        result7 = main.Mininet.pingHost( src="speaker2", target=peer64514 )
+        result8 = main.Mininet.pingHost( src="speaker2", target=peer64515 )
+        result9 = main.Mininet.pingHost( src="speaker2", target=peer64516 )
 
         pingResult3 = ( result7 == main.FALSE ) and ( result8 == main.TRUE ) \
                                                 and ( result9 == main.TRUE )
-        utilities.assert_equals( expect = True, actual = pingResult2,
-                                 onpass = "Speaker2 ping peers successful",
-                                 onfail = "Speaker2 ping peers NOT successful" )
+        utilities.assert_equals( expect=True, actual=pingResult2,
+                                 onpass="Speaker2 ping peers successful",
+                                 onfail="Speaker2 ping peers NOT successful" )
 
         if pingResult3 == False:
             main.cleanup()
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                     main.FALSE,
+                                     kwargs={'isPENDING':False},
+                                     attempts=10 )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-            onpass = "Flow status is correct!",
-            onfail = "Flow status is wrong!" )
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
 
 
     def CASE8( self, main ):
@@ -548,19 +586,19 @@
         import time
         main.case( "Start the edge sw32, check P-2-P and M-2-S intents, ping test" )
         main.step( "Start sw32" )
-        result1 = main.Mininet.switch( SW = "sw32", OPTION = "start" )
+        result1 = main.Mininet.switch( SW="sw32", OPTION="start" )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = result1,
-            onpass = "Starting switch succeeded!",
-            onfail = "Starting switch failed!" )
+            expect=main.TRUE,
+            actual=result1,
+            onpass="Starting switch succeeded!",
+            onfail="Starting switch failed!" )
 
         result2 = main.Mininet.assignSwController( "sw32", ONOS1Ip )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = result2,
-            onpass = "Connect switch to ONOS succeeded!",
-            onfail = "Connect switch to ONOS failed!" )
+            expect=main.TRUE,
+            actual=result2,
+            onpass="Connect switch to ONOS succeeded!",
+            onfail="Connect switch to ONOS failed!" )
 
         if result1 and result2:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
@@ -573,22 +611,26 @@
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                     main.FALSE,
+                                     kwargs={'isPENDING':False},
+                                     attempts=10 )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-            onpass = "Flow status is correct!",
-            onfail = "Flow status is wrong!" )
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
 
         # Ping test
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker1"],
-                       peers = ["peer64514", "peer64515", "peer64516"],
-                       expectAllSuccess = True )
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker2"],
-                       peers = [peer64514, peer64515, peer64516],
-                       expectAllSuccess = True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker1"],
+                       peers=["peer64514", "peer64515", "peer64516"],
+                       expectAllSuccess=True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker2"],
+                       peers=[peer64514, peer64515, peer64516],
+                       expectAllSuccess=True )
         main.Functions.pingHostToHost( main,
-                        hosts = ["host64514", "host64515", "host64516"],
-                        expectAllSuccess = True )
+                        hosts=["host64514", "host64515", "host64516"],
+                        expectAllSuccess=True )
 
 
     def CASE9( self, main ):
@@ -608,10 +650,10 @@
         main.log.info( main.Mininet.checkFlows( "sw7" ) )
 
         main.step( "Stop sw11" )
-        result = main.Mininet.switch( SW = "sw11", OPTION = "stop" )
-        utilities.assertEquals( expect = main.TRUE, actual = result,
-                                onpass = "Stopping switch succeeded!",
-                                onfail = "Stopping switch failed!" )
+        result = main.Mininet.switch( SW="sw11", OPTION="stop" )
+        utilities.assertEquals( expect=main.TRUE, actual=result,
+                                onpass="Stopping switch succeeded!",
+                                onfail="Stopping switch failed!" )
         if result:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
@@ -624,21 +666,25 @@
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                     main.FALSE,
+                                     kwargs={'isPENDING':False},
+                                     attempts=10 )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-            onpass = "Flow status is correct!",
-            onfail = "Flow status is wrong!" )
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
         # Ping test
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker1"],
-                       peers = ["peer64514", "peer64515", "peer64516"],
-                       expectAllSuccess = True )
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker2"],
-                       peers = [peer64514, peer64515, peer64516],
-                       expectAllSuccess = True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker1"],
+                       peers=["peer64514", "peer64515", "peer64516"],
+                       expectAllSuccess=True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker2"],
+                       peers=[peer64514, peer64515, peer64516],
+                       expectAllSuccess=True )
         main.Functions.pingHostToHost( main,
-                        hosts = ["host64514", "host64515", "host64516"],
-                        expectAllSuccess = True )
+                        hosts=["host64514", "host64515", "host64516"],
+                        expectAllSuccess=True )
 
 
     def CASE10( self, main ):
@@ -656,14 +702,14 @@
         main.log.info( main.Mininet.checkFlows( "sw7" ) )
 
         main.step( "Start sw11" )
-        result1 = main.Mininet.switch( SW = "sw11", OPTION = "start" )
-        utilities.assertEquals( expect = main.TRUE, actual = result1,
-                                onpass = "Starting switch succeeded!",
-                                onfail = "Starting switch failed!" )
+        result1 = main.Mininet.switch( SW="sw11", OPTION="start" )
+        utilities.assertEquals( expect=main.TRUE, actual=result1,
+                                onpass="Starting switch succeeded!",
+                                onfail="Starting switch failed!" )
         result2 = main.Mininet.assignSwController( "sw11", ONOS1Ip )
-        utilities.assertEquals( expect = main.TRUE, actual = result2,
-                                onpass = "Connect switch to ONOS succeeded!",
-                                onfail = "Connect switch to ONOS failed!" )
+        utilities.assertEquals( expect=main.TRUE, actual=result2,
+                                onpass="Connect switch to ONOS succeeded!",
+                                onfail="Connect switch to ONOS failed!" )
         if result1 and result2:
             time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
             main.Functions.checkRouteNum( main, 3 )
@@ -679,21 +725,25 @@
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                     main.FALSE,
+                                     kwargs={'isPENDING':False},
+                                     attempts=10 )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-            onpass = "Flow status is correct!",
-            onfail = "Flow status is wrong!" )
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
         # Ping test
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker1"],
-                       peers = ["peer64514", "peer64515", "peer64516"],
-                       expectAllSuccess = True )
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker2"],
-                       peers = [peer64514, peer64515, peer64516],
-                       expectAllSuccess = True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker1"],
+                       peers=["peer64514", "peer64515", "peer64516"],
+                       expectAllSuccess=True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker2"],
+                       peers=[peer64514, peer64515, peer64516],
+                       expectAllSuccess=True )
         main.Functions.pingHostToHost( main,
-                        hosts = ["host64514", "host64515", "host64516"],
-                        expectAllSuccess = True )
+                        hosts=["host64514", "host64515", "host64516"],
+                        expectAllSuccess=True )
 
 
     def CASE11(self, main):
@@ -705,21 +755,25 @@
         main.Functions.checkM2SintentNum( main, 3 )
         main.Functions.checkP2PintentNum( main, 18 * 2 )
         main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                     main.FALSE,
+                                     kwargs={'isPENDING':False},
+                                     attempts=10 )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-            onpass = "Flow status is correct!",
-            onfail = "Flow status is wrong!" )
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
 
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker1"],
-                       peers = ["peer64514", "peer64515", "peer64516"],
-                       expectAllSuccess = True )
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker2"],
-                       peers = [peer64514, peer64515, peer64516],
-                       expectAllSuccess = True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker1"],
+                       peers=["peer64514", "peer64515", "peer64516"],
+                       expectAllSuccess=True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker2"],
+                       peers=[peer64514, peer64515, peer64516],
+                       expectAllSuccess=True )
         main.Functions.pingHostToHost( main,
-                        hosts = ["host64514", "host64515", "host64516"],
-                        expectAllSuccess = True )
+                        hosts=["host64514", "host64515", "host64516"],
+                        expectAllSuccess=True )
 
         main.step( "Kill speaker1" )
         command1 = "ps -e | grep bgp -c"
@@ -737,10 +791,10 @@
 
         result3 = main.Mininet.node( "root", command1 )
 
-        utilities.assert_equals( expect = True,
-                                 actual = ( "4" in result3 ),
-                                 onpass = "Kill speaker1 succeeded",
-                                 onfail = "Kill speaker1 failed" )
+        utilities.assert_equals( expect=True,
+                                 actual=( "4" in result3 ),
+                                 onpass="Kill speaker1 succeeded",
+                                 onfail="Kill speaker1 failed" )
         if ( "4" not in result3 ) :
             main.log.info( result3 )
             main.cleanup()
@@ -752,23 +806,27 @@
         main.Functions.checkP2PintentNum( main, 18 * 2 )
 
         main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                     main.FALSE,
+                                     kwargs={'isPENDING':False},
+                                     attempts=10 )
         utilities.assertEquals( \
-            expect = main.TRUE,
-            actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-            onpass = "Flow status is correct!",
-            onfail = "Flow status is wrong!" )
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
 
         '''
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker1"],
-                       peers = ["peer64514", "peer64515", "peer64516"],
-                       expectAllSuccess = False )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker1"],
+                       peers=["peer64514", "peer64515", "peer64516"],
+                       expectAllSuccess=False )
         '''
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker2"],
-                       peers = [peer64514, peer64515, peer64516],
-                       expectAllSuccess = True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker2"],
+                       peers=[peer64514, peer64515, peer64516],
+                       expectAllSuccess=True )
         main.Functions.pingHostToHost( main,
-                        hosts = ["host64514", "host64515", "host64516"],
-                        expectAllSuccess = True )
+                        hosts=["host64514", "host64515", "host64516"],
+                        expectAllSuccess=True )
 
 
     def CASE12( self, main ):
@@ -794,44 +852,52 @@
         else:
             uninstallResult = main.ONOSbench.onosStop( ONOS3Ip )
 
-        utilities.assert_equals( expect = main.TRUE,
-                                 actual = uninstallResult,
-                                 onpass = "Uninstall ONOS leader succeeded",
-                                 onfail = "Uninstall ONOS leader failed" )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=uninstallResult,
+                                 onpass="Uninstall ONOS leader succeeded",
+                                 onfail="Uninstall ONOS leader failed" )
         if uninstallResult != main.TRUE:
             main.cleanup()
             main.exit()
         time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
 
         if leaderIP == ONOS1Ip:
-            main.Functions.checkRouteNum( main, 3, ONOScli = "ONOScli2" )
-            main.Functions.checkM2SintentNum( main, 3, ONOScli = "ONOScli2" )
-            main.Functions.checkP2PintentNum( main, 18 * 2, ONOScli = "ONOScli2" )
+            main.Functions.checkRouteNum( main, 3, ONOScli="ONOScli2" )
+            main.Functions.checkM2SintentNum( main, 3, ONOScli="ONOScli2" )
+            main.Functions.checkP2PintentNum( main, 18 * 2, ONOScli="ONOScli2" )
 
             main.step( "Check whether all flow status are ADDED" )
+            flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                         main.FALSE,
+                                         kwargs={'isPENDING':False},
+                                         attempts=10 )
             utilities.assertEquals( \
-                expect = main.TRUE,
-                actual = main.ONOScli2.checkFlowsState( isPENDING_ADD = False ),
-                onpass = "Flow status is correct!",
-                onfail = "Flow status is wrong!" )
+                expect=main.TRUE,
+                actual=flowCheck,
+                onpass="Flow status is correct!",
+                onfail="Flow status is wrong!" )
         else:
             main.Functions.checkRouteNum( main, 3 )
             main.Functions.checkM2SintentNum( main, 3 )
             main.Functions.checkP2PintentNum( main, 18 * 2 )
 
             main.step( "Check whether all flow status are ADDED" )
+            flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+                                         main.FALSE,
+                                         kwargs={'isPENDING':False},
+                                         attempts=10 )
             utilities.assertEquals( \
-                expect = main.TRUE,
-                actual = main.ONOScli1.checkFlowsState( isPENDING_ADD = False ),
-                onpass = "Flow status is correct!",
-                onfail = "Flow status is wrong!" )
+                expect=main.TRUE,
+                actual=flowCheck,
+                onpass="Flow status is correct!",
+                onfail="Flow status is wrong!" )
 
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker1"],
-                       peers = ["peer64514", "peer64515", "peer64516"],
-                       expectAllSuccess = True )
-        main.Functions.pingSpeakerToPeer( main, speakers = ["speaker2"],
-                       peers = [peer64514, peer64515, peer64516],
-                       expectAllSuccess = True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker1"],
+                       peers=["peer64514", "peer64515", "peer64516"],
+                       expectAllSuccess=True )
+        main.Functions.pingSpeakerToPeer( main, speakers=["speaker2"],
+                       peers=[peer64514, peer64515, peer64516],
+                       expectAllSuccess=True )
         main.Functions.pingHostToHost( main,
-                        hosts = ["host64514", "host64515", "host64516"],
-                        expectAllSuccess = True )
+                        hosts=["host64514", "host64515", "host64516"],
+                        expectAllSuccess=True )