From cccf7b92c189bcadf6898019730d84bfd4fe70b6 Mon Sep 17 00:00:00 2001 From: xiaoxi_chen Date: Fri, 12 Jul 2013 16:51:50 +0800 Subject: [PATCH] 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 --- cinder/utils.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) 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.""" -- 2.45.2