summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Harbott <j.harbott@x-ion.de>2018-03-18 09:33:19 +0000
committerJens Harbott <j.harbott@x-ion.de>2018-03-21 09:17:01 +0000
commit26cb0f6fcbdc96c25a3ec6abcf6d6785cfec15df (patch)
tree73578f816280eeb250696b90eadec568ca495ffc
parentd9734a916df951220d92d71f168473c474089701 (diff)
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
Notes
Notes (review): Code-Review+1: sunzhen123 <sunzhen@awcloud.com> Code-Review+2: Colleen Murphy <colleen@gazlene.net> Code-Review+2: Morgan Fainberg <morgan.fainberg@gmail.com> Workflow+1: Morgan Fainberg <morgan.fainberg@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 28 Mar 2018 18:39:57 +0000 Reviewed-on: https://review.openstack.org/554044 Project: openstack/keystoneauth Branch: refs/heads/master
-rw-r--r--keystoneauth1/identity/generic/base.py13
-rw-r--r--keystoneauth1/tests/unit/identity/test_identity_common.py24
2 files changed, 34 insertions, 3 deletions
diff --git a/keystoneauth1/identity/generic/base.py b/keystoneauth1/identity/generic/base.py
index 8994d50..543f85e 100644
--- a/keystoneauth1/identity/generic/base.py
+++ b/keystoneauth1/identity/generic/base.py
@@ -138,7 +138,8 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
138 authenticated=False) 138 authenticated=False)
139 except (exceptions.DiscoveryFailure, 139 except (exceptions.DiscoveryFailure,
140 exceptions.HttpError, 140 exceptions.HttpError,
141 exceptions.ConnectionError): 141 exceptions.SSLError,
142 exceptions.ConnectionError) as e:
142 LOG.warning('Failed to discover available identity versions when ' 143 LOG.warning('Failed to discover available identity versions when '
143 'contacting %s. Attempting to parse version from URL.', 144 'contacting %s. Attempting to parse version from URL.',
144 self.auth_url) 145 self.auth_url)
@@ -153,6 +154,11 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
153 plugin = self.create_plugin(session, (2, 0), self.auth_url) 154 plugin = self.create_plugin(session, (2, 0), self.auth_url)
154 elif path.startswith('/v3'): 155 elif path.startswith('/v3'):
155 plugin = self.create_plugin(session, (3, 0), self.auth_url) 156 plugin = self.create_plugin(session, (3, 0), self.auth_url)
157 else:
158 raise exceptions.DiscoveryFailure(
159 'Could not find versioned identity endpoints when '
160 'attempting to authenticate. Please check that your '
161 'auth_url is correct. %s' % e)
156 162
157 else: 163 else:
158 # NOTE(jamielennox): version_data is always in oldest to newest 164 # NOTE(jamielennox): version_data is always in oldest to newest
@@ -191,8 +197,9 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
191 return plugin 197 return plugin
192 198
193 # so there were no URLs that i could use for auth of any version. 199 # so there were no URLs that i could use for auth of any version.
194 raise exceptions.DiscoveryFailure('Could not determine a suitable URL ' 200 raise exceptions.DiscoveryFailure(
195 'for the plugin') 201 'Could not find versioned identity endpoints when attempting '
202 'to authenticate. Please check that your auth_url is correct.')
196 203
197 def get_auth_ref(self, session, **kwargs): 204 def get_auth_ref(self, session, **kwargs):
198 if not self._plugin: 205 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 93f1a70..9438abe 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):
1928 endpoint_filter=self.ENDPOINT_FILTER) 1928 endpoint_filter=self.ENDPOINT_FILTER)
1929 1929
1930 self.assertIn(name, str(e)) 1930 self.assertIn(name, str(e))
1931
1932
1933class DiscoveryFailures(utils.TestCase):
1934 TEST_ROOT_URL = 'http://127.0.0.1:5000/'
1935
1936 def test_connection_error(self):
1937 self.requests_mock.get(self.TEST_ROOT_URL,
1938 exc=exceptions.ConnectionError)
1939 sess = session.Session()
1940 p = identity.generic.password.Password(self.TEST_ROOT_URL)
1941 self.assertRaises(exceptions.DiscoveryFailure, p.get_auth_ref, sess)
1942
1943 def test_client_exception(self):
1944 self.requests_mock.get(self.TEST_ROOT_URL,
1945 exc=exceptions.ClientException)
1946 sess = session.Session()
1947 p = identity.generic.password.Password(self.TEST_ROOT_URL)
1948 self.assertRaises(exceptions.ClientException, p.get_auth_ref, sess)
1949
1950 def test_ssl_error(self):
1951 self.requests_mock.get(self.TEST_ROOT_URL, exc=exceptions.SSLError)
1952 sess = session.Session()
1953 p = identity.generic.password.Password(self.TEST_ROOT_URL)
1954 self.assertRaises(exceptions.DiscoveryFailure, p.get_auth_ref, sess)