From: Seif Lotfy Date: Fri, 9 Aug 2013 13:37:38 +0000 (+0000) Subject: Fix ratelimiting X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2acb6f329bb404e224e525b946c0aa6cdc74040c;p=openstack-build%2Fcinder-build.git Fix ratelimiting Current master does now respect ratelimiting, since parsing of the api-paste.ini was faulty. api-paste.ini limited user limiting by setting a line as follows: user::(GET, *, ".*", 4, minute) which was passed to the Limiter as kwargs with "user" as a key. Thus multiple user limiting was not possible as well as extracting the id of the user was bound to fail, since we checked on the key with startswith("user:") An example config in the api-paste.ini has to look as follows: limits = (POST, "*", .*, 10, MINUTE) limits.:(GET, "*", .*, 4, minute) limits.:(GET, "*", .*, 2, minute) Fixes bug: 1206976 Change-Id: I4adbe3dbe3a0bd607d6e675f230b0442b08ec791 --- diff --git a/cinder/api/v1/limits.py b/cinder/api/v1/limits.py index b8a0ad848..f108b1b15 100644 --- a/cinder/api/v1/limits.py +++ b/cinder/api/v1/limits.py @@ -292,8 +292,8 @@ class Limiter(object): # Pick up any per-user limit information for key, value in kwargs.items(): - if key.startswith('user:'): - username = key[5:] + if key.startswith('limits.'): + username = key[7:] self.levels[username] = self.parse_limits(value) def get_limits(self, username=None): diff --git a/cinder/api/v2/limits.py b/cinder/api/v2/limits.py index b8a0ad848..f108b1b15 100644 --- a/cinder/api/v2/limits.py +++ b/cinder/api/v2/limits.py @@ -292,8 +292,8 @@ class Limiter(object): # Pick up any per-user limit information for key, value in kwargs.items(): - if key.startswith('user:'): - username = key[5:] + if key.startswith('limits.'): + username = key[7:] self.levels[username] = self.parse_limits(value) def get_limits(self, username=None): diff --git a/cinder/tests/api/v1/test_limits.py b/cinder/tests/api/v1/test_limits.py index 873f747ec..816ba08da 100644 --- a/cinder/tests/api/v1/test_limits.py +++ b/cinder/tests/api/v1/test_limits.py @@ -406,7 +406,7 @@ class LimiterTest(BaseLimitTestSuite): def setUp(self): """Run before each test.""" super(LimiterTest, self).setUp() - userlimits = {'user:user3': ''} + userlimits = {'limits.user3': ''} self.limiter = limits.Limiter(TEST_LIMITS, **userlimits) def _check(self, num, verb, url, username=None): diff --git a/cinder/tests/api/v2/test_limits.py b/cinder/tests/api/v2/test_limits.py index ec7c152fb..9b58d51de 100644 --- a/cinder/tests/api/v2/test_limits.py +++ b/cinder/tests/api/v2/test_limits.py @@ -406,7 +406,7 @@ class LimiterTest(BaseLimitTestSuite): def setUp(self): """Run before each test.""" super(LimiterTest, self).setUp() - userlimits = {'user:user3': ''} + userlimits = {'limits.user3': ''} self.limiter = limits.Limiter(TEST_LIMITS, **userlimits) def _check(self, num, verb, url, username=None):