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
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
@ -52,6 +54,8 @@ class QuotaSetsController(wsgi.Controller):
|
|||||||
attr_dict[quota_resource] = {'allow_post': False,
|
attr_dict[quota_resource] = {'allow_post': False,
|
||||||
'allow_put': True,
|
'allow_put': True,
|
||||||
'convert_to': convert_to_int,
|
'convert_to': convert_to_int,
|
||||||
|
'validate': {'type:range':
|
||||||
|
[-1, sys.maxsize]},
|
||||||
'is_visible': True}
|
'is_visible': True}
|
||||||
self._update_extended_attributes = False
|
self._update_extended_attributes = False
|
||||||
|
|
||||||
@ -98,7 +102,7 @@ class QuotaSetsController(wsgi.Controller):
|
|||||||
body = base.Controller.prepare_request_body(
|
body = base.Controller.prepare_request_body(
|
||||||
request.context, body, False, self._resource_name,
|
request.context, body, False, self._resource_name,
|
||||||
EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION])
|
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)
|
self._driver.update_quota_limit(request.context, id, key, value)
|
||||||
return {self._resource_name: self._get_quotas(request, id)}
|
return {self._resource_name: self._get_quotas(request, id)}
|
||||||
|
|
||||||
|
@ -175,6 +175,36 @@ class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
|
|||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(400, res.status_int)
|
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):
|
def test_update_quotas_with_non_support_resource_returns_400(self):
|
||||||
tenant_id = 'tenant_id1'
|
tenant_id = 'tenant_id1'
|
||||||
env = {'quantum.context': context.Context('', tenant_id,
|
env = {'quantum.context': context.Context('', tenant_id,
|
||||||
@ -251,26 +281,12 @@ class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
|
|||||||
tenant_id,
|
tenant_id,
|
||||||
network=4)
|
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):
|
def test_quotas_limit_check_with_invalid_quota_value(self):
|
||||||
tenant_id = 'tenant_id1'
|
tenant_id = 'tenant_id1'
|
||||||
with testtools.ExpectedException(exceptions.InvalidQuotaValue):
|
with testtools.ExpectedException(exceptions.InvalidQuotaValue):
|
||||||
quota.QUOTAS.limit_check(context.Context('', tenant_id),
|
quota.QUOTAS.limit_check(context.Context('', tenant_id),
|
||||||
tenant_id,
|
tenant_id,
|
||||||
network=-1)
|
network=-2)
|
||||||
|
|
||||||
def test_quotas_get_tenant_from_request_context(self):
|
def test_quotas_get_tenant_from_request_context(self):
|
||||||
tenant_id = 'tenant_id1'
|
tenant_id = 'tenant_id1'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user