diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index 8ae6f7d48..aabfa5d54 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -247,11 +247,16 @@ class ShowQuota(command.ShowOne): return quota._info def get_network_quota(self, parsed_args): - if parsed_args.quota_class or parsed_args.default: + if parsed_args.quota_class: return {} if self.app.client_manager.is_network_endpoint_enabled(): project = self._get_project(parsed_args) - return self.app.client_manager.network.get_quota(project) + client = self.app.client_manager.network + if parsed_args.default: + network_quota = client.get_quota_default(project) + else: + network_quota = client.get_quota(project) + return network_quota else: return {} diff --git a/openstackclient/tests/functional/common/test_quota.py b/openstackclient/tests/functional/common/test_quota.py index fd45be38a..9687cdb0d 100644 --- a/openstackclient/tests/functional/common/test_quota.py +++ b/openstackclient/tests/functional/common/test_quota.py @@ -17,6 +17,7 @@ class QuotaTests(base.TestCase): """Functional tests for quota. """ # Test quota information for compute, network and volume. EXPECTED_FIELDS = ['instances', 'networks', 'volumes'] + EXPECTED_CLASS_FIELDS = ['instances', 'volumes'] PROJECT_NAME = None @classmethod @@ -40,3 +41,13 @@ class QuotaTests(base.TestCase): raw_output = self.openstack('quota show') for expected_field in self.EXPECTED_FIELDS: self.assertIn(expected_field, raw_output) + + def test_quota_show_with_default_option(self): + raw_output = self.openstack('quota show --default') + for expected_field in self.EXPECTED_FIELDS: + self.assertIn(expected_field, raw_output) + + def test_quota_show_with_class_option(self): + raw_output = self.openstack('quota show --class') + for expected_field in self.EXPECTED_CLASS_FIELDS: + self.assertIn(expected_field, raw_output) diff --git a/openstackclient/tests/unit/common/test_quota.py b/openstackclient/tests/unit/common/test_quota.py index cbe4cb80e..ac03cb604 100644 --- a/openstackclient/tests/unit/common/test_quota.py +++ b/openstackclient/tests/unit/common/test_quota.py @@ -383,6 +383,8 @@ class TestQuotaShow(TestQuota): ) self.network = self.app.client_manager.network self.network.get_quota = mock.Mock(return_value=network_fakes.QUOTA) + self.network.get_quota_default = mock.Mock( + return_value=network_fakes.QUOTA) self.cmd = quota.ShowQuota(self.app, None) @@ -403,6 +405,7 @@ class TestQuotaShow(TestQuota): identity_fakes.project_id) self.network.get_quota.assert_called_once_with( identity_fakes.project_id) + self.assertNotCalled(self.network.get_quota_default) def test_quota_show_with_default(self): arglist = [ @@ -422,6 +425,9 @@ class TestQuotaShow(TestQuota): identity_fakes.project_id) self.volume_quotas_mock.defaults.assert_called_once_with( identity_fakes.project_id) + self.network.get_quota_default.assert_called_once_with( + identity_fakes.project_id) + self.assertNotCalled(self.network.get_quota) def test_quota_show_with_class(self): arglist = [ @@ -441,6 +447,8 @@ class TestQuotaShow(TestQuota): identity_fakes.project_id) self.volume_quotas_class_mock.get.assert_called_once_with( identity_fakes.project_id) + 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, [], []) @@ -452,3 +460,4 @@ class TestQuotaShow(TestQuota): identity_fakes.project_id) self.network.get_quota.assert_called_once_with( identity_fakes.project_id) + self.assertNotCalled(self.network.get_quota_default) diff --git a/releasenotes/notes/bug-1204956-af47c7f34ecc19c3.yaml b/releasenotes/notes/bug-1204956-af47c7f34ecc19c3.yaml new file mode 100644 index 000000000..65def078b --- /dev/null +++ b/releasenotes/notes/bug-1204956-af47c7f34ecc19c3.yaml @@ -0,0 +1,5 @@ +--- +features: + - Supported to fetch network project default quota with command + ``quota show --default``. + [Bug `1204956 `_]