Test: Install vtn cord app during cord-tester setup to make it consistent with ONOS cord apps being loaded.

Don't install cord if already installed which is true when specifying external controller for setup.

When running the tester in cord mode, make sure to install cord apps after restarting ONOS on cord to bring it back to the same state as before restart.

Change-Id: If4961867f5b08c4079660961f6a30be9011b3a57
diff --git a/src/test/apps/vtn-1.0-SNAPSHOT.oar b/src/test/apps/vtn-1.0-SNAPSHOT.oar
new file mode 100644
index 0000000..4bc8852
--- /dev/null
+++ b/src/test/apps/vtn-1.0-SNAPSHOT.oar
Binary files differ
diff --git a/src/test/setup/cord-test.py b/src/test/setup/cord-test.py
index ac81fa7..ccd6d92 100755
--- a/src/test/setup/cord-test.py
+++ b/src/test/setup/cord-test.py
@@ -277,8 +277,9 @@
         onos_ip = onos.ip()
 
     print('Onos IP %s, Test type %s' %(onos_ip, args.test_type))
-    print('Installing ONOS cord apps')
-    Onos.install_cord_apps(onos_ip = onos_ip)
+    if args.test_controller:
+        print('Installing ONOS cord apps')
+        Onos.install_cord_apps(onos_ip = onos_ip)
 
     print('Installing cord tester ONOS app %s' %onos_app_file)
     OnosCtrl.install_app(args.app, onos_ip = onos_ip)
@@ -388,7 +389,7 @@
             ##Unexpected case. Specify the external controller ip when running on cord node
             print('Specify ONOS ip using \"-e\" option when running the cord-tester on cord node')
             sys.exit(1)
-        onos_cord = OnosCord(onos_cord_loc)
+        onos_cord = OnosCord(onos_ip, onos_cord_loc)
 
     #don't spawn onos if the user had started it externally
     onos_cnt['image'] = args.onos.split(':')[0]
@@ -400,8 +401,10 @@
         onos_ip = onos.ip()
 
     print('Onos IP %s' %onos_ip)
-    print('Installing ONOS cord apps')
-    Onos.install_cord_apps(onos_ip = onos_ip)
+    if args.test_controller:
+        print('Installing ONOS cord apps')
+        Onos.install_cord_apps(onos_ip = onos_ip)
+
     print('Installing cord tester ONOS app %s' %onos_app_file)
     OnosCtrl.install_app(args.app, onos_ip = onos_ip)
 
diff --git a/src/test/utils/CordContainer.py b/src/test/utils/CordContainer.py
index da99655..4f06b2f 100644
--- a/src/test/utils/CordContainer.py
+++ b/src/test/utils/CordContainer.py
@@ -202,8 +202,10 @@
     onos_config_dir = os.path.join(onos_cord_dir, 'config')
     docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
 
-    def __init__(self, conf):
+    def __init__(self, onos_ip, conf, boot_delay = 60):
+        self.onos_ip = onos_ip
         self.cord_conf_dir = conf
+        self.boot_delay = boot_delay
         if os.access(self.cord_conf_dir, os.F_OK) and not os.access(self.onos_cord_dir, os.F_OK):
             os.mkdir(self.onos_cord_dir)
             os.mkdir(self.onos_config_dir)
@@ -252,6 +254,9 @@
         #start the container using docker-compose
         cmd = 'cd {} && docker-compose up -d'.format(self.onos_cord_dir)
         os.system(cmd)
+        #Delay to make sure ONOS fully boots
+        time.sleep(self.boot_delay)
+        Onos.install_cord_apps(onos_ip = self.onos_ip)
 
     def build_image(self):
         build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir)
@@ -266,6 +271,7 @@
     onos_cord_apps = ( ('cord-config', '1.0-SNAPSHOT'),
                        ('aaa', '1.0-SNAPSHOT'),
                        ('igmp', '1.0-SNAPSHOT'),
+                       ('vtn', '1.0-SNAPSHOT'),
                        )
     ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620 ]
     host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/onos-config')
diff --git a/src/test/utils/CordTestServer.py b/src/test/utils/CordTestServer.py
index a77b977..d946acb 100644
--- a/src/test/utils/CordTestServer.py
+++ b/src/test/utils/CordTestServer.py
@@ -28,7 +28,6 @@
 
 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,8 +37,10 @@
 
 class CordTestServer(object):
 
+    onos_cord = None
+
     def __restart_onos(self, config = None):
-        if g_onos_cord:
+        if self.onos_cord:
             onos_config = '{}/network-cfg.json'.format(OnosCord.onos_config_dir)
         else:
             onos_config = '{}/network-cfg.json'.format(Onos.host_config_dir)
@@ -49,8 +50,8 @@
             except:
                 pass
         print('Restarting ONOS')
-        if g_onos_cord:
-            g_onos_cord.start(restart = True, network_cfg = config)
+        if self.onos_cord:
+            self.onos_cord.start(restart = True, network_cfg = config)
         else:
             Onos(restart = True, network_cfg = config)
         return 'DONE'
@@ -99,10 +100,9 @@
 @nottest
 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
+    CordTestServer.onos_cord = onos_cord
     if daemonize is True:
         d = daemon.DaemonContext(files_preserve = [server],
                                  detach_process = True)