]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Cast the quota set values to integer before checking their validity
authorSylvain Baubeau <sylvain.baubeau@enovance.com>
Fri, 14 Feb 2014 17:13:50 +0000 (18:13 +0100)
committerSylvain Baubeau <sylvain.baubeau@enovance.com>
Fri, 14 Feb 2014 17:13:50 +0000 (18:13 +0100)
Change-Id: I56409607d435a5e2ff702ccb9f19c5d12b432570
Closes-Bug: #1280159

cinder/api/contrib/quotas.py

index 3dd9919b4348485e423c0adcdc3a3e164de79ff4..ae56ca48bba36a0abd3d5f80db1b2ee3d5615c12 100644 (file)
@@ -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: