quota: Add 'quota delete' command

We had previously indicated that people use 'quota set' for unsetting a
project's quotas, however, there was nothing that actually allowed us to
do this. Correct that oversight.

Change-Id: I04057e766b8ccf94bf219972249b68dc2bb796d4
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2022-09-22 18:09:08 +01:00
parent bfdf900d0a
commit 45bec041b2
8 changed files with 197 additions and 5 deletions

View File

@ -91,7 +91,7 @@ qos-show,volume qos show,Shows a specified qos specs.
quota-class-show,quota show --class,Lists quotas for a quota class.
quota-class-update,quota set --class,Updates quotas for a quota class.
quota-defaults,quota show --default,Lists default quotas for a tenant.
quota-delete,,Delete the quotas for a tenant.
quota-delete,quota delete --volume,Delete the quotas for a tenant.
quota-show,quota show,Lists quotas for a tenant.
quota-update,quota set,Updates quotas for a tenant.
quota-usage,,Lists quota usage for a tenant.

1 absolute-limits limits show --absolute Lists absolute limits for a user.
91 quota-class-show quota show --class Lists quotas for a quota class.
92 quota-class-update quota set --class Updates quotas for a quota class.
93 quota-defaults quota show --default Lists default quotas for a tenant.
94 quota-delete quota delete --volume Delete the quotas for a tenant.
95 quota-show quota show Lists quotas for a tenant.
96 quota-update quota set Updates quotas for a tenant.
97 quota-usage Lists quota usage for a tenant.

View File

@ -188,7 +188,7 @@ qos-policy-list,network qos policy list,List QoS policies that belong to a given
qos-policy-show,network qos policy show,Show information of a given qos policy.
qos-policy-update,network qos policy set,Update a given qos policy.
quota-default-show,quota show --default,Show default quotas for a given tenant.
quota-delete,,Delete defined quotas of a given tenant.
quota-delete,quota delete --network,Delete defined quotas of a given tenant.
quota-list,quota list,List quotas of all tenants who have non-default quota values.
quota-show,quota show,Show quotas for a given tenant.
quota-update,quota set,Define tenant's quotas not to use defaults.

1 address-scope-create address scope create Create an address scope for a given tenant.
188 qos-policy-show network qos policy show Show information of a given qos policy.
189 qos-policy-update network qos policy set Update a given qos policy.
190 quota-default-show quota show --default Show default quotas for a given tenant.
191 quota-delete quota delete --network Delete defined quotas of a given tenant.
192 quota-list quota list List quotas of all tenants who have non-default quota values.
193 quota-show quota show Show quotas for a given tenant.
194 quota-update quota set Define tenant's quotas not to use defaults.

View File

@ -70,7 +70,7 @@ pause,server pause,Pause a server.
quota-class-show,quota show --class,List the quotas for a quota class.
quota-class-update,quota set --class,Update the quotas for a quota class.
quota-defaults,quota list,List the default quotas for a tenant.
quota-delete,quota set,Delete quota for a tenant/user so their quota will Revert back to default.
quota-delete,quota delete --compute,Delete quota for a tenant/user so their quota will Revert back to default.
quota-show,quota show,List the quotas for a tenant/user.
quota-update,quota set,Update the quotas for a tenant/user.
reboot,server reboot,Reboot a server.

1 add-secgroup server add security group Add a Security Group to a server.
70 quota-class-show quota show --class List the quotas for a quota class.
71 quota-class-update quota set --class Update the quotas for a quota class.
72 quota-defaults quota list List the default quotas for a tenant.
73 quota-delete quota set quota delete --compute Delete quota for a tenant/user so their quota will Revert back to default.
74 quota-show quota show List the quotas for a tenant/user.
75 quota-update quota set Update the quotas for a tenant/user.
76 reboot server reboot Reboot a server.

View File

