]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Merge "Add valid check and unit tests on quota class"
authorJenkins <jenkins@review.openstack.org>
Fri, 22 Nov 2013 05:06:05 +0000 (05:06 +0000)
committerGerrit Code Review <review@openstack.org>
Fri, 22 Nov 2013 05:06:05 +0000 (05:06 +0000)
1  2 
cinder/api/contrib/quota_classes.py

index 72bffcb2e855c8ba90cfac6a349fa98c58cfff9b,8d4b8ebf87ea1371bd2b448dad10c3d772743b41..c7e6d5f167fe5a7f582e58a455b47987daddd2af
@@@ -68,14 -68,17 +68,22 @@@ class QuotaClassSetsController(wsgi.Con
          context = req.environ['cinder.context']
          authorize(context)
          quota_class = id
 +        if not self.is_valid_body(body, 'quota_class_set'):
 +            msg = (_("Missing required element quota_class_set"
 +                     " in request body."))
 +            raise webob.exc.HTTPBadRequest(explanation=msg)
 +
          for key in body['quota_class_set'].keys():
              if key in QUOTAS:
-                 value = int(body['quota_class_set'][key])
+                 try:
+                     value = int(body['quota_class_set'][key])
+                 except ValueError:
+                     msg = _("Quota class limit must be specified as an"
+                             " integer value.")
+                     raise webob.exc.HTTPBadRequest(explanation=msg)
+                 if value < -1:
+                     msg = _("Quota class limit must be -1 or greater.")
+                     raise webob.exc.HTTPBadRequest(explanation=msg)
                  try:
                      db.quota_class_update(context, quota_class, key, value)
                  except exception.QuotaClassNotFound: