Support fetching network project default quota
Neutron server and openstacksdk had supported to fetch network project default quota, this patch add the CLI support in openstackclient. Change-Id: If0ef74c268c41a866c62156da0603a40ae4e6e31 Closes-Bug: #1204956 Depends-On: I6a4e2a146351dd1e7d652442511f1ef2c279da42
This commit is contained in:
		| @@ -247,11 +247,16 @@ class ShowQuota(command.ShowOne): | |||||||
|         return quota._info |         return quota._info | ||||||
|  |  | ||||||
|     def get_network_quota(self, parsed_args): |     def get_network_quota(self, parsed_args): | ||||||
|         if parsed_args.quota_class or parsed_args.default: |         if parsed_args.quota_class: | ||||||
|             return {} |             return {} | ||||||
|         if self.app.client_manager.is_network_endpoint_enabled(): |         if self.app.client_manager.is_network_endpoint_enabled(): | ||||||
|             project = self._get_project(parsed_args) |             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: |         else: | ||||||
|             return {} |             return {} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ class QuotaTests(base.TestCase): | |||||||
|     """Functional tests for quota. """ |     """Functional tests for quota. """ | ||||||
|     # Test quota information for compute, network and volume. |     # Test quota information for compute, network and volume. | ||||||
|     EXPECTED_FIELDS = ['instances', 'networks', 'volumes'] |     EXPECTED_FIELDS = ['instances', 'networks', 'volumes'] | ||||||
|  |     EXPECTED_CLASS_FIELDS = ['instances', 'volumes'] | ||||||
|     PROJECT_NAME = None |     PROJECT_NAME = None | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
| @@ -40,3 +41,13 @@ class QuotaTests(base.TestCase): | |||||||
|         raw_output = self.openstack('quota show') |         raw_output = self.openstack('quota show') | ||||||
|         for expected_field in self.EXPECTED_FIELDS: |         for expected_field in self.EXPECTED_FIELDS: | ||||||
|             self.assertIn(expected_field, raw_output) |             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) | ||||||
|   | |||||||
| @@ -383,6 +383,8 @@ class TestQuotaShow(TestQuota): | |||||||
|         ) |         ) | ||||||
|         self.network = self.app.client_manager.network |         self.network = self.app.client_manager.network | ||||||
|         self.network.get_quota = mock.Mock(return_value=network_fakes.QUOTA) |         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) |         self.cmd = quota.ShowQuota(self.app, None) | ||||||
|  |  | ||||||
| @@ -403,6 +405,7 @@ class TestQuotaShow(TestQuota): | |||||||
|             identity_fakes.project_id) |             identity_fakes.project_id) | ||||||
|         self.network.get_quota.assert_called_once_with( |         self.network.get_quota.assert_called_once_with( | ||||||
|             identity_fakes.project_id) |             identity_fakes.project_id) | ||||||
|  |         self.assertNotCalled(self.network.get_quota_default) | ||||||
|  |  | ||||||
|     def test_quota_show_with_default(self): |     def test_quota_show_with_default(self): | ||||||
|         arglist = [ |         arglist = [ | ||||||
| @@ -422,6 +425,9 @@ class TestQuotaShow(TestQuota): | |||||||
|             identity_fakes.project_id) |             identity_fakes.project_id) | ||||||
|         self.volume_quotas_mock.defaults.assert_called_once_with( |         self.volume_quotas_mock.defaults.assert_called_once_with( | ||||||
|             identity_fakes.project_id) |             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): |     def test_quota_show_with_class(self): | ||||||
|         arglist = [ |         arglist = [ | ||||||
| @@ -441,6 +447,8 @@ class TestQuotaShow(TestQuota): | |||||||
|             identity_fakes.project_id) |             identity_fakes.project_id) | ||||||
|         self.volume_quotas_class_mock.get.assert_called_once_with( |         self.volume_quotas_class_mock.get.assert_called_once_with( | ||||||
|             identity_fakes.project_id) |             identity_fakes.project_id) | ||||||
|  |         self.assertNotCalled(self.network.get_quota) | ||||||
|  |         self.assertNotCalled(self.network.get_quota_default) | ||||||
|  |  | ||||||
|     def test_quota_show_no_project(self): |     def test_quota_show_no_project(self): | ||||||
|         parsed_args = self.check_parser(self.cmd, [], []) |         parsed_args = self.check_parser(self.cmd, [], []) | ||||||
| @@ -452,3 +460,4 @@ class TestQuotaShow(TestQuota): | |||||||
|             identity_fakes.project_id) |             identity_fakes.project_id) | ||||||
|         self.network.get_quota.assert_called_once_with( |         self.network.get_quota.assert_called_once_with( | ||||||
|             identity_fakes.project_id) |             identity_fakes.project_id) | ||||||
|  |         self.assertNotCalled(self.network.get_quota_default) | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								releasenotes/notes/bug-1204956-af47c7f34ecc19c3.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								releasenotes/notes/bug-1204956-af47c7f34ecc19c3.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | --- | ||||||
|  | features: | ||||||
|  |   - Supported to fetch network project default quota with command | ||||||
|  |     ``quota show --default``. | ||||||
|  |     [Bug `1204956 <https://bugs.launchpad.net/neutron/+bug/1204956>`_] | ||||||
		Reference in New Issue
	
	Block a user
	 Rui Chen
					Rui Chen