Merge "Add onos-1.14 test schedules"
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 84930de..7541780 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -830,14 +830,7 @@
                     isReachable = main.FALSE
         except pexpect.TIMEOUT:
             main.log.exception( self.name + ": TIMEOUT exception" )
-            response = self.handle.before
-            # NOTE: Send ctrl-c to make sure command is stopped
-            self.handle.send( "\x03" )
-            self.handle.expect( "Interrupt" )
-            response += self.handle.before + self.handle.after
-            self.handle.expect( "mininet>" )
-            response += self.handle.before + self.handle.after
-            main.log.debug( response )
+            self.exitFromCmd( self.hostPrompt )
             isReachable = main.FALSE
         except pexpect.EOF:
             main.log.error( self.name + ": EOF exception found" )
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index ef87e00..08138c2 100755
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -2673,8 +2673,7 @@
         except pexpect.TIMEOUT:
             main.log.exception( self.name + ": TIMEOUT exception found in onosDiagnostics" )
             main.log.error( self.name + ":    " + self.handle.before )
-            self.handle.send( "\x03" )  # Control-C
-            self.handle.expect( self.prompt )
+            self.exitFromCmd( self.prompt, 100 )
             return main.FALSE
         except pexpect.EOF:
             main.log.error( self.name + ": EOF exception found" )
diff --git a/TestON/drivers/common/clidriver.py b/TestON/drivers/common/clidriver.py
index 0b34df4..6f8e257 100644
--- a/TestON/drivers/common/clidriver.py
+++ b/TestON/drivers/common/clidriver.py
@@ -554,3 +554,34 @@
             main.log.error( self.name + ": EOF exception found" )
             main.log.error( self.name + ":    " + self.handle.before )
             main.cleanAndExit()
+
+    def exitFromCmd( self, expect, retry=10 ):
+        """
+        Call this function when sending ctrl+c is required to kill the current
+        command. It will retry multiple times until the running command is
+        completely killed and expected string is returned from the handle.
+        Required:
+            expect: the expected string which indicates that the previous command
+                    was killed successfully.
+        Optional:
+            retry: maximum number of ctrl+c that will be sent.
+        """
+        try:
+            while retry >= 0:
+                main.log.debug( self.name + ": sending ctrl+c to kill the command" )
+                self.handle.send( "\x03" )
+                i = self.handle.expect( [ expect, pexpect.TIMEOUT ], timeout=3 )
+                main.log.debug( self.handle.before )
+                if i == 0:
+                    main.log.debug( self.name + ": successfully killed the command" )
+                    return main.TRUE
+                retry -= 1
+            main.log.warn( self.name + ": failed to kill the command" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.error( self.name + ": EOF exception found" )
+            main.log.error( self.name + ":     " + self.handle.before )
+            return main.FALSE
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            return main.FALSE