Skip to content

Commit 1c6d396

Browse files
committed
Allow "--force" flag in quota network commands
This flag allows to set a new Neutron quota resource limit without checking first the current resource usage. The new limit will be set anyway. This flag was used only by the compute engine. Related-Bug: #1953170 Change-Id: I7084f8208b804236ac99e6842db7a45854ce54d7
1 parent e91e0e0 commit 1c6d396

4 files changed

Lines changed: 57 additions & 1 deletion

File tree

openstackclient/common/quota.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ def get_parser(self, prog_name):
533533
parser.add_argument(
534534
'--force',
535535
action='store_true',
536-
help=_('Force quota update (only supported by compute)')
536+
help=_('Force quota update (only supported by compute and '
537+
'network)')
537538
)
538539
parser.add_argument(
539540
'--check-limit',
@@ -569,6 +570,8 @@ def take_action(self, parsed_args):
569570
network_kwargs = {}
570571
if parsed_args.check_limit:
571572
network_kwargs['check_limit'] = True
573+
if parsed_args.force:
574+
network_kwargs['force'] = True
572575

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

openstackclient/tests/functional/common/test_quota.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,21 @@ def test_quota_set_class(self):
169169
self.assertTrue(cmd_output["key-pairs"] >= 0)
170170
self.assertTrue(cmd_output["snapshots"] >= 0)
171171

172+
def _restore_quota_limit(self, resource, limit, project):
173+
self.openstack('quota set --%s %s %s' % (resource, limit, project))
174+
172175
def test_quota_network_set_with_check_limit(self):
173176
if not self.haz_network:
174177
self.skipTest('No Network service present')
175178
if not self.is_extension_enabled('quota-check-limit'):
176179
self.skipTest('No "quota-check-limit" extension present')
177180

181+
cmd_output = json.loads(self.openstack(
182+
'quota list -f json --network'
183+
))
184+
self.addCleanup(self._restore_quota_limit, 'network',
185+
cmd_output[0]['Networks'], self.PROJECT_NAME)
186+
178187
self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
179188
cmd_output = json.loads(self.openstack(
180189
'quota list -f json --network'
@@ -190,3 +199,41 @@ def test_quota_network_set_with_check_limit(self):
190199
self.assertRaises(exceptions.CommandFailed, self.openstack,
191200
'quota set --networks 1 --check-limit ' +
192201
self.PROJECT_NAME)
202+
203+
def test_quota_network_set_with_force(self):
204+
if not self.haz_network:
205+
self.skipTest('No Network service present')
206+
# NOTE(ralonsoh): the Neutron support for the flag "check-limit" was
207+
# added with the extension "quota-check-limit". The flag "force" was
208+
# added too in order to change the behaviour of Neutron quota engine
209+
# and mimic the Nova one: by default the engine will check the resource
210+
# usage before setting the new limit; with "force", this check will be
211+
# skipped (in Yoga, this behaviour is still NOT the default in
212+
# Neutron).
213+
if not self.is_extension_enabled('quota-check-limit'):
214+
self.skipTest('No "quota-check-limit" extension present')
215+
216+
cmd_output = json.loads(self.openstack(
217+
'quota list -f json --network'
218+
))
219+
self.addCleanup(self._restore_quota_limit, 'network',
220+
cmd_output[0]['Networks'], self.PROJECT_NAME)
221+
222+
self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
223+
cmd_output = json.loads(self.openstack(
224+
'quota list -f json --network'
225+
))
226+
self.assertIsNotNone(cmd_output)
227+
self.assertEqual(40, cmd_output[0]['Networks'])
228+
229+
# That will ensure we have at least two networks in the system.
230+
for _ in range(2):
231+
self.openstack('network create --project %s %s' %
232+
(self.PROJECT_NAME, uuid.uuid4().hex))
233+
234+
self.openstack('quota set --networks 1 --force ' + self.PROJECT_NAME)
235+
cmd_output = json.loads(self.openstack(
236+
'quota list -f json --network'
237+
))
238+
self.assertIsNotNone(cmd_output)
239+
self.assertEqual(1, cmd_output[0]['Networks'])

openstackclient/tests/unit/common/test_quota.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ def test_quota_set_with_force(self):
935935
}
936936
kwargs_network = {
937937
'subnet': network_fakes.QUOTA['subnet'],
938+
'force': True,
938939
}
939940
self.compute_quotas_mock.update.assert_called_once_with(
940941
self.projects[0].id,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- Add ``--force`` options to the ``openstack quota set`` command for network
4+
service commands. Neutron quota engine now accepts "force" flag to set
5+
a new resource quota limit, regardless of the current resource usage.

0 commit comments

Comments
 (0)