diff --git a/nova/api/openstack/compute/quota_sets.py b/nova/api/openstack/compute/quota_sets.py index bf5adaad98..e9d4a7e6c0 100644 --- a/nova/api/openstack/compute/quota_sets.py +++ b/nova/api/openstack/compute/quota_sets.py @@ -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, diff --git a/nova/api/openstack/compute/schemas/quota_sets.py b/nova/api/openstack/compute/schemas/quota_sets.py index f4ae63cf11..38a9f80e25 100644 --- a/nova/api/openstack/compute/schemas/quota_sets.py +++ b/nova/api/openstack/compute/schemas/quota_sets.py @@ -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', diff --git a/nova/tests/unit/api/openstack/compute/test_quotas.py b/nova/tests/unit/api/openstack/compute/test_quotas.py index 317970d9d7..2c595fdfba 100644 --- a/nova/tests/unit/api/openstack/compute/test_quotas.py +++ b/nova/tests/unit/api/openstack/compute/test_quotas.py @@ -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