From 09ff9a0f4c118f50924d2fc078d6a4501e696224 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 29 Nov 2021 11:26:13 +0000 Subject: [PATCH] quota: Deprecate "force" behavior for network quotas In change Idc1b99492d609eb699d0a6bef6cd760458a774f6, we added a '--check-limit' option to enable "no force" behavior for network quotas. This was already the default for compute quotas. Provide a path for harmonizing the behavior of the two options by instead using a '--no-force' option which will become the eventual default for the network quotas also. Change-Id: I25828a3d68e2e900f498e17a0d01fb70be77548e Signed-off-by: Stephen Finucane --- openstackclient/common/quota.py | 51 +++++++++++++++---- .../tests/functional/common/test_quota.py | 4 +- .../tests/unit/common/test_quota.py | 7 +-- ...no-force-limit-quota-cc7f291dd1b537c1.yaml | 13 +++++ 4 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 releasenotes/notes/no-force-limit-quota-cc7f291dd1b537c1.yaml diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index 10f40a75d4..510437ddd5 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -15,6 +15,7 @@ """Quota action implementations""" +import argparse import itertools import logging import sys @@ -621,20 +622,37 @@ class SetQuota(common.NetDetectionMixin, command.Command): metavar='', help=_('Set quotas for a specific '), ) - parser.add_argument( + force_group = parser.add_mutually_exclusive_group() + force_group.add_argument( '--force', action='store_true', + dest='force', + # TODO(stephenfin): Change the default to False in Z or later + default=None, help=_( - 'Force quota update (only supported by compute and network)' + 'Force quota update (only supported by compute and network) ' + '(default for network)' ), ) - parser.add_argument( - '--check-limit', - action='store_true', + force_group.add_argument( + '--no-force', + action='store_false', + dest='force', + default=None, help=_( - 'Check quota limit when updating (only supported by network)' + 'Do not force quota update ' + '(only supported by compute and network) ' + '(default for compute)' ), ) + # kept here for backwards compatibility/to keep the neutron folks happy + force_group.add_argument( + '--check-limit', + action='store_false', + dest='force', + default=None, + help=argparse.SUPPRESS, + ) return parser def take_action(self, parsed_args): @@ -657,8 +675,8 @@ class SetQuota(common.NetDetectionMixin, command.Command): if value is not None: compute_kwargs[k] = value - if parsed_args.force: - compute_kwargs['force'] = True + if parsed_args.force is not None: + compute_kwargs['force'] = parsed_args.force volume_kwargs = {} for k, v in VOLUME_QUOTAS.items(): @@ -669,10 +687,21 @@ class SetQuota(common.NetDetectionMixin, command.Command): volume_kwargs[k] = value network_kwargs = {} - if parsed_args.check_limit: - network_kwargs['check_limit'] = True - if parsed_args.force: + if parsed_args.force is True: + # Unlike compute, network doesn't provide a simple boolean option. + # Instead, it provides two options: 'force' and 'check_limit' + # (a.k.a. 'not force') network_kwargs['force'] = True + elif parsed_args.force is False: + network_kwargs['check_limit'] = True + else: + msg = _( + "This command currently defaults to '--force' when modifying " + "network quotas. This behavior will change in a future " + "release. Consider explicitly providing '--force' or " + "'--no-force' options to avoid changes in behavior." + ) + self.log.warning(msg) if self.app.client_manager.is_network_endpoint_enabled(): for k, v in NETWORK_QUOTAS.items(): diff --git a/openstackclient/tests/functional/common/test_quota.py b/openstackclient/tests/functional/common/test_quota.py index 08ec626f86..9089cba5c0 100644 --- a/openstackclient/tests/functional/common/test_quota.py +++ b/openstackclient/tests/functional/common/test_quota.py @@ -176,7 +176,7 @@ class QuotaTests(base.TestCase): def _restore_quota_limit(self, resource, limit, project): self.openstack('quota set --%s %s %s' % (resource, limit, project)) - def test_quota_network_set_with_check_limit(self): + def test_quota_network_set_with_no_force(self): if not self.haz_network: self.skipTest('No Network service present') if not self.is_extension_enabled('quota-check-limit'): @@ -201,7 +201,7 @@ class QuotaTests(base.TestCase): (self.PROJECT_NAME, uuid.uuid4().hex)) self.assertRaises(exceptions.CommandFailed, self.openstack, - 'quota set --networks 1 --check-limit ' + + 'quota set --networks 1 --no-force ' + self.PROJECT_NAME) def test_quota_network_set_with_force(self): diff --git a/openstackclient/tests/unit/common/test_quota.py b/openstackclient/tests/unit/common/test_quota.py index 0900200e96..320e6b51b3 100644 --- a/openstackclient/tests/unit/common/test_quota.py +++ b/openstackclient/tests/unit/common/test_quota.py @@ -985,19 +985,19 @@ class TestQuotaSet(TestQuota): ) self.assertIsNone(result) - def test_quota_set_with_check_limit(self): + def test_quota_set_with_no_force(self): arglist = [ '--subnets', str(network_fakes.QUOTA['subnet']), '--volumes', str(volume_fakes.QUOTA['volumes']), '--cores', str(compute_fakes.core_num), - '--check-limit', + '--no-force', self.projects[0].name, ] verifylist = [ ('subnet', network_fakes.QUOTA['subnet']), ('volumes', volume_fakes.QUOTA['volumes']), ('cores', compute_fakes.core_num), - ('check_limit', True), + ('force', False), ('project', self.projects[0].name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -1006,6 +1006,7 @@ class TestQuotaSet(TestQuota): kwargs_compute = { 'cores': compute_fakes.core_num, + 'force': False, } kwargs_volume = { 'volumes': volume_fakes.QUOTA['volumes'], diff --git a/releasenotes/notes/no-force-limit-quota-cc7f291dd1b537c1.yaml b/releasenotes/notes/no-force-limit-quota-cc7f291dd1b537c1.yaml new file mode 100644 index 0000000000..53b7eb8d3b --- /dev/null +++ b/releasenotes/notes/no-force-limit-quota-cc7f291dd1b537c1.yaml @@ -0,0 +1,13 @@ +--- +features: + - Add ``--no-force`` option to the ``openstack quota set`` command (only + for compute and network commands). When specified, the compute and network + quota engine will check the resource usage before setting the new quota + limit. This is the default behavior of the compute quota engine and will + become the default for the network quota engine in a future release. +deprecations: + - The ``openstack quota set`` command currently defaults to ``--force`` + behavior for network quotas. This behavior is now deprecated and a future + release will switch to ``--no-force`` behavior. Users should explicitly + specify one of these options to prevent a potentially breaking change in + behavior.