From d25216bddabc77fb54c514269ee55800c87f558c Mon Sep 17 00:00:00 2001 From: Thiago da Silva Date: Mon, 16 May 2016 15:57:47 -0400 Subject: [PATCH] remove double checks on account/container info Continuing the clean up in account and container info, removed duplicated validation from account_info and container_info methods, since the same validations were recently added to get_account_info and get_container_info. Change-Id: I1ad745fe809367d22649c83f38c4de7a74cac44e Signed-off-by: Thiago da Silva --- swift/proxy/controllers/base.py | 10 ++-------- test/unit/proxy/controllers/test_base.py | 7 ++++--- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index 61ef64f473..c5e8ebd08f 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -349,11 +349,10 @@ def get_container_info(env, app, swift_source=None): # Old data format in memcache immediately after a Swift upgrade; clean # 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: 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: info[field] = 0 else: @@ -1499,10 +1498,7 @@ class Controller(object): or not is_success(info['status']) or not info.get('account_really_exists', True)): return None, None, None - if info.get('container_count') is None: - container_count = 0 - else: - container_count = int(info['container_count']) + container_count = info['container_count'] return partition, nodes, container_count def container_info(self, account, container, req=None): @@ -1535,8 +1531,6 @@ class Controller(object): else: info['partition'] = part info['nodes'] = nodes - if info.get('storage_policy') is None: - info['storage_policy'] = 0 return info def _make_request(self, nodes, part, method, path, headers, query, diff --git a/test/unit/proxy/controllers/test_base.py b/test/unit/proxy/controllers/test_base.py index 1ab0037fa4..b241a5cec1 100644 --- a/test/unit/proxy/controllers/test_base.py +++ b/test/unit/proxy/controllers/test_base.py @@ -209,7 +209,8 @@ class TestFuncs(unittest.TestCase): self.assertEqual(info_c['object_count'], 1000) # Make sure the env cache is set 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()} self.assertEqual(env['swift.infocache'].get('account/a'), exp_cached_info_a) @@ -340,7 +341,7 @@ class TestFuncs(unittest.TestCase): req = Request.blank("/v1/AUTH_account/cont", environ={'swift.cache': FakeCache({})}) 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['object_count'], 1000) @@ -365,7 +366,7 @@ class TestFuncs(unittest.TestCase): req = Request.blank("/v1/account/cont", environ={'swift.cache': FakeCache(cache_stub)}) 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['object_count'], 10) self.assertEqual(resp['status'], 404)