Container info memcache change broke ratelimiting.

Change-Id: I6379db52a75ed40080dd220f7fa72bcaffd0953c
This commit is contained in:
David Goetz 2013-04-24 12:46:13 -07:00
parent 7f534fac38
commit 449363653e
2 changed files with 8 additions and 3 deletions

View File

@ -121,7 +121,7 @@ class RateLimitMiddleware(object):
container_info = self.memcache_client.get(memcache_key)
if isinstance(container_info, dict):
container_size = container_info.get(
'count', container_info.get('container_size', 0))
'object_count', container_info.get('container_size', 0))
container_rate = self.get_container_maxrate(container_size)
if container_rate:
keys.append(("ratelimit/%s/%s" % (account_name,

View File

@ -21,7 +21,8 @@ from threading import Thread
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_container_memcache_key, \
headers_to_container_info
from swift.common.memcached import MemcacheConnectionError
from swift.common.swob import Request
@ -184,7 +185,7 @@ class TestRateLimit(unittest.TestCase):
'container_ratelimit_3': 200}
fake_memcache = FakeMemcache()
fake_memcache.store[get_container_memcache_key('a', 'c')] = \
{'count': 5}
{'object_count': '5'}
the_app = ratelimit.RateLimitMiddleware(None, conf_dict,
logger=FakeLogger())
the_app.memcache_client = fake_memcache
@ -199,6 +200,10 @@ class TestRateLimit(unittest.TestCase):
self.assertEquals(len(the_app.get_ratelimitable_key_tuples(
'PUT', 'a', 'c', 'o')), 1)
def test_memcached_container_info_dict(self):
mdict = headers_to_container_info({'x-container-object-count': '45'})
self.assertEquals(mdict['object_count'], '45')
def test_ratelimit_old_memcache_format(self):
current_rate = 13
conf_dict = {'account_ratelimit': current_rate,