Make info caching work across subrequests

Previously, if you called get_account_info, get_container_info, or
get_object_info, then the results of that call would be cached in the
WSGI environment as top-level keys. This is okay, except that if you,
in middleware, copy the WSGI environment and then make a subrequest
using the copy, information retrieved in the subrequest is cached
only in the copy and not in the original. This can mean lots of extra
trips to memcache for, say, SLO validation where the segments are in
another container; the object HEAD ends up getting container info for
the segment container, but then the next object HEAD gets it again.

This commit moves the cache for get_*_info into a dictionary at
environ['swift.infocache']; this way, you can shallow-copy the request
environment and still get the benefits from the cache.

Change-Id: I3481b38b41c33cd1e39e19baab56193c5f9bf6ac
This commit is contained in:
Samuel Merritt
2016-01-21 13:19:30 -08:00
parent 177e531a2e
commit ce90a1e79e
13 changed files with 284 additions and 193 deletions

View File

@@ -1099,7 +1099,8 @@ def make_env(env, method=None, path=None, agent='Swift', query_string=None,
'SERVER_PROTOCOL', 'swift.cache', 'swift.source', 'SERVER_PROTOCOL', 'swift.cache', 'swift.source',
'swift.trans_id', 'swift.authorize_override', 'swift.trans_id', 'swift.authorize_override',
'swift.authorize', 'HTTP_X_USER_ID', 'HTTP_X_PROJECT_ID', 'swift.authorize', 'HTTP_X_USER_ID', 'HTTP_X_PROJECT_ID',
'HTTP_REFERER', 'swift.orig_req_method', 'swift.log_info'): 'HTTP_REFERER', 'swift.orig_req_method', 'swift.log_info',
'swift.infocache'):
if name in env: if name in env:
newenv[name] = env[name] newenv[name] = env[name]
if method: if method:

View File

