Support Fenix and sample implementation accordingly
[doctor.git] / doctor_tests / installer / apex.py
index 9b0010e..3c97378 100644 (file)
@@ -114,6 +114,22 @@ class ApexInstaller(BaseInstaller):
     def set_apply_patches(self):
         self.log.info('Set apply patches start......')
 
+        if self.conf.test_case != 'fault_management':
+            if self.use_containers:
+                restart_cmd = self._set_docker_restart_cmd("nova-compute")
+            else:
+                restart_cmd = 'sudo systemctl restart' \
+                              ' openstack-nova-compute.service'
+            for node_ip in self.computes:
+                client = SSHClient(node_ip, self.node_user_name,
+                                   key_filename=self.key_file)
+                self.compute_clients.append(client)
+                self._run_apply_patches(client,
+                                        restart_cmd,
+                                        [self.nc_set_compute_script],
+                                        python=self.python)
+            time.sleep(10)
+
         set_scripts = [self.cm_set_script]
 
         if self.use_containers:
@@ -147,24 +163,6 @@ class ApexInstaller(BaseInstaller):
                                     set_scripts,
                                     python=self.python)
 
-        if self.conf.test_case != 'fault_management':
-            if self.use_containers:
-                restart_cmd = self._set_docker_restart_cmd("nova-compute")
-            else:
-                restart_cmd = 'sudo systemctl restart' \
-                              ' openstack-nova-compute.service'
-            for node_ip in self.computes:
-                client = SSHClient(node_ip, self.node_user_name,
-                                   key_filename=self.key_file)
-                self.compute_clients.append(client)
-                self._run_apply_patches(client,
-                                        restart_cmd,
-                                        [self.nc_set_compute_script],
-                                        python=self.python)
-
-        if self.conf.test_case != 'fault_management':
-            time.sleep(10)
-
     def restore_apply_patches(self):
         self.log.info('restore apply patches start......')
 
@@ -192,20 +190,39 @@ class ApexInstaller(BaseInstaller):
                 restart_cmd += ' openstack-congress-server.service'
             restore_scripts.append(self.cg_restore_script)
 
-        for client in self.controller_clients:
-            self._run_apply_patches(client,
-                                    restart_cmd,
-                                    restore_scripts,
-                                    python=self.python)
-
+        for client, node_ip in zip(self.controller_clients, self.controllers):
+            retry = 0
+            while retry < 2:
+                try:
+                    self._run_apply_patches(client,
+                                            restart_cmd,
+                                            restore_scripts,
+                                            python=self.python)
+                except Exception:
+                    if retry > 0:
+                        raise Exception("SSHClient to %s feiled" % node_ip)
+                    client = SSHClient(node_ip, self.node_user_name,
+                                       key_filename=self.key_file)
+                    retry += 1
+                break
         if self.conf.test_case != 'fault_management':
             if self.use_containers:
                 restart_cmd = self._set_docker_restart_cmd("nova-compute")
             else:
                 restart_cmd = 'sudo systemctl restart' \
                               ' openstack-nova-compute.service'
-            for client in self.compute_clients:
-                self._run_apply_patches(client,
-                                        restart_cmd,
-                                        [self.nc_restore_compute_script],
-                                        python=self.python)
+            for client, node_ip in zip(self.compute_clients, self.computes):
+                retry = 0
+                while retry < 2:
+                    try:
+                        self._run_apply_patches(
+                            client, restart_cmd,
+                            [self.nc_restore_compute_script],
+                            python=self.python)
+                    except Exception:
+                        if retry > 0:
+                            raise Exception("SSHClient to %s feiled" % node_ip)
+                        client = SSHClient(node_ip, self.node_user_name,
+                                           key_filename=self.key_file)
+                        retry += 1
+                    break