Raise IdentityError if auth_url doesn't exist

Otherwise a TypeError, not understandable for the user, is raised. This
happens for example when using tempest account-generator with no
identity uri defined in the config file.

Also added unit tests for this specific case.

Change-Id: Ia8d523f973240300e0010b9b28f5ee63b2b84341
This commit is contained in:
Adrien Cunin 2016-01-25 10:47:01 +01:00
parent f4b5b12aaf
commit 4725111e18
4 changed files with 16 additions and 0 deletions

View File

@ -28,6 +28,9 @@ class TokenClient(rest_client.RestClient):
None, None, None, disable_ssl_certificate_validation=dscv,
ca_certs=ca_certs, trace_requests=trace_requests)
if auth_url is None:
raise exceptions.IdentityError("Couldn't determine auth_url")
# Normalize URI to ensure /tokens is in it.
if 'tokens' not in auth_url:
auth_url = auth_url.rstrip('/') + '/tokens'

View File

@ -28,6 +28,9 @@ class V3TokenClient(rest_client.RestClient):
None, None, None, disable_ssl_certificate_validation=dscv,
ca_certs=ca_certs, trace_requests=trace_requests)
if auth_url is None:
raise exceptions.IdentityError("Couldn't determine auth_url")
if 'auth/tokens' not in auth_url:
auth_url = auth_url.rstrip('/') + '/auth/tokens'

View File

@ -18,6 +18,7 @@ import httplib2
from oslotest import mockpatch
from tempest_lib.common import rest_client
from tempest_lib import exceptions
from tempest_lib.services.identity.v2 import token_client
from tempest_lib.tests import base
from tempest_lib.tests import fake_http
@ -29,6 +30,10 @@ class TestTokenClientV2(base.TestCase):
super(TestTokenClientV2, self).setUp()
self.fake_200_http = fake_http.fake_httplib2(return_type=200)
def test_init_without_authurl(self):
self.assertRaises(exceptions.IdentityError,
token_client.TokenClient, None)
def test_auth(self):
token_client_v2 = token_client.TokenClient('fake_url')
post_mock = self.useFixture(mockpatch.PatchObject(

View File

@ -18,6 +18,7 @@ import httplib2
from oslotest import mockpatch
from tempest_lib.common import rest_client
from tempest_lib import exceptions
from tempest_lib.services.identity.v3 import token_client
from tempest_lib.tests import base
from tempest_lib.tests import fake_http
@ -29,6 +30,10 @@ class TestTokenClientV2(base.TestCase):
super(TestTokenClientV2, self).setUp()
self.fake_201_http = fake_http.fake_httplib2(return_type=201)
def test_init_without_authurl(self):
self.assertRaises(exceptions.IdentityError,
token_client.V3TokenClient, None)
def test_auth(self):
token_client_v3 = token_client.V3TokenClient('fake_url')
post_mock = self.useFixture(mockpatch.PatchObject(