summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-02-02 04:06:57 +0000
committerGerrit Code Review <review@openstack.org>2016-02-02 04:06:57 +0000
commit72fe3e25e27dfa6d377fbda1318b5db3ce4d6e6d (patch)
treeb1a9c92e1eb4a33b237fbbb8df7adb144feeacf6 /openstackclient
parent180ba2f733a870af752e7d459619e13bc287789f (diff)
parent5d1a93362da1109a9f49c32c142a8a4df0a97a9e (diff)
downloadpython-openstackclient-72fe3e25e27dfa6d377fbda1318b5db3ce4d6e6d.tar.gz
Merge "Fix showing network quotas for a project"
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/common/quota.py11
-rw-r--r--openstackclient/tests/common/test_quota.py25
-rw-r--r--openstackclient/tests/network/v2/fakes.py12
3 files changed, 37 insertions, 11 deletions
diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py
index 480abbd9..f208948e 100644
--- a/openstackclient/common/quota.py
+++ b/openstackclient/common/quota.py
@@ -188,10 +188,13 @@ class ShowQuota(command.ShowOne):
def get_network_quota(self, parsed_args):
if parsed_args.quota_class or parsed_args.default:
return {}
- service_catalog = self.app.client_manager.auth_ref.service_catalog
- if 'network' in service_catalog.get_endpoints():
- network_client = self.app.client_manager.network
- return network_client.show_quota(parsed_args.project)['quota']
+ if self.app.client_manager.is_network_endpoint_enabled():
+ identity_client = self.app.client_manager.identity
+ project = utils.find_resource(
+ identity_client.projects,
+ parsed_args.project,
+ ).id
+ return self.app.client_manager.network.get_quota(project)
else:
return {}
diff --git a/openstackclient/tests/common/test_quota.py b/openstackclient/tests/common/test_quota.py
index 485b8a8b..edf29c9b 100644
--- a/openstackclient/tests/common/test_quota.py
+++ b/openstackclient/tests/common/test_quota.py
@@ -214,13 +214,15 @@ class TestQuotaShow(TestQuota):
loaded=True,
)
- self.service_catalog_mock.get_endpoints.return_value = [
- fakes.FakeResource(
- None,
- copy.deepcopy(identity_fakes.ENDPOINT),
- loaded=True,
- )
- ]
+ fake_network_endpoint = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.ENDPOINT),
+ loaded=True,
+ )
+
+ self.service_catalog_mock.get_endpoints.return_value = {
+ 'network': fake_network_endpoint
+ }
self.quotas_class_mock.get.return_value = FakeQuotaResource(
None,
@@ -244,6 +246,8 @@ class TestQuotaShow(TestQuota):
endpoint=fakes.AUTH_URL,
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)
@@ -260,6 +264,9 @@ class TestQuotaShow(TestQuota):
self.cmd.take_action(parsed_args)
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):
arglist = [
@@ -276,6 +283,8 @@ class TestQuotaShow(TestQuota):
self.cmd.take_action(parsed_args)
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):
arglist = [
@@ -293,3 +302,5 @@ class TestQuotaShow(TestQuota):
self.quotas_class_mock.get.assert_called_with(
identity_fakes.project_id)
+ self.volume_quotas_class_mock.get.assert_called_with(
+ identity_fakes.project_id)
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index 88370feb..4c862bd3 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -26,6 +26,18 @@ extension_updated = '2013-07-09T12:00:0-00:00'
extension_alias = 'Dystopian'
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():
extension = mock.Mock()