Merge "Validate maximum limit for quota"

This commit is contained in:
Jenkins 2015-07-16 18:11:48 +00:00 committed by Gerrit Code Review
commit 09aa893e93
2 changed files with 16 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import webob
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
import nova.context
from nova import db
from nova import exception
from nova.i18n import _
from nova import objects
@ -65,11 +66,16 @@ class QuotaSetsController(wsgi.Controller):
return dict(quota_set=result)
def _validate_quota_limit(self, resource, limit, minimum, maximum):
# NOTE: -1 is a flag value for unlimited
if limit < -1:
# NOTE: -1 is a flag value for unlimited, maximum value is limited
# by SQL standard integer type `INT` which is `0x7FFFFFFF`, it's a
# general value for SQL, using a hardcoded value here is not a
# `nice` way, but it seems like the only way for now:
# http://dev.mysql.com/doc/refman/5.0/en/integer-types.html
# http://www.postgresql.org/docs/9.1/static/datatype-numeric.html
if limit < -1 or limit > db.MAX_INT:
msg = (_("Quota limit %(limit)s for %(resource)s "
"must be -1 or greater.") %
{'limit': limit, 'resource': resource})
"must be in the range of -1 and %(max)s.") %
{'limit': limit, 'resource': resource, 'max': db.MAX_INT})
raise webob.exc.HTTPBadRequest(explanation=msg)
def conv_inf(value):

View File

@ -22,6 +22,7 @@ import webob
from nova.api.openstack.compute.contrib import quotas as quotas_v2
from nova.api.openstack.compute.plugins.v3 import quota_sets as quotas_v21
from nova.api.openstack import extensions
from nova import db
from nova import exception
from nova import quota
from nova import test
@ -167,6 +168,11 @@ class QuotaSetsTestV21(BaseQuotaSetsTest):
self.controller._validate_quota_limit,
resource, 50, -1, -1)
# Invalid - limit is larger than 0x7FFFFFFF
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._validate_quota_limit,
resource, db.MAX_INT + 1, -1, -1)
def test_quotas_defaults(self):
uri = '/v2/fake_tenant/os-quota-sets/fake_tenant/defaults'