From 4725111e18a6b10e702c7ccd9cdfc1f6936fc19c Mon Sep 17 00:00:00 2001 From: Adrien Cunin Date: Mon, 25 Jan 2016 10:47:01 +0100 Subject: [PATCH] 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 --- tempest_lib/services/identity/v2/token_client.py | 3 +++ tempest_lib/services/identity/v3/token_client.py | 3 +++ tempest_lib/tests/services/identity/v2/test_token_client.py | 5 +++++ tempest_lib/tests/services/identity/v3/test_token_client.py | 5 +++++ 4 files changed, 16 insertions(+) diff --git a/tempest_lib/services/identity/v2/token_client.py b/tempest_lib/services/identity/v2/token_client.py index 621f8b3..10c437c 100644 --- a/tempest_lib/services/identity/v2/token_client.py +++ b/tempest_lib/services/identity/v2/token_client.py @@ -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' diff --git a/tempest_lib/services/identity/v3/token_client.py b/tempest_lib/services/identity/v3/token_client.py index 5fb64d3..504b165 100644 --- a/tempest_lib/services/identity/v3/token_client.py +++ b/tempest_lib/services/identity/v3/token_client.py @@ -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' diff --git a/tempest_lib/tests/services/identity/v2/test_token_client.py b/tempest_lib/tests/services/identity/v2/test_token_client.py index cc309c7..f75bef8 100644 --- a/tempest_lib/tests/services/identity/v2/test_token_client.py +++ b/tempest_lib/tests/services/identity/v2/test_token_client.py @@ -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( diff --git a/tempest_lib/tests/services/identity/v3/test_token_client.py b/tempest_lib/tests/services/identity/v3/test_token_client.py index 4ff3109..ed82b87 100644 --- a/tempest_lib/tests/services/identity/v3/test_token_client.py +++ b/tempest_lib/tests/services/identity/v3/test_token_client.py @@ -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(