def _ssh_client(self, host_name): """Returns an SSH client for use in a 'with' block. When the 'with' context exits, the client will be kept for reuse. """ with self._ssh_client_lock: clients = self._ssh_clients_by_host_name[host_name] if clients: client = clients.pop() else: # IMPALA-7460: Insulate this import away from the global context so as to avoid # requiring Paramiko unless it's absolutely needed. from tests.util.ssh_util import SshClient LOG.debug("Creating new SSH client for %s", host_name) client = SshClient() client.connect(host_name, username=self.ssh_user, key_filename=self.ssh_key_file) error_occurred = False try: yield client except Exception: error_occurred = True raise finally: if not error_occurred: with self._ssh_client_lock: self._ssh_clients_by_host_name[host_name].append(client)
def _ssh_client(self, host_name): """Returns an SSH client for use in a 'with' block. When the 'with' context exits, the client will be kept for reuse. """ with self._ssh_client_lock: clients = self._ssh_clients_by_host_name[host_name] if clients: client = clients.pop() else: LOG.debug("Creating new SSH client for %s", host_name) client = SshClient() client.connect(host_name, username=self.ssh_user, key_filename=self.ssh_key_file) error_occurred = False try: yield client except Exception: error_occurred = True raise finally: if not error_occurred: with self._ssh_client_lock: self._ssh_clients_by_host_name[host_name].append(client)