Merge "DbQuotaDriver allows negative quotas to be set."
This commit is contained in:
commit
18109293c5
@ -15,6 +15,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from oslo.config import cfg
|
||||
import webob
|
||||
|
||||
@ -52,6 +54,8 @@ class QuotaSetsController(wsgi.Controller):
|
||||
attr_dict[quota_resource] = {'allow_post': False,
|
||||
'allow_put': True,
|
||||
'convert_to': convert_to_int,
|
||||
'validate': {'type:range':
|
||||
[-1, sys.maxsize]},
|
||||
'is_visible': True}
|
||||
self._update_extended_attributes = False
|
||||
|
||||
@ -98,7 +102,7 @@ class QuotaSetsController(wsgi.Controller):
|
||||
body = base.Controller.prepare_request_body(
|
||||
request.context, body, False, self._resource_name,
|
||||
EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION])
|
||||
for key, value in body[self._resource_name].iteritems():
|
||||
for key, value in body[self._resource_name].items():
|
||||
self._driver.update_quota_limit(request.context, id, key, value)
|
||||
return {self._resource_name: self._get_quotas(request, id)}
|
||||
|
||||
|
@ -175,6 +175,36 @@ class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_update_quotas_with_negative_integer_returns_400(self):
|
||||
tenant_id = 'tenant_id1'
|
||||
env = {'quantum.context': context.Context('', tenant_id,
|
||||
is_admin=True)}
|
||||
quotas = {'quota': {'network': -2}}
|
||||
res = self.api.put(_get_path('quotas', id=tenant_id, fmt=self.fmt),
|
||||
self.serialize(quotas), extra_environ=env,
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_update_quotas_to_unlimited(self):
|
||||
tenant_id = 'tenant_id1'
|
||||
env = {'quantum.context': context.Context('', tenant_id,
|
||||
is_admin=True)}
|
||||
quotas = {'quota': {'network': -1}}
|
||||
res = self.api.put(_get_path('quotas', id=tenant_id, fmt=self.fmt),
|
||||
self.serialize(quotas), extra_environ=env,
|
||||
expect_errors=False)
|
||||
self.assertEqual(200, res.status_int)
|
||||
|
||||
def test_update_quotas_exceeding_current_limit(self):
|
||||
tenant_id = 'tenant_id1'
|
||||
env = {'quantum.context': context.Context('', tenant_id,
|
||||
is_admin=True)}
|
||||
quotas = {'quota': {'network': 120}}
|
||||
res = self.api.put(_get_path('quotas', id=tenant_id, fmt=self.fmt),
|
||||
self.serialize(quotas), extra_environ=env,
|
||||
expect_errors=False)
|
||||
self.assertEqual(200, res.status_int)
|
||||
|
||||
def test_update_quotas_with_non_support_resource_returns_400(self):
|
||||
tenant_id = 'tenant_id1'
|
||||
env = {'quantum.context': context.Context('', tenant_id,
|
||||
@ -251,26 +281,12 @@ class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
|
||||
tenant_id,
|
||||
network=4)
|
||||
|
||||
def test_quotas_limit_check_with_over_quota(self):
|
||||
tenant_id = 'tenant_id1'
|
||||
env = {'quantum.context': context.Context('', tenant_id,
|
||||
is_admin=True)}
|
||||
quotas = {'quota': {'network': 5}}
|
||||
res = self.api.put(_get_path('quotas', id=tenant_id,
|
||||
fmt=self.fmt),
|
||||
self.serialize(quotas), extra_environ=env)
|
||||
self.assertEqual(200, res.status_int)
|
||||
with testtools.ExpectedException(exceptions.OverQuota):
|
||||
quota.QUOTAS.limit_check(context.Context('', tenant_id),
|
||||
tenant_id,
|
||||
network=6)
|
||||
|
||||
def test_quotas_limit_check_with_invalid_quota_value(self):
|
||||
tenant_id = 'tenant_id1'
|
||||
with testtools.ExpectedException(exceptions.InvalidQuotaValue):
|
||||
quota.QUOTAS.limit_check(context.Context('', tenant_id),
|
||||
tenant_id,
|
||||
network=-1)
|
||||
network=-2)
|
||||
|
||||
def test_quotas_get_tenant_from_request_context(self):
|
||||
tenant_id = 'tenant_id1'
|
||||
|
Loading…
x
Reference in New Issue
Block a user