summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangxiyuan <wangxiyuan@huawei.com>2018-02-08 19:04:36 +0800
committerwangxiyuan <wangxiyuan@huawei.com>2018-02-22 16:31:11 +0800
commit33a712bed791a94df2824fb1ace1a5c3f58342c1 (patch)
treee1c4351b1dd14a4eb543e7311841d8011de5f186
parentce06c0ce1035964ecf117bd56f769174508dc269 (diff)
downloadkeystonemiddleware-33a712bed791a94df2824fb1ace1a5c3f58342c1.tar.gz
Fix the AttributeError: __exit__ error
The memcache client class actually has no __exit__ function. Remove the "with" usage to avoid the __exit__ error. Change-Id: I15b3d08f4afae289e7eb0848ff1db08141196d3c Closes-Bug: #1747565
-rw-r--r--keystonemiddleware/auth_token/_cache.py3
-rw-r--r--keystonemiddleware/tests/unit/auth_token/test_cache.py8
2 files changed, 8 insertions, 3 deletions
diff --git a/keystonemiddleware/auth_token/_cache.py b/keystonemiddleware/auth_token/_cache.py
index 18f4882..c148349 100644
--- a/keystonemiddleware/auth_token/_cache.py
+++ b/keystonemiddleware/auth_token/_cache.py
@@ -98,8 +98,7 @@ class _MemcacheClientPool(object):
@contextlib.contextmanager
def reserve(self):
- with self._pool.get() as client:
- yield client
+ yield self._pool.get()
class TokenCache(object):
diff --git a/keystonemiddleware/tests/unit/auth_token/test_cache.py b/keystonemiddleware/tests/unit/auth_token/test_cache.py
index 542f9a1..52e657c 100644
--- a/keystonemiddleware/tests/unit/auth_token/test_cache.py
+++ b/keystonemiddleware/tests/unit/auth_token/test_cache.py
@@ -151,11 +151,17 @@ class TestLiveMemcache(base.BaseAuthTokenTestCase):
token_cache.set(token, data)
self.assertEqual(token_cache.get(token), data)
- def test_memcache_pool_init(self):
+ def test_memcache_pool(self):
conf = {
'memcached_servers': ','.join(MEMCACHED_SERVERS),
'memcache_use_advanced_pool': True
}
+ token = six.b(uuid.uuid4().hex)
+ data = uuid.uuid4().hex
+
token_cache = self.create_simple_middleware(conf=conf)._token_cache
token_cache.initialize({})
+
+ token_cache.set(token, data)
+ self.assertEqual(token_cache.get(token), data)