Skip to content

Commit 837cbfb

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "quota: Deprecate "force" behavior for network quotas"
2 parents b0b4747 + 09ff9a0 commit 837cbfb

File tree

4 files changed

+59
-16
lines changed

4 files changed

+59
-16
lines changed

openstackclient/common/quota.py

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
"""Quota action implementations"""
1717

18+
import argparse
1819
import itertools
1920
import logging
2021
import sys
@@ -621,20 +622,37 @@ def get_parser(self, prog_name):
621622
metavar='<volume-type>',
622623
help=_('Set quotas for a specific <volume-type>'),
623624
)
624-
parser.add_argument(
625+
force_group = parser.add_mutually_exclusive_group()
626+
force_group.add_argument(
625627
'--force',
626628
action='store_true',
629+
dest='force',
630+
# TODO(stephenfin): Change the default to False in Z or later
631+
default=None,
627632
help=_(
628-
'Force quota update (only supported by compute and network)'
633+
'Force quota update (only supported by compute and network) '
634+
'(default for network)'
629635
),
630636
)
631-
parser.add_argument(
632-
'--check-limit',
633-
action='store_true',
637+
force_group.add_argument(
638+
'--no-force',
639+
action='store_false',
640+
dest='force',
641+
default=None,
634642
help=_(
635-
'Check quota limit when updating (only supported by network)'
643+
'Do not force quota update '
644+
'(only supported by compute and network) '
645+
'(default for compute)'
636646
),
637647
)
648+
# kept here for backwards compatibility/to keep the neutron folks happy
649+
force_group.add_argument(
650+
'--check-limit',
651+
action='store_false',
652+
dest='force',
653+
default=None,
654+
help=argparse.SUPPRESS,
655+
)
638656
return parser
639657

640658
def take_action(self, parsed_args):
@@ -657,8 +675,8 @@ def take_action(self, parsed_args):
657675
if value is not None:
658676
compute_kwargs[k] = value
659677

660-
if parsed_args.force:
661-
compute_kwargs['force'] = True
678+
if parsed_args.force is not None:
679+
compute_kwargs['force'] = parsed_args.force
662680

663681
volume_kwargs = {}
664682
for k, v in VOLUME_QUOTAS.items():
@@ -669,10 +687,21 @@ def take_action(self, parsed_args):
669687
volume_kwargs[k] = value
670688

671689
network_kwargs = {}
672-
if parsed_args.check_limit:
673-
network_kwargs['check_limit'] = True
674-
if parsed_args.force:
690+
if parsed_args.force is True:
691+
# Unlike compute, network doesn't provide a simple boolean option.
692+
# Instead, it provides two options: 'force' and 'check_limit'
693+
# (a.k.a. 'not force')
675694
network_kwargs['force'] = True
695+
elif parsed_args.force is False:
696+
network_kwargs['check_limit'] = True
697+
else:
698+
msg = _(
699+
"This command currently defaults to '--force' when modifying "
700+
"network quotas. This behavior will change in a future "
701+
"release. Consider explicitly providing '--force' or "
702+
"'--no-force' options to avoid changes in behavior."
703+
)
704+
self.log.warning(msg)
676705

677706
if self.app.client_manager.is_network_endpoint_enabled():
678707
for k, v in NETWORK_QUOTAS.items():

openstackclient/tests/functional/common/test_quota.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_quota_set_class(self):
176176
def _restore_quota_limit(self, resource, limit, project):
177177
self.openstack('quota set --%s %s %s' % (resource, limit, project))
178178

179-
def test_quota_network_set_with_check_limit(self):
179+
def test_quota_network_set_with_no_force(self):
180180
if not self.haz_network:
181181
self.skipTest('No Network service present')
182182
if not self.is_extension_enabled('quota-check-limit'):
@@ -201,7 +201,7 @@ def test_quota_network_set_with_check_limit(self):
201201
(self.PROJECT_NAME, uuid.uuid4().hex))
202202

203203
self.assertRaises(exceptions.CommandFailed, self.openstack,
204-
'quota set --networks 1 --check-limit ' +
204+
'quota set --networks 1 --no-force ' +
205205
self.PROJECT_NAME)
206206

207207
def test_quota_network_set_with_force(self):

openstackclient/tests/unit/common/test_quota.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -983,19 +983,19 @@ def test_quota_set_with_force(self):
983983
)
984984
self.assertIsNone(result)
985985

986-
def test_quota_set_with_check_limit(self):
986+
def test_quota_set_with_no_force(self):
987987
arglist = [
988988
'--subnets', str(network_fakes.QUOTA['subnet']),
989989
'--volumes', str(volume_fakes.QUOTA['volumes']),
990990
'--cores', str(compute_fakes.core_num),
991-
'--check-limit',
991+
'--no-force',
992992
self.projects[0].name,
993993
]
994994
verifylist = [
995995
('subnet', network_fakes.QUOTA['subnet']),
996996
('volumes', volume_fakes.QUOTA['volumes']),
997997
('cores', compute_fakes.core_num),
998-
('check_limit', True),
998+
('force', False),
999999
('project', self.projects[0].name),
10001000
]
10011001
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -1004,6 +1004,7 @@ def test_quota_set_with_check_limit(self):
10041004

10051005
kwargs_compute = {
10061006
'cores': compute_fakes.core_num,
1007+
'force': False,
10071008
}
10081009
kwargs_volume = {
10091010
'volumes': volume_fakes.QUOTA['volumes'],
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
features:
3+
- Add ``--no-force`` option to the ``openstack quota set`` command (only
4+
for compute and network commands). When specified, the compute and network
5+
quota engine will check the resource usage before setting the new quota
6+
limit. This is the default behavior of the compute quota engine and will
7+
become the default for the network quota engine in a future release.
8+
deprecations:
9+
- The ``openstack quota set`` command currently defaults to ``--force``
10+
behavior for network quotas. This behavior is now deprecated and a future
11+
release will switch to ``--no-force`` behavior. Users should explicitly
12+
specify one of these options to prevent a potentially breaking change in
13+
behavior.

0 commit comments

Comments
 (0)