Catch authorization failures
Catch the most common authorization exceptions. Fixes bug 1048560 Change-Id: I81c562d6093e94e827e6583dcb31db8408980476
This commit is contained in:
parent
9b3c4f847d
commit
3265ad5241
@ -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.v2_0 import client as ksclient
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
_ksclient = ksclient.Client(username=user,
|
try:
|
||||||
password=key,
|
_ksclient = ksclient.Client(username=user,
|
||||||
tenant_name=os_options.get('tenant_name'),
|
password=key,
|
||||||
tenant_id=os_options.get('tenant_id'),
|
tenant_name=os_options.get('tenant_name'),
|
||||||
auth_url=auth_url)
|
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'
|
service_type = os_options.get('service_type') or 'object-store'
|
||||||
endpoint_type = os_options.get('endpoint_type') or 'publicURL'
|
endpoint_type = os_options.get('endpoint_type') or 'publicURL'
|
||||||
try:
|
try:
|
||||||
|
@ -240,6 +240,15 @@ class TestGetAuth(MockHttpTest):
|
|||||||
'http://www.tests.com', 'asdf', 'asdf',
|
'http://www.tests.com', 'asdf', 'asdf',
|
||||||
os_options=os_options, auth_version='2.0')
|
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):
|
class TestGetAccount(MockHttpTest):
|
||||||
|
|
||||||
def test_no_content(self):
|
def test_no_content(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user