@@ -381,6 +381,7 @@ def _set_info_cache(app, env, account, container, resp):
:param container: the unquoted container name or None :param container: the unquoted container name or None
:param resp: the response received or None if info cache should be cleared :param resp: the response received or None if info cache should be cleared
""" """
infocache = env.setdefault('swift.infocache', {})
if container: if container:
cache_time = app.recheck_container_existence cache_time = app.recheck_container_existence
@@ -399,7 +400,7 @@ def _set_info_cache(app, env, account, container, resp):
# Next actually set both memcache and the env cache # Next actually set both memcache and the env cache
memcache = getattr(app, 'memcache', None) or env.get('swift.cache') memcache = getattr(app, 'memcache', None) or env.get('swift.cache')
if not cache_time: if not cache_time:
env.pop(env_key, None) infocache.pop(env_key, None)
if memcache: if memcache:
memcache.delete(cache_key) memcache.delete(cache_key)
return return
@@ -410,7 +411,7 @@ def _set_info_cache(app, env, account, container, resp):
info = headers_to_account_info(resp.headers, resp.status_int) info = headers_to_account_info(resp.headers, resp.status_int)
if memcache: if memcache:
memcache.set(cache_key, info, time=cache_time) memcache.set(cache_key, info, time=cache_time)
env[env_key] = info infocache[env_key] = info
def _set_object_info_cache(app, env, account, container, obj, resp): def _set_object_info_cache(app, env, account, container, obj, resp):
@@ -433,12 +434,12 @@ def _set_object_info_cache(app, env, account, container, obj, resp):
env_key = get_object_env_key(account, container, obj) env_key = get_object_env_key(account, container, obj)
if not resp: if 'swift.infocache' in env and not resp:
env.pop(env_key, None) env['swift.infocache'].pop(env_key, None)
return return
info = headers_to_object_info(resp.headers, resp.status_int) info = headers_to_object_info(resp.headers, resp.status_int)
env[env_key] = info env.setdefault('swift.infocache', {})[env_key] = info
def clear_info_cache(app, env, account, container=None): def clear_info_cache(app, env, account, container=None):
@@ -464,8 +465,8 @@ def _get_info_cache(app, env, account, container=None):
""" """
cache_key, env_key = _get_cache_key(account, container) cache_key, env_key = _get_cache_key(account, container)
if env_key in env: if 'swift.infocache' in env and env_key in env['swift.infocache']:
return env[env_key] return env['swift.infocache'][env_key]
memcache = getattr(app, 'memcache', None) or env.get('swift.cache') memcache = getattr(app, 'memcache', None) or env.get('swift.cache')
if memcache: if memcache:
info = memcache.get(cache_key) info = memcache.get(cache_key)
@@ -473,11 +474,11 @@ def _get_info_cache(app, env, account, container=None):
for key in info: for key in info:
if isinstance(info[key], six.text_type): if isinstance(info[key], six.text_type):
info[key] = info[key].encode("utf-8") info[key] = info[key].encode("utf-8")
if isinstance(info[key], dict): elif isinstance(info[key], dict):
for subkey, value in info[key].items(): for subkey, value in info[key].items():
if isinstance(value, six.text_type): if isinstance(value, six.text_type):
info[key][subkey] = value.encode("utf-8") info[key][subkey] = value.encode("utf-8")
env[env_key] = info env.setdefault('swift.infocache', {})[env_key] = info
return info return info
return None return None
@@ -497,6 +498,7 @@ def _prepare_pre_auth_info_request(env, path, swift_source):
# This is a sub request for container metadata- drop the Origin header from # This is a sub request for container metadata- drop the Origin header from
# the request so the it is not treated as a CORS request. # the request so the it is not treated as a CORS request.
newenv.pop('HTTP_ORIGIN', None) newenv.pop('HTTP_ORIGIN', None)
# Note that Request.blank expects quoted path # Note that Request.blank expects quoted path
return Request.blank(quote(path), environ=newenv) return Request.blank(quote(path), environ=newenv)
@@ -513,6 +515,10 @@ def get_info(app, env, account, container=None, ret_not_found=False,
:param env: the environment used by the current request :param env: the environment used by the current request
:param account: The unquoted name of the account :param account: The unquoted name of the account
:param container: The unquoted name of the container (or None if account) :param container: The unquoted name of the container (or None if account)
:param ret_not_found: if True, return info dictionary on 404;
if False, return None on 404
:param swift_source: swift source logged for any subrequests made while
retrieving the account or container info
:returns: the cached info or None if cannot be retrieved :returns: the cached info or None if cannot be retrieved
""" """
info = _get_info_cache(app, env, account, container) info = _get_info_cache(app, env, account, container)
@@ -531,14 +537,15 @@ def get_info(app, env, account, container=None, ret_not_found=False,
req = _prepare_pre_auth_info_request( req = _prepare_pre_auth_info_request(
env, path, (swift_source or 'GET_INFO')) env, path, (swift_source or 'GET_INFO'))
# Whenever we do a GET/HEAD, the GETorHEAD_base will set the info in # Whenever we do a GET/HEAD, the GETorHEAD_base will set the info in the
# the environment under environ[env_key] and in memcache. We will # environment under environ['swift.infocache'][env_key] and in memcache.
# pick the one from environ[env_key] and use it to set the caller env # We will pick the one from environ['swift.infocache'][env_key] and use
# it to set the caller env
resp = req.get_response(app) resp = req.get_response(app)
cache_key, env_key = _get_cache_key(account, container) cache_key, env_key = _get_cache_key(account, container)
try: try:
info = resp.environ[env_key] info = resp.environ['swift.infocache'][env_key]
env[env_key] = info env.setdefault('swift.infocache', {})[env_key] = info
if ret_not_found or is_success(info['status']): if ret_not_found or is_success(info['status']):
return info return info
except (KeyError, AttributeError): except (KeyError, AttributeError):
@@ -561,7 +568,7 @@ def _get_object_info(app, env, account, container, obj, swift_source=None):
:returns: the cached info or None if cannot be retrieved :returns: the cached info or None if cannot be retrieved
""" """
env_key = get_object_env_key(account, container, obj) env_key = get_object_env_key(account, container, obj)
info = env.get(env_key) info = env.get('swift.infocache', {}).get(env_key)
if info: if info:
return info return info
# Not in cached, let's try the object servers # Not in cached, let's try the object servers
@@ -572,8 +579,8 @@ def _get_object_info(app, env, account, container, obj, swift_source=None):
# pick the one from environ[env_key] and use it to set the caller env # pick the one from environ[env_key] and use it to set the caller env
resp = req.get_response(app) resp = req.get_response(app)
try: try:
info = resp.environ[env_key] info = resp.environ['swift.infocache'][env_key]
env[env_key] = info env.setdefault('swift.infocache', {})[env_key] = info
return info return info
except (KeyError, AttributeError): except (KeyError, AttributeError):
pass pass

View File

@@ -59,7 +59,8 @@ class FakeApp(object):
if env['REQUEST_METHOD'] == "HEAD" and \ if env['REQUEST_METHOD'] == "HEAD" and \
env['PATH_INFO'] == '/v1/a/c2/o2': env['PATH_INFO'] == '/v1/a/c2/o2':
env_key = get_object_env_key('a', 'c2', 'o2') env_key = get_object_env_key('a', 'c2', 'o2')
env[env_key] = headers_to_object_info(self.headers, 200) env.setdefault('swift.infocache', {})[env_key] = \
headers_to_object_info(self.headers, 200)
start_response('200 OK', self.headers) start_response('200 OK', self.headers)
elif env['REQUEST_METHOD'] == "HEAD" and \ elif env['REQUEST_METHOD'] == "HEAD" and \
env['PATH_INFO'] == '/v1/a/c2/o3': env['PATH_INFO'] == '/v1/a/c2/o3':
@@ -67,7 +68,8 @@ class FakeApp(object):
else: else:
# Cache the account_info (same as a real application) # Cache the account_info (same as a real application)
cache_key, env_key = _get_cache_key('a', None) cache_key, env_key = _get_cache_key('a', None)
env[env_key] = headers_to_account_info(self.headers, 200) env.setdefault('swift.infocache', {})[env_key] = \
headers_to_account_info(self.headers, 200)
start_response('200 OK', self.headers) start_response('200 OK', self.headers)
return [] return []

View File

@@ -205,7 +205,8 @@ cluster_dfw1 = http://dfw1.host/v1/
def test_invalid_sig(self): def test_invalid_sig(self):
req = swob.Request.blank( req = swob.Request.blank(
'/v1/a/c', headers={'x-container-sync-auth': 'US nonce sig'}) '/v1/a/c', headers={'x-container-sync-auth': 'US nonce sig'})
req.environ[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'} infocache = req.environ.setdefault('swift.infocache', {})
infocache[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'}
resp = req.get_response(self.sync) resp = req.get_response(self.sync)
self.assertEqual(resp.status, '401 Unauthorized') self.assertEqual(resp.status, '401 Unauthorized')
self.assertEqual( self.assertEqual(
@@ -224,7 +225,8 @@ cluster_dfw1 = http://dfw1.host/v1/
req = swob.Request.blank('/v1/a/c', headers={ req = swob.Request.blank('/v1/a/c', headers={
'x-container-sync-auth': 'US nonce ' + sig, 'x-container-sync-auth': 'US nonce ' + sig,
'x-backend-inbound-x-timestamp': ts}) 'x-backend-inbound-x-timestamp': ts})
req.environ[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'} infocache = req.environ.setdefault('swift.infocache', {})
infocache[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'}
resp = req.get_response(self.sync) resp = req.get_response(self.sync)
self.assertEqual(resp.status, '200 OK') self.assertEqual(resp.status, '200 OK')
self.assertEqual(resp.body, 'Response to Authorized Request') self.assertEqual(resp.body, 'Response to Authorized Request')
@@ -238,7 +240,8 @@ cluster_dfw1 = http://dfw1.host/v1/
self.sync.realms_conf.key2('US'), 'abc') self.sync.realms_conf.key2('US'), 'abc')
req = swob.Request.blank( req = swob.Request.blank(
'/v1/a/c', headers={'x-container-sync-auth': 'US nonce ' + sig}) '/v1/a/c', headers={'x-container-sync-auth': 'US nonce ' + sig})
req.environ[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'} infocache = req.environ.setdefault('swift.infocache', {})
infocache[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'}
resp = req.get_response(self.sync) resp = req.get_response(self.sync)
self.assertEqual(resp.status, '200 OK') self.assertEqual(resp.status, '200 OK')
self.assertEqual(resp.body, 'Response to Authorized Request') self.assertEqual(resp.body, 'Response to Authorized Request')

View File

@@ -130,8 +130,9 @@ class TestFormPost(unittest.TestCase):
meta[meta_name] = key meta[meta_name] = key
_junk, account, _junk, _junk = split_path(path, 2, 4) _junk, account, _junk, _junk = split_path(path, 2, 4)
req.environ['swift.account/' + account] = self._fake_cache_env( req.environ.setdefault('swift.infocache', {})
account, tempurl_keys) req.environ['swift.infocache']['swift.account/' + account] = \
self._fake_cache_env(account, tempurl_keys)
return req return req
def _fake_cache_env(self, account, tempurl_keys=()): def _fake_cache_env(self, account, tempurl_keys=()):
@@ -221,6 +222,7 @@ class TestFormPost(unittest.TestCase):
'SERVER_NAME': '172.16.83.128', 'SERVER_NAME': '172.16.83.128',
'SERVER_PORT': '8080', 'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_PROTOCOL': 'HTTP/1.0',
'swift.infocache': {},
'wsgi.errors': wsgi_errors, 'wsgi.errors': wsgi_errors,
'wsgi.multiprocess': False, 'wsgi.multiprocess': False,
'wsgi.multithread': True, 'wsgi.multithread': True,
@@ -247,8 +249,8 @@ class TestFormPost(unittest.TestCase):
sig, env, body = self._make_sig_env_body( sig, env, body = self._make_sig_env_body(
'/v1/AUTH_test/container', '', 1024, 10, int(time() - 10), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() - 10), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -351,9 +353,10 @@ class TestFormPost(unittest.TestCase):
'SERVER_NAME': '172.16.83.128', 'SERVER_NAME': '172.16.83.128',
'SERVER_PORT': '8080', 'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_PROTOCOL': 'HTTP/1.0',
'swift.infocache': {
'swift.account/AUTH_test': self._fake_cache_env( 'swift.account/AUTH_test': self._fake_cache_env(
'AUTH_test', [key]), 'AUTH_test', [key]),
'swift.container/AUTH_test/container': {'meta': {}}, 'swift.container/AUTH_test/container': {'meta': {}}},
'wsgi.errors': wsgi_errors, 'wsgi.errors': wsgi_errors,
'wsgi.input': wsgi_input, 'wsgi.input': wsgi_input,
'wsgi.multiprocess': False, 'wsgi.multiprocess': False,
@@ -467,9 +470,10 @@ class TestFormPost(unittest.TestCase):
'SERVER_NAME': '172.16.83.128', 'SERVER_NAME': '172.16.83.128',
'SERVER_PORT': '8080', 'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_PROTOCOL': 'HTTP/1.0',
'swift.infocache': {
'swift.account/AUTH_test': self._fake_cache_env( 'swift.account/AUTH_test': self._fake_cache_env(
'AUTH_test', [key]), 'AUTH_test', [key]),
'swift.container/AUTH_test/container': {'meta': {}}, 'swift.container/AUTH_test/container': {'meta': {}}},
'wsgi.errors': wsgi_errors, 'wsgi.errors': wsgi_errors,
'wsgi.input': wsgi_input, 'wsgi.input': wsgi_input,
'wsgi.multiprocess': False, 'wsgi.multiprocess': False,
@@ -586,9 +590,10 @@ class TestFormPost(unittest.TestCase):
'SERVER_NAME': '172.16.83.128', 'SERVER_NAME': '172.16.83.128',
'SERVER_PORT': '8080', 'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_PROTOCOL': 'HTTP/1.0',
'swift.infocache': {
'swift.account/AUTH_test': self._fake_cache_env( 'swift.account/AUTH_test': self._fake_cache_env(
'AUTH_test', [key]), 'AUTH_test', [key]),
'swift.container/AUTH_test/container': {'meta': {}}, 'swift.container/AUTH_test/container': {'meta': {}}},
'wsgi.errors': wsgi_errors, 'wsgi.errors': wsgi_errors,
'wsgi.input': wsgi_input, 'wsgi.input': wsgi_input,
'wsgi.multiprocess': False, 'wsgi.multiprocess': False,
@@ -701,9 +706,10 @@ class TestFormPost(unittest.TestCase):
'SERVER_NAME': '172.16.83.128', 'SERVER_NAME': '172.16.83.128',
'SERVER_PORT': '8080', 'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_PROTOCOL': 'HTTP/1.0',
'swift.infocache': {
'swift.account/AUTH_test': self._fake_cache_env( 'swift.account/AUTH_test': self._fake_cache_env(
'AUTH_test', [key]), 'AUTH_test', [key]),
'swift.container/AUTH_test/container': {'meta': {}}, 'swift.container/AUTH_test/container': {'meta': {}}},
'wsgi.errors': wsgi_errors, 'wsgi.errors': wsgi_errors,
'wsgi.input': wsgi_input, 'wsgi.input': wsgi_input,
'wsgi.multiprocess': False, 'wsgi.multiprocess': False,
@@ -747,9 +753,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', 'http://brim.net', 5, 10, '/v1/AUTH_test/container', 'http://brim.net', 5, 10,
int(time() + 86400), key) int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'XX' + b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'XX' + b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -783,9 +790,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', 'http://brim.net', 5, 10, '/v1/AUTH_test/container', 'http://brim.net', 5, 10,
int(time() + 86400), key) int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -814,9 +822,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', 'http://brim.net', 1024, 1, '/v1/AUTH_test/container', 'http://brim.net', 1024, 1,
int(time() + 86400), key) int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -855,9 +864,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
env['QUERY_STRING'] = 'this=should&not=get&passed' env['QUERY_STRING'] = 'this=should&not=get&passed'
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp( self.app = FakeApp(
iter([('201 Created', {}, ''), iter([('201 Created', {}, ''),
('201 Created', {}, '')]), ('201 Created', {}, '')]),
@@ -890,9 +900,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', 'http://brim.net', 1024, 10, '/v1/AUTH_test/container', 'http://brim.net', 1024, 10,
int(time() + 86400), key) int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('404 Not Found', {}, ''), self.app = FakeApp(iter([('404 Not Found', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -976,9 +987,10 @@ class TestFormPost(unittest.TestCase):
if six.PY3: if six.PY3:
wsgi_input = wsgi_input.encode('utf-8') wsgi_input = wsgi_input.encode('utf-8')
env['wsgi.input'] = BytesIO(wsgi_input) env['wsgi.input'] = BytesIO(wsgi_input)
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1047,9 +1059,10 @@ class TestFormPost(unittest.TestCase):
if six.PY3: if six.PY3:
wsgi_input = wsgi_input.encode('utf-8') wsgi_input = wsgi_input.encode('utf-8')
env['wsgi.input'] = BytesIO(wsgi_input) env['wsgi.input'] = BytesIO(wsgi_input)
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1087,9 +1100,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', 'http://redirect', 1024, 10, '/v1/AUTH_test/container', 'http://redirect', 1024, 10,
int(time() + 86400), key, user_agent=False) int(time() + 86400), key, user_agent=False)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1108,9 +1122,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', 'http://redirect', 1024, 10, '/v1/AUTH_test/container', 'http://redirect', 1024, 10,
int(time() + 86400), key, user_agent=False) int(time() + 86400), key, user_agent=False)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
env['HTTP_ORIGIN'] = 'http://localhost:5000' env['HTTP_ORIGIN'] = 'http://localhost:5000'
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', ('201 Created',
@@ -1137,9 +1152,10 @@ class TestFormPost(unittest.TestCase):
int(time() + 86400), key) int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) 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 # Stick it in X-Account-Meta-Temp-URL-Key-2 and make sure we get it
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', ['bert', key]) self._fake_cache_env('AUTH_test', ['bert', key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = \
{'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1173,9 +1189,11 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', 'http://redirect', 1024, 10, '/v1/AUTH_test/container', 'http://redirect', 1024, 10,
int(time() + 86400), key) int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env('AUTH_test') env['swift.infocache']['swift.account/AUTH_test'] = (
self._fake_cache_env('AUTH_test'))
# Stick it in X-Container-Meta-Temp-URL-Key-2 and ensure we get it # Stick it in X-Container-Meta-Temp-URL-Key-2 and ensure we get it
env['swift.container/AUTH_test/container'] = {'meta': meta} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': meta}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1199,9 +1217,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', 'http://redirect', 1024, 10, '/v1/AUTH_test/container', 'http://redirect', 1024, 10,
int(time() + 86400), key) int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1237,9 +1256,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', 'http://redirect?one=two', 1024, 10, '/v1/AUTH_test/container', 'http://redirect?one=two', 1024, 10,
int(time() + 86400), key) int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1275,9 +1295,10 @@ class TestFormPost(unittest.TestCase):
sig, env, body = self._make_sig_env_body( sig, env, body = self._make_sig_env_body(
'/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1312,8 +1333,8 @@ class TestFormPost(unittest.TestCase):
sig, env, body = self._make_sig_env_body( sig, env, body = self._make_sig_env_body(
'/v1/AUTH_test/container', '', 1024, 10, int(time() - 10), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() - 10), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1346,8 +1367,8 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
# Change key to invalidate sig # Change key to invalidate sig
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key + ' is bogus now']) self._fake_cache_env('AUTH_test', [key + ' is bogus now']))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1379,8 +1400,8 @@ class TestFormPost(unittest.TestCase):
sig, env, body = self._make_sig_env_body( sig, env, body = self._make_sig_env_body(
'/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'XX' + b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'XX' + b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1412,8 +1433,8 @@ class TestFormPost(unittest.TestCase):
sig, env, body = self._make_sig_env_body( sig, env, body = self._make_sig_env_body(
'/v2/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '/v2/AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1445,8 +1466,8 @@ class TestFormPost(unittest.TestCase):
sig, env, body = self._make_sig_env_body( sig, env, body = self._make_sig_env_body(
'//AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '//AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1478,8 +1499,8 @@ class TestFormPost(unittest.TestCase):
sig, env, body = self._make_sig_env_body( sig, env, body = self._make_sig_env_body(
'/v1//container', '', 1024, 10, int(time() + 86400), key) '/v1//container', '', 1024, 10, int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1511,8 +1532,8 @@ class TestFormPost(unittest.TestCase):
sig, env, body = self._make_sig_env_body( sig, env, body = self._make_sig_env_body(
'/v1/AUTH_tst/container', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_tst/container', '', 1024, 10, int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([ self.app = FakeApp(iter([
('200 Ok', {'x-account-meta-temp-url-key': 'def'}, ''), ('200 Ok', {'x-account-meta-temp-url-key': 'def'}, ''),
('201 Created', {}, ''), ('201 Created', {}, ''),
@@ -1546,8 +1567,8 @@ class TestFormPost(unittest.TestCase):
sig, env, body = self._make_sig_env_body( sig, env, body = self._make_sig_env_body(
'/v1/AUTH_test', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_test', '', 1024, 10, int(time() + 86400), key)
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1584,8 +1605,8 @@ class TestFormPost(unittest.TestCase):
body[i] = 'badvalue' body[i] = 'badvalue'
break break
env['wsgi.input'] = BytesIO(b'\r\n'.join(body)) env['wsgi.input'] = BytesIO(b'\r\n'.join(body))
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1625,9 +1646,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
wsgi_input = b'\r\n'.join(x_delete_body_part + body) wsgi_input = b'\r\n'.join(x_delete_body_part + body)
env['wsgi.input'] = BytesIO(wsgi_input) env['wsgi.input'] = BytesIO(wsgi_input)
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1668,8 +1690,8 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
wsgi_input = b'\r\n'.join(x_delete_body_part + body) wsgi_input = b'\r\n'.join(x_delete_body_part + body)
env['wsgi.input'] = BytesIO(wsgi_input) env['wsgi.input'] = BytesIO(wsgi_input)
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1703,9 +1725,10 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
wsgi_input = b'\r\n'.join(x_delete_body_part + body) wsgi_input = b'\r\n'.join(x_delete_body_part + body)
env['wsgi.input'] = BytesIO(wsgi_input) env['wsgi.input'] = BytesIO(wsgi_input)
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
env['swift.container/AUTH_test/container'] = {'meta': {}} env['swift.infocache']['swift.container/AUTH_test/container'] = {
'meta': {}}
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)
@@ -1746,8 +1769,8 @@ class TestFormPost(unittest.TestCase):
'/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key) '/v1/AUTH_test/container', '', 1024, 10, int(time() + 86400), key)
wsgi_input = b'\r\n'.join(x_delete_body_part + body) wsgi_input = b'\r\n'.join(x_delete_body_part + body)
env['wsgi.input'] = BytesIO(wsgi_input) env['wsgi.input'] = BytesIO(wsgi_input)
env['swift.account/AUTH_test'] = self._fake_cache_env( env['swift.infocache']['swift.account/AUTH_test'] = (
'AUTH_test', [key]) self._fake_cache_env('AUTH_test', [key]))
self.app = FakeApp(iter([('201 Created', {}, ''), self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')])) ('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app) self.auth = tempauth.filter_factory({})(self.app)

View File

@@ -252,7 +252,7 @@ class SwiftAuth(unittest.TestCase):
path = '/v1/' + account path = '/v1/' + account
# fake cached account info # fake cached account info
_, info_key = _get_cache_key(account, None) _, info_key = _get_cache_key(account, None)
env = {info_key: {'status': 0, 'sysmeta': {}}, env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}},
'keystone.token_info': _fake_token_info(version='3')} 'keystone.token_info': _fake_token_info(version='3')}
req = Request.blank(path, environ=env, headers=headers) req = Request.blank(path, environ=env, headers=headers)
req.method = 'POST' req.method = 'POST'
@@ -281,7 +281,7 @@ class SwiftAuth(unittest.TestCase):
path = '/v1/' + account path = '/v1/' + account
# fake cached account info # fake cached account info
_, info_key = _get_cache_key(account, None) _, info_key = _get_cache_key(account, None)
env = {info_key: {'status': 0, 'sysmeta': {}}, env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}},
'keystone.token_info': _fake_token_info(version='3')} 'keystone.token_info': _fake_token_info(version='3')}
req = Request.blank(path, environ=env, headers=headers) req = Request.blank(path, environ=env, headers=headers)
req.method = 'POST' req.method = 'POST'
@@ -303,7 +303,7 @@ class SwiftAuth(unittest.TestCase):
path = '/v1/' + account path = '/v1/' + account
_, info_key = _get_cache_key(account, None) _, info_key = _get_cache_key(account, None)
# v2 token # v2 token
env = {info_key: {'status': 0, 'sysmeta': {}}, env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}},
'keystone.token_info': _fake_token_info(version='2')} 'keystone.token_info': _fake_token_info(version='2')}
req = Request.blank(path, environ=env, headers=headers) req = Request.blank(path, environ=env, headers=headers)
req.method = 'POST' req.method = 'POST'
@@ -325,7 +325,7 @@ class SwiftAuth(unittest.TestCase):
path = '/v1/' + account path = '/v1/' + account
_, info_key = _get_cache_key(account, None) _, info_key = _get_cache_key(account, None)
# v2 token # v2 token
env = {info_key: {'status': 0, 'sysmeta': {}}, env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}},
'keystone.token_info': _fake_token_info(version='2')} 'keystone.token_info': _fake_token_info(version='2')}
req = Request.blank(path, environ=env, headers=headers) req = Request.blank(path, environ=env, headers=headers)
req.method = 'POST' req.method = 'POST'
@@ -382,7 +382,7 @@ class ServiceTokenFunctionality(unittest.TestCase):
service_role=service_role) service_role=service_role)
(version, account, _junk, _junk) = split_path(path, 2, 4, True) (version, account, _junk, _junk) = split_path(path, 2, 4, True)
_, info_key = _get_cache_key(account, None) _, info_key = _get_cache_key(account, None)
env = {info_key: {'status': 0, 'sysmeta': {}}, env = {'swift.infocache': {info_key: {'status': 0, 'sysmeta': {}}},
'keystone.token_info': _fake_token_info(version='2')} 'keystone.token_info': _fake_token_info(version='2')}
if environ: if environ:
env.update(environ) env.update(environ)
@@ -596,8 +596,9 @@ class TestAuthorize(BaseTestAuthorize):
path = '/v1/%s/c' % account path = '/v1/%s/c' % account
# fake cached account info # fake cached account info
_, info_key = _get_cache_key(account, None) _, info_key = _get_cache_key(account, None)
default_env = {'REMOTE_USER': identity['HTTP_X_TENANT_ID'], default_env = {
info_key: {'status': 200, 'sysmeta': {}}} 'REMOTE_USER': identity['HTTP_X_TENANT_ID'],
'swift.infocache': {info_key: {'status': 200, 'sysmeta': {}}}}
default_env.update(identity) default_env.update(identity)
if env: if env:
default_env.update(env) default_env.update(env)
@@ -986,7 +987,7 @@ class TestAuthorize(BaseTestAuthorize):
info = {'sysmeta': sysmeta} info = {'sysmeta': sysmeta}
_, info_key = _get_cache_key('AUTH_1234', None) _, info_key = _get_cache_key('AUTH_1234', None)
env = {'PATH_INFO': '/v1/AUTH_1234', env = {'PATH_INFO': '/v1/AUTH_1234',
info_key: info} 'swift.infocache': {info_key: info}}
# account does not exist # account does not exist
info['status'] = 404 info['status'] = 404
@@ -1029,7 +1030,8 @@ class TestIsNameAllowedInACL(BaseTestAuthorize):
# pretend account exists # pretend account exists
info = {'status': 200, 'sysmeta': sysmeta} info = {'status': 200, 'sysmeta': sysmeta}
_, info_key = _get_cache_key(account, None) _, info_key = _get_cache_key(account, None)
req = Request.blank(path, environ={info_key: info}) req = Request.blank(path,
environ={'swift.infocache': {info_key: info}})
if scoped == 'account': if scoped == 'account':
project_name = 'account_name' project_name = 'account_name'
@@ -1215,7 +1217,7 @@ class TestSetProjectDomain(BaseTestAuthorize):
sysmeta['project-domain-id'] = sysmeta_project_domain_id sysmeta['project-domain-id'] = sysmeta_project_domain_id
info = {'status': status, 'sysmeta': sysmeta} info = {'status': status, 'sysmeta': sysmeta}
_, info_key = _get_cache_key(account, None) _, info_key = _get_cache_key(account, None)
env = {info_key: info} env = {'swift.infocache': {info_key: info}}
# create fake env identity # create fake env identity
env_id = self._get_env_id(tenant_id=req_project_id, env_id = self._get_env_id(tenant_id=req_project_id,

View File

@@ -245,8 +245,9 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase):
'status': 200, 'object_count': 1} 'status': 200, 'object_count': 1}
req = Request.blank('/v1/a/c2/o2', req = Request.blank('/v1/a/c2/o2',
environ={'REQUEST_METHOD': 'COPY', environ={'REQUEST_METHOD': 'COPY',
'swift.infocache': {
'swift.container/a/c': a_c_cache, 'swift.container/a/c': a_c_cache,
'swift.container/a2/c': a2_c_cache}, 'swift.container/a2/c': a2_c_cache}},
headers={'Destination': '/c/o', headers={'Destination': '/c/o',
'Destination-Account': 'a2'}) 'Destination-Account': 'a2'})
res = req.get_response(self.copy_filter) res = req.get_response(self.copy_filter)
@@ -261,8 +262,9 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase):
'status': 200, 'object_count': 1} 'status': 200, 'object_count': 1}
req = Request.blank('/v1/a2/c/o', req = Request.blank('/v1/a2/c/o',
environ={'REQUEST_METHOD': 'PUT', environ={'REQUEST_METHOD': 'PUT',
'swift.infocache': {
'swift.container/a/c': a_c_cache, 'swift.container/a/c': a_c_cache,
'swift.container/a2/c': a2_c_cache}, 'swift.container/a2/c': a2_c_cache}},
headers={'X-Copy-From': '/c2/o2', headers={'X-Copy-From': '/c2/o2',
'X-Copy-From-Account': 'a'}) 'X-Copy-From-Account': 'a'})
res = req.get_response(self.copy_filter) res = req.get_response(self.copy_filter)

