diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index 72d6f61539..407a7aed93 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -107,18 +107,6 @@ def delay_denial(func): return func -def get_account_memcache_key(account): - cache_key, env_key = _get_cache_key(account, None) - return cache_key - - -def get_container_memcache_key(account, container): - if not container: - raise ValueError("container not provided") - cache_key, env_key = _get_cache_key(account, container) - return cache_key - - def _prep_headers_to_info(headers, server_type): """ Helper method that iterates once over a dict of headers, @@ -424,17 +412,24 @@ def get_account_info(env, app, swift_source=None): return info -def _get_cache_key(account, container): +def get_cache_key(account, container=None, obj=None): """ - Get the keys for both memcache (cache_key) and env (env_key) - where info about accounts and containers is cached + Get the keys for both memcache and env['swift.infocache'] (cache_key) + where info about accounts, containers, and objects is cached :param account: The name of the account :param container: The name of the container (or None if account) - :returns: a tuple of (cache_key, env_key) + :param obj: The name of the object (or None if account or container) + :returns: a string cache_key """ - if container: + if obj: + if not (account and container): + raise ValueError('Object cache key requires account and container') + cache_key = 'object/%s/%s/%s' % (account, container, obj) + elif container: + if not account: + raise ValueError('Container cache key requires account') cache_key = 'container/%s/%s' % (account, container) else: cache_key = 'account/%s' % account @@ -442,22 +437,7 @@ def _get_cache_key(account, container): # This allows caching both account and container and ensures that when we # copy this env to form a new request, it won't accidentally reuse the # old container or account info - env_key = 'swift.%s' % cache_key - return cache_key, env_key - - -def get_object_env_key(account, container, obj): - """ - Get the keys for env (env_key) where info about object is cached - - :param account: The name of the account - :param container: The name of the container - :param obj: The name of the object - :returns: a string env_key - """ - env_key = 'swift.object/%s/%s/%s' % (account, - container, obj) - return env_key + return cache_key def set_info_cache(app, env, account, container, resp): @@ -483,7 +463,7 @@ def set_info_cache(app, env, account, container, resp): cache_time = int(resp.headers.get( 'X-Backend-Recheck-Account-Existence', DEFAULT_RECHECK_ACCOUNT_EXISTENCE)) - cache_key, env_key = _get_cache_key(account, container) + cache_key = get_cache_key(account, container) if resp: if resp.status_int in (HTTP_NOT_FOUND, HTTP_GONE): @@ -494,7 +474,7 @@ def set_info_cache(app, env, account, container, resp): # Next actually set both memcache and the env cache memcache = getattr(app, 'memcache', None) or env.get('swift.cache') if not cache_time: - infocache.pop(env_key, None) + infocache.pop(cache_key, None) if memcache: memcache.delete(cache_key) return @@ -505,7 +485,7 @@ def set_info_cache(app, env, account, container, resp): info = headers_to_account_info(resp.headers, resp.status_int) if memcache: memcache.set(cache_key, info, time=cache_time) - infocache[env_key] = info + infocache[cache_key] = info return info @@ -525,14 +505,14 @@ def set_object_info_cache(app, env, account, container, obj, resp): :returns: the object info """ - env_key = get_object_env_key(account, container, obj) + cache_key = get_cache_key(account, container, obj) if 'swift.infocache' in env and not resp: - env['swift.infocache'].pop(env_key, None) + env['swift.infocache'].pop(cache_key, None) return info = headers_to_object_info(resp.headers, resp.status_int) - env.setdefault('swift.infocache', {})[env_key] = info + env.setdefault('swift.infocache', {})[cache_key] = info return info @@ -559,9 +539,9 @@ def _get_info_from_infocache(env, account, container=None): :returns: a dictionary of cached info on cache hit, None on miss """ - _junk, env_key = _get_cache_key(account, container) - if 'swift.infocache' in env and env_key in env['swift.infocache']: - return env['swift.infocache'][env_key] + cache_key = get_cache_key(account, container) + if 'swift.infocache' in env and cache_key in env['swift.infocache']: + return env['swift.infocache'][cache_key] return None @@ -577,7 +557,7 @@ def _get_info_from_memcache(app, env, account, container=None): :returns: a dictionary of cached info on cache hit, None on miss. Also returns None if memcache is not in use. """ - cache_key, env_key = _get_cache_key(account, container) + cache_key = get_cache_key(account, container) memcache = getattr(app, 'memcache', None) or env.get('swift.cache') if memcache: info = memcache.get(cache_key) @@ -589,7 +569,7 @@ def _get_info_from_memcache(app, env, account, container=None): for subkey, value in info[key].items(): if isinstance(value, six.text_type): info[key][subkey] = value.encode("utf-8") - env.setdefault('swift.infocache', {})[env_key] = info + env.setdefault('swift.infocache', {})[cache_key] = info return info return None @@ -680,8 +660,8 @@ def _get_object_info(app, env, account, container, obj, swift_source=None): :param obj: The unquoted name of the object :returns: the cached info or None if cannot be retrieved """ - env_key = get_object_env_key(account, container, obj) - info = env.get('swift.infocache', {}).get(env_key) + cache_key = get_cache_key(account, container, obj) + info = env.get('swift.infocache', {}).get(cache_key) if info: return info # Not in cache, let's try the object servers diff --git a/test/unit/common/middleware/test_account_quotas.py b/test/unit/common/middleware/test_account_quotas.py index 87574bd14f..3ebbe37bd7 100644 --- a/test/unit/common/middleware/test_account_quotas.py +++ b/test/unit/common/middleware/test_account_quotas.py @@ -18,9 +18,8 @@ from swift.common.swob import Request, wsgify, HTTPForbidden, \ from swift.common.middleware import account_quotas, copy -from swift.proxy.controllers.base import _get_cache_key, \ - headers_to_account_info, get_object_env_key, \ - headers_to_object_info +from swift.proxy.controllers.base import get_cache_key, \ + headers_to_account_info, headers_to_object_info class FakeCache(object): @@ -58,8 +57,8 @@ class FakeApp(object): return aresp(env, start_response) if env['REQUEST_METHOD'] == "HEAD" and \ env['PATH_INFO'] == '/v1/a/c2/o2': - env_key = get_object_env_key('a', 'c2', 'o2') - env.setdefault('swift.infocache', {})[env_key] = \ + cache_key = get_cache_key('a', 'c2', 'o2') + env.setdefault('swift.infocache', {})[cache_key] = \ headers_to_object_info(self.headers, 200) start_response('200 OK', self.headers) elif env['REQUEST_METHOD'] == "HEAD" and \ @@ -67,8 +66,8 @@ class FakeApp(object): start_response('404 Not Found', []) else: # Cache the account_info (same as a real application) - cache_key, env_key = _get_cache_key('a', None) - env.setdefault('swift.infocache', {})[env_key] = \ + cache_key = get_cache_key('a') + env.setdefault('swift.infocache', {})[cache_key] = \ headers_to_account_info(self.headers, 200) start_response('200 OK', self.headers) return [] diff --git a/test/unit/common/middleware/test_container_sync.py b/test/unit/common/middleware/test_container_sync.py index 9d5f1dd332..6d30eeb6b1 100644 --- a/test/unit/common/middleware/test_container_sync.py +++ b/test/unit/common/middleware/test_container_sync.py @@ -23,7 +23,7 @@ import mock from swift.common import swob from swift.common.middleware import container_sync -from swift.proxy.controllers.base import _get_cache_key +from swift.proxy.controllers.base import get_cache_key from swift.proxy.controllers.info import InfoController from test.unit import FakeLogger @@ -206,7 +206,7 @@ cluster_dfw1 = http://dfw1.host/v1/ req = swob.Request.blank( '/v1/a/c', headers={'x-container-sync-auth': 'US nonce sig'}) infocache = req.environ.setdefault('swift.infocache', {}) - infocache[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'} + infocache[get_cache_key('a', 'c')] = {'sync_key': 'abc'} resp = req.get_response(self.sync) self.assertEqual(resp.status, '401 Unauthorized') self.assertEqual( @@ -226,7 +226,7 @@ cluster_dfw1 = http://dfw1.host/v1/ 'x-container-sync-auth': 'US nonce ' + sig, 'x-backend-inbound-x-timestamp': ts}) infocache = req.environ.setdefault('swift.infocache', {}) - infocache[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'} + infocache[get_cache_key('a', 'c')] = {'sync_key': 'abc'} resp = req.get_response(self.sync) self.assertEqual(resp.status, '200 OK') self.assertEqual(resp.body, 'Response to Authorized Request') @@ -241,7 +241,7 @@ cluster_dfw1 = http://dfw1.host/v1/ req = swob.Request.blank( '/v1/a/c', headers={'x-container-sync-auth': 'US nonce ' + sig}) infocache = req.environ.setdefault('swift.infocache', {}) - infocache[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'} + infocache[get_cache_key('a', 'c')] = {'sync_key': 'abc'} resp = req.get_response(self.sync) self.assertEqual(resp.status, '200 OK') self.assertEqual(resp.body, 'Response to Authorized Request') diff --git a/test/unit/common/middleware/test_formpost.py b/test/unit/common/middleware/test_formpost.py index 6e9da72857..fabfe1931f 100644 --- a/test/unit/common/middleware/test_formpost.py +++ b/test/unit/common/middleware/test_formpost.py @@ -24,6 +24,7 @@ from six import BytesIO from swift.common.swob import Request, Response from swift.common.middleware import tempauth, formpost from swift.common.utils import split_path +from swift.proxy.controllers.base import get_cache_key class FakeApp(object): @@ -131,7 +132,7 @@ class TestFormPost(unittest.TestCase): _junk, account, _junk, _junk = split_path(path, 2, 4) req.environ.setdefault('swift.infocache', {}) - req.environ['swift.infocache']['swift.account/' + account] = \ + req.environ['swift.infocache'][get_cache_key(account)] = \ self._fake_cache_env(account, tempurl_keys) return req @@ -249,7 +250,7 @@ class TestFormPost(unittest.TestCase): sig, env, body = self._make_sig_env_body( '/v1/AUTH_test/container', '', 1024, 10, int(time() - 10), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -354,9 +355,10 @@ class TestFormPost(unittest.TestCase): 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', 'swift.infocache': { - 'swift.account/AUTH_test': self._fake_cache_env( + get_cache_key('AUTH_test'): self._fake_cache_env( 'AUTH_test', [key]), - 'swift.container/AUTH_test/container': {'meta': {}}}, + get_cache_key('AUTH_test', 'container'): { + 'meta': {}}}, 'wsgi.errors': wsgi_errors, 'wsgi.input': wsgi_input, 'wsgi.multiprocess': False, @@ -471,9 +473,10 @@ class TestFormPost(unittest.TestCase): 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', 'swift.infocache': { - 'swift.account/AUTH_test': self._fake_cache_env( + get_cache_key('AUTH_test'): self._fake_cache_env( 'AUTH_test', [key]), - 'swift.container/AUTH_test/container': {'meta': {}}}, + get_cache_key('AUTH_test', 'container'): { + 'meta': {}}}, 'wsgi.errors': wsgi_errors, 'wsgi.input': wsgi_input, 'wsgi.multiprocess': False, @@ -591,9 +594,10 @@ class TestFormPost(unittest.TestCase): 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', 'swift.infocache': { - 'swift.account/AUTH_test': self._fake_cache_env( + get_cache_key('AUTH_test'): self._fake_cache_env( 'AUTH_test', [key]), - 'swift.container/AUTH_test/container': {'meta': {}}}, + get_cache_key('AUTH_test', 'container'): { + 'meta': {}}}, 'wsgi.errors': wsgi_errors, 'wsgi.input': wsgi_input, 'wsgi.multiprocess': False, @@ -707,9 +711,10 @@ class TestFormPost(unittest.TestCase): 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', 'swift.infocache': { - 'swift.account/AUTH_test': self._fake_cache_env( + get_cache_key('AUTH_test'): self._fake_cache_env( 'AUTH_test', [key]), - 'swift.container/AUTH_test/container': {'meta': {}}}, + get_cache_key('AUTH_test', 'container'): { + 'meta': {}}}, 'wsgi.errors': wsgi_errors, 'wsgi.input': wsgi_input, 'wsgi.multiprocess': False, @@ -753,10 +758,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', 'http://brim.net', 5, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'XX' + b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -790,10 +795,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', 'http://brim.net', 5, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -822,10 +827,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', 'http://brim.net', 1024, 1, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -864,10 +869,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) env['QUERY_STRING'] = 'this=should¬=get&passed' env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp( iter([('201 Created', {}, ''), ('201 Created', {}, '')]), @@ -900,10 +905,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', 'http://brim.net', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('404 Not Found', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -987,10 +992,10 @@ class TestFormPost(unittest.TestCase): if six.PY3: wsgi_input = wsgi_input.encode('utf-8') env['wsgi.input'] = BytesIO(wsgi_input) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1059,10 +1064,10 @@ class TestFormPost(unittest.TestCase): if six.PY3: wsgi_input = wsgi_input.encode('utf-8') env['wsgi.input'] = BytesIO(wsgi_input) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1100,10 +1105,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', 'http://redirect', 1024, 10, int(time() + 86400), key, user_agent=False) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1122,10 +1127,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', 'http://redirect', 1024, 10, int(time() + 86400), key, user_agent=False) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} env['HTTP_ORIGIN'] = 'http://localhost:5000' self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', @@ -1152,10 +1157,10 @@ class TestFormPost(unittest.TestCase): int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) # Stick it in X-Account-Meta-Temp-URL-Key-2 and make sure we get it - env['swift.infocache']['swift.account/AUTH_test'] = ( - self._fake_cache_env('AUTH_test', ['bert', key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = \ - {'meta': {}} + env['swift.infocache'][get_cache_key('AUTH_test')] = ( + self._fake_cache_env('AUTH_test', [key])) + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1189,11 +1194,11 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', 'http://redirect', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test')) # Stick it in X-Container-Meta-Temp-URL-Key-2 and ensure we get it - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': meta} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': meta} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1217,10 +1222,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', 'http://redirect', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1256,10 +1261,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', 'http://redirect?one=two', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1295,10 +1300,10 @@ class TestFormPost(unittest.TestCase): sig, env, body = self._make_sig_env_body( '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1333,7 +1338,7 @@ class TestFormPost(unittest.TestCase): sig, env, body = self._make_sig_env_body( '/v1/AUTH_test/container', '', 1024, 10, int(time() - 10), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -1367,7 +1372,7 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) # Change key to invalidate sig - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key + ' is bogus now'])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -1400,7 +1405,7 @@ class TestFormPost(unittest.TestCase): sig, env, body = self._make_sig_env_body( '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'XX' + b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -1433,7 +1438,7 @@ class TestFormPost(unittest.TestCase): sig, env, body = self._make_sig_env_body( '/v2/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -1466,7 +1471,7 @@ class TestFormPost(unittest.TestCase): sig, env, body = self._make_sig_env_body( '//AUTH_test/container', '', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -1499,7 +1504,7 @@ class TestFormPost(unittest.TestCase): sig, env, body = self._make_sig_env_body( '/v1//container', '', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -1532,7 +1537,7 @@ class TestFormPost(unittest.TestCase): sig, env, body = self._make_sig_env_body( '/v1/AUTH_tst/container', '', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([ ('200 Ok', {'x-account-meta-temp-url-key': 'def'}, ''), @@ -1567,7 +1572,7 @@ class TestFormPost(unittest.TestCase): sig, env, body = self._make_sig_env_body( '/v1/AUTH_test', '', 1024, 10, int(time() + 86400), key) env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -1605,7 +1610,7 @@ class TestFormPost(unittest.TestCase): body[i] = 'badvalue' break env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -1646,10 +1651,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) wsgi_input = b'\r\n'.join(x_delete_body_part + body) env['wsgi.input'] = BytesIO(wsgi_input) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1690,7 +1695,7 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) wsgi_input = b'\r\n'.join(x_delete_body_part + body) env['wsgi.input'] = BytesIO(wsgi_input) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) @@ -1725,10 +1730,10 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) wsgi_input = b'\r\n'.join(x_delete_body_part + body) env['wsgi.input'] = BytesIO(wsgi_input) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) - env['swift.infocache']['swift.container/AUTH_test/container'] = { - 'meta': {}} + env['swift.infocache'][get_cache_key( + 'AUTH_test', 'container')] = {'meta': {}} self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) self.auth = tempauth.filter_factory({})(self.app) @@ -1769,7 +1774,7 @@ class TestFormPost(unittest.TestCase): '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) wsgi_input = b'\r\n'.join(x_delete_body_part + body) env['wsgi.input'] = BytesIO(wsgi_input) - env['swift.infocache']['swift.account/AUTH_test'] = ( + env['swift.infocache'][get_cache_key('AUTH_test')] = ( self._fake_cache_env('AUTH_test', [key])) self.app = FakeApp(iter([('201 Created', {}, ''), ('201 Created', {}, '')])) diff --git a/test/unit/common/middleware/test_keystoneauth.py b/test/unit/common/middleware/test_keystoneauth.py index 4b82c88dc4..96d0ed4902 100644 --- a/test/unit/common/middleware/test_keystoneauth.py +++ b/test/unit/common/middleware/test_keystoneauth.py @@ -19,7 +19,7 @@ from swift.common.middleware import keystoneauth from swift.common.swob import Request, Response from swift.common.http import HTTP_FORBIDDEN from swift.common.utils import split_path -from swift.proxy.controllers.base import _get_cache_key +from swift.proxy.controllers.base import get_cache_key from test.unit import FakeLogger UNKNOWN_ID = keystoneauth.UNKNOWN_ID @@ -251,7 +251,7 @@ class SwiftAuth(unittest.TestCase): account = get_account_for_tenant(self.test_auth, proj_id) path = '/v1/' + account # fake cached account info - _, info_key = _get_cache_key(account, None) + info_key = get_cache_key(account) env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}}, 'keystone.token_info': _fake_token_info(version='3')} req = Request.blank(path, environ=env, headers=headers) @@ -280,7 +280,7 @@ class SwiftAuth(unittest.TestCase): account = get_account_for_tenant(self.test_auth, proj_id) path = '/v1/' + account # fake cached account info - _, info_key = _get_cache_key(account, None) + info_key = get_cache_key(account) env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}}, 'keystone.token_info': _fake_token_info(version='3')} req = Request.blank(path, environ=env, headers=headers) @@ -301,7 +301,7 @@ class SwiftAuth(unittest.TestCase): headers = get_identity_headers(tenant_id=proj_id, role='admin') account = get_account_for_tenant(self.test_auth, proj_id) path = '/v1/' + account - _, info_key = _get_cache_key(account, None) + info_key = get_cache_key(account) # v2 token env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}}, 'keystone.token_info': _fake_token_info(version='2')} @@ -323,7 +323,7 @@ class SwiftAuth(unittest.TestCase): role='reselleradmin') account = get_account_for_tenant(self.test_auth, proj_id) path = '/v1/' + account - _, info_key = _get_cache_key(account, None) + info_key = get_cache_key(account) # v2 token env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}}, 'keystone.token_info': _fake_token_info(version='2')} @@ -381,7 +381,7 @@ class ServiceTokenFunctionality(unittest.TestCase): role=user_role, service_role=service_role) (version, account, _junk, _junk) = split_path(path, 2, 4, True) - _, info_key = _get_cache_key(account, None) + info_key = get_cache_key(account) env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}}, 'keystone.token_info': _fake_token_info(version='2')} if environ: @@ -595,7 +595,7 @@ class TestAuthorize(BaseTestAuthorize): if not path: path = '/v1/%s/c' % account # fake cached account info - _, info_key = _get_cache_key(account, None) + info_key = get_cache_key(account) default_env = { 'REMOTE_USER': identity['HTTP_X_TENANT_ID'], 'swift.infocache': {info_key: {'status': 200, 'sysmeta': {}}}} @@ -985,7 +985,7 @@ class TestAuthorize(BaseTestAuthorize): def test_get_project_domain_id(self): sysmeta = {} info = {'sysmeta': sysmeta} - _, info_key = _get_cache_key('AUTH_1234', None) + info_key = get_cache_key('AUTH_1234') env = {'PATH_INFO': '/v1/AUTH_1234', 'swift.infocache': {info_key: info}} @@ -1029,7 +1029,7 @@ class TestIsNameAllowedInACL(BaseTestAuthorize): # pretend account exists info = {'status': 200, 'sysmeta': sysmeta} - _, info_key = _get_cache_key(account, None) + info_key = get_cache_key(account) req = Request.blank(path, environ={'swift.infocache': {info_key: info}}) @@ -1216,7 +1216,7 @@ class TestSetProjectDomain(BaseTestAuthorize): if sysmeta_project_domain_id: sysmeta['project-domain-id'] = sysmeta_project_domain_id info = {'status': status, 'sysmeta': sysmeta} - _, info_key = _get_cache_key(account, None) + info_key = get_cache_key(account) env = {'swift.infocache': {info_key: info}} # create fake env identity diff --git a/test/unit/common/middleware/test_quotas.py b/test/unit/common/middleware/test_quotas.py index f4eba5b76c..0bec5cad51 100644 --- a/test/unit/common/middleware/test_quotas.py +++ b/test/unit/common/middleware/test_quotas.py @@ -246,8 +246,8 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase): req = Request.blank('/v1/a/c2/o2', environ={'REQUEST_METHOD': 'COPY', 'swift.infocache': { - 'swift.container/a/c': a_c_cache, - 'swift.container/a2/c': a2_c_cache}}, + 'container/a/c': a_c_cache, + 'container/a2/c': a2_c_cache}}, headers={'Destination': '/c/o', 'Destination-Account': 'a2'}) res = req.get_response(self.copy_filter) @@ -263,8 +263,8 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase): req = Request.blank('/v1/a2/c/o', environ={'REQUEST_METHOD': 'PUT', 'swift.infocache': { - 'swift.container/a/c': a_c_cache, - 'swift.container/a2/c': a2_c_cache}}, + 'container/a/c': a_c_cache, + 'container/a2/c': a2_c_cache}}, headers={'X-Copy-From': '/c2/o2', 'X-Copy-From-Account': 'a'}) res = req.get_response(self.copy_filter) diff --git a/test/unit/common/middleware/test_ratelimit.py b/test/unit/common/middleware/test_ratelimit.py index 66ca43d033..0fc6a61a11 100644 --- a/test/unit/common/middleware/test_ratelimit.py +++ b/test/unit/common/middleware/test_ratelimit.py @@ -21,7 +21,7 @@ from contextlib import contextmanager from test.unit import FakeLogger from swift.common.middleware import ratelimit -from swift.proxy.controllers.base import get_container_memcache_key, \ +from swift.proxy.controllers.base import get_cache_key, \ headers_to_container_info from swift.common.memcached import MemcacheConnectionError from swift.common.swob import Request @@ -185,7 +185,7 @@ class TestRateLimit(unittest.TestCase): conf_dict = {'account_ratelimit': current_rate, 'container_ratelimit_3': 200} fake_memcache = FakeMemcache() - fake_memcache.store[get_container_memcache_key('a', 'c')] = \ + fake_memcache.store[get_cache_key('a', 'c')] = \ {'object_count': '5'} the_app = ratelimit.filter_factory(conf_dict)(FakeApp()) the_app.memcache_client = fake_memcache @@ -229,7 +229,7 @@ class TestRateLimit(unittest.TestCase): conf_dict = {'account_ratelimit': current_rate, 'container_ratelimit_3': 200} fake_memcache = FakeMemcache() - fake_memcache.store[get_container_memcache_key('a', 'c')] = \ + fake_memcache.store[get_cache_key('a', 'c')] = \ {'container_size': 5} the_app = ratelimit.filter_factory(conf_dict)(FakeApp()) the_app.memcache_client = fake_memcache @@ -431,7 +431,7 @@ class TestRateLimit(unittest.TestCase): req.method = 'PUT' req.environ['swift.cache'] = FakeMemcache() req.environ['swift.cache'].set( - get_container_memcache_key('a', 'c'), + get_cache_key('a', 'c'), {'object_count': 1}) time_override = [0, 0, 0, 0, None] @@ -465,7 +465,7 @@ class TestRateLimit(unittest.TestCase): req.method = 'GET' req.environ['swift.cache'] = FakeMemcache() req.environ['swift.cache'].set( - get_container_memcache_key('a', 'c'), + get_cache_key('a', 'c'), {'object_count': 1}) with mock.patch('swift.common.middleware.ratelimit.get_account_info', diff --git a/test/unit/common/middleware/test_tempurl.py b/test/unit/common/middleware/test_tempurl.py index fed3cbd17d..0d5ed07111 100644 --- a/test/unit/common/middleware/test_tempurl.py +++ b/test/unit/common/middleware/test_tempurl.py @@ -97,7 +97,7 @@ class TestTempURL(unittest.TestCase): meta[meta_name] = key ic = environ.setdefault('swift.infocache', {}) - ic['swift.account/' + account] = { + ic['account/' + account] = { 'status': 204, 'container_count': '0', 'total_object_count': '0', @@ -109,7 +109,7 @@ class TestTempURL(unittest.TestCase): meta_name = 'Temp-URL-key' + (("-%d" % (i + 1) if i else "")) meta[meta_name] = key - container_cache_key = 'swift.container/' + account + '/c' + container_cache_key = 'container/' + account + '/c' ic.setdefault(container_cache_key, {'meta': meta}) def test_passthrough(self): @@ -169,7 +169,7 @@ class TestTempURL(unittest.TestCase): meta_name = 'Temp-URL-key' + (("-%d" % (idx + 1) if idx else "")) if key: meta[meta_name] = key - ic['swift.container/a/c'] = {'meta': meta} + ic['container/a/c'] = {'meta': meta} method = 'GET' expires = int(time() + 86400) diff --git a/test/unit/proxy/controllers/test_account.py b/test/unit/proxy/controllers/test_account.py index 4ef77f3dab..86206f02a1 100644 --- a/test/unit/proxy/controllers/test_account.py +++ b/test/unit/proxy/controllers/test_account.py @@ -69,11 +69,10 @@ class TestAccountController(unittest.TestCase): req = Request.blank('/v1/AUTH_bob', {'PATH_INFO': '/v1/AUTH_bob'}) resp = controller.HEAD(req) self.assertEqual(2, resp.status_int // 100) - self.assertTrue( - 'swift.account/AUTH_bob' in resp.environ['swift.infocache']) + self.assertIn('account/AUTH_bob', resp.environ['swift.infocache']) self.assertEqual( headers_to_account_info(resp.headers), - resp.environ['swift.infocache']['swift.account/AUTH_bob']) + resp.environ['swift.infocache']['account/AUTH_bob']) def test_swift_owner(self): owner_headers = { @@ -228,13 +227,20 @@ class TestAccountController(unittest.TestCase): self.assertEqual(1, len(resp.headers)) # we always get Content-Type self.assertEqual(2, len(resp.environ)) - def test_memcache_key_impossible_cases(self): + def test_cache_key_impossible_cases(self): # For test coverage: verify that defensive coding does defend, in cases # that shouldn't arise naturally - self.assertRaises( - ValueError, - lambda: swift.proxy.controllers.base.get_container_memcache_key( - '/a', None)) + with self.assertRaises(ValueError): + # Container needs account + swift.proxy.controllers.base.get_cache_key(None, 'c') + + with self.assertRaises(ValueError): + # Object needs account + swift.proxy.controllers.base.get_cache_key(None, 'c', 'o') + + with self.assertRaises(ValueError): + # Object needs container + swift.proxy.controllers.base.get_cache_key('a', None, 'o') def test_stripping_swift_admin_headers(self): # Verify that a GET/HEAD which receives privileged headers from the diff --git a/test/unit/proxy/controllers/test_base.py b/test/unit/proxy/controllers/test_base.py index 07c237b599..689c6c88a8 100644 --- a/test/unit/proxy/controllers/test_base.py +++ b/test/unit/proxy/controllers/test_base.py @@ -19,8 +19,7 @@ import unittest from mock import patch from swift.proxy.controllers.base import headers_to_container_info, \ headers_to_account_info, headers_to_object_info, get_container_info, \ - get_container_memcache_key, get_account_info, get_account_memcache_key, \ - get_object_env_key, get_info, get_object_info, \ + get_cache_key, get_account_info, get_info, get_object_info, \ Controller, GetOrHeadHandler, bytes_to_skip from swift.common.swob import Request, HTTPException, RESPONSE_REASONS from swift.common import exceptions @@ -210,7 +209,6 @@ class TestFuncs(unittest.TestCase): # cached app.responses.stats['account'] = 0 app.responses.stats['container'] = 0 - del(env['swift.infocache']['swift.account/a']) info_c = get_info(app, env, 'a', 'c') # Check that you got proper info self.assertEqual(info_a['status'], 200) @@ -274,11 +272,10 @@ class TestFuncs(unittest.TestCase): self.assertEqual(resp['versions'], "\xe1\xbd\x8a\x39") def test_get_container_info_env(self): - cache_key = get_container_memcache_key("account", "cont") - env_key = 'swift.%s' % cache_key + cache_key = get_cache_key("account", "cont") req = Request.blank( "/v1/account/cont", - environ={'swift.infocache': {env_key: {'bytes': 3867}}, + environ={'swift.infocache': {cache_key: {'bytes': 3867}}, 'swift.cache': FakeCache({})}) resp = get_container_info(req.environ, 'xxx') self.assertEqual(resp['bytes'], 3867) @@ -344,11 +341,10 @@ class TestFuncs(unittest.TestCase): self.assertEqual(resp['total_object_count'], 10) def test_get_account_info_env(self): - cache_key = get_account_memcache_key("account") - env_key = 'swift.%s' % cache_key + cache_key = get_cache_key("account") req = Request.blank( "/v1/account", - environ={'swift.infocache': {env_key: {'bytes': 3867}}, + environ={'swift.infocache': {cache_key: {'bytes': 3867}}, 'swift.cache': FakeCache({})}) resp = get_account_info(req.environ, 'xxx') self.assertEqual(resp['bytes'], 3867) @@ -358,10 +354,10 @@ class TestFuncs(unittest.TestCase): 'length': 3333, 'type': 'application/json', 'meta': {}} - env_key = get_object_env_key("account", "cont", "obj") + cache_key = get_cache_key("account", "cont", "obj") req = Request.blank( "/v1/account/cont/obj", - environ={'swift.infocache': {env_key: cached}, + environ={'swift.infocache': {cache_key: cached}, 'swift.cache': FakeCache({})}) resp = get_object_info(req.environ, 'xxx') self.assertEqual(resp['length'], 3333) diff --git a/test/unit/proxy/controllers/test_container.py b/test/unit/proxy/controllers/test_container.py index fc5692d8c5..f08a90dfb1 100644 --- a/test/unit/proxy/controllers/test_container.py +++ b/test/unit/proxy/controllers/test_container.py @@ -103,11 +103,10 @@ class TestContainerController(TestRingBase): resp = controller.HEAD(req) self.assertEqual(2, resp.status_int // 100) # Make sure it's in both swift.infocache and memcache - self.assertTrue( - "swift.container/a/c" in req.environ['swift.infocache']) + self.assertIn("container/a/c", resp.environ['swift.infocache']) self.assertEqual( headers_to_container_info(resp.headers), - resp.environ['swift.infocache']['swift.container/a/c']) + resp.environ['swift.infocache']['container/a/c']) from_memcache = self.app.memcache.get('container/a/c') self.assertTrue(from_memcache) diff --git a/test/unit/proxy/controllers/test_obj.py b/test/unit/proxy/controllers/test_obj.py index a34fee34a4..35a2178c1c 100755 --- a/test/unit/proxy/controllers/test_obj.py +++ b/test/unit/proxy/controllers/test_obj.py @@ -93,7 +93,7 @@ class PatchedObjControllerApp(proxy_server.Application): # Seed the cache with our container info so that the real # get_container_info finds it. ic = env.setdefault('swift.infocache', {}) - cache_key = "swift.container/%s/%s" % (account, container) + cache_key = "container/%s/%s" % (account, container) old_value = ic.get(cache_key) diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index a2757f472e..7aac742c19 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -73,9 +73,8 @@ from swift.common.ring import RingData from swift.common.utils import mkdirs, normalize_timestamp, NullLogger from swift.common.wsgi import monkey_patch_mimetools, loadapp from swift.proxy.controllers import base as proxy_base -from swift.proxy.controllers.base import get_container_memcache_key, \ - get_account_memcache_key, cors_validation, get_account_info, \ - get_container_info +from swift.proxy.controllers.base import get_cache_key, cors_validation, \ + get_account_info, get_container_info import swift.proxy.controllers import swift.proxy.controllers.obj from swift.common.header_key_dict import HeaderKeyDict @@ -482,14 +481,14 @@ class TestController(unittest.TestCase): self.controller.account_info(self.account) self.assertEqual(count, 123) with save_globals(): - cache_key = get_account_memcache_key(self.account) + cache_key = get_cache_key(self.account) account_info = {'status': 200, 'container_count': 1234} self.memcache.set(cache_key, account_info) partition, nodes, count = \ self.controller.account_info(self.account) self.assertEqual(count, 1234) with save_globals(): - cache_key = get_account_memcache_key(self.account) + cache_key = get_cache_key(self.account) account_info = {'status': 200, 'container_count': '1234'} self.memcache.set(cache_key, account_info) partition, nodes, count = \ @@ -517,7 +516,7 @@ class TestController(unittest.TestCase): # Test the internal representation in memcache # 'container_count' changed from int to str - cache_key = get_account_memcache_key(self.account) + cache_key = get_cache_key(self.account) container_info = {'status': 200, 'account_really_exists': True, 'container_count': '12345', @@ -545,7 +544,7 @@ class TestController(unittest.TestCase): # Test the internal representation in memcache # 'container_count' changed from 0 to None - cache_key = get_account_memcache_key(self.account) + cache_key = get_cache_key(self.account) account_info = {'status': 404, 'container_count': None, # internally keep None 'total_object_count': None, @@ -622,8 +621,7 @@ class TestController(unittest.TestCase): self.account, self.container, self.request) self.check_container_info_return(ret) - cache_key = get_container_memcache_key(self.account, - self.container) + cache_key = get_cache_key(self.account, self.container) cache_value = self.memcache.get(cache_key) self.assertTrue(isinstance(cache_value, dict)) self.assertEqual(200, cache_value.get('status')) @@ -645,8 +643,7 @@ class TestController(unittest.TestCase): self.account, self.container, self.request) self.check_container_info_return(ret, True) - cache_key = get_container_memcache_key(self.account, - self.container) + cache_key = get_cache_key(self.account, self.container) cache_value = self.memcache.get(cache_key) self.assertTrue(isinstance(cache_value, dict)) self.assertEqual(404, cache_value.get('status')) @@ -661,8 +658,7 @@ class TestController(unittest.TestCase): self.account, self.container, self.request) self.check_container_info_return(ret, True) - cache_key = get_container_memcache_key(self.account, - self.container) + cache_key = get_cache_key(self.account, self.container) cache_value = self.memcache.get(cache_key) self.assertTrue(isinstance(cache_value, dict)) self.assertEqual(404, cache_value.get('status')) @@ -6351,18 +6347,18 @@ class TestContainerController(unittest.TestCase): self.assertIn('x-works', res.headers) self.assertEqual(res.headers['x-works'], 'yes') if c_expected: - self.assertIn('swift.container/a/c', infocache) + self.assertIn('container/a/c', infocache) self.assertEqual( - infocache['swift.container/a/c']['status'], + infocache['container/a/c']['status'], c_expected) else: - self.assertNotIn('swift.container/a/c', infocache) + self.assertNotIn('container/a/c', infocache) if a_expected: - self.assertIn('swift.account/a', infocache) - self.assertEqual(infocache['swift.account/a']['status'], + self.assertIn('account/a', infocache) + self.assertEqual(infocache['account/a']['status'], a_expected) else: - self.assertNotIn('swift.account/a', res.environ) + self.assertNotIn('account/a', res.environ) set_http_connect(*statuses, **kwargs) self.app.memcache.store = {} @@ -6376,18 +6372,18 @@ class TestContainerController(unittest.TestCase): self.assertTrue('x-works' in res.headers) self.assertEqual(res.headers['x-works'], 'yes') if c_expected: - self.assertIn('swift.container/a/c', infocache) + self.assertIn('container/a/c', infocache) self.assertEqual( - infocache['swift.container/a/c']['status'], + infocache['container/a/c']['status'], c_expected) else: - self.assertNotIn('swift.container/a/c', infocache) + self.assertNotIn('container/a/c', infocache) if a_expected: - self.assertIn('swift.account/a', infocache) - self.assertEqual(infocache['swift.account/a']['status'], + self.assertIn('account/a', infocache) + self.assertEqual(infocache['account/a']['status'], a_expected) else: - self.assertNotIn('swift.account/a', infocache) + self.assertNotIn('account/a', infocache) # In all the following tests cache 200 for account # return and cache vary for container # return 200 and cache 200 for account and container @@ -7000,7 +6996,7 @@ class TestContainerController(unittest.TestCase): res = controller.GET(req) self.assertEqual(res.status_int, 204) ic = res.environ['swift.infocache'] - self.assertEqual(ic['swift.container/a/c']['status'], 204) + self.assertEqual(ic['container/a/c']['status'], 204) self.assertEqual(res.content_length, 0) self.assertTrue('transfer-encoding' not in res.headers) @@ -7018,7 +7014,7 @@ class TestContainerController(unittest.TestCase): self.app.update_request(req) res = controller.GET(req) self.assertEqual( - res.environ['swift.infocache']['swift.container/a/c']['status'], + res.environ['swift.infocache']['container/a/c']['status'], 201) self.assertTrue(called[0]) @@ -7488,7 +7484,7 @@ class TestAccountController(unittest.TestCase): self.assertEqual(res.status_int, expected) infocache = res.environ.get('swift.infocache', {}) if env_expected: - self.assertEqual(infocache['swift.account/a']['status'], + self.assertEqual(infocache['account/a']['status'], env_expected) set_http_connect(*statuses) req = Request.blank('/v1/a/', {}) @@ -7497,7 +7493,7 @@ class TestAccountController(unittest.TestCase): infocache = res.environ.get('swift.infocache', {}) self.assertEqual(res.status_int, expected) if env_expected: - self.assertEqual(infocache['swift.account/a']['status'], + self.assertEqual(infocache['account/a']['status'], env_expected) def test_OPTIONS(self):