Synchronize the vtn/fabric configuration after activating the synchronizer apps.
And then restart the xos synchronizer containers.

Change-Id: I2f68f95544a671073a601d50f1405ad1b064dd7d
diff --git a/src/test/cli/clidriver.py b/src/test/cli/clidriver.py
index b10a432..8fc92ca 100644
--- a/src/test/cli/clidriver.py
+++ b/src/test/cli/clidriver.py
@@ -1,12 +1,12 @@
-# 
+#
 # Copyright 2016-present Ciena Corporation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
-# 
+#
 # http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -62,10 +62,13 @@
         connect_result = super( CLI, self ).connect()
         ssh_newkey = 'Are you sure you want to continue connecting'
         refused = "ssh: connect to host " + \
-            self.ip_address + " port 22: Connection refused"
+            self.ip_address + " port {}: Connection refused".format(self.port)
         if self.port:
-            ssh_hosts_file = os.path.join(os.getenv('HOME'), '.ssh', 'known_hosts')
-            cmd_host_remove = 'ssh-keygen -f "%s" -R [%s]:8101' %(ssh_hosts_file, self.ip_address)
+            if os.getuid() == 0:
+                ssh_hosts_file = '/root/.ssh/known_hosts'
+            else:
+                ssh_hosts_file = os.path.join(os.getenv('HOME'), '.ssh', 'known_hosts')
+            cmd_host_remove = 'ssh-keygen -f "%s" -R [%s]:8101 2>/dev/null' %(ssh_hosts_file, self.ip_address)
             os.system(cmd_host_remove)
             #main.log.info('SSH host remove cmd: %s' %cmd_host_remove)
             main.log.info('Spawning pexpect for ip %s' %self.ip_address)
@@ -73,7 +76,7 @@
                 'ssh -p ' +
                 self.port +
                 ' ' +
-                '-o StrictHostKeyChecking=no ' + 
+                '-o StrictHostKeyChecking=no ' +
                 self.user_name +
                 '@' +
                 self.ip_address,
diff --git a/src/test/utils/CordContainer.py b/src/test/utils/CordContainer.py
index 0834302..0db31ad 100644
--- a/src/test/utils/CordContainer.py
+++ b/src/test/utils/CordContainer.py
@@ -385,7 +385,7 @@
                 return cli
             else:
                 retries += 1
-                time.sleep(2)
+                time.sleep(3)
 
         return None
 
@@ -415,17 +415,6 @@
         self.cliExit(cli)
 
     def synchronize(self, cfg_unlink = False):
-        cfg = None
-        #restore the saved config after restart
-        if os.access(self.onos_cfg_save_loc, os.F_OK):
-            with open(self.onos_cfg_save_loc, 'r') as f:
-                cfg = json.load(f)
-                try:
-                    OnosCtrl.config(cfg, controller = self.onos_ip)
-                    if cfg_unlink is True:
-                        os.unlink(self.onos_cfg_save_loc)
-                except:
-                    pass
 
         if not self.synchronizer_map.has_key(self.synchronizer):
             return
@@ -451,7 +440,22 @@
             print('Installing tester app from url: %s' %app_url)
             OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip)
 
-        #restart the xos synchronizer container
+        cfg = None
+        #restore the saved config after applications are activated
+        if os.access(self.onos_cfg_save_loc, os.F_OK):
+            with open(self.onos_cfg_save_loc, 'r') as f:
+                cfg = json.load(f)
+                try:
+                    OnosCtrl.config(cfg, controller = self.onos_ip)
+                    if cfg_unlink is True:
+                        os.unlink(self.onos_cfg_save_loc)
+                except:
+                    pass
+
+        if hasattr(self, 'synchronize_{}'.format(self.synchronizer)):
+            getattr(self, 'synchronize_{}'.format(self.synchronizer))(cfg = cfg)
+
+        #now restart the xos synchronizer container
         cmd = 'cd /opt/cord_profile/onboarding-docker-compose && \
         docker-compose -p {} restart xos_synchronizer_{}'.format(self.service_profile, self.synchronizer)
         try:
@@ -459,9 +463,6 @@
             os.system(cmd)
         except: pass
 
-        if hasattr(self, 'synchronize_{}'.format(self.synchronizer)):
-            getattr(self, 'synchronize_{}'.format(self.synchronizer))(cfg = cfg)
-
     def start(self, restart = False, network_cfg = None):
         if network_cfg is not None:
             json_data = json.dumps(network_cfg, indent=4)
@@ -473,7 +474,7 @@
         #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),
-                 'sleep 45',
+                 'sleep 60',
         ]
         for cmd in cmds:
             try:
@@ -506,7 +507,7 @@
                 'rm -rf {}'.format(self.onos_config_dir),
                 'mv {} {}'.format(self.docker_yaml_saved, self.docker_yaml),
                 'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
-                'sleep 45',
+                'sleep 60',
         ]
         for cmd in cmds:
             try: