From 75cba9d1cbdd7b14b0d507af27f896c6c45e713e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Kap=C5=82o=C5=84ski?= Date: Fri, 19 Oct 2018 12:46:21 +0300 Subject: Add support for get details of Quota With passing "--detail" argument to "openstack quota list", details about current usage should be returned. It is currently supported by Nova and Neutron so details of resources from those projects can be returned. Change-Id: I48fda15b34283bb7c66ea18ed28262f48b9229fe Related-Bug: #1716043 --- openstackclient/tests/unit/common/test_quota.py | 87 +++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 4 deletions(-) (limited to 'openstackclient/tests/unit/common') diff --git a/openstackclient/tests/unit/common/test_quota.py b/openstackclient/tests/unit/common/test_quota.py index 1a3da31d..4f9e321b 100644 --- a/openstackclient/tests/unit/common/test_quota.py +++ b/openstackclient/tests/unit/common/test_quota.py @@ -197,6 +197,85 @@ class TestQuotaList(TestQuota): self.cmd = quota.ListQuota(self.app, None) + @staticmethod + def _get_detailed_reference_data(quota): + reference_data = [] + for name, values in quota.to_dict().items(): + if type(values) is dict: + if 'used' in values: + # For network quota it's "used" key instead of "in_use" + in_use = values['used'] + else: + in_use = values['in_use'] + resource_values = [ + in_use, + values['reserved'], + values['limit']] + reference_data.append(tuple([name] + resource_values)) + return reference_data + + def test_quota_list_details_compute(self): + detailed_quota = ( + compute_fakes.FakeQuota.create_one_comp_detailed_quota()) + + detailed_column_header = ( + 'Resource', + 'In Use', + 'Reserved', + 'Limit', + ) + detailed_reference_data = ( + self._get_detailed_reference_data(detailed_quota)) + + self.compute.quotas.get = mock.Mock(return_value=detailed_quota) + + arglist = [ + '--detail', '--compute', + ] + verifylist = [ + ('detail', True), + ('compute', True), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + ret_quotas = list(data) + + self.assertEqual(detailed_column_header, columns) + self.assertEqual( + sorted(detailed_reference_data), sorted(ret_quotas)) + + def test_quota_list_details_network(self): + detailed_quota = ( + network_fakes.FakeQuota.create_one_net_detailed_quota()) + + detailed_column_header = ( + 'Resource', + 'In Use', + 'Reserved', + 'Limit', + ) + detailed_reference_data = ( + self._get_detailed_reference_data(detailed_quota)) + + self.network.get_quota = mock.Mock(return_value=detailed_quota) + + arglist = [ + '--detail', '--network', + ] + verifylist = [ + ('detail', True), + ('network', True), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + ret_quotas = list(data) + + self.assertEqual(detailed_column_header, columns) + self.assertEqual( + sorted(detailed_reference_data), sorted(ret_quotas)) + def test_quota_list_compute(self): # Two projects with non-default quotas self.compute.quotas.get = mock.Mock( @@ -827,13 +906,13 @@ class TestQuotaShow(TestQuota): self.cmd.take_action(parsed_args) self.compute_quotas_mock.get.assert_called_once_with( - self.projects[0].id, + self.projects[0].id, detail=False ) self.volume_quotas_mock.get.assert_called_once_with( self.projects[0].id, ) self.network.get_quota.assert_called_once_with( - self.projects[0].id, + self.projects[0].id, details=False ) self.assertNotCalled(self.network.get_quota_default) @@ -889,12 +968,12 @@ class TestQuotaShow(TestQuota): self.cmd.take_action(parsed_args) self.compute_quotas_mock.get.assert_called_once_with( - identity_fakes.project_id, + identity_fakes.project_id, detail=False ) self.volume_quotas_mock.get.assert_called_once_with( identity_fakes.project_id, ) self.network.get_quota.assert_called_once_with( - identity_fakes.project_id, + identity_fakes.project_id, details=False ) self.assertNotCalled(self.network.get_quota_default) -- cgit v1.2.1