Be more helpful when version discovery fails
Modify the error message for failed discovery in an attempt to better help the user fixing the issue. Include a reference to the actual exception that occured in the error message. Add SSLError to the list of caught exceptions so that we can log this case, too. Add some unit tests to verify the handling of possible exceptions during version discovery. Change-Id: I9c26ab35d5515a937e016421e26e844212cb0bb3 Closes-Bug: 1749144
This commit is contained in:
parent
d9734a916d
commit
26cb0f6fcb
|
@ -138,7 +138,8 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
|
|||
authenticated=False)
|
||||
except (exceptions.DiscoveryFailure,
|
||||
exceptions.HttpError,
|
||||
exceptions.ConnectionError):
|
||||
exceptions.SSLError,
|
||||
exceptions.ConnectionError) as e:
|
||||
LOG.warning('Failed to discover available identity versions when '
|
||||
'contacting %s. Attempting to parse version from URL.',
|
||||
self.auth_url)
|
||||
|
@ -153,6 +154,11 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
|
|||
plugin = self.create_plugin(session, (2, 0), self.auth_url)
|
||||
elif path.startswith('/v3'):
|
||||
plugin = self.create_plugin(session, (3, 0), self.auth_url)
|
||||
else:
|
||||
raise exceptions.DiscoveryFailure(
|
||||
'Could not find versioned identity endpoints when '
|
||||
'attempting to authenticate. Please check that your '
|
||||
'auth_url is correct. %s' % e)
|
||||
|
||||
else:
|
||||
# NOTE(jamielennox): version_data is always in oldest to newest
|
||||
|
@ -191,8 +197,9 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
|
|||
return plugin
|
||||
|
||||
# so there were no URLs that i could use for auth of any version.
|
||||
raise exceptions.DiscoveryFailure('Could not determine a suitable URL '
|
||||
'for the plugin')
|
||||
raise exceptions.DiscoveryFailure(
|
||||
'Could not find versioned identity endpoints when attempting '
|
||||
'to authenticate. Please check that your auth_url is correct.')
|
||||
|
||||
def get_auth_ref(self, session, **kwargs):
|
||||
if not self._plugin:
|
||||
|
|
|
@ -1928,3 +1928,27 @@ class GenericAuthPluginTests(utils.TestCase):
|
|||
endpoint_filter=self.ENDPOINT_FILTER)
|
||||
|
||||
self.assertIn(name, str(e))
|
||||
|
||||
|
||||
class DiscoveryFailures(utils.TestCase):
|
||||
TEST_ROOT_URL = 'http://127.0.0.1:5000/'
|
||||
|
||||
def test_connection_error(self):
|
||||
self.requests_mock.get(self.TEST_ROOT_URL,
|
||||
exc=exceptions.ConnectionError)
|
||||
sess = session.Session()
|
||||
p = identity.generic.password.Password(self.TEST_ROOT_URL)
|
||||
self.assertRaises(exceptions.DiscoveryFailure, p.get_auth_ref, sess)
|
||||
|
||||
def test_client_exception(self):
|
||||
self.requests_mock.get(self.TEST_ROOT_URL,
|
||||
exc=exceptions.ClientException)
|
||||
sess = session.Session()
|
||||
p = identity.generic.password.Password(self.TEST_ROOT_URL)
|
||||
self.assertRaises(exceptions.ClientException, p.get_auth_ref, sess)
|
||||
|
||||
def test_ssl_error(self):
|
||||
self.requests_mock.get(self.TEST_ROOT_URL, exc=exceptions.SSLError)
|
||||
sess = session.Session()
|
||||
p = identity.generic.password.Password(self.TEST_ROOT_URL)
|
||||
self.assertRaises(exceptions.DiscoveryFailure, p.get_auth_ref, sess)
|
||||
|
|
Loading…
Reference in New Issue