Test: Implement setup --cord mode for cord-tester.
This would make the cord-tester listen for ONOS restart requests on the cord.
The restart is implemented using docker-compose when running the test agent on the ONOS compute node.
This is required because the tests restart ONOS with different configurations and the cord-tester agent
restarts bind the config volume to the xos/onos container before restarting ONOS.

Also implement fetching the device id properly when running tester under OLT configuration.
One can also override with OLT_DEVICE_ID env in the test container when multiple devices are connected to ONOS.

This is used by the subscriber test to override the pmc-olt driver for the device id when running
single-channel N subscriber tests.

Change-Id: I1fa27dd21ccacec35f38030443ad298b59718f4b
diff --git a/src/test/utils/CordTestServer.py b/src/test/utils/CordTestServer.py
index e263939..a77b977 100644
--- a/src/test/utils/CordTestServer.py
+++ b/src/test/utils/CordTestServer.py
@@ -13,7 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-from CordContainer import Container, Onos, Quagga, Radius, reinitContainerClients
+from CordContainer import Container, Onos, OnosCord, Quagga, Radius, reinitContainerClients
 from nose.tools import nottest
 from SimpleXMLRPCServer import SimpleXMLRPCServer
 import daemon
@@ -28,6 +28,7 @@
 
 CORD_TEST_HOST = '172.17.0.1'
 CORD_TEST_PORT = 25000
+g_onos_cord = None
 
 class QuaggaStopWrapper(Container):
     def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'latest'):
@@ -38,14 +39,20 @@
 class CordTestServer(object):
 
     def __restart_onos(self, config = None):
-        onos_config = '{}/network-cfg.json'.format(Onos.host_config_dir)
+        if g_onos_cord:
+            onos_config = '{}/network-cfg.json'.format(OnosCord.onos_config_dir)
+        else:
+            onos_config = '{}/network-cfg.json'.format(Onos.host_config_dir)
         if config is None:
             try:
                 os.unlink(onos_config)
             except:
                 pass
         print('Restarting ONOS')
-        Onos(restart = True, network_cfg = config)
+        if g_onos_cord:
+            g_onos_cord.start(restart = True, network_cfg = config)
+        else:
+            Onos(restart = True, network_cfg = config)
         return 'DONE'
 
     def restart_onos(self, kwargs):
@@ -90,9 +97,12 @@
         return 'DONE'
 
 @nottest
-def cord_test_server_start(daemonize = True, cord_test_host = CORD_TEST_HOST, cord_test_port = CORD_TEST_PORT):
+def cord_test_server_start(daemonize = True, cord_test_host = CORD_TEST_HOST,
+                           cord_test_port = CORD_TEST_PORT, onos_cord = None):
+    global g_onos_cord
     server = SimpleXMLRPCServer( (cord_test_host, cord_test_port) )
     server.register_instance(CordTestServer())
+    g_onos_cord = onos_cord
     if daemonize is True:
         d = daemon.DaemonContext(files_preserve = [server],
                                  detach_process = True)