summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-10-13 18:25:45 +0000
committerGerrit Code Review <review@openstack.org>2017-10-13 18:25:45 +0000
commit33403348a253230b79e36e27077e52db4ab28418 (patch)
treec657ad115c3cfb6f3c6553e305c989f5fe21b01f /openstackclient
parent885b1149c309667c6e4c3092b67fef3c01a15178 (diff)
parentf6f5ce03c5b8a03180db24a02dda5b30f40b4cee (diff)
downloadpython-openstackclient-33403348a253230b79e36e27077e52db4ab28418.tar.gz
Merge "Optimize getting endpoint list"
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/identity/common.py10
-rw-r--r--openstackclient/identity/v3/endpoint.py3
-rw-r--r--openstackclient/tests/unit/identity/v3/test_endpoint.py2
3 files changed, 14 insertions, 1 deletions
diff --git a/openstackclient/identity/common.py b/openstackclient/identity/common.py
index 3dc5adbb..e119f660 100644
--- a/openstackclient/identity/common.py
+++ b/openstackclient/identity/common.py
@@ -26,6 +26,16 @@ from osc_lib import utils
from openstackclient.i18n import _
+def find_service_in_list(service_list, service_id):
+ """Find a service by id in service list."""
+
+ for service in service_list:
+ if service.id == service_id:
+ return service
+ raise exceptions.CommandError(
+ "No service with a type, name or ID of '%s' exists." % service_id)
+
+
def find_service(identity_client, name_type_or_id):
"""Find a service by id, name or type."""
diff --git a/openstackclient/identity/v3/endpoint.py b/openstackclient/identity/v3/endpoint.py
index 15760a17..3b4dd0de 100644
--- a/openstackclient/identity/v3/endpoint.py
+++ b/openstackclient/identity/v3/endpoint.py
@@ -167,9 +167,10 @@ class ListEndpoint(command.Lister):
if parsed_args.region:
kwargs['region'] = parsed_args.region
data = identity_client.endpoints.list(**kwargs)
+ service_list = identity_client.services.list()
for ep in data:
- service = common.find_service(identity_client, ep.service_id)
+ service = common.find_service_in_list(service_list, ep.service_id)
ep.service_name = get_service_name(service)
ep.service_type = service.type
return (columns,
diff --git a/openstackclient/tests/unit/identity/v3/test_endpoint.py b/openstackclient/tests/unit/identity/v3/test_endpoint.py
index 765fbedd..fad53fcb 100644
--- a/openstackclient/tests/unit/identity/v3/test_endpoint.py
+++ b/openstackclient/tests/unit/identity/v3/test_endpoint.py
@@ -295,6 +295,7 @@ class TestEndpointList(TestEndpoint):
# This is the return value for common.find_resource(service)
self.services_mock.get.return_value = self.service
+ self.services_mock.list.return_value = [self.service]
# Get the command object to test
self.cmd = endpoint.ListEndpoint(self.app, None)
@@ -726,6 +727,7 @@ class TestEndpointListServiceWithoutName(TestEndpointList):
# This is the return value for common.find_resource(service)
self.services_mock.get.return_value = self.service
+ self.services_mock.list.return_value = [self.service]
# Get the command object to test
self.cmd = endpoint.ListEndpoint(self.app, None)