diff options
| author | Kevin L. Mitchell <kevin.mitchell@rackspace.com> | 2011-07-14 11:37:32 -0500 |
|---|---|---|
| committer | Kevin L. Mitchell <kevin.mitchell@rackspace.com> | 2011-07-14 11:37:32 -0500 |
| commit | cbf05e0b6351c9577e7e992da072d190c8c9a592 (patch) | |
| tree | 967e1dacb75475ef3bc3174a9b7aabf1473b053e /nova/api | |
| parent | 6daf6d30dfeab459a0b672d909b115b1a5ce86c3 (diff) | |
| download | nova-cbf05e0b6351c9577e7e992da072d190c8c9a592.tar.gz nova-cbf05e0b6351c9577e7e992da072d190c8c9a592.tar.xz nova-cbf05e0b6351c9577e7e992da072d190c8c9a592.zip | |
Comment on parse_limits(); expand an exception message; add unit tests; fix a minor discovered bug
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/limits.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/nova/api/openstack/limits.py b/nova/api/openstack/limits.py index 8642a28f9..bc76547d8 100644 --- a/nova/api/openstack/limits.py +++ b/nova/api/openstack/limits.py @@ -327,6 +327,11 @@ class Limiter(object): return None, None + # Note: This method gets called before the class is instantiated, + # so this must be either a static method or a class method. It is + # used to develop a list of limits to feed to the constructor. We + # put this in the class so that subclasses can override the + # default limit parsing. @staticmethod def parse_limits(limits): """ @@ -351,14 +356,16 @@ class Limiter(object): result = [] for group in limits.split(';'): group = group.strip() - if group[0] != '(' or group[-1] != ')': - raise ValueError("Groups must be surrounded by parentheses") + if group[:1] != '(' or group[-1:] != ')': + raise ValueError("Limit rules must be surrounded by " + "parentheses") group = group[1:-1] # Extract the Limit arguments args = [a.strip() for a in group.split(',')] if len(args) != 5: - raise ValueError("Groups must contain exactly 5 elements") + raise ValueError("Limit rules must contain the following " + "arguments: verb, uri, regex, value, unit") # Pull out the arguments verb, uri, regex, value, unit = args @@ -464,6 +471,11 @@ class WsgiLimiterProxy(object): return resp.getheader("X-Wait-Seconds"), resp.read() or None + # Note: This method gets called before the class is instantiated, + # so this must be either a static method or a class method. It is + # used to develop a list of limits to feed to the constructor. + # This implementation returns an empty list, since all limit + # decisions are made by a remote server. @staticmethod def parse_limits(limits): """ |
