From 73e1540d5cdc426b76018f4b954d3637c082c317 Mon Sep 17 00:00:00 2001 From: "Dr. Jens Harbott" Date: Fri, 3 Jan 2020 12:06:12 +0000 Subject: [PATCH] Stop re-using client connections The re-use of client connections in common/ssh.py depended on a bug in tempest that causes leaked connections, see #1853264. Since that bug in tempest was fixed, we now need to create a fresh connection every time we need one. Closes-Bug: #1858260 Related-Bug: #1853264 Co-Authored-By: Rodolfo Alonso Hernandez Change-Id: I128340f14e7e9570b23721686504e12458e85773 --- neutron_tempest_plugin/common/ssh.py | 29 +--------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/neutron_tempest_plugin/common/ssh.py b/neutron_tempest_plugin/common/ssh.py index 96f0ef9c..fa731d80 100644 --- a/neutron_tempest_plugin/common/ssh.py +++ b/neutron_tempest_plugin/common/ssh.py @@ -133,47 +133,20 @@ class Client(ssh.Client): look_for_keys=look_for_keys, key_filename=key_file, port=port, create_proxy_client=False, **kwargs) - # attribute used to keep reference to opened client connection - _client = None - def connect(self, *args, **kwargs): """Creates paramiko.SSHClient and connect it to remote SSH server - In case this method is called more times it returns the same client - and no new SSH connection is created until close method is called. - :returns: paramiko.Client connected to remote server. :raises tempest.lib.exceptions.SSHTimeout: in case it fails to connect to remote server. """ - client = self._client - if client is None: - client = super(Client, self)._get_ssh_connection( - *args, **kwargs) - self._client = client - - return client - - # This overrides superclass protected method to make sure exec_command - # method is going to reuse the same SSH client and connection if called - # more times - _get_ssh_connection = connect + return super(Client, self)._get_ssh_connection(*args, **kwargs) # This overrides superclass test_connection_auth method forbidding it to # close connection test_connection_auth = connect - def close(self): - """Closes connection to SSH server and cleanup resources.""" - client = self._client - if client is not None: - client.close() - self._client = None - - def __exit__(self, _exception_type, _exception_value, _traceback): - self.close() - def open_session(self): """Gets connection to SSH server and open a new paramiko.Channel