Changed pingall loop structure | added karaftimeout to OnosCHO
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 5b7da13..0d27b43 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -248,16 +248,20 @@
         topoDict = self.numSwitchesN_links( *topoArgList )
         return topoDict
 
-    def pingall( self, timeout=300, shortCircuit=False, numFailedPings=1):
+    def pingall( self, timeout=300, shortCircuit=False, acceptableFailed=0):
         """
            Verifies the reachability of the hosts using pingall command.
            Optional parameter timeout allows you to specify how long to
            wait for pingall to complete
            Optional:
+           timeout(seconds) - This is the pexpect timeout; The function will
+                              timeout if the amount of time between failed
+                              pings exceedes this time and pingall is still
+                              running
            shortCircuit - Break the pingall based on the number of failed hosts
-           ping
-           numFailedPings - initialized the number required for the pingall to
-           break defaults to 1 
+                          ping
+           acceptableFailed - Set the number of acceptable failed pings for the
+                              function to still return main.TRUE
            Returns:
            main.TRUE if pingall completes with no pings dropped
            otherwise main.FALSE"""
@@ -265,92 +269,61 @@
             main.log.info(
                 self.name +
                 ": Checking reachabilty to the hosts using pingall" )
-            try:
-                if not shortCircuit:
-                    response = self.execute(
-                        cmd="pingall",
-                        prompt="mininet>",
-                        timeout=int( timeout ) )
-                else:
-                    response = ""
-                    self.handle.sendline( "pingall" )
-                    i = self.handle.expect( [ "mininet>","X",
-                                              pexpect.EOF,
-                                              pexpect.TIMEOUT ],
-                                            timeout )
-                    if i == 0:
-                        main.log.info( "mininet> prompt found!" )
-                        response = str( self.handle.before )
-                    if i == 1:
-                        main.log.info( self.name + 
-                                       ": Cannot ping some of the hosts")
-                        failedPings = 1
-                        while failedPings < numFailedPings:
-                            j = self.handle.expect( [ "mininet>","X",
-                                                      pexpect.EOF,
-                                                      pexpect.TIMEOUT ],
-                                                      timeout )
-                            if j == 0:
-                                main.log.info( self.name + ": pingall finished")
-                                break
-                            if j == 1:
-                                failedPings = failedPings + 1
-                            if j == 2:
-                                main.log.error( self.name + 
-                                                ": EOF exception found" )
-                                main.log.error( self.name + ":     " +
-                                                self.handle.before )
-                                main.cleanup()
-                                main.exit()
-                            if j == 3:
-                                main.log.error( self.name + 
-                                                ": TIMEOUT exception found" )
-                                main.log.error( self.name +
-                                                ":     " +
-                                                str( self.handle.before ) )
-                                break
-                        
-                        main.log.info( self.name + ": failed to ping " + 
-                                str( failedPings ) + " host" )
-                        main.log.info( str( self.handle.before ) )
-                        response = str( self.handle.before )
-                    if i == 2:
-                        main.log.error( self.name + ": EOF exception found" )
-                        main.log.error( self.name + ":     "
-                                        + self.handle.before )
-                        main.cleanup()
-                        main.exit()
-                    if i == 3:
-                        main.log.error( self.name +
-                                        ": TIMEOUT exception found" )
-                        main.log.error( self.name +
-                                        ":     " +
-                                        str( self.handle.before ) )
-
-            except pexpect.EOF:
-                main.log.error( self.name + ": EOF exception found" )
-                main.log.error( self.name + ":     " + self.handle.before )
-                main.cleanup()
-                main.exit()
-            except pexpect.TIMEOUT:
-                # We may not want to kill the test if pexpect times out
-                main.log.error( self.name + ": TIMEOUT exception found" )
-                main.log.error( self.name +
-                                ":     " +
-                                str( self.handle.before ) )
-            # NOTE: mininet's pingall rounds, so we will check the number of
-            # passed and number of failed
-            pattern = "Results\:\s0\%\sdropped\s\(" +\
-                      "(?P<passed>[\d]+)/(?P=passed)"
+            response = ""
+            failedPings = 0
+            returnValue = main.TRUE
+            self.handle.sendline( "pingall" )
+            while True:
+                i = self.handle.expect( [ "mininet>","X",
+                                          pexpect.EOF,
+                                          pexpect.TIMEOUT ],
+                                          timeout )
+                if i == 0:
+                    main.log.info( self.name + ": pingall finished")
+                    response += self.handle.before
+                    break
+                elif i == 1:
+                    response += self.handle.before + self.handle.after
+                    failedPings = failedPings + 1
+                    if failedPings >= acceptableFailed:
+                        returnValue = main.FALSE
+                        if shortCircuit:
+                            main.log.error( self.name +
+                                            ": Aborting pingall - "
+                                            + str( failedPings ) +
+                                            " pings failed" )
+                            break
+                elif i == 2:
+                    main.log.error( self.name +
+                                    ": EOF exception found" )
+                    main.log.error( self.name + ":     " +
+                                    self.handle.before )
+                    main.cleanup()
+                    main.exit()
+                elif i == 3:
+                    response += self.handle.before
+                    main.log.error( self.name +
+                                    ": TIMEOUT exception found" )
+                    main.log.error( self.name +
+                                    ":     " +
+                                    str( response ) )
+                    # NOTE: Send ctrl-c to make sure pingall is done
+                    self.handle.send( "\x03" )
+                    self.handle.expect( "Interrupt" )
+                    self.handle.send( "" )
+                    self.handle.expect( "mininet>" )
+                    break
+            pattern = "Results\:"
+            main.log.info( "Pingall output: " + str( response ) )
             if re.search( pattern, response ):
