]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Refactor SSHPool.get() to use Pool.get()
authorxiaoxi_chen <xiaoxi.chen@intel.com>
Fri, 12 Jul 2013 08:51:50 +0000 (16:51 +0800)
committerxiaoxi_chen <xiaoxi.chen@intel.com>
Fri, 12 Jul 2013 15:41:44 +0000 (23:41 +0800)
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

index 276e80d295fc6311ecd573360430c1d0f8f7ea5a..c332b4e3b29aabd525862f98ed16bd03216c0dfd 100644 (file)
@@ -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."""