Merge "remove double checks on account/container info"

This commit is contained in:
Jenkins 2016-11-14 04:30:41 +00:00 committed by Gerrit Code Review
commit 72e413a9ef
2 changed files with 6 additions and 11 deletions

View File

@ -349,11 +349,10 @@ def get_container_info(env, app, swift_source=None):
# Old data format in memcache immediately after a Swift upgrade; clean # Old data format in memcache immediately after a Swift upgrade; clean
# it up so consumers of get_container_info() aren't exposed to it. # it up so consumers of get_container_info() aren't exposed to it.
info.setdefault('storage_policy', '0')
if 'object_count' not in info and 'container_size' in info: if 'object_count' not in info and 'container_size' in info:
info['object_count'] = info.pop('container_size') info['object_count'] = info.pop('container_size')
for field in ('bytes', 'object_count'): for field in ('storage_policy', 'bytes', 'object_count'):
if info.get(field) is None: if info.get(field) is None:
info[field] = 0 info[field] = 0
else: else:
@ -1499,10 +1498,7 @@ class Controller(object):
or not is_success(info['status']) or not is_success(info['status'])
or not info.get('account_really_exists', True)): or not info.get('account_really_exists', True)):
return None, None, None return None, None, None
if info.get('container_count') is None: container_count = info['container_count']
container_count = 0
else:
container_count = int(info['container_count'])
return partition, nodes, container_count return partition, nodes, container_count
def container_info(self, account, container, req=None): def container_info(self, account, container, req=None):
@ -1535,8 +1531,6 @@ class Controller(object):
else: else:
info['partition'] = part info['partition'] = part
info['nodes'] = nodes info['nodes'] = nodes
if info.get('storage_policy') is None:
info['storage_policy'] = 0
return info return info
def _make_request(self, nodes, part, method, path, headers, query, def _make_request(self, nodes, part, method, path, headers, query,

View File

@ -209,7 +209,8 @@ class TestFuncs(unittest.TestCase):
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
exp_cached_info_c = { exp_cached_info_c = {
k: str(v) if k in ('bytes', 'object_count') else v k: str(v) if k in (
'bytes', 'object_count', 'storage_policy') else v
for k, v in info_c.items()} for k, v in info_c.items()}
self.assertEqual(env['swift.infocache'].get('account/a'), self.assertEqual(env['swift.infocache'].get('account/a'),
exp_cached_info_a) exp_cached_info_a)
@ -340,7 +341,7 @@ class TestFuncs(unittest.TestCase):
req = Request.blank("/v1/AUTH_account/cont", req = Request.blank("/v1/AUTH_account/cont",
environ={'swift.cache': FakeCache({})}) environ={'swift.cache': FakeCache({})})
resp = get_container_info(req.environ, FakeApp()) resp = get_container_info(req.environ, FakeApp())
self.assertEqual(resp['storage_policy'], '0') self.assertEqual(resp['storage_policy'], 0)
self.assertEqual(resp['bytes'], 6666) self.assertEqual(resp['bytes'], 6666)
self.assertEqual(resp['object_count'], 1000) self.assertEqual(resp['object_count'], 1000)
@ -365,7 +366,7 @@ class TestFuncs(unittest.TestCase):
req = Request.blank("/v1/account/cont", req = Request.blank("/v1/account/cont",
environ={'swift.cache': FakeCache(cache_stub)}) environ={'swift.cache': FakeCache(cache_stub)})
resp = get_container_info(req.environ, FakeApp()) resp = get_container_info(req.environ, FakeApp())
self.assertEqual(resp['storage_policy'], '0') self.assertEqual(resp['storage_policy'], 0)
self.assertEqual(resp['bytes'], 3333) self.assertEqual(resp['bytes'], 3333)
self.assertEqual(resp['object_count'], 10) self.assertEqual(resp['object_count'], 10)
self.assertEqual(resp['status'], 404) self.assertEqual(resp['status'], 404)