Test: Support to restart ONOS specifying ONOS container name/ip when running under cluster mode

Change-Id: Ifc70184c54d6df3a44ddce64e28b338fc565f0b7
diff --git a/src/test/utils/CordContainer.py b/src/test/utils/CordContainer.py
index 38ac752..4cfc79c 100644
--- a/src/test/utils/CordContainer.py
+++ b/src/test/utils/CordContainer.py
@@ -496,6 +496,25 @@
             onos.remove_container(onos.name, force=True)
 
     @classmethod
+    def restart_node(cls, node = None, network_cfg = None):
+        if node is None:
+            cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
+        else:
+            #Restarts a node in the cluster
+            valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
+            if valid_node:
+                onos = valid_node.pop()
+                if onos.exists():
+                    onos.kill()
+                onos.remove_container(onos.name, force=True)
+                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)
+                print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
+                time.sleep(onos.boot_delay)
+                onos.ipaddr = onos.ip()
+
+    @classmethod
     def install_cord_apps(cls, onos_ip = None):
         for app, version in cls.onos_cord_apps:
             app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
diff --git a/src/test/utils/CordTestServer.py b/src/test/utils/CordTestServer.py
index 45183d3..e236008 100644
--- a/src/test/utils/CordTestServer.py
+++ b/src/test/utils/CordTestServer.py
@@ -40,7 +40,7 @@
 
     onos_cord = None
 
-    def __restart_onos(self, config = None):
+    def __restart_onos(self, node = None, config = None):
         if self.onos_cord:
             onos_config = '{}/network-cfg.json'.format(OnosCord.onos_config_dir)
         else:
@@ -54,7 +54,7 @@
         if self.onos_cord:
             self.onos_cord.start(restart = True, network_cfg = config)
         else:
-            Onos(restart = True, network_cfg = config, image = Onos.IMAGE, tag = Onos.TAG)
+            Onos.restart_node(node = node, network_cfg = config)
         return 'DONE'
 
     def restart_onos(self, kwargs):
@@ -153,9 +153,9 @@
     return rpc_server_instance().restart_onos(kwargs)
 
 @nottest
-def cord_test_onos_restart(config = None):
+def cord_test_onos_restart(node = None, config = None):
     '''Send ONOS restart to server'''
-    data = __cord_test_onos_restart(config = config)
+    data = __cord_test_onos_restart(node = node, config = config)
     if data == 'DONE':
         return True
     return False