Fix endpoint query
oepnstacksdk returns generators, not lists, so we have to convert the returned values before length check or index access. Also keystone does not accept endpoint_type with URL suffix. Closes-Bug: #2123895 Change-Id: Icbf1eb9bab08690a35e402e7a5bd1e0b8912e88d Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
@@ -305,6 +305,7 @@ class _EnforcerUtils:
|
|||||||
try:
|
try:
|
||||||
services = self.connection.services(type=service_type,
|
services = self.connection.services(type=service_type,
|
||||||
name=service_name)
|
name=service_name)
|
||||||
|
services = list(services)
|
||||||
if len(services) > 1:
|
if len(services) > 1:
|
||||||
raise ValueError("Multiple services found")
|
raise ValueError("Multiple services found")
|
||||||
service_id = services[0].id
|
service_id = services[0].id
|
||||||
@@ -315,6 +316,7 @@ class _EnforcerUtils:
|
|||||||
try:
|
try:
|
||||||
regions = self.connection.regions(
|
regions = self.connection.regions(
|
||||||
name=CONF.oslo_limit.endpoint_region_name)
|
name=CONF.oslo_limit.endpoint_region_name)
|
||||||
|
regions = list(regions)
|
||||||
if len(regions) > 1:
|
if len(regions) > 1:
|
||||||
raise ValueError("Multiple regions found")
|
raise ValueError("Multiple regions found")
|
||||||
region_id = regions[0].id
|
region_id = regions[0].id
|
||||||
@@ -328,6 +330,7 @@ class _EnforcerUtils:
|
|||||||
service_id=service_id, region_id=region_id,
|
service_id=service_id, region_id=region_id,
|
||||||
interface=CONF.oslo_limit.endpoint_interface,
|
interface=CONF.oslo_limit.endpoint_interface,
|
||||||
)
|
)
|
||||||
|
endpoints = list(endpoints)
|
||||||
except os_exceptions.ResourceNotFound:
|
except os_exceptions.ResourceNotFound:
|
||||||
raise ValueError("Endpoint not found")
|
raise ValueError("Endpoint not found")
|
||||||
|
|
||||||
|
@@ -39,9 +39,8 @@ _options = [
|
|||||||
help=_("Region to which the endpoint belongs")),
|
help=_("Region to which the endpoint belongs")),
|
||||||
cfg.StrOpt(
|
cfg.StrOpt(
|
||||||
'endpoint_interface',
|
'endpoint_interface',
|
||||||
default='publicURL',
|
default='public',
|
||||||
choices=['public', 'publicURL', 'internal', 'internalURL',
|
choices=['public', 'internal', 'admin'],
|
||||||
'admin', 'adminURL'],
|
|
||||||
help=_("The interface for endpoint discovery")),
|
help=_("The interface for endpoint discovery")),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@@ -437,7 +437,7 @@ class TestEnforcerUtils(base.BaseTestCase):
|
|||||||
self.mock_conn.services.assert_called_once_with(type='SERVICE_TYPE',
|
self.mock_conn.services.assert_called_once_with(type='SERVICE_TYPE',
|
||||||
name='SERVICE_NAME')
|
name='SERVICE_NAME')
|
||||||
self.mock_conn.endpoints.assert_called_once_with(
|
self.mock_conn.endpoints.assert_called_once_with(
|
||||||
service_id='SERVICE_ID', region_id=None, interface='publicURL')
|
service_id='SERVICE_ID', region_id=None, interface='public')
|
||||||
|
|
||||||
def test_get_endpoint_lookup_multiple_endpoints(self):
|
def test_get_endpoint_lookup_multiple_endpoints(self):
|
||||||
self.config_fixture.config(group='oslo_limit', endpoint_id=None)
|
self.config_fixture.config(group='oslo_limit', endpoint_id=None)
|
||||||
@@ -462,7 +462,7 @@ class TestEnforcerUtils(base.BaseTestCase):
|
|||||||
self.mock_conn.services.assert_called_once_with(type='SERVICE_TYPE',
|
self.mock_conn.services.assert_called_once_with(type='SERVICE_TYPE',
|
||||||
name='SERVICE_NAME')
|
name='SERVICE_NAME')
|
||||||
self.mock_conn.endpoints.assert_called_once_with(
|
self.mock_conn.endpoints.assert_called_once_with(
|
||||||
service_id='SERVICE_ID', region_id=None, interface='publicURL')
|
service_id='SERVICE_ID', region_id=None, interface='public')
|
||||||
|
|
||||||
def test_get_endpoint_lookup_endpoint_not_found(self):
|
def test_get_endpoint_lookup_endpoint_not_found(self):
|
||||||
self.config_fixture.config(group='oslo_limit', endpoint_id=None)
|
self.config_fixture.config(group='oslo_limit', endpoint_id=None)
|
||||||
@@ -485,7 +485,7 @@ class TestEnforcerUtils(base.BaseTestCase):
|
|||||||
self.mock_conn.services.assert_called_once_with(type='SERVICE_TYPE',
|
self.mock_conn.services.assert_called_once_with(type='SERVICE_TYPE',
|
||||||
name='SERVICE_NAME')
|
name='SERVICE_NAME')
|
||||||
self.mock_conn.endpoints.assert_called_once_with(
|
self.mock_conn.endpoints.assert_called_once_with(
|
||||||
service_id='SERVICE_ID', region_id=None, interface='publicURL')
|
service_id='SERVICE_ID', region_id=None, interface='public')
|
||||||
|
|
||||||
def test_get_endpoint_lookup_multiple_service(self):
|
def test_get_endpoint_lookup_multiple_service(self):
|
||||||
self.config_fixture.config(group='oslo_limit', endpoint_id=None)
|
self.config_fixture.config(group='oslo_limit', endpoint_id=None)
|
||||||
@@ -557,7 +557,7 @@ class TestEnforcerUtils(base.BaseTestCase):
|
|||||||
self.mock_conn.regions.assert_called_once_with(name='regionOne')
|
self.mock_conn.regions.assert_called_once_with(name='regionOne')
|
||||||
self.mock_conn.endpoints.assert_called_once_with(
|
self.mock_conn.endpoints.assert_called_once_with(
|
||||||
service_id='SERVICE_ID', region_id='REGION_ID',
|
service_id='SERVICE_ID', region_id='REGION_ID',
|
||||||
interface='publicURL')
|
interface='public')
|
||||||
|
|
||||||
def test_get_endpoint_lookup_with_region_not_found(self):
|
def test_get_endpoint_lookup_with_region_not_found(self):
|
||||||
self.config_fixture.config(group='oslo_limit', endpoint_id=None)
|
self.config_fixture.config(group='oslo_limit', endpoint_id=None)
|
||||||
|
6
releasenotes/notes/bug-2123895-d46347955768fab1.yaml
Normal file
6
releasenotes/notes/bug-2123895-d46347955768fab1.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
`bug 2123895` <https://bugs.launchpad.net/oslo.limit/+bug/2123895>`_:
|
||||||
|
Fixed the capability to query endpoint id from Keystone, which consistently
|
||||||
|
failed due to internal TypeError.
|
Reference in New Issue
Block a user