Merge "Add networks to quota's update json-schema when network quota enabled"

This commit is contained in:
Jenkins
2016-08-30 11:59:39 +00:00
committed by Gerrit Code Review
3 changed files with 26 additions and 0 deletions
+11
View File
@@ -26,6 +26,7 @@ from nova.api.openstack.compute.schemas import quota_sets
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api import validation
import nova.conf
from nova import exception
from nova.i18n import _
from nova import objects
@@ -33,6 +34,7 @@ from nova.policies import quota_sets as qs_policies
from nova import quota
CONF = nova.conf.CONF
ALIAS = "os-quota-sets"
QUOTAS = quota.QUOTAS
@@ -140,6 +142,15 @@ class QuotaSetsController(wsgi.Controller):
user_id = params.get('user_id', [None])[0]
quota_set = body['quota_set']
# NOTE(alex_xu): The CONF.enable_network_quota was deprecated due to
# it is only used by nova-network, and nova-network will be deprecated
# also. So when CONF.enable_newtork_quota is removed, the networks
# quota will disappeare also.
if not CONF.enable_network_quota and 'networks' in quota_set:
raise webob.exc.HTTPBadRequest(
explanation=_('The networks quota is disabled'))
force_update = strutils.bool_from_string(quota_set.get('force',
'False'))
settable_quotas = QUOTAS.get_settable_quotas(context, project_id,
@@ -40,6 +40,7 @@ quota_resources = {
'injected_file_path_bytes': common_quota,
'server_groups': common_quota,
'server_group_members': common_quota,
'networks': common_quota
}
update_quota_set = copy.deepcopy(quota_resources)
@@ -50,6 +51,7 @@ del update_quota_set_v236['fixed_ips']
del update_quota_set_v236['floating_ips']
del update_quota_set_v236['security_groups']
del update_quota_set_v236['security_group_rules']
del update_quota_set_v236['networks']
update = {
'type': 'object',
@@ -280,6 +280,19 @@ class QuotaSetsTestV21(BaseQuotaSetsTest):
self.mox.VerifyAll()
self.assertEqual(202, self.get_delete_status_int(res))
def test_update_network_quota_disabled(self):
self.flags(enable_network_quota=False)
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
self._get_http_request(),
1234, body={'quota_set': {'networks': 1}})
def test_update_network_quota_enabled(self):
self.flags(enable_network_quota=True)
tenant_networks._register_network_quota()
self.controller.update(self._get_http_request(),
1234, body={'quota_set': {'networks': 1}})
del quota.QUOTAS._resources['networks']
class ExtendedQuotasTestV21(BaseQuotaSetsTest):
plugin = quotas_v21