Merge "Driver/utils fixes"
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 1e31f31..cc6fa9f 100755
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -435,7 +435,7 @@
 
     def log( self, cmdStr, level="", noExit=False ):
         """
-            log  the commands in the onos CLI.
+            log the commands in the onos CLI.
             returns main.TRUE on success
             returns main.FALSE if Error occurred
             if noExit is True, TestON will not exit, but clean up
@@ -447,24 +447,21 @@
             lvlStr = ""
             if level:
                 lvlStr = "--level=" + level
-
-            self.handle.sendline( "log:log " + lvlStr + " " + cmdStr )
-            self.handle.expect( "log:log" )
-            self.handle.expect( self.karafPrompt )
-
-            response = self.handle.before
-            if re.search( "Error", response ):
-                main.log.debug( response )
+            handle = self.sendline( "log:log " + lvlStr + " " + cmdStr, noExit=noExit )
+            assert handle is not None, "Error in sendline"
+            assert "Command not found:" not in handle, handle
+            if re.search( "Error", handle ):
+                main.log.error( self.name + ": Error in logging message" )
+                main.log.error( handle )
                 return main.FALSE
-            return main.TRUE
-        except pexpect.TIMEOUT:
-            main.log.exception( self.name + ": TIMEOUT exception found" )
-            main.log.error( self.name + ":    " + self.handle.before )
-            if noExit:
-                main.cleanup()
-                return None
             else:
-                main.cleanAndExit()
+                return main.TRUE
+        except AssertionError:
+            main.log.exception( "" )
+            return None
+        except TypeError:
+            main.log.exception( self.name + ": Object not as expected" )
+            return None
         except pexpect.EOF:
             main.log.error( self.name + ": EOF exception found" )
             main.log.error( self.name + ":    " + self.handle.before )
@@ -5330,16 +5327,21 @@
         Level defaults to INFO
         """
         try:
-            self.handle.sendline( "log:set %s %s" % ( level, app ) )
-            self.handle.expect( self.karafPrompt )
-
-            response = self.handle.before
-            if re.search( "Error", response ):
+            handle = self.sendline( "log:set %s %s" % ( level, app ) )
+            assert handle is not None, "Error in sendline"
+            assert "Command not found:" not in handle, handle
+            if re.search( "Error", handle ):
+                main.log.error( self.name + ": Error in setting log level" )
+                main.log.error( handle )
                 return main.FALSE
-            return main.TRUE
-        except pexpect.TIMEOUT:
-            main.log.exception( self.name + ": TIMEOUT exception found" )
-            main.cleanAndExit()
+            else:
+                return main.TRUE
+        except AssertionError:
+            main.log.exception( "" )
+            return None
+        except TypeError:
+            main.log.exception( self.name + ": Object not as expected" )
+            return None
         except pexpect.EOF:
             main.log.error( self.name + ": EOF exception found" )
             main.log.error( self.name + ":    " + self.handle.before )
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index 78b8477..06caa7c 100755
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -1149,6 +1149,7 @@
                                       "onos\sstart/running,\sprocess",
                                       "ONOS\sis\salready\sinstalled",
                                       "does not exist",
+                                      "Failed to start",
                                       self.prompt,
                                       pexpect.TIMEOUT ], timeout=180 )
             if i == 0:
@@ -1175,11 +1176,16 @@
                 self.handle.expect( self.prompt )
                 return main.FALSE
             elif i == 4:
+                # Service failed to start
+                main.log.error( "ONOS service failed to start" )
+                self.handle.expect( self.prompt )
+                return main.FALSE
+            elif i == 5:
                 # prompt
                 main.log.info( self.name + ": ONOS was installed on {} {}.".format(  node,
                                "but not started" if 'n' in options else "and started" ) )
                 return main.TRUE
-            elif i == 5:
+            elif i == 6:
                 # timeout
                 main.log.info(
                     "Installation of ONOS on " +
diff --git a/TestON/tests/dependencies/Cluster.py b/TestON/tests/dependencies/Cluster.py
index 2e79481..2e16a45 100644
--- a/TestON/tests/dependencies/Cluster.py
+++ b/TestON/tests/dependencies/Cluster.py
@@ -543,7 +543,7 @@
                 result = result and t.result
         return result
 
-    def installOnos( self, installMax=True, installParallel=True ):
+    def installOnos( self, installMax=True, installParallel=True, retries=5 ):
         """
         Description:
             Installing onos.
@@ -560,16 +560,21 @@
             options = "-f"
             if installMax and i >= self.numCtrls:
                 options = "-nf"
+            args = [ ctrl.Bench.onosInstall, main.FALSE ]
+            kwargs={ "node" : ctrl.ipAddress,
+                     "options" : options }
             if installParallel:
-                t = main.Thread( target=ctrl.Bench.onosInstall,
+                t = main.Thread( target=utilities.retry,
                                  name="onos-install-" + ctrl.name,
-                                 kwargs={ "node" : ctrl.ipAddress,
-                                          "options" : options } )
+                                 args=args,
+                                 kwargs={ 'kwargs': kwargs,
+                                          'attempts': retries } )
+
                 threads.append( t )
                 t.start()
             else:
                 result = result and \
-                            main.ONOSbench.onosInstall( node=ctrl.ipAddress, options=options )
+                            utilities.retry( args=args, kwargs=kwargs, attempts=retries )
             i += 1
         if installParallel:
             for t in threads: