diff --git a/swiftclient/client.py b/swiftclient/client.py index cac480b9..4c5e2099 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -237,11 +237,17 @@ def get_keystoneclient_2_0(auth_url, user, key, os_options): """ from keystoneclient.v2_0 import client as ksclient from keystoneclient import exceptions - _ksclient = ksclient.Client(username=user, - password=key, - tenant_name=os_options.get('tenant_name'), - tenant_id=os_options.get('tenant_id'), - auth_url=auth_url) + try: + _ksclient = ksclient.Client(username=user, + password=key, + tenant_name=os_options.get('tenant_name'), + tenant_id=os_options.get('tenant_id'), + auth_url=auth_url) + except exceptions.Unauthorized: + raise ClientException('Unauthorised. Check username, password' + ' and tenant name/id') + except exceptions.AuthorizationFailure, err: + raise ClientException('Authorization Failure. %s' % err) service_type = os_options.get('service_type') or 'object-store' endpoint_type = os_options.get('endpoint_type') or 'publicURL' try: diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py index 08bf6cc8..d8d385ac 100644 --- a/tests/test_swiftclient.py +++ b/tests/test_swiftclient.py @@ -240,6 +240,15 @@ class TestGetAuth(MockHttpTest): 'http://www.tests.com', 'asdf', 'asdf', os_options=os_options, auth_version='2.0') + def test_auth_v2_ks_exception(self): + c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0( + {}, + c.ClientException) + self.assertRaises(c.ClientException, c.get_auth, + 'http://www.tests.com', 'asdf', 'asdf', + os_options={}, + auth_version='2.0') + class TestGetAccount(MockHttpTest): def test_no_content(self):