From 2da4aa99aaca3debcda1d046b7806a8f83ac8090 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 7 Oct 2022 17:12:39 +0100 Subject: [PATCH] quota: Fix issues with delete quota command We were passing a project object rather than just the ID. Also correct a typo in the call to delete network quotas. Change-Id: I2292db7932ec01026f0e54014e3d02218792617a Signed-off-by: Stephen Finucane --- openstackclient/common/quota.py | 6 ++--- .../tests/unit/common/test_quota.py | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index 10f40a75d..f2d097fc1 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -972,12 +972,12 @@ class DeleteQuota(command.Command): # compute quotas if parsed_args.service in {'all', 'compute'}: compute_client = self.app.client_manager.compute - compute_client.quotas.delete(project) + compute_client.quotas.delete(project.id) # volume quotas if parsed_args.service in {'all', 'volume'}: volume_client = self.app.client_manager.volume - volume_client.quotas.delete(project) + volume_client.quotas.delete(project.id) # network quotas (but only if we're not using nova-network, otherwise # we already deleted the quotas in the compute step) @@ -986,6 +986,6 @@ class DeleteQuota(command.Command): and self.app.client_manager.is_network_endpoint_enabled() ): network_client = self.app.client_manager.network - network_client.quotas.delete(project) + network_client.delete_quota(project.id) return None diff --git a/openstackclient/tests/unit/common/test_quota.py b/openstackclient/tests/unit/common/test_quota.py index 682799b39..f798137ae 100644 --- a/openstackclient/tests/unit/common/test_quota.py +++ b/openstackclient/tests/unit/common/test_quota.py @@ -62,8 +62,8 @@ 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.network = mock.Mock() + self.network_mock = self.app.client_manager.network self.app.client_manager.auth_ref = mock.Mock() self.app.client_manager.auth_ref.service_catalog = mock.Mock() @@ -660,7 +660,6 @@ class TestQuotaSet(TestQuota): loaded=True, ) - self.network_mock = self.app.client_manager.network self.network_mock.update_quota = mock.Mock() self.cmd = quota.SetQuota(self.app, None) @@ -1272,6 +1271,8 @@ class TestQuotaDelete(TestQuota): def setUp(self): super().setUp() + self.network_mock.delete_quota = mock.Mock() + self.cmd = quota.DeleteQuota(self.app, None) def test_delete(self): @@ -1291,13 +1292,13 @@ class TestQuotaDelete(TestQuota): 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.projects[0].id, ) self.volume_quotas_mock.delete.assert_called_once_with( - self.projects[0], + self.projects[0].id, ) - self.network_quotas_mock.delete.assert_called_once_with( - self.projects[0], + self.network_mock.delete_quota.assert_called_once_with( + self.projects[0].id, ) def test_delete__compute(self): @@ -1318,10 +1319,10 @@ class TestQuotaDelete(TestQuota): 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.projects[0].id, ) self.volume_quotas_mock.delete.assert_not_called() - self.network_quotas_mock.delete.assert_not_called() + self.network_mock.delete_quota.assert_not_called() def test_delete__volume(self): """Delete volume quotas only""" @@ -1342,9 +1343,9 @@ class TestQuotaDelete(TestQuota): 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.projects[0].id, ) - self.network_quotas_mock.delete.assert_not_called() + self.network_mock.delete_quota.assert_not_called() def test_delete__network(self): """Delete network quotas only""" @@ -1365,6 +1366,6 @@ class TestQuotaDelete(TestQuota): 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], + self.network_mock.delete_quota.assert_called_once_with( + self.projects[0].id, )