From 26cb0f6fcbdc96c25a3ec6abcf6d6785cfec15df Mon Sep 17 00:00:00 2001 From: Jens Harbott Date: Sun, 18 Mar 2018 09:33:19 +0000 Subject: [PATCH] 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 --- keystoneauth1/identity/generic/base.py | 13 +++++++--- .../unit/identity/test_identity_common.py | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/keystoneauth1/identity/generic/base.py b/keystoneauth1/identity/generic/base.py index 8994d500..543f85e5 100644 --- a/keystoneauth1/identity/generic/base.py +++ b/keystoneauth1/identity/generic/base.py @@ -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: diff --git a/keystoneauth1/tests/unit/identity/test_identity_common.py b/keystoneauth1/tests/unit/identity/test_identity_common.py index 93f1a707..9438abe8 100644 --- a/keystoneauth1/tests/unit/identity/test_identity_common.py +++ b/keystoneauth1/tests/unit/identity/test_identity_common.py @@ -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)