@ -697,3 +697,82 @@ class ShowQuota(command.ShowOne, BaseQuota):
info['project_name'] = project_name
return zip(*sorted(info.items()))
class DeleteQuota(command.Command):
_description = _(
"Delete configured quota for a project and revert to defaults."
)
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument(
'project',
metavar='<project>',
help=_('Delete quotas for this project (name or ID)'),
)
option = parser.add_mutually_exclusive_group()
option.add_argument(
'--all',
action='store_const',
const='all',
dest='service',
default='all',
help=_('Delete project quotas for all services (default)'),
)
option.add_argument(
'--compute',
action='store_const',
const='compute',
dest='service',
default='all',
help=_(
'Delete compute quotas for the project '
'(including network quotas when using nova-network)'
),
)
option.add_argument(
'--volume',
action='store_const',
const='volume',
dest='service',
default='all',
help=_('Delete volume quotas for the project'),
)
option.add_argument(
'--network',
action='store_const',
const='network',
dest='service',
default='all',
help=_('Delete network quotas for the project'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
project = utils.find_resource(
identity_client.projects,
parsed_args.project,
)
# compute quotas
if parsed_args.service in {'all', 'compute'}:
compute_client = self.app.client_manager.compute
compute_client.quotas.delete(project)
# volume quotas
if parsed_args.service in {'all', 'volume'}:
volume_client = self.app.client_manager.volume
volume_client.quotas.delete(project)
# network quotas (but only if we're not using nova-network, otherwise
# we already deleted the quotas in the compute step)
if (
parsed_args.service in {'all', 'network'}
and self.app.client_manager.is_network_endpoint_enabled()
):
network_client = self.app.client_manager.network
network_client.quotas.delete(project)
return None

View File

@ -62,6 +62,9 @@ class TestQuota(compute_fakes.TestComputev2):
self.app.client_manager.volume.quota_classes
self.volume_quotas_class_mock.reset_mock()
self.app.client_manager.network.quotas = mock.Mock()
self.network_quotas_mock = self.app.client_manager.network.quotas
self.app.client_manager.auth_ref = mock.Mock()
self.app.client_manager.auth_ref.service_catalog = mock.Mock()
self.service_catalog_mock = \
@ -1154,3 +1157,107 @@ class TestQuotaShow(TestQuota):
self.assertEqual(len(network_fakes.QUOTA) - 1, len(result))
# Go back to default mock
self.network.get_quota = orig_get_quota
class TestQuotaDelete(TestQuota):
"""Test cases for quota delete command"""
def setUp(self):
super().setUp()
self.cmd = quota.DeleteQuota(self.app, None)
def test_delete(self):
"""Delete all quotas"""
arglist = [
self.projects[0].id,
]
verifylist = [
('service', 'all'),
('project', self.projects[0].id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
self.projects_mock.get.assert_called_once_with(self.projects[0].id)
self.compute_quotas_mock.delete.assert_called_once_with(
self.projects[0],
)
self.volume_quotas_mock.delete.assert_called_once_with(
self.projects[0],
)
self.network_quotas_mock.delete.assert_called_once_with(
self.projects[0],
)
def test_delete__compute(self):
"""Delete compute quotas only"""
arglist = [
'--compute',
self.projects[0].id,
]
verifylist = [
('service', 'compute'),
('project', self.projects[0].id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
self.projects_mock.get.assert_called_once_with(self.projects[0].id)
self.compute_quotas_mock.delete.assert_called_once_with(
self.projects[0],
)
self.volume_quotas_mock.delete.assert_not_called()
self.network_quotas_mock.delete.assert_not_called()
def test_delete__volume(self):
"""Delete volume quotas only"""
arglist = [
'--volume',
self.projects[0].id,
]
verifylist = [
('service', 'volume'),
('project', self.projects[0].id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
self.projects_mock.get.assert_called_once_with(self.projects[0].id)
self.compute_quotas_mock.delete.assert_not_called()
self.volume_quotas_mock.delete.assert_called_once_with(
self.projects[0],
)
self.network_quotas_mock.delete.assert_not_called()
def test_delete__network(self):
"""Delete network quotas only"""
arglist = [
'--network',
self.projects[0].id,
]
verifylist = [
('service', 'network'),
('project', self.projects[0].id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
self.projects_mock.get.assert_called_once_with(self.projects[0].id)
self.compute_quotas_mock.delete.assert_not_called()
self.volume_quotas_mock.delete.assert_not_called()
self.network_quotas_mock.delete.assert_called_once_with(
self.projects[0],
)

View File

@ -0,0 +1,5 @@
---
features:
- |
Added a new command, ``quota delete``, that will allow admins delete quotas
set for projects. Supported by the compute, volume, and network services.

View File

@ -49,6 +49,7 @@ openstack.common =
quota_list = openstackclient.common.quota:ListQuota
quota_set = openstackclient.common.quota:SetQuota
quota_show = openstackclient.common.quota:ShowQuota
quota_delete = openstackclient.common.quota:DeleteQuota
versions_show = openstackclient.common.versions:ShowVersions
openstack.compute.v2 =

View File

@ -134,7 +134,7 @@ show-source = True
# H203: Use assertIs(Not)None to check for None
enable-extensions = H203
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,releasenotes
# W504 is disabled since you must choose between this or W503
ignore = W504
# W503 and W504 are disabled since they're not very useful
ignore = W503,W504
import-order-style = pep8
application_import_names = openstackclient