View File

@@ -96,7 +96,8 @@ class TestTempURL(unittest.TestCase):
if key: if key:
meta[meta_name] = key meta[meta_name] = key
environ['swift.account/' + account] = { ic = environ.setdefault('swift.infocache', {})
ic['swift.account/' + account] = {
'status': 204, 'status': 204,
'container_count': '0', 'container_count': '0',
'total_object_count': '0', 'total_object_count': '0',
@@ -109,7 +110,7 @@ class TestTempURL(unittest.TestCase):
meta[meta_name] = key meta[meta_name] = key
container_cache_key = 'swift.container/' + account + '/c' container_cache_key = 'swift.container/' + account + '/c'
environ.setdefault(container_cache_key, {'meta': meta}) ic.setdefault(container_cache_key, {'meta': meta})
def test_passthrough(self): def test_passthrough(self):
resp = self._make_request('/v1/a/c/o').get_response(self.tempurl) resp = self._make_request('/v1/a/c/o').get_response(self.tempurl)
@@ -159,7 +160,8 @@ class TestTempURL(unittest.TestCase):
self.assert_valid_sig(expires, path, [key1, key2], sig) self.assert_valid_sig(expires, path, [key1, key2], sig)
def test_get_valid_container_keys(self): def test_get_valid_container_keys(self):
environ = {} ic = {}
environ = {'swift.infocache': ic}
# Add two static container keys # Add two static container keys
container_keys = ['me', 'other'] container_keys = ['me', 'other']
meta = {} meta = {}
@@ -167,7 +169,7 @@ class TestTempURL(unittest.TestCase):
meta_name = 'Temp-URL-key' + (("-%d" % (idx + 1) if idx else "")) meta_name = 'Temp-URL-key' + (("-%d" % (idx + 1) if idx else ""))
if key: if key:
meta[meta_name] = key meta[meta_name] = key
environ['swift.container/a/c'] = {'meta': meta} ic['swift.container/a/c'] = {'meta': meta}
method = 'GET' method = 'GET'
expires = int(time() + 86400) expires = int(time() + 86400)

View File

@@ -839,6 +839,11 @@ class TestWSGI(unittest.TestCase):
self.assertTrue('HTTP_REFERER' in newenv) self.assertTrue('HTTP_REFERER' in newenv)
self.assertEqual(newenv['HTTP_REFERER'], 'http://blah.example.com') self.assertEqual(newenv['HTTP_REFERER'], 'http://blah.example.com')
def test_make_env_keeps_infocache(self):
oldenv = {'swift.infocache': {}}
newenv = wsgi.make_env(oldenv)
self.assertIs(newenv.get('swift.infocache'), oldenv['swift.infocache'])
class TestServersPerPortStrategy(unittest.TestCase): class TestServersPerPortStrategy(unittest.TestCase):
def setUp(self): def setUp(self):

View File

@@ -68,9 +68,11 @@ class TestAccountController(unittest.TestCase):
req = Request.blank('/v1/AUTH_bob', {'PATH_INFO': '/v1/AUTH_bob'}) req = Request.blank('/v1/AUTH_bob', {'PATH_INFO': '/v1/AUTH_bob'})
resp = controller.HEAD(req) resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100) self.assertEqual(2, resp.status_int // 100)
self.assertTrue('swift.account/AUTH_bob' in resp.environ) self.assertTrue(
self.assertEqual(headers_to_account_info(resp.headers), 'swift.account/AUTH_bob' in resp.environ['swift.infocache'])
resp.environ['swift.account/AUTH_bob']) self.assertEqual(
headers_to_account_info(resp.headers),
resp.environ['swift.infocache']['swift.account/AUTH_bob'])
def test_swift_owner(self): def test_swift_owner(self):
owner_headers = { owner_headers = {

View File

@@ -120,10 +120,10 @@ class FakeApp(object):
def __init__(self, response_factory=None, statuses=None): def __init__(self, response_factory=None, statuses=None):
self.responses = response_factory or \ self.responses = response_factory or \
DynamicResponseFactory(*statuses or []) DynamicResponseFactory(*statuses or [])
self.sources = [] self.captured_envs = []
def __call__(self, environ, start_response): def __call__(self, environ, start_response):
self.sources.append(environ.get('swift.source')) self.captured_envs.append(environ)
response = self.responses.get_response(environ) response = self.responses.get_response(environ)
reason = RESPONSE_REASONS[response.status_int][0] reason = RESPONSE_REASONS[response.status_int][0]
start_response('%d %s' % (response.status_int, reason), start_response('%d %s' % (response.status_int, reason),
@@ -167,31 +167,37 @@ class TestFuncs(unittest.TestCase):
'http_connect', fake_http_connect(200)): 'http_connect', fake_http_connect(200)):
resp = base.GETorHEAD_base(req, 'object', iter(nodes), 'part', resp = base.GETorHEAD_base(req, 'object', iter(nodes), 'part',
'/a/c/o/with/slashes') '/a/c/o/with/slashes')
self.assertTrue('swift.object/a/c/o/with/slashes' in resp.environ) infocache = resp.environ['swift.infocache']
self.assertTrue('swift.object/a/c/o/with/slashes' in infocache)
self.assertEqual( self.assertEqual(
resp.environ['swift.object/a/c/o/with/slashes']['status'], 200) infocache['swift.object/a/c/o/with/slashes']['status'], 200)
req = Request.blank('/v1/a/c/o') req = Request.blank('/v1/a/c/o')
with patch('swift.proxy.controllers.base.' with patch('swift.proxy.controllers.base.'
'http_connect', fake_http_connect(200)): 'http_connect', fake_http_connect(200)):
resp = base.GETorHEAD_base(req, 'object', iter(nodes), 'part', resp = base.GETorHEAD_base(req, 'object', iter(nodes), 'part',
'/a/c/o') '/a/c/o')
self.assertTrue('swift.object/a/c/o' in resp.environ) infocache = resp.environ['swift.infocache']
self.assertEqual(resp.environ['swift.object/a/c/o']['status'], 200) self.assertTrue('swift.object/a/c/o' in infocache)
self.assertEqual(infocache['swift.object/a/c/o']['status'], 200)
req = Request.blank('/v1/a/c') req = Request.blank('/v1/a/c')
with patch('swift.proxy.controllers.base.' with patch('swift.proxy.controllers.base.'
'http_connect', fake_http_connect(200)): 'http_connect', fake_http_connect(200)):
resp = base.GETorHEAD_base(req, 'container', iter(nodes), 'part', resp = base.GETorHEAD_base(req, 'container', iter(nodes), 'part',
'/a/c') '/a/c')
self.assertTrue('swift.container/a/c' in resp.environ) infocache = resp.environ['swift.infocache']
self.assertEqual(resp.environ['swift.container/a/c']['status'], 200) self.assertTrue('swift.container/a/c' in infocache)
self.assertEqual(infocache['swift.container/a/c']['status'], 200)
req = Request.blank('/v1/a') req = Request.blank('/v1/a')
with patch('swift.proxy.controllers.base.' with patch('swift.proxy.controllers.base.'
'http_connect', fake_http_connect(200)): 'http_connect', fake_http_connect(200)):
resp = base.GETorHEAD_base(req, 'account', iter(nodes), 'part', resp = base.GETorHEAD_base(req, 'account', iter(nodes), 'part',
'/a') '/a')
self.assertTrue('swift.account/a' in resp.environ) infocache = resp.environ['swift.infocache']
self.assertEqual(resp.environ['swift.account/a']['status'], 200) self.assertTrue('swift.account/a' in infocache)
self.assertEqual(infocache['swift.account/a']['status'], 200)
# Run the above tests again, but this time with concurrent_reads # Run the above tests again, but this time with concurrent_reads
# turned on # turned on
@@ -209,26 +215,28 @@ class TestFuncs(unittest.TestCase):
resp = base.GETorHEAD_base( resp = base.GETorHEAD_base(
req, 'object', iter(nodes), 'part', '/a/c/o/with/slashes', req, 'object', iter(nodes), 'part', '/a/c/o/with/slashes',
concurrency=concurrent_get_threads) concurrency=concurrent_get_threads)
self.assertTrue('swift.object/a/c/o/with/slashes' in resp.environ) infocache = resp.environ['swift.infocache']
self.assertTrue('swift.object/a/c/o/with/slashes' in infocache)
self.assertEqual( self.assertEqual(
resp.environ['swift.object/a/c/o/with/slashes']['status'], 200) infocache['swift.object/a/c/o/with/slashes']['status'], 200)
req = Request.blank('/v1/a/c/o') req = Request.blank('/v1/a/c/o')
with patch('swift.proxy.controllers.base.http_connect', with patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200, slow_connect=True)): fake_http_connect(200, slow_connect=True)):
resp = base.GETorHEAD_base( resp = base.GETorHEAD_base(
req, 'object', iter(nodes), 'part', '/a/c/o', req, 'object', iter(nodes), 'part', '/a/c/o',
concurrency=concurrent_get_threads) concurrency=concurrent_get_threads)
self.assertTrue('swift.object/a/c/o' in resp.environ) infocache = resp.environ['swift.infocache']
self.assertEqual(resp.environ['swift.object/a/c/o']['status'], 200) self.assertTrue('swift.object/a/c/o' in infocache)
self.assertEqual(infocache['swift.object/a/c/o']['status'], 200)
req = Request.blank('/v1/a/c') req = Request.blank('/v1/a/c')
with patch('swift.proxy.controllers.base.http_connect', with patch('swift.proxy.controllers.base.http_connect',
fake_http_connect(200, slow_connect=True)): fake_http_connect(200, slow_connect=True)):
resp = base.GETorHEAD_base( resp = base.GETorHEAD_base(
req, 'container', iter(nodes), 'part', '/a/c', req, 'container', iter(nodes), 'part', '/a/c',
concurrency=concurrent_get_threads) concurrency=concurrent_get_threads)
self.assertTrue('swift.container/a/c' in resp.environ) infocache = resp.environ['swift.infocache']
self.assertEqual(resp.environ['swift.container/a/c']['status'], self.assertTrue('swift.container/a/c' in infocache)
200) self.assertEqual(infocache['swift.container/a/c']['status'], 200)
req = Request.blank('/v1/a') req = Request.blank('/v1/a')
with patch('swift.proxy.controllers.base.http_connect', with patch('swift.proxy.controllers.base.http_connect',
@@ -236,8 +244,9 @@ class TestFuncs(unittest.TestCase):
resp = base.GETorHEAD_base( resp = base.GETorHEAD_base(
req, 'account', iter(nodes), 'part', '/a', req, 'account', iter(nodes), 'part', '/a',
concurrency=concurrent_get_threads) concurrency=concurrent_get_threads)
self.assertTrue('swift.account/a' in resp.environ) infocache = resp.environ['swift.infocache']
self.assertEqual(resp.environ['swift.account/a']['status'], 200) self.assertTrue('swift.account/a' in infocache)
self.assertEqual(infocache['swift.account/a']['status'], 200)
def test_get_info(self): def test_get_info(self):
app = FakeApp() app = FakeApp()
@@ -249,7 +258,7 @@ class TestFuncs(unittest.TestCase):
self.assertEqual(info_a['bytes'], 6666) self.assertEqual(info_a['bytes'], 6666)
self.assertEqual(info_a['total_object_count'], 1000) self.assertEqual(info_a['total_object_count'], 1000)
# Make sure the env cache is set # Make sure the env cache is set
self.assertEqual(env.get('swift.account/a'), info_a) self.assertEqual(env['swift.infocache'].get('swift.account/a'), info_a)
# Make sure the app was called # Make sure the app was called
self.assertEqual(app.responses.stats['account'], 1) self.assertEqual(app.responses.stats['account'], 1)
@@ -260,7 +269,7 @@ class TestFuncs(unittest.TestCase):
self.assertEqual(info_a['bytes'], 6666) self.assertEqual(info_a['bytes'], 6666)
self.assertEqual(info_a['total_object_count'], 1000) self.assertEqual(info_a['total_object_count'], 1000)
# Make sure the env cache is set # Make sure the env cache is set
self.assertEqual(env.get('swift.account/a'), info_a) self.assertEqual(env['swift.infocache'].get('swift.account/a'), info_a)
# Make sure the app was NOT called AGAIN # Make sure the app was NOT called AGAIN
self.assertEqual(app.responses.stats['account'], 1) self.assertEqual(app.responses.stats['account'], 1)
@@ -271,8 +280,10 @@ class TestFuncs(unittest.TestCase):
self.assertEqual(info_c['bytes'], 6666) self.assertEqual(info_c['bytes'], 6666)
self.assertEqual(info_c['object_count'], 1000) self.assertEqual(info_c['object_count'], 1000)
# Make sure the env cache is set # Make sure the env cache is set
self.assertEqual(env.get('swift.account/a'), info_a) self.assertEqual(
self.assertEqual(env.get('swift.container/a/c'), info_c) env['swift.infocache'].get('swift.account/a'), info_a)
self.assertEqual(
env['swift.infocache'].get('swift.container/a/c'), info_c)
# Make sure the app was called for container # Make sure the app was called for container
self.assertEqual(app.responses.stats['container'], 1) self.assertEqual(app.responses.stats['container'], 1)
@@ -286,22 +297,25 @@ class TestFuncs(unittest.TestCase):
self.assertEqual(info_c['bytes'], 6666) self.assertEqual(info_c['bytes'], 6666)
self.assertEqual(info_c['object_count'], 1000) self.assertEqual(info_c['object_count'], 1000)
# Make sure the env cache is set # Make sure the env cache is set
self.assertEqual(env.get('swift.account/a'), info_a) self.assertEqual(
self.assertEqual(env.get('swift.container/a/c'), info_c) env['swift.infocache'].get('swift.account/a'), info_a)
self.assertEqual(
env['swift.infocache'].get('swift.container/a/c'), info_c)
# check app calls both account and container # check app calls both account and container
self.assertEqual(app.responses.stats['account'], 1) self.assertEqual(app.responses.stats['account'], 1)
self.assertEqual(app.responses.stats['container'], 1) self.assertEqual(app.responses.stats['container'], 1)
# This time do an env cached call to container while account is not # This time do an env cached call to container while account is not
# cached # cached
del(env['swift.account/a']) del(env['swift.infocache']['swift.account/a'])
info_c = get_info(app, env, 'a', 'c') info_c = get_info(app, env, 'a', 'c')
# Check that you got proper info # Check that you got proper info
self.assertEqual(info_a['status'], 200) self.assertEqual(info_a['status'], 200)
self.assertEqual(info_c['bytes'], 6666) self.assertEqual(info_c['bytes'], 6666)
self.assertEqual(info_c['object_count'], 1000) self.assertEqual(info_c['object_count'], 1000)
# Make sure the env cache is set and account still not cached # Make sure the env cache is set and account still not cached
self.assertEqual(env.get('swift.container/a/c'), info_c) self.assertEqual(
env['swift.infocache'].get('swift.container/a/c'), info_c)
# no additional calls were made # no additional calls were made
self.assertEqual(app.responses.stats['account'], 1) self.assertEqual(app.responses.stats['account'], 1)
self.assertEqual(app.responses.stats['container'], 1) self.assertEqual(app.responses.stats['container'], 1)
@@ -315,7 +329,8 @@ class TestFuncs(unittest.TestCase):
self.assertEqual(info_a['bytes'], None) self.assertEqual(info_a['bytes'], None)
self.assertEqual(info_a['total_object_count'], None) self.assertEqual(info_a['total_object_count'], None)
# Make sure the env cache is set # Make sure the env cache is set
self.assertEqual(env.get('swift.account/a'), info_a) self.assertEqual(
env['swift.infocache'].get('swift.account/a'), info_a)
# and account was called # and account was called
self.assertEqual(app.responses.stats['account'], 1) self.assertEqual(app.responses.stats['account'], 1)
@@ -326,7 +341,8 @@ class TestFuncs(unittest.TestCase):
self.assertEqual(info_a['bytes'], None) self.assertEqual(info_a['bytes'], None)
self.assertEqual(info_a['total_object_count'], None) self.assertEqual(info_a['total_object_count'], None)
# Make sure the env cache is set # Make sure the env cache is set
self.assertEqual(env.get('swift.account/a'), info_a) self.assertEqual(
env['swift.infocache'].get('swift.account/a'), info_a)
# add account was NOT called AGAIN # add account was NOT called AGAIN
self.assertEqual(app.responses.stats['account'], 1) self.assertEqual(app.responses.stats['account'], 1)
@@ -336,7 +352,8 @@ class TestFuncs(unittest.TestCase):
info_a = get_info(app, env, 'a') info_a = get_info(app, env, 'a')
# Check that you got proper info # Check that you got proper info
self.assertEqual(info_a, None) self.assertEqual(info_a, None)
self.assertEqual(env['swift.account/a']['status'], 404) self.assertEqual(
env['swift.infocache']['swift.account/a']['status'], 404)
# and account was called # and account was called
self.assertEqual(app.responses.stats['account'], 1) self.assertEqual(app.responses.stats['account'], 1)
@@ -344,7 +361,8 @@ class TestFuncs(unittest.TestCase):
info_a = get_info(None, env, 'a') info_a = get_info(None, env, 'a')
# Check that you got proper info # Check that you got proper info
self.assertEqual(info_a, None) self.assertEqual(info_a, None)
self.assertEqual(env['swift.account/a']['status'], 404) self.assertEqual(
env['swift.infocache']['swift.account/a']['status'], 404)
# add account was NOT called AGAIN # add account was NOT called AGAIN
self.assertEqual(app.responses.stats['account'], 1) self.assertEqual(app.responses.stats['account'], 1)
@@ -352,14 +370,16 @@ class TestFuncs(unittest.TestCase):
app = FakeApp() app = FakeApp()
req = Request.blank("/v1/a/c", environ={'swift.cache': FakeCache()}) req = Request.blank("/v1/a/c", environ={'swift.cache': FakeCache()})
get_container_info(req.environ, app, swift_source='MC') get_container_info(req.environ, app, swift_source='MC')
self.assertEqual(app.sources, ['GET_INFO', 'MC']) self.assertEqual([e['swift.source'] for e in app.captured_envs],
['GET_INFO', 'MC'])
def test_get_object_info_swift_source(self): def test_get_object_info_swift_source(self):
app = FakeApp() app = FakeApp()
req = Request.blank("/v1/a/c/o", req = Request.blank("/v1/a/c/o",
environ={'swift.cache': FakeCache()}) environ={'swift.cache': FakeCache()})
get_object_info(req.environ, app, swift_source='LU') get_object_info(req.environ, app, swift_source='LU')
self.assertEqual(app.sources, ['LU']) self.assertEqual([e['swift.source'] for e in app.captured_envs],
['LU'])
def test_get_container_info_no_cache(self): def test_get_container_info_no_cache(self):
req = Request.blank("/v1/AUTH_account/cont", req = Request.blank("/v1/AUTH_account/cont",
@@ -401,8 +421,9 @@ class TestFuncs(unittest.TestCase):
def test_get_container_info_env(self): def test_get_container_info_env(self):
cache_key = get_container_memcache_key("account", "cont") cache_key = get_container_memcache_key("account", "cont")
env_key = 'swift.%s' % cache_key env_key = 'swift.%s' % cache_key
req = Request.blank("/v1/account/cont", req = Request.blank(
environ={env_key: {'bytes': 3867}, "/v1/account/cont",
environ={'swift.infocache': {env_key: {'bytes': 3867}},
'swift.cache': FakeCache({})}) 'swift.cache': FakeCache({})})
resp = get_container_info(req.environ, 'xxx') resp = get_container_info(req.environ, 'xxx')
self.assertEqual(resp['bytes'], 3867) self.assertEqual(resp['bytes'], 3867)
@@ -411,7 +432,18 @@ class TestFuncs(unittest.TestCase):
app = FakeApp() app = FakeApp()
req = Request.blank("/v1/a", environ={'swift.cache': FakeCache()}) req = Request.blank("/v1/a", environ={'swift.cache': FakeCache()})
get_account_info(req.environ, app, swift_source='MC') get_account_info(req.environ, app, swift_source='MC')
self.assertEqual(app.sources, ['MC']) self.assertEqual([e['swift.source'] for e in app.captured_envs],
['MC'])
def test_get_account_info_infocache(self):
app = FakeApp()
ic = {}
req = Request.blank("/v1/a", environ={'swift.cache': FakeCache(),
'swift.infocache': ic})
get_account_info(req.environ, app)
got_infocaches = [e['swift.infocache'] for e in app.captured_envs]
self.assertEqual(1, len(got_infocaches))
self.assertIs(ic, got_infocaches[0])
def test_get_account_info_no_cache(self): def test_get_account_info_no_cache(self):
app = FakeApp() app = FakeApp()
@@ -451,8 +483,9 @@ class TestFuncs(unittest.TestCase):
def test_get_account_info_env(self): def test_get_account_info_env(self):
cache_key = get_account_memcache_key("account") cache_key = get_account_memcache_key("account")
env_key = 'swift.%s' % cache_key env_key = 'swift.%s' % cache_key
req = Request.blank("/v1/account", req = Request.blank(
environ={env_key: {'bytes': 3867}, "/v1/account",
environ={'swift.infocache': {env_key: {'bytes': 3867}},
'swift.cache': FakeCache({})}) 'swift.cache': FakeCache({})})
resp = get_account_info(req.environ, 'xxx') resp = get_account_info(req.environ, 'xxx')
self.assertEqual(resp['bytes'], 3867) self.assertEqual(resp['bytes'], 3867)
@@ -463,8 +496,9 @@ class TestFuncs(unittest.TestCase):
'type': 'application/json', 'type': 'application/json',
'meta': {}} 'meta': {}}
env_key = get_object_env_key("account", "cont", "obj") env_key = get_object_env_key("account", "cont", "obj")
req = Request.blank("/v1/account/cont/obj", req = Request.blank(
environ={env_key: cached, "/v1/account/cont/obj",
environ={'swift.infocache': {env_key: cached},
'swift.cache': FakeCache({})}) 'swift.cache': FakeCache({})})
resp = get_object_info(req.environ, 'xxx') resp = get_object_info(req.environ, 'xxx')
self.assertEqual(resp['length'], 3333) self.assertEqual(resp['length'], 3333)

View File

@@ -102,9 +102,11 @@ class TestContainerController(TestRingBase):
req = Request.blank('/v1/a/c', {'PATH_INFO': '/v1/a/c'}) req = Request.blank('/v1/a/c', {'PATH_INFO': '/v1/a/c'})
resp = controller.HEAD(req) resp = controller.HEAD(req)
self.assertEqual(2, resp.status_int // 100) self.assertEqual(2, resp.status_int // 100)
self.assertTrue("swift.container/a/c" in resp.environ) self.assertTrue(
self.assertEqual(headers_to_container_info(resp.headers), "swift.container/a/c" in resp.environ['swift.infocache'])
resp.environ['swift.container/a/c']) self.assertEqual(
headers_to_container_info(resp.headers),
resp.environ['swift.infocache']['swift.container/a/c'])
def test_swift_owner(self): def test_swift_owner(self):
owner_headers = { owner_headers = {

View File

@@ -6319,22 +6319,23 @@ class TestContainerController(unittest.TestCase):
res = controller.HEAD(req) res = controller.HEAD(req)
self.assertEqual(res.status[:len(str(expected))], self.assertEqual(res.status[:len(str(expected))],
str(expected)) str(expected))
infocache = res.environ.get('swift.infocache', {})
if expected < 400: if expected < 400:
self.assertTrue('x-works' in res.headers) self.assertIn('x-works', res.headers)
self.assertEqual(res.headers['x-works'], 'yes') self.assertEqual(res.headers['x-works'], 'yes')
if c_expected: if c_expected:
self.assertTrue('swift.container/a/c' in res.environ) self.assertIn('swift.container/a/c', infocache)
self.assertEqual( self.assertEqual(
res.environ['swift.container/a/c']['status'], infocache['swift.container/a/c']['status'],
c_expected) c_expected)
else: else:
self.assertTrue('swift.container/a/c' not in res.environ) self.assertNotIn('swift.container/a/c', infocache)
if a_expected: if a_expected:
self.assertTrue('swift.account/a' in res.environ) self.assertIn('swift.account/a', infocache)
self.assertEqual(res.environ['swift.account/a']['status'], self.assertEqual(infocache['swift.account/a']['status'],
a_expected) a_expected)
else: else:
self.assertTrue('swift.account/a' not in res.environ) self.assertNotIn('swift.account/a', res.environ)
set_http_connect(*statuses, **kwargs) set_http_connect(*statuses, **kwargs)
self.app.memcache.store = {} self.app.memcache.store = {}
@@ -6343,22 +6344,23 @@ class TestContainerController(unittest.TestCase):
res = controller.GET(req) res = controller.GET(req)
self.assertEqual(res.status[:len(str(expected))], self.assertEqual(res.status[:len(str(expected))],
str(expected)) str(expected))
infocache = res.environ.get('swift.infocache', {})
if expected < 400: if expected < 400:
self.assertTrue('x-works' in res.headers) self.assertTrue('x-works' in res.headers)
self.assertEqual(res.headers['x-works'], 'yes') self.assertEqual(res.headers['x-works'], 'yes')
if c_expected: if c_expected:
self.assertTrue('swift.container/a/c' in res.environ) self.assertIn('swift.container/a/c', infocache)
self.assertEqual( self.assertEqual(
res.environ['swift.container/a/c']['status'], infocache['swift.container/a/c']['status'],
c_expected) c_expected)
else: else:
self.assertTrue('swift.container/a/c' not in res.environ) self.assertNotIn('swift.container/a/c', infocache)
if a_expected: if a_expected:
self.assertTrue('swift.account/a' in res.environ) self.assertIn('swift.account/a', infocache)
self.assertEqual(res.environ['swift.account/a']['status'], self.assertEqual(infocache['swift.account/a']['status'],
a_expected) a_expected)
else: else:
self.assertTrue('swift.account/a' not in res.environ) self.assertNotIn('swift.account/a', infocache)
# In all the following tests cache 200 for account # In all the following tests cache 200 for account
# return and ache vary for container # return and ache vary for container
# return 200 and cache 200 for and container # return 200 and cache 200 for and container
@@ -6970,8 +6972,8 @@ class TestContainerController(unittest.TestCase):
self.app.update_request(req) self.app.update_request(req)
res = controller.GET(req) res = controller.GET(req)
self.assertEqual(res.status_int, 204) self.assertEqual(res.status_int, 204)
self.assertEqual( ic = res.environ['swift.infocache']
res.environ['swift.container/a/c']['status'], 204) self.assertEqual(ic['swift.container/a/c']['status'], 204)
self.assertEqual(res.content_length, 0) self.assertEqual(res.content_length, 0)
self.assertTrue('transfer-encoding' not in res.headers) self.assertTrue('transfer-encoding' not in res.headers)
@@ -6989,7 +6991,9 @@ class TestContainerController(unittest.TestCase):
req.environ['swift.authorize'] = authorize req.environ['swift.authorize'] = authorize
self.app.update_request(req) self.app.update_request(req)
res = controller.GET(req) res = controller.GET(req)
self.assertEqual(res.environ['swift.container/a/c']['status'], 201) self.assertEqual(
res.environ['swift.infocache']['swift.container/a/c']['status'],
201)
self.assertTrue(called[0]) self.assertTrue(called[0])
def test_HEAD_calls_authorize(self): def test_HEAD_calls_authorize(self):
@@ -7457,16 +7461,18 @@ class TestAccountController(unittest.TestCase):
self.app.update_request(req) self.app.update_request(req)
res = method(req) res = method(req)
self.assertEqual(res.status_int, expected) self.assertEqual(res.status_int, expected)
infocache = res.environ.get('swift.infocache', {})
if env_expected: if env_expected:
self.assertEqual(res.environ['swift.account/a']['status'], self.assertEqual(infocache['swift.account/a']['status'],
env_expected) env_expected)
set_http_connect(*statuses) set_http_connect(*statuses)
req = Request.blank('/v1/a/', {}) req = Request.blank('/v1/a/', {})
self.app.update_request(req) self.app.update_request(req)
res = method(req) res = method(req)
infocache = res.environ.get('swift.infocache', {})
self.assertEqual(res.status_int, expected) self.assertEqual(res.status_int, expected)
if env_expected: if env_expected:
self.assertEqual(res.environ['swift.account/a']['status'], self.assertEqual(infocache['swift.account/a']['status'],
env_expected) env_expected)
def test_OPTIONS(self): def test_OPTIONS(self):