Fixed bug with account_info

There was a bug where account_info wasn't converting the
container_count value to an int. Causes max container count cap to
get hit pretty quick since '0' > 0.

Change-Id: Ibfc6eebbff5a00aaebb47e9731dd053b60e3caa4
This commit is contained in:
gholt 2013-03-12 19:15:35 +00:00
parent 5e427e5e3b
commit f6d1fa1c15
2 changed files with 36 additions and 3 deletions

View File

@ -387,7 +387,10 @@ class Controller(object):
container_count = 0
else:
result_code = cache_value['status']
container_count = cache_value['container_count']
try:
container_count = int(cache_value['container_count'])
except ValueError:
container_count = 0
if result_code == HTTP_OK:
return partition, nodes, container_count
elif result_code == HTTP_NOT_FOUND and not autocreate:
@ -456,7 +459,11 @@ class Controller(object):
account_info,
time=cache_timeout)
if result_code == HTTP_OK:
return partition, nodes, account_info['container_count']
try:
container_count = int(account_info['container_count'])
except ValueError:
container_count = 0
return partition, nodes, container_count
return None, None, None
def container_info(self, account, container, account_autocreate=False):

View File

@ -247,7 +247,7 @@ def fake_http_connect(*code_iter, **kwargs):
'x-object-meta-test': 'testing',
'etag': etag,
'x-works': 'yes',
'x-account-container-count': 12345}
'x-account-container-count': kwargs.get('count', 12345)}
if not self.timestamp:
del headers['x-timestamp']
try:
@ -445,6 +445,32 @@ class TestController(unittest.TestCase):
self.assertEqual(p, partition)
self.assertEqual(n, nodes)
def test_account_info_container_count(self):
with save_globals():
set_http_connect(200, count=123)
partition, nodes, count = \
self.controller.account_info(self.account)
self.assertEquals(count, 123)
with save_globals():
set_http_connect(200, count='123')
partition, nodes, count = \
self.controller.account_info(self.account)
self.assertEquals(count, 123)
with save_globals():
cache_key = get_account_memcache_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.assertEquals(count, 1234)
with save_globals():
cache_key = get_account_memcache_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.assertEquals(count, 1234)
def test_make_requests(self):
with save_globals():
set_http_connect(200)