Onos cord instance wrapper works now across test case restarts.
Fix the vrouter test case to activate the relevant apps for vrouter.

Change-Id: I392f8a18052435b140996ba68e2071cf378f1798
diff --git a/src/test/setup/cord-test.py b/src/test/setup/cord-test.py
index 3e66fd8..b71e68e 100755
--- a/src/test/setup/cord-test.py
+++ b/src/test/setup/cord-test.py
@@ -196,6 +196,7 @@
         uplink = self.port_map['uplink']
         wan = self.port_map['wan']
         port_list = self.port_map['switch_port_list'] + self.port_map['switch_relay_port_list']
+        print('Provisioning the ports for the test container\n')
         for host_intf, ports in port_list:
             uplink = self.port_map[host_intf]['uplink']
             for port in ports:
diff --git a/src/test/utils/CordContainer.py b/src/test/utils/CordContainer.py
index d1db4ff..2f34675 100644
--- a/src/test/utils/CordContainer.py
+++ b/src/test/utils/CordContainer.py
@@ -193,8 +193,7 @@
             print('Infinity time pause the container %s' %cnt['Id'])
         return 'success'
 
-    def connect_to_br(self):
-        index = 0
+    def connect_to_br(self, index = 0):
         self.CONFIG_LOCK.acquire()
         try:
             with docker_netns(self.name) as pid:
@@ -213,7 +212,7 @@
                         br = ip.link_lookup(ifname=quagga_config['bridge'])
                     br = br[0]
                     ip.link('set', index=br, state='up')
-                    ifname = '{0}-{1}'.format(self.name, index)
+                    ifname = '{0}-{1}'.format(self.name[:12], index)
                     ifs = ip.link_lookup(ifname=ifname)
                     if len(ifs) > 0:
                        ip.link_remove(ifs[0])
@@ -294,7 +293,7 @@
     """Use this when running the cord tester agent on the onos compute node"""
     onos_config_dir_guest = '/root/onos/config'
 
-    def __init__(self, onos_ip, conf, service_profile, synchronizer, start = True, boot_delay = 60):
+    def __init__(self, onos_ip, conf, service_profile, synchronizer, start = True, boot_delay = 25):
         if not os.access(conf, os.F_OK):
             raise Exception('ONOS cord configuration location %s is invalid' %conf)
         if not os.access(service_profile, os.F_OK):
@@ -337,7 +336,7 @@
             self.volumes = volumes
 
         ##Create an container instance of xos onos
-        self.xos_onos = Container(xos_onos_name, image, tag = '')
+        super(OnosCord, self).__init__(xos_onos_name, image, tag = '', quagga_config = Onos.QUAGGA_CONFIG)
         self.last_cfg = None
         if self.start_wrapper:
             #fetch the current config of onos cord instance and save it
@@ -356,7 +355,10 @@
             json_data = json.dumps(network_cfg, indent=4)
             with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f:
                 f.write(json_data)
-        if restart is False:
+
+        #we avoid using docker-compose restart for now.
+        #since we don't want to retain the metadata across restarts
+        if True:
             #stop and start and synchronize the services before installing tester cord apps
             cmds = [ 'cd {} && docker-compose down'.format(self.onos_cord_dir),
                      'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
@@ -374,6 +376,12 @@
             try:
                 os.system(cmd)
             except: pass
+
+        ##we could also connect container to default docker network but disabled for now
+        #Container.connect_to_network(self.name, 'bridge')
+
+        #connect container to the quagga bridge
+        self.connect_to_br(index = 0)
         print('Waiting %d seconds for ONOS instance to start' %self.boot_delay)
         time.sleep(self.boot_delay)
 
diff --git a/src/test/vrouter/vrouterTest.py b/src/test/vrouter/vrouterTest.py
index 7b416a6..97df637 100644
--- a/src/test/vrouter/vrouterTest.py
+++ b/src/test/vrouter/vrouterTest.py
@@ -41,7 +41,7 @@
 
 class vrouter_exchange(CordLogger):
 
-    apps = ('org.onosproject.vrouter', 'org.onosproject.fwd')
+    apps = ('org.onosproject.proxyarp', 'org.onosproject.hostprovider', 'org.onosproject.vrouter', 'org.onosproject.fwd')
     device_id = 'of:' + get_mac()
     vrouter_device_dict = { "devices" : {
                 "{}".format(device_id) : {
@@ -108,6 +108,16 @@
             },
         }
 
+    @classmethod
+    def activate_apps(cls, deactivate = False):
+        for app in cls.apps:
+            onos_ctrl = OnosCtrl(app)
+            if deactivate is False:
+                onos_ctrl.activate()
+            else:
+                onos_ctrl.deactivate()
+            time.sleep(2)
+
     def cliEnter(self):
         retries = 0
         while retries < 3:
@@ -294,6 +304,8 @@
         vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
                                                  peer_address = peer_address, route_update = route_update)
         cls.start_onos(network_cfg = vrouter_configs)
+        cls.activate_apps()
+        time.sleep(5)
         cls.vrouter_host_load()
         ##Start quagga
         cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
@@ -652,6 +664,3 @@
         time.sleep(60)
         self.vrouter_traffic_verify(positive_test = True)
         assert_equal(res, True)
-
-
-