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 <ralonsoh@redhat.com> Change-Id: I128340f14e7e9570b23721686504e12458e85773
This commit is contained in:
parent
858fa49a6f
commit
73e1540d5c
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue