summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keystonemiddleware/auth_token/_cache.py6
-rw-r--r--keystonemiddleware/tests/unit/auth_token/test_cache.py23
-rw-r--r--releasenotes/notes/bug-1782404-c4e37bbc83756a89.yaml8
3 files changed, 36 insertions, 1 deletions
diff --git a/keystonemiddleware/auth_token/_cache.py b/keystonemiddleware/auth_token/_cache.py
index c148349..8951b37 100644
--- a/keystonemiddleware/auth_token/_cache.py
+++ b/keystonemiddleware/auth_token/_cache.py
@@ -98,7 +98,11 @@ class _MemcacheClientPool(object):
98 98
99 @contextlib.contextmanager 99 @contextlib.contextmanager
100 def reserve(self): 100 def reserve(self):
101 yield self._pool.get() 101 # NOTE(morgan): We must use "acquire" if we want all the added context
102 # manager logic that places the connection back into the pool at the
103 # end of it's use.
104 with self._pool.acquire() as client:
105 yield client
102 106
103 107
104class TokenCache(object): 108class TokenCache(object):
diff --git a/keystonemiddleware/tests/unit/auth_token/test_cache.py b/keystonemiddleware/tests/unit/auth_token/test_cache.py
index 52e657c..eb537a6 100644
--- a/keystonemiddleware/tests/unit/auth_token/test_cache.py
+++ b/keystonemiddleware/tests/unit/auth_token/test_cache.py
@@ -12,8 +12,10 @@
12 12
13import uuid 13import uuid
14 14
15import fixtures
15import six 16import six
16 17
18from keystonemiddleware.auth_token import _cache
17from keystonemiddleware.auth_token import _exceptions as exc 19from keystonemiddleware.auth_token import _exceptions as exc
18from keystonemiddleware.tests.unit.auth_token import base 20from keystonemiddleware.tests.unit.auth_token import base
19from keystonemiddleware.tests.unit import utils 21from keystonemiddleware.tests.unit import utils
@@ -165,3 +167,24 @@ class TestLiveMemcache(base.BaseAuthTokenTestCase):
165 167
166 token_cache.set(token, data) 168 token_cache.set(token, data)
167 self.assertEqual(token_cache.get(token), data) 169 self.assertEqual(token_cache.get(token), data)
170
171
172class TestMemcachePoolAbstraction(utils.TestCase):
173 def setUp(self):
174 super(TestMemcachePoolAbstraction, self).setUp()
175 self.useFixture(fixtures.MockPatch(
176 'oslo_cache._memcache_pool._MemcacheClient'))
177
178 def test_abstraction_layer_reserve_places_connection_back_in_pool(self):
179 cache_pool = _cache._MemcacheClientPool(
180 memcache_servers=[], arguments={}, maxsize=1, unused_timeout=10)
181 conn = None
182 with cache_pool.reserve() as client:
183 self.assertEqual(cache_pool._pool._acquired, 1)
184 conn = client
185
186 self.assertEqual(cache_pool._pool._acquired, 0)
187 with cache_pool.reserve() as client:
188 # Make sure the connection we got before is in-fact the one we
189 # get again.
190 self.assertEqual(conn, client)
diff --git a/releasenotes/notes/bug-1782404-c4e37bbc83756a89.yaml b/releasenotes/notes/bug-1782404-c4e37bbc83756a89.yaml
new file mode 100644
index 0000000..852685c
--- /dev/null
+++ b/releasenotes/notes/bug-1782404-c4e37bbc83756a89.yaml
@@ -0,0 +1,8 @@
1---
2fixes:
3 - >
4 [`bug 1782404 <https://bugs.launchpad.net/keystonemiddleware/+bug/1782404>`_]
5 Keystonemiddleware incorrectly implemented an abstraction for the memcache
6 client pool that utilized a `queue.Queue` `get` method instead of the
7 supplied `acquire()` context manager. The `acquire()` context manager
8 properly places the client connection back into the pool after `__exit__`.