]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Allow disabling of long-lived SSH connections.
authorAvishay Traeger <avishay@il.ibm.com>
Wed, 6 Feb 2013 21:04:15 +0000 (23:04 +0200)
committerAvishay Traeger <avishay@il.ibm.com>
Wed, 6 Feb 2013 21:07:14 +0000 (23:07 +0200)
Currently, SSHPool connections are kept alive indefinitely.  This can
be good for many cases, but sometimes it is not desirable.  For
example, this causes unit tests which use SSH to not complete because
of the open connections.  This patch allows users to revert back
to paramiko's regular timeout policy.

Change-Id: Ifa96508b38d90610390c9ec3d48a7de75d02f08b

cinder/utils.py

index 1d5e89c5c9017a79cd37170fbc7ce38c5c1ca272..63786e5940e4deda34a54a3bebb51976ea95adac 100644 (file)
@@ -277,7 +277,7 @@ class SSHPool(pools.Pool):
         self.port = port
         self.login = login
         self.password = password
-        self.conn_timeout = conn_timeout
+        self.conn_timeout = conn_timeout if conn_timeout else None
         self.privatekey = privatekey
         super(SSHPool, self).__init__(*args, **kwargs)
 
@@ -310,9 +310,10 @@ class SSHPool(pools.Pool):
             # the sockettimeout to None and setting a keepalive packet so that,
             # the server will keep the connection open. All that does is send
             # a keepalive packet every ssh_conn_timeout seconds.
-            transport = ssh.get_transport()
-            transport.sock.settimeout(None)
-            transport.set_keepalive(self.conn_timeout)
+            if self.conn_timeout:
+                transport = ssh.get_transport()
+                transport.sock.settimeout(None)
+                transport.set_keepalive(self.conn_timeout)
             return ssh
         except Exception as e:
             msg = _("Error connecting via ssh: %s") % e