Changes to ONOS cluster tests.
Wait for sometime before ONOS restart.
Handle leaders command exception in the cluster restart test before failing the test.

Change-Id: If8afbef1e09657619e7230ddadd818a7598442d7
diff --git a/src/test/cluster/clusterTest.py b/src/test/cluster/clusterTest.py
index 11a398f..6fa9119 100644
--- a/src/test/cluster/clusterTest.py
+++ b/src/test/cluster/clusterTest.py
@@ -96,7 +96,11 @@
 
     def get_leader(self, controller = None):
         self.cliEnter(controller = controller)
-        result = json.loads(self.cli.leaders(jsonFormat = True))
+        try:
+            result = json.loads(self.cli.leaders(jsonFormat = True))
+        except:
+            result = None
+
         if result is None:
             log.info('Leaders command failure for controller %s' %controller)
         else:
@@ -366,7 +370,7 @@
             log.info('ITERATION: %d. Restarting Controller %s' %(num + 1, controller))
             try:
                 cord_test_onos_restart(node = controller)
-                time.sleep(30)
+                time.sleep(60)
             except:
                 time.sleep(5)
                 continue
diff --git a/src/test/utils/CordContainer.py b/src/test/utils/CordContainer.py
index a228819..a5dbdc6 100644
--- a/src/test/utils/CordContainer.py
+++ b/src/test/utils/CordContainer.py
@@ -570,7 +570,7 @@
             onos.remove_container(onos.name, force=True)
 
     @classmethod
-    def restart_node(cls, node = None, network_cfg = None):
+    def restart_node(cls, node = None, network_cfg = None, timeout = 10):
         if node is None:
             cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
         else:
@@ -581,6 +581,8 @@
                 if onos.exists():
                     onos.kill()
                 onos.remove_container(onos.name, force=True)
+                if timeout > 0:
+                    time.sleep(timeout)
                 print('Restarting ONOS container %s' %onos.name)
                 onos.start(ports = onos.ports, environment = onos.env,
                            host_config = onos.host_config, volumes = onos.volumes, tty = True)
diff --git a/src/test/utils/CordTestServer.py b/src/test/utils/CordTestServer.py
index 4f097b0..e529219 100644
--- a/src/test/utils/CordTestServer.py
+++ b/src/test/utils/CordTestServer.py
@@ -35,7 +35,7 @@
 
     onos_cord = None
 
-    def __restart_onos(self, node = None, config = None):
+    def __restart_onos(self, node = None, config = None, timeout = 10):
         if self.onos_cord:
             onos_config = '{}/network-cfg.json'.format(OnosCord.onos_config_dir)
         else:
@@ -49,7 +49,7 @@
         if self.onos_cord:
             self.onos_cord.start(restart = True, network_cfg = config)
         else:
-            Onos.restart_node(node = node, network_cfg = config)
+            Onos.restart_node(node = node, network_cfg = config, timeout = timeout)
         return 'DONE'
 
     def restart_onos(self, kwargs):
@@ -194,9 +194,9 @@
     return rpc_server_instance().restart_onos(kwargs)
 
 @nottest
-def cord_test_onos_restart(node = None, config = None):
+def cord_test_onos_restart(node = None, config = None, timeout = 10):
     '''Send ONOS restart to server'''
-    data = __cord_test_onos_restart(node = node, config = config)
+    data = __cord_test_onos_restart(node = node, config = config, timeout = timeout)
     if data == 'DONE':
         return True
     return False