Skip to content

Commit f6f5ce0

Browse files
author
Anton Frolov
committed
Optimize getting endpoint list
Currently ListEndpoint.take_action method unconditionally iterates over all endpoints and issue GET /v3/services/<ep.service_id> request for each endpoint. In case of HTTPS keystone endpoint this can take significant amout of time, and it only getting worse in case of multiple regions. This commit change this logic to making just two GET requests: first it gets endpoint list, then it gets service list, searching service in the list instead of issuing GET /v3/services/<id> request. Change-Id: I22b61c0b45b0205a2f5a4608c2473cb7814fe3cf Closes-Bug: 1719413
1 parent 953d74b commit f6f5ce0

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

openstackclient/identity/common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
from openstackclient.i18n import _
2727

2828

29+
def find_service_in_list(service_list, service_id):
30+
"""Find a service by id in service list."""
31+
32+
for service in service_list:
33+
if service.id == service_id:
34+
return service
35+
raise exceptions.CommandError(
36+
"No service with a type, name or ID of '%s' exists." % service_id)
37+
38+
2939
def find_service(identity_client, name_type_or_id):
3040
"""Find a service by id, name or type."""
3141

openstackclient/identity/v3/endpoint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ def take_action(self, parsed_args):
167167
if parsed_args.region:
168168
kwargs['region'] = parsed_args.region
169169
data = identity_client.endpoints.list(**kwargs)
170+
service_list = identity_client.services.list()
170171

171172
for ep in data:
172-
service = common.find_service(identity_client, ep.service_id)
173+
service = common.find_service_in_list(service_list, ep.service_id)
173174
ep.service_name = get_service_name(service)
174175
ep.service_type = service.type
175176
return (columns,

openstackclient/tests/unit/identity/v3/test_endpoint.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def setUp(self):
295295

296296
# This is the return value for common.find_resource(service)
297297
self.services_mock.get.return_value = self.service
298+
self.services_mock.list.return_value = [self.service]
298299

299300
# Get the command object to test
300301
self.cmd = endpoint.ListEndpoint(self.app, None)
@@ -726,6 +727,7 @@ def setUp(self):
726727

727728
# This is the return value for common.find_resource(service)
728729
self.services_mock.get.return_value = self.service
730+
self.services_mock.list.return_value = [self.service]
729731

730732
# Get the command object to test
731733
self.cmd = endpoint.ListEndpoint(self.app, None)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
fixes:
3+
- |
4+
Fix an issue with ``endpoint list`` working slow because it is issuing one GET
5+
request to /v3/services/<id> Keystone API for each endpoint. In case of HTTPS
6+
keystone endpoint and multiple regions it can take significant amount of time.
7+
[Bug `1719413 <https://bugs.launchpad.net/python-openstackclient/+bug/1719413>`_]
8+

0 commit comments

Comments
 (0)