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
This commit is contained in:
parent
e91e0e001c
commit
1c6d396ba3
@ -533,7 +533,8 @@ class SetQuota(common.NetDetectionMixin, command.Command):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--force',
|
'--force',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help=_('Force quota update (only supported by compute)')
|
help=_('Force quota update (only supported by compute and '
|
||||||
|
'network)')
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--check-limit',
|
'--check-limit',
|
||||||
@ -569,6 +570,8 @@ class SetQuota(common.NetDetectionMixin, command.Command):
|
|||||||
network_kwargs = {}
|
network_kwargs = {}
|
||||||
if parsed_args.check_limit:
|
if parsed_args.check_limit:
|
||||||
network_kwargs['check_limit'] = True
|
network_kwargs['check_limit'] = True
|
||||||
|
if parsed_args.force:
|
||||||
|
network_kwargs['force'] = True
|
||||||
|
|
||||||
if self.app.client_manager.is_network_endpoint_enabled():
|
if self.app.client_manager.is_network_endpoint_enabled():
|
||||||
for k, v in NETWORK_QUOTAS.items():
|
for k, v in NETWORK_QUOTAS.items():
|
||||||
|
@ -169,12 +169,21 @@ class QuotaTests(base.TestCase):
|
|||||||
self.assertTrue(cmd_output["key-pairs"] >= 0)
|
self.assertTrue(cmd_output["key-pairs"] >= 0)
|
||||||
self.assertTrue(cmd_output["snapshots"] >= 0)
|
self.assertTrue(cmd_output["snapshots"] >= 0)
|
||||||
|
|
||||||
|
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_check_limit(self):
|
||||||
if not self.haz_network:
|
if not self.haz_network:
|
||||||
self.skipTest('No Network service present')
|
self.skipTest('No Network service present')
|
||||||
if not self.is_extension_enabled('quota-check-limit'):
|
if not self.is_extension_enabled('quota-check-limit'):
|
||||||
self.skipTest('No "quota-check-limit" extension present')
|
self.skipTest('No "quota-check-limit" extension present')
|
||||||
|
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'quota list -f json --network'
|
||||||
|
))
|
||||||
|
self.addCleanup(self._restore_quota_limit, 'network',
|
||||||
|
cmd_output[0]['Networks'], self.PROJECT_NAME)
|
||||||
|
|
||||||
self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
|
self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
|
||||||
cmd_output = json.loads(self.openstack(
|
cmd_output = json.loads(self.openstack(
|
||||||
'quota list -f json --network'
|
'quota list -f json --network'
|
||||||
@ -190,3 +199,41 @@ class QuotaTests(base.TestCase):
|
|||||||
self.assertRaises(exceptions.CommandFailed, self.openstack,
|
self.assertRaises(exceptions.CommandFailed, self.openstack,
|
||||||
'quota set --networks 1 --check-limit ' +
|
'quota set --networks 1 --check-limit ' +
|
||||||
self.PROJECT_NAME)
|
self.PROJECT_NAME)
|
||||||
|
|
||||||
|
def test_quota_network_set_with_force(self):
|
||||||
|
if not self.haz_network:
|
||||||
|
self.skipTest('No Network service present')
|
||||||
|
# NOTE(ralonsoh): the Neutron support for the flag "check-limit" was
|
||||||
|
# added with the extension "quota-check-limit". The flag "force" was
|
||||||
|
# added too in order to change the behaviour of Neutron quota engine
|
||||||
|
# and mimic the Nova one: by default the engine will check the resource
|
||||||
|
# usage before setting the new limit; with "force", this check will be
|
||||||
|
# skipped (in Yoga, this behaviour is still NOT the default in
|
||||||
|
# Neutron).
|
||||||
|
if not self.is_extension_enabled('quota-check-limit'):
|
||||||
|
self.skipTest('No "quota-check-limit" extension present')
|
||||||
|
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'quota list -f json --network'
|
||||||
|
))
|
||||||
|
self.addCleanup(self._restore_quota_limit, 'network',
|
||||||
|
cmd_output[0]['Networks'], self.PROJECT_NAME)
|
||||||
|
|
||||||
|
self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'quota list -f json --network'
|
||||||
|
))
|
||||||
|
self.assertIsNotNone(cmd_output)
|
||||||
|
self.assertEqual(40, cmd_output[0]['Networks'])
|
||||||
|
|
||||||
|
# That will ensure we have at least two networks in the system.
|
||||||
|
for _ in range(2):
|
||||||
|
self.openstack('network create --project %s %s' %
|
||||||
|
(self.PROJECT_NAME, uuid.uuid4().hex))
|
||||||
|
|
||||||
|
self.openstack('quota set --networks 1 --force ' + self.PROJECT_NAME)
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'quota list -f json --network'
|
||||||
|
))
|
||||||
|
self.assertIsNotNone(cmd_output)
|
||||||
|
self.assertEqual(1, cmd_output[0]['Networks'])
|
||||||
|
@ -935,6 +935,7 @@ class TestQuotaSet(TestQuota):
|
|||||||
}
|
}
|
||||||
kwargs_network = {
|
kwargs_network = {
|
||||||
'subnet': network_fakes.QUOTA['subnet'],
|
'subnet': network_fakes.QUOTA['subnet'],
|
||||||
|
'force': True,
|
||||||
}
|
}
|
||||||
self.compute_quotas_mock.update.assert_called_once_with(
|
self.compute_quotas_mock.update.assert_called_once_with(
|
||||||
self.projects[0].id,
|
self.projects[0].id,
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Add ``--force`` options to the ``openstack quota set`` command for network
|
||||||
|
service commands. Neutron quota engine now accepts "force" flag to set
|
||||||
|
a new resource quota limit, regardless of the current resource usage.
|
Loading…
x
Reference in New Issue
Block a user