Merge "Fix the cache interface to use time= by default."
This commit is contained in:
@@ -331,7 +331,6 @@ class AuthProtocol(object):
|
||||
|
||||
# Token caching via memcache
|
||||
self._cache = None
|
||||
self._use_keystone_cache = False
|
||||
self._cache_initialized = False # cache already initialzied?
|
||||
# memcache value treatment, ENCRYPT or MAC
|
||||
self._memcache_security_strategy = \
|
||||
@@ -373,7 +372,6 @@ class AuthProtocol(object):
|
||||
else:
|
||||
# use Keystone memcache
|
||||
self._cache = memorycache.get_client(memcache_servers)
|
||||
self._use_keystone_cache = True
|
||||
self._cache_initialized = True
|
||||
|
||||
def _conf_get(self, name):
|
||||
@@ -915,14 +913,16 @@ class AuthProtocol(object):
|
||||
cache_key = CACHE_KEY_TEMPLATE % memcache_crypt.get_cache_key(keys)
|
||||
data_to_store = memcache_crypt.protect_data(keys, serialized_data)
|
||||
|
||||
# we need to special-case set() because of the incompatibility between
|
||||
# Swift MemcacheRing and python-memcached. See
|
||||
# https://bugs.launchpad.net/swift/+bug/1095730
|
||||
if self._use_keystone_cache:
|
||||
# Historically the swift cache conection used the argument
|
||||
# timeout= for the cache timeout, but this has been unified
|
||||
# with the official python memcache client with time= since
|
||||
# grizzly, we still need to handle folsom for a while until
|
||||
# this could get removed.
|
||||
try:
|
||||
self._cache.set(cache_key,
|
||||
data_to_store,
|
||||
time=self.token_cache_time)
|
||||
else:
|
||||
except(TypeError):
|
||||
self._cache.set(cache_key,
|
||||
data_to_store,
|
||||
timeout=self.token_cache_time)
|
||||
|
@@ -414,10 +414,10 @@ class DisableModuleFixture(fixtures.Fixture):
|
||||
sys.meta_path.insert(0, finder)
|
||||
|
||||
|
||||
class FakeSwiftMemcacheRing(memorycache.Client):
|
||||
# NOTE(vish): swift memcache uses param timeout instead of time
|
||||
class FakeSwiftOldMemcacheClient(memorycache.Client):
|
||||
# NOTE(vish,chmou): old swift memcache uses param timeout instead of time
|
||||
def set(self, key, value, timeout=0, min_compress_len=0):
|
||||
sup = super(FakeSwiftMemcacheRing, self)
|
||||
sup = super(FakeSwiftOldMemcacheClient, self)
|
||||
sup.set(key, value, timeout, min_compress_len)
|
||||
|
||||
|
||||
@@ -1036,16 +1036,18 @@ class AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest):
|
||||
self.assertRaises(auth_token.InvalidUserToken,
|
||||
self._get_cached_token, token)
|
||||
|
||||
def test_memcache_set_expired(self):
|
||||
def test_memcache_set_expired(self, extra_conf={}, extra_environ={}):
|
||||
token_cache_time = 10
|
||||
conf = {
|
||||
'token_cache_time': token_cache_time,
|
||||
'signing_dir': CERTDIR,
|
||||
}
|
||||
conf.update(extra_conf)
|
||||
self.set_middleware(conf=conf)
|
||||
req = webob.Request.blank('/')
|
||||
token = self.token_dict['signed_token_scoped']
|
||||
req.headers['X-Auth-Token'] = token
|
||||
req.environ.update(extra_environ)
|
||||
try:
|
||||
now = datetime.datetime.utcnow()
|
||||
timeutils.set_time_override(now)
|
||||
@@ -1057,11 +1059,15 @@ class AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest):
|
||||
finally:
|
||||
timeutils.clear_time_override()
|
||||
|
||||
def test_old_swift_memcache_set_expired(self):
|
||||
extra_conf = {'cache': 'swift.cache'}
|
||||
extra_environ = {'swift.cache': FakeSwiftOldMemcacheClient()}
|
||||
self.test_memcache_set_expired(extra_conf, extra_environ)
|
||||
|
||||
def test_swift_memcache_set_expired(self):
|
||||
self.middleware._cache = FakeSwiftMemcacheRing()
|
||||
self.middleware._use_keystone_cache = False
|
||||
self.middleware._cache_initialized = True
|
||||
self.test_memcache_set_expired()
|
||||
extra_conf = {'cache': 'swift.cache'}
|
||||
extra_environ = {'swift.cache': memorycache.Client()}
|
||||
self.test_memcache_set_expired(extra_conf, extra_environ)
|
||||
|
||||
def test_use_cache_from_env(self):
|
||||
env = {'swift.cache': 'CACHE_TEST'}
|
||||
|
Reference in New Issue
Block a user