From 767b3db4116e7fba8275c67c2a4d7caad0bf647b Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Wed, 27 Jul 2016 09:54:34 +0800 Subject: [PATCH] Add networks to quota's update json-schema when network quota enabled The enable of network quota is configurable. But the json-schema of quota update won't be updated accroding configuration. This leads to user can't update network quota from API. This patch add network quota when it's enabled. Change-Id: I922525bfe55c42d2bf187c3bcd30536c8adf1c4f Closes-Bug: #1606740 --- nova/api/openstack/compute/quota_sets.py | 11 +++++++++++ nova/api/openstack/compute/schemas/quota_sets.py | 2 ++ .../tests/unit/api/openstack/compute/test_quotas.py | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/nova/api/openstack/compute/quota_sets.py b/nova/api/openstack/compute/quota_sets.py index 4236ae2877..5a8a104551 100644 --- a/nova/api/openstack/compute/quota_sets.py +++ b/nova/api/openstack/compute/quota_sets.py @@ -25,6 +25,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 @@ -32,6 +33,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 @@ -155,6 +157,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