summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2022-09-23 18:00:34 +0100
committerStephen Finucane <sfinucan@redhat.com>2022-09-30 12:40:15 +0100
commit04e68e0d5a49be93f79d6d71821ab8cd0b0ce589 (patch)
treea9b60de6ced03d9a2cd4aca06e20428155b16a49 /openstackclient/tests
parent47e667e71d997ad4a7b0dd86bf462f746c964b54 (diff)
downloadpython-openstackclient-04e68e0d5a49be93f79d6d71821ab8cd0b0ce589.tar.gz
quota: Add 'quota show --usage' option
Provide an more sane way to get usage information for a particular project's quotas. This requires using the 'Lister' command type since the 'ShowOne' command type only allows for simple key-value pair output. We also add a note indicating that the '<project>' argument is optional. Change-Id: Ic7342cf08f024cc690049414c5eef5b9a7594677 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/functional/common/test_quota.py4
-rw-r--r--openstackclient/tests/unit/common/test_quota.py68
2 files changed, 58 insertions, 14 deletions
diff --git a/openstackclient/tests/functional/common/test_quota.py b/openstackclient/tests/functional/common/test_quota.py
index 783294df..08ec626f 100644
--- a/openstackclient/tests/functional/common/test_quota.py
+++ b/openstackclient/tests/functional/common/test_quota.py
@@ -114,6 +114,7 @@ class QuotaTests(base.TestCase):
cmd_output = json.loads(self.openstack(
'quota show -f json ' + self.PROJECT_NAME
))
+ cmd_output = {x['Resource']: x['Limit'] for x in cmd_output}
self.assertIsNotNone(cmd_output)
self.assertEqual(
31,
@@ -136,6 +137,7 @@ class QuotaTests(base.TestCase):
self.assertIsNotNone(cmd_output)
# We don't necessarily know the default quotas, we're checking the
# returned attributes
+ cmd_output = {x['Resource']: x['Limit'] for x in cmd_output}
self.assertTrue(cmd_output["cores"] >= 0)
self.assertTrue(cmd_output["backups"] >= 0)
if self.haz_network:
@@ -150,6 +152,7 @@ class QuotaTests(base.TestCase):
'quota show -f json --class default'
))
self.assertIsNotNone(cmd_output)
+ cmd_output = {x['Resource']: x['Limit'] for x in cmd_output}
self.assertEqual(
33,
cmd_output["key-pairs"],
@@ -166,6 +169,7 @@ class QuotaTests(base.TestCase):
self.assertIsNotNone(cmd_output)
# We don't necessarily know the default quotas, we're checking the
# returned attributes
+ cmd_output = {x['Resource']: x['Limit'] for x in cmd_output}
self.assertTrue(cmd_output["key-pairs"] >= 0)
self.assertTrue(cmd_output["snapshots"] >= 0)
diff --git a/openstackclient/tests/unit/common/test_quota.py b/openstackclient/tests/unit/common/test_quota.py
index 663b62ea..53aab5f2 100644
--- a/openstackclient/tests/unit/common/test_quota.py
+++ b/openstackclient/tests/unit/common/test_quota.py
@@ -1094,17 +1094,20 @@ class TestQuotaShow(TestQuota):
self.cmd.take_action(parsed_args)
self.compute_quotas_mock.get.assert_called_once_with(
- self.projects[0].id, detail=False
+ self.projects[0].id,
+ detail=False,
)
self.volume_quotas_mock.get.assert_called_once_with(
- self.projects[0].id, usage=False
+ self.projects[0].id,
+ usage=False,
)
self.network.get_quota.assert_called_once_with(
- self.projects[0].id, details=False
+ self.projects[0].id,
+ details=False,
)
self.assertNotCalled(self.network.get_quota_default)
- def test_quota_show_with_default(self):
+ def test_quota_show__with_default(self):
arglist = [
'--default',
self.projects[0].name,
@@ -1128,30 +1131,67 @@ class TestQuotaShow(TestQuota):
)
self.assertNotCalled(self.network.get_quota)
- def test_quota_show_with_class(self):
+ def test_quota_show__with_class(self):
arglist = [
'--class',
- self.projects[0].name,
+ 'default',
]
verifylist = [
('quota_class', True),
- ('project', self.projects[0].name),
+ ('project', 'default'), # project is actually a class here
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
- self.compute_quotas_class_mock.get.assert_called_once_with(
+ self.compute_quotas_class_mock.get.assert_called_once_with('default')
+ self.volume_quotas_class_mock.get.assert_called_once_with('default')
+ # neutron doesn't have the concept of quota classes
+ self.assertNotCalled(self.network.get_quota)
+ self.assertNotCalled(self.network.get_quota_default)
+
+ def test_quota_show__with_usage(self):
+ # update mocks to return detailed quota instead
+ self.compute_quota = \
+ compute_fakes.FakeQuota.create_one_comp_detailed_quota()
+ self.compute_quotas_mock.get.return_value = self.compute_quota
+ self.volume_quota = \
+ volume_fakes.FakeQuota.create_one_detailed_quota()
+ self.volume_quotas_mock.get.return_value = self.volume_quota
+ self.network.get_quota.return_value = \
+ network_fakes.FakeQuota.create_one_net_detailed_quota()
+
+ arglist = [
+ '--usage',
self.projects[0].name,
+ ]
+ verifylist = [
+ ('usage', True),
+ ('project', self.projects[0].name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.cmd.take_action(parsed_args)
+
+ self.compute_quotas_mock.get.assert_called_once_with(
+ self.projects[0].id,
+ detail=True,
)
- self.volume_quotas_class_mock.get.assert_called_once_with(
- self.projects[0].name,
+ self.volume_quotas_mock.get.assert_called_once_with(
+ self.projects[0].id,
+ usage=True,
+ )
+ self.network.get_quota.assert_called_once_with(
+ self.projects[0].id,
+ details=True,
)
- self.assertNotCalled(self.network.get_quota)
- self.assertNotCalled(self.network.get_quota_default)
- def test_quota_show_no_project(self):
- parsed_args = self.check_parser(self.cmd, [], [])
+ def test_quota_show__no_project(self):
+ arglist = []
+ verifylist = [
+ ('project', None),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)