bugfix: add doctor datasource in congress
[doctor.git] / doctor_tests / installer / base.py
index 76bbeb1..953b36d 100644 (file)
@@ -58,22 +58,33 @@ class BaseInstaller(object):
     def setup_stunnel(self):
         self.log.info('Setup ssh stunnel in %s installer......'
                       % self.conf.installer.type)
+        tunnels = [self.conf.consumer.port]
+        if self.conf.test_case == 'maintenance':
+            tunnel_uptime = 1200
+            tunnels += [self.conf.app_manager.port, self.conf.inspector.port]
+        elif self.conf.test_case == 'all':
+            tunnel_uptime = 1800
+            tunnels += [self.conf.app_manager.port, self.conf.inspector.port]
+        else:
+            tunnel_uptime = 600
 
         for node_ip in self.controllers:
-            cmd = ("ssh -o UserKnownHostsFile=/dev/null"
-                   " -o StrictHostKeyChecking=no"
-                   " -i %s %s@%s -R %s:localhost:%s"
-                   " sleep 600 > ssh_tunnel.%s.log"
-                   " 2>&1 < /dev/null &"
-                   % (self.key_file,
-                      self.node_user_name,
-                      node_ip,
-                      self.conf.consumer.port,
-                      self.conf.consumer.port,
-                      node_ip))
-            server = subprocess.Popen(cmd, shell=True)
-            self.servers.append(server)
-            server.communicate()
+            for port in tunnels:
+                self.log.info('tunnel for port %s' % port)
+                cmd = ("ssh -o UserKnownHostsFile=/dev/null"
+                       " -o StrictHostKeyChecking=no"
+                       " -i %s %s@%s -R %s:localhost:%s"
+                       " sleep %s > ssh_tunnel.%s"
+                       " 2>&1 < /dev/null "
+                       % (self.key_file,
+                          self.node_user_name,
+                          node_ip,
+                          port,
+                          port,
+                          tunnel_uptime,
+                          node_ip))
+                server = subprocess.Popen('exec ' + cmd, shell=True)
+                self.servers.append(server)
 
     def _get_ssh_key(self, client, key_path):
         self.log.info('Get SSH keys from %s installer......'
@@ -107,16 +118,18 @@ class BaseInstaller(object):
                       % (output, command, self.conf.installer.type))
         return output
 
-    def _run_apply_patches(self, client, restart_cmd, script_name):
+    def _run_apply_patches(self, client, restart_cmd, script_names):
         installer_dir = os.path.dirname(os.path.realpath(__file__))
-        script_abs_path = '{0}/{1}/{2}'.format(installer_dir,
-                                               'common', script_name)
 
-        client.scp(script_abs_path, script_name)
-        cmd = 'sudo python %s' % script_name
-        ret, output = client.ssh(cmd)
-        if ret:
-            raise Exception('Do the command in controller'
-                            ' node failed, ret=%s, cmd=%s, output=%s'
-                            % (ret, cmd, output))
-        client.ssh(restart_cmd)
+        if isinstance(script_names, list):
+            for script_name in script_names:
+                script_abs_path = '{0}/{1}/{2}'.format(installer_dir,
+                                                       'common', script_name)
+                client.scp(script_abs_path, script_name)
+                cmd = 'sudo python3 %s' % script_name
+                ret, output = client.ssh(cmd)
+                if ret:
+                    raise Exception('Do the command in controller'
+                                    ' node failed, ret=%s, cmd=%s, output=%s'
+                                    % (ret, cmd, output))
+            client.ssh(restart_cmd)