From: xiaoxi_chen Date: Fri, 12 Jul 2013 08:51:50 +0000 (+0800) Subject: Refactor SSHPool.get() to use Pool.get() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=cccf7b92c189bcadf6898019730d84bfd4fe70b6;p=openstack-build%2Fcinder-build.git Refactor SSHPool.get() to use Pool.get() In previous code of SSHPool.get(), we pasted the code from Pool.get() and check if a connection is active before return it. However, it's much simpler and cleaner to just call the Pool.get() and then check the connection before return. With this,we can free ourselves from manually keeping up with code of Pool.get() in upstream package eventlet As a side effect,this patch fixed bug #1194393 which caused by a previous bug in eventlet codes before revision 1072 fixed bug #1194393 Change-Id: Ic2bf2fa1ad82cf8669b6c491c955dcab39eb1510 --- diff --git a/cinder/utils.py b/cinder/utils.py index 276e80d29..c332b4e3b 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -233,19 +233,13 @@ class SSHPool(pools.Pool): before returning it. For dead connections create and return a new connection. """ - if self.free_items: - conn = self.free_items.popleft() - if conn: - if conn.get_transport().is_active(): - return conn - else: - conn.close() - return self.create() - if self.current_size < self.max_size: - created = self.create() - self.current_size += 1 - return created - return self.channel.get() + conn = super(SSHPool, self).get() + if conn: + if conn.get_transport().is_active(): + return conn + else: + conn.close() + return self.create() def remove(self, ssh): """Close an ssh client and remove it from free_items."""