From a444ca8646103042d665536796168252a8ca1031 Mon Sep 17 00:00:00 2001 From: Sylvain Baubeau Date: Fri, 14 Feb 2014 18:13:50 +0100 Subject: [PATCH] Cast the quota set values to integer before checking their validity Change-Id: I56409607d435a5e2ff702ccb9f19c5d12b432570 Closes-Bug: #1280159 --- cinder/api/contrib/quotas.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cinder/api/contrib/quotas.py b/cinder/api/contrib/quotas.py index 3dd9919b4..ae56ca48b 100644 --- a/cinder/api/contrib/quotas.py +++ b/cinder/api/contrib/quotas.py @@ -56,7 +56,9 @@ class QuotaSetsController(wsgi.Controller): return dict(quota_set=quota_set) def _validate_quota_limit(self, limit): - if not isinstance(limit, int): + try: + limit = int(limit) + except ValueError: msg = _("Quota limit must be specified as an integer value.") raise webob.exc.HTTPBadRequest(explanation=msg) @@ -65,6 +67,8 @@ class QuotaSetsController(wsgi.Controller): msg = _("Quota limit must be -1 or greater.") raise webob.exc.HTTPBadRequest(explanation=msg) + return limit + def _get_quotas(self, context, id, usages=False): values = QUOTAS.get_project_quotas(context, id, usages=usages) @@ -115,8 +119,7 @@ class QuotaSetsController(wsgi.Controller): if key in NON_QUOTA_KEYS: continue - self._validate_quota_limit(body['quota_set'][key]) - value = int(body['quota_set'][key]) + value = self._validate_quota_limit(body['quota_set'][key]) try: db.quota_update(context, project_id, key, value) except exception.ProjectQuotaNotFound: -- 2.45.2