Corrent using auth_type=none in clouds.yaml

First, we expect the 'auth' dict to never be empty, but it's actually
empty for the none auth type.

Second, we do not respect <service type>_endpoint_override, which are
very handy when used with the none auth type.

This change fixes both.

Change-Id: If05498095da88a85342e994bba9841a304c963a0
This commit is contained in:
Dmitry Tantsur 2019-06-12 10:44:12 +02:00
parent fa42d45b12
commit d2a97c14a6
4 changed files with 45 additions and 2 deletions

View File

@ -101,7 +101,7 @@ def check_valid_authentication_options(options, auth_plugin_name):
msgs = [] msgs = []
# when no auth params are passed in, user advised to use os-cloud # when no auth params are passed in, user advised to use os-cloud
if not options.auth: if not options.auth and auth_plugin_name != 'none':
msgs.append(_( msgs.append(_(
'Set a cloud-name with --os-cloud or OS_CLOUD' 'Set a cloud-name with --os-cloud or OS_CLOUD'
)) ))

View File

@ -202,9 +202,15 @@ class ClientManager(object):
self._auth_ref = self.auth.get_auth_ref(self.session) self._auth_ref = self.auth.get_auth_ref(self.session)
return self._auth_ref return self._auth_ref
def _override_for(self, service_type):
key = '%s_endpoint_override' % service_type.replace('-', '_')
return self._cli_options.config.get(key)
def is_service_available(self, service_type): def is_service_available(self, service_type):
"""Check if a service type is in the current Service Catalog""" """Check if a service type is in the current Service Catalog"""
# If there is an override, assume the service is available
if self._override_for(service_type):
return True
# Trigger authentication necessary to discover endpoint # Trigger authentication necessary to discover endpoint
if self.auth_ref: if self.auth_ref:
service_catalog = self.auth_ref.service_catalog service_catalog = self.auth_ref.service_catalog
@ -226,6 +232,11 @@ class ClientManager(object):
def get_endpoint_for_service_type(self, service_type, region_name=None, def get_endpoint_for_service_type(self, service_type, region_name=None,
interface='public'): interface='public'):
"""Return the endpoint URL for the service type.""" """Return the endpoint URL for the service type."""
# Overrides take priority unconditionally
override = self._override_for(service_type)
if override:
return override
if not interface: if not interface:
interface = 'public' interface = 'public'
# See if we are using password flow auth, i.e. we have a # See if we are using password flow auth, i.e. we have a

View File

@ -419,6 +419,31 @@ class TestClientManager(utils.TestClientManager):
self.assertEqual(client_manager.auth.project_id, fakes.PROJECT_ID) self.assertEqual(client_manager.auth.project_id, fakes.PROJECT_ID)
self.assertTrue(client_manager._auth_setup_completed) self.assertTrue(client_manager._auth_setup_completed)
def test_client_manager_none_auth(self):
# test token auth
client_manager = self._make_clientmanager(
auth_args={},
auth_plugin_name='none',
)
self.assertIsNone(
client_manager.get_endpoint_for_service_type('compute'))
def test_client_manager_endpoint_override(self):
# test token auth
client_manager = self._make_clientmanager(
auth_args={},
config_args={'compute_endpoint_override': 'http://example.com',
'foo_bar_endpoint_override': 'http://example2.com'},
auth_plugin_name='none',
)
self.assertEqual(
'http://example.com',
client_manager.get_endpoint_for_service_type('compute'))
self.assertEqual(
'http://example2.com',
client_manager.get_endpoint_for_service_type('foo-bar'))
self.assertTrue(client_manager.is_service_available('compute'))
class TestClientManagerSDK(utils.TestClientManager): class TestClientManagerSDK(utils.TestClientManager):

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixes incorrect error when using ``auth_type: none`` in ``clouds.yaml``.
- |
Respects the ``<service type>_endpoint_override`` configuration options,
similarly to openstacksdk.