From 1b04cf979f44ffe0f80308855ec2e973b1c961eb Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Tue, 28 Feb 2017 15:47:00 -0800 Subject: [PATCH] Add destructor to SSHClient Newer versions of paramiko require a client object to be explicitly closed. Fortunately, we wrap all of our use of paramiko client objects in our own class. Add a destructor to our class which closes the client object. Note, this has been tested to work (and is needed) even if a connection is not established. Change-Id: I5dff7ed254567968b42d053b85004769f8647ecb (cherry picked from commit d616e61723207ed0e29ea69d67908a00ebf2cdfb) --- nodepool/sshclient.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/nodepool/sshclient.py b/nodepool/sshclient.py index 51faca093..8be0c0089 100644 --- a/nodepool/sshclient.py +++ b/nodepool/sshclient.py @@ -25,14 +25,17 @@ class SSHClient(object): def __init__(self, ip, username, password=None, pkey=None, key_filename=None, log=None, look_for_keys=False, allow_agent=False): - client = paramiko.SSHClient() - client.set_missing_host_key_policy(paramiko.WarningPolicy()) - client.connect(ip, username=username, password=password, pkey=pkey, - key_filename=key_filename, look_for_keys=look_for_keys, - allow_agent=allow_agent) - self.client = client + self.client = paramiko.SSHClient() + self.client.set_missing_host_key_policy(paramiko.WarningPolicy()) + self.client.connect(ip, username=username, password=password, + pkey=pkey, key_filename=key_filename, + look_for_keys=look_for_keys, + allow_agent=allow_agent) self.log = log + def __del__(self): + self.client.close() + def ssh(self, action, command, get_pty=True, output=False): if self.log: self.log.debug("*** START to %s" % action)