Retry Hosts call on consistent Map timeouts

Change-Id: I7f2fd9c1973d8543d576eb57473edc7ab1ea8209
(cherry picked from commit baf5316af9eb1b9df6e5dbcc37e6fd6f94551b14)
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index cce13d3..eafc7ab 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -924,6 +924,16 @@
             if jsonFormat:
                 cmdStr += " -j"
             handle = self.sendline( cmdStr )
+            try:
+                # 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 TypeError:
             main.log.exception( self.name + ": Object not as expected" )
diff --git a/TestON/tests/HAclusterRestart/HAclusterRestart.py b/TestON/tests/HAclusterRestart/HAclusterRestart.py
index ed8b2d2..2677b8d 100644
--- a/TestON/tests/HAclusterRestart/HAclusterRestart.py
+++ b/TestON/tests/HAclusterRestart/HAclusterRestart.py
@@ -2181,9 +2181,11 @@
             ipResult = main.TRUE
             threads = []
             for i in range( main.numCtrls ):
-                t = main.Thread( target=main.CLIs[i].hosts,
+                t = main.Thread( target=utilities.retry,
                                  name="hosts-" + str( i ),
-                                 args=[ ] )
+                                 args=[ main.CLIs[i].hosts, [ None ] ],
+                                 kwargs= { 'sleep': 5, 'attempts': 5,
+                                           'randomTime': True } )
                 threads.append( t )
                 t.start()
 
@@ -2324,7 +2326,7 @@
                     elif i == 28:
                         deviceId = "2800".zfill(16)
                     mappings[ macId ] = deviceId
-                if hosts[ controller ] and "Error" not in hosts[ controller ]:
+                if hosts[ controller ] is not None and "Error" not in hosts[ controller ]:
                     if hosts[ controller ] == []:
                         main.log.warn( "There are no hosts discovered" )
                         noHosts = True
diff --git a/TestON/tests/HAkillNodes/HAkillNodes.py b/TestON/tests/HAkillNodes/HAkillNodes.py
index 411857e..4525713 100644
--- a/TestON/tests/HAkillNodes/HAkillNodes.py
+++ b/TestON/tests/HAkillNodes/HAkillNodes.py
@@ -2178,9 +2178,11 @@
             ipResult = main.TRUE
             threads = []
             for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].hosts,
+                t = main.Thread( target=utilities.retry,
                                  name="hosts-" + str( i ),
-                                 args=[ ] )
+                                 args=[ main.CLIs[i].hosts, [ None ] ],
+                                 kwargs= { 'sleep': 5, 'attempts': 5,
+                                           'randomTime': True } )
                 threads.append( t )
                 t.start()
 
@@ -2321,7 +2323,7 @@
                     elif i == 28:
                         deviceId = "2800".zfill(16)
                     mappings[ macId ] = deviceId
-                if hosts[ controller ] and "Error" not in hosts[ controller ]:
+                if hosts[ controller ] is not None and "Error" not in hosts[ controller ]:
                     if hosts[ controller ] == []:
                         main.log.warn( "There are no hosts discovered" )
                         zeroHosts = True
diff --git a/TestON/tests/HAsanity/HAsanity.py b/TestON/tests/HAsanity/HAsanity.py
index 1a5bbfe..340df87 100644
--- a/TestON/tests/HAsanity/HAsanity.py
+++ b/TestON/tests/HAsanity/HAsanity.py
@@ -2074,9 +2074,11 @@
             ipResult = main.TRUE
             threads = []
             for i in range( main.numCtrls ):
-                t = main.Thread( target=main.CLIs[i].hosts,
+                t = main.Thread( target=utilities.retry,
                                  name="hosts-" + str( i ),
-                                 args=[ ] )
+                                 args=[ main.CLIs[i].hosts, [ None ] ],
+                                 kwargs= { 'sleep': 5, 'attempts': 5,
+                                           'randomTime': True } )
                 threads.append( t )
                 t.start()
 
@@ -2217,7 +2219,7 @@
                     elif i == 28:
                         deviceId = "2800".zfill(16)
                     mappings[ macId ] = deviceId
-                if hosts[ controller ] and "Error" not in hosts[ controller ]:
+                if hosts[ controller ] is not None and "Error" not in hosts[ controller ]:
                     if hosts[ controller ] == []:
                         main.log.warn( "There are no hosts discovered" )
                         zeroHosts = True
diff --git a/TestON/tests/HAstopNodes/HAstopNodes.py b/TestON/tests/HAstopNodes/HAstopNodes.py
index cb5032b..2127d54 100644
--- a/TestON/tests/HAstopNodes/HAstopNodes.py
+++ b/TestON/tests/HAstopNodes/HAstopNodes.py
@@ -2167,9 +2167,11 @@
             ipResult = main.TRUE
             threads = []
             for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].hosts,
+                t = main.Thread( target=utilities.retry,
                                  name="hosts-" + str( i ),
-                                 args=[ ] )
+                                 args=[ main.CLIs[i].hosts, [ None ] ],
+                                 kwargs= { 'sleep': 5, 'attempts': 5,
+                                           'randomTime': True } )
                 threads.append( t )
                 t.start()
 
@@ -2310,7 +2312,7 @@
                     elif i == 28:
                         deviceId = "2800".zfill(16)
                     mappings[ macId ] = deviceId
-                if hosts[ controller ] and "Error" not in hosts[ controller ]:
+                if hosts[ controller ] is not None and "Error" not in hosts[ controller ]:
                     if hosts[ controller ] == []:
                         main.log.warn( "There are no hosts discovered" )
                         zeroHosts = True