Fix showing network quotas for a project
The OpenStack SDK is now used for the network client. However, the 'openstack quota show' command wasn't updated for the client change. As a result, the command will fail to show network quotas when a project name is specified. For example: $ openstack quota show admin 'Proxy' object has no attribute 'show_quota' This patch set fixes the command by using the OpenStack SDK to get network quotas for a project. Change-Id: I59a7b6780a7b80cd09e79d40d214751b25d3016e Related-To: blueprint neutron-client Closes-Bug: #1528249
This commit is contained in:
		 Richard Theis
					Richard Theis
				
			
				
					committed by
					
						 Steve Martinelli
						Steve Martinelli
					
				
			
			
				
	
			
			
			 Steve Martinelli
						Steve Martinelli
					
				
			
						parent
						
							e9ff42eee7
						
					
				
				
					commit
					5d1a93362d
				
			| @@ -196,10 +196,13 @@ class ShowQuota(show.ShowOne): | |||||||
|     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 or parsed_args.default: | ||||||
|             return {} |             return {} | ||||||
|         service_catalog = self.app.client_manager.auth_ref.service_catalog |         if self.app.client_manager.is_network_endpoint_enabled(): | ||||||
|         if 'network' in service_catalog.get_endpoints(): |             identity_client = self.app.client_manager.identity | ||||||
|             network_client = self.app.client_manager.network |             project = utils.find_resource( | ||||||
|             return network_client.show_quota(parsed_args.project)['quota'] |                 identity_client.projects, | ||||||
|  |                 parsed_args.project, | ||||||
|  |                 ).id | ||||||
|  |             return self.app.client_manager.network.get_quota(project) | ||||||
|         else: |         else: | ||||||
|             return {} |             return {} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -214,13 +214,15 @@ class TestQuotaShow(TestQuota): | |||||||
|             loaded=True, |             loaded=True, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         self.service_catalog_mock.get_endpoints.return_value = [ |         fake_network_endpoint = fakes.FakeResource( | ||||||
|             fakes.FakeResource( |  | ||||||
|             None, |             None, | ||||||
|             copy.deepcopy(identity_fakes.ENDPOINT), |             copy.deepcopy(identity_fakes.ENDPOINT), | ||||||
|             loaded=True, |             loaded=True, | ||||||
|         ) |         ) | ||||||
|         ] |  | ||||||
|  |         self.service_catalog_mock.get_endpoints.return_value = { | ||||||
|  |             'network': fake_network_endpoint | ||||||
|  |         } | ||||||
|  |  | ||||||
|         self.quotas_class_mock.get.return_value = FakeQuotaResource( |         self.quotas_class_mock.get.return_value = FakeQuotaResource( | ||||||
|             None, |             None, | ||||||
| @@ -244,6 +246,8 @@ class TestQuotaShow(TestQuota): | |||||||
|             endpoint=fakes.AUTH_URL, |             endpoint=fakes.AUTH_URL, | ||||||
|             token=fakes.AUTH_TOKEN, |             token=fakes.AUTH_TOKEN, | ||||||
|         ) |         ) | ||||||
|  |         self.network = self.app.client_manager.network | ||||||
|  |         self.network.get_quota = mock.Mock(return_value=network_fakes.QUOTA) | ||||||
|  |  | ||||||
|         self.cmd = quota.ShowQuota(self.app, None) |         self.cmd = quota.ShowQuota(self.app, None) | ||||||
|  |  | ||||||
| @@ -260,6 +264,9 @@ class TestQuotaShow(TestQuota): | |||||||
|         self.cmd.take_action(parsed_args) |         self.cmd.take_action(parsed_args) | ||||||
|  |  | ||||||
|         self.quotas_mock.get.assert_called_with(identity_fakes.project_id) |         self.quotas_mock.get.assert_called_with(identity_fakes.project_id) | ||||||
|  |         self.volume_quotas_mock.get.assert_called_with( | ||||||
|  |             identity_fakes.project_id) | ||||||
|  |         self.network.get_quota.assert_called_with(identity_fakes.project_id) | ||||||
|  |  | ||||||
|     def test_quota_show_with_default(self): |     def test_quota_show_with_default(self): | ||||||
|         arglist = [ |         arglist = [ | ||||||
| @@ -276,6 +283,8 @@ class TestQuotaShow(TestQuota): | |||||||
|         self.cmd.take_action(parsed_args) |         self.cmd.take_action(parsed_args) | ||||||
|  |  | ||||||
|         self.quotas_mock.defaults.assert_called_with(identity_fakes.project_id) |         self.quotas_mock.defaults.assert_called_with(identity_fakes.project_id) | ||||||
|  |         self.volume_quotas_mock.defaults.assert_called_with( | ||||||
|  |             identity_fakes.project_id) | ||||||
|  |  | ||||||
|     def test_quota_show_with_class(self): |     def test_quota_show_with_class(self): | ||||||
|         arglist = [ |         arglist = [ | ||||||
| @@ -293,3 +302,5 @@ class TestQuotaShow(TestQuota): | |||||||
|  |  | ||||||
|         self.quotas_class_mock.get.assert_called_with( |         self.quotas_class_mock.get.assert_called_with( | ||||||
|             identity_fakes.project_id) |             identity_fakes.project_id) | ||||||
|  |         self.volume_quotas_class_mock.get.assert_called_with( | ||||||
|  |             identity_fakes.project_id) | ||||||
|   | |||||||
| @@ -26,6 +26,18 @@ extension_updated = '2013-07-09T12:00:0-00:00' | |||||||
| extension_alias = 'Dystopian' | extension_alias = 'Dystopian' | ||||||
| extension_links = '[{"href":''"https://github.com/os/network", "type"}]' | extension_links = '[{"href":''"https://github.com/os/network", "type"}]' | ||||||
|  |  | ||||||
|  | QUOTA = { | ||||||
|  |     "subnet": 10, | ||||||
|  |     "network": 10, | ||||||
|  |     "floatingip": 50, | ||||||
|  |     "subnetpool": -1, | ||||||
|  |     "security_group_rule": 100, | ||||||
|  |     "security_group": 10, | ||||||
|  |     "router": 10, | ||||||
|  |     "rbac_policy": -1, | ||||||
|  |     "port": 50, | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| def create_extension(): | def create_extension(): | ||||||
|     extension = mock.Mock() |     extension = mock.Mock() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user