-                main.log.info( self.name + ": All hosts are reachable" )
-                return main.TRUE
+                main.log.info( self.name + ": Pingall finished with "
+                               + str( failedPings ) + " failed pings" )
+                return returnValue
             else:
-                main.log.error( self.name + ": Unable to reach all the hosts" )
-                main.log.info( "Pingall output: " + str( response ) )
                 # NOTE: Send ctrl-c to make sure pingall is done
                 self.handle.send( "\x03" )
                 self.handle.expect( "Interrupt" )
+                self.handle.send( "" )
                 self.handle.expect( "mininet>" )
                 return main.FALSE
         else:
diff --git a/TestON/tests/OnosCHO/OnosCHO.py b/TestON/tests/OnosCHO/OnosCHO.py
index b48c44f..37f7f66 100644
--- a/TestON/tests/OnosCHO/OnosCHO.py
+++ b/TestON/tests/OnosCHO/OnosCHO.py
@@ -141,7 +141,7 @@
             t = main.Thread( target=main.CLIs[i].startOnosCli,
                              threadID=main.threadID,
                              name="startOnosCli",
-                             args=[ main.nodes[i].ip_address ] )
+                             args=[ main.nodes[i].ip_address, karafTimeout ] )
             pool.append(t)
             t.start()
             main.threadID = main.threadID + 1
@@ -464,7 +464,7 @@
             for i in xrange(1,(main.numMNswitches + 1), int( main.numCtrls ) ):
                 pool = []
                 for cli in main.CLIs:
-                    if i >= len( main.numMNswitches  ) + 1:
+                    if i >=  main.numMNswitches + 1:
                         break
                     dpid = "of:00000000000000" + format( i,'02x' )
                     t = main.Thread(target = cli.getDevicePortsEnabledCount,threadID = main.threadID, name = "getDevicePortsEnabledCount",args = [dpid])
@@ -488,7 +488,7 @@
             for i in xrange( 1,( main.numMNswitches + 1 ), int( main.numCtrls) ):
                 pool = []
                 for cli in main.CLIs:
-                    if i >= len( main.numMNswitches  ) + 1:
+                    if i >=  main.numMNswitches + 1:
                         break
                     dpid = "of:00000000000000" + format( i,'02x' )
                     t = main.Thread( target = cli.getDeviceLinksActiveCount,
@@ -788,6 +788,8 @@
         for i in xrange( 1,(main.numMNswitches + 1), int( main.numCtrls ) ):
             pool = []
             for cli in main.CLIs:
+                if i >=  main.numMNswitches + 1:
+                    break
                 dpid = "of:00000000000000" + format( i,'02x' )
                 t = main.Thread(target = cli.getDevicePortsEnabledCount,
                         threadID = main.threadID,
@@ -1175,7 +1177,7 @@
         main.step( "Verify Ping across all hosts" )
         pingResultLinkUp = main.FALSE
         time1 = time.time()
-        pingResultLinkUp = main.Mininet1.pingall()
+        pingResultLinkUp = main.Mininet1.pingall( timeout=main.pingTimeout,shortCircuit=True )
         time2 = time.time()
         timeDiff = round( ( time2 - time1 ), 2 )
         main.log.report(
@@ -1319,7 +1321,7 @@
         main.step( "Verify Ping across all hosts" )
         pingResultLinkUp = main.FALSE
         time1 = time.time()
-        pingResultLinkUp = main.Mininet1.pingall(timeout = main.pingTimeout)
+        pingResultLinkUp = main.Mininet1.pingall(timeout = main.pingTimeout, shortCircuit = True )
         time2 = time.time()
         timeDiff = round( ( time2 - time1 ), 2 )
         main.log.report(
@@ -1432,7 +1434,7 @@
         main.step( "Verify Ping across all hosts" )
         pingResultLinkUp = main.FALSE
         time1 = time.time()
-        pingResultLinkUp = main.Mininet1.pingall(timeout = main.pingTimeout)
+        pingResultLinkUp = main.Mininet1.pingall(timeout=main.pingTimeout,shortCircuit=True)
         time2 = time.time()
         timeDiff = round( ( time2 - time1 ), 2 )
         main.log.report(
@@ -1545,7 +1547,7 @@
         main.step( "Verify Ping across all hosts" )
         pingResultLinkUp = main.FALSE
         time1 = time.time()
-        pingResultLinkUp = main.Mininet1.pingall(timeout = main.pingTimeout)
+        pingResultLinkUp = main.Mininet1.pingall(timeout=main.pingTimeout,shortCircuit=True)
         time2 = time.time()
         timeDiff = round( ( time2 - time1 ), 2 )
         main.log.report(
@@ -1665,7 +1667,7 @@
         main.step( "Verify Ping across all hosts" )
         pingResultLinkUp = main.FALSE
         time1 = time.time()
-        pingResultLinkUp = main.Mininet1.pingall(timeout = main.pingTimeout)
+        pingResultLinkUp = main.Mininet1.pingall(timeout=main.pingTimeout,shortCircuit=True)
         time2 = time.time()
         timeDiff = round( ( time2 - time1 ), 2 )
         main.log.report(