Merge "New exception when auth_url is not specified"

This commit is contained in:
Jenkins 2014-03-06 21:03:46 +00:00 committed by Gerrit Code Review
commit 42f48fb1e7
3 changed files with 37 additions and 0 deletions

View File

@ -226,6 +226,9 @@ class HTTPClient(httplib2.Http):
'password': self.password, },
'tenantName': self.tenant_name, }, }
if self.auth_url is None:
raise exceptions.NoAuthURLProvided()
token_url = self.auth_url + "/tokens"
# Make sure we follow redirects when trying to reach Keystone
@ -250,6 +253,9 @@ class HTTPClient(httplib2.Http):
self._extract_service_catalog(resp_body)
def _get_endpoint_url(self):
if self.auth_url is None:
raise exceptions.NoAuthURLProvided()
url = self.auth_url + '/tokens/%s/endpoints' % self.auth_token
try:
resp, body = self._cs_request(url, "GET")

View File

@ -151,6 +151,10 @@ class BadInputError(Exception):
pass
class NoAuthURLProvided(BadInputError):
message = _("auth_url was not provided to the Neutron client")
class Error(Exception):
def __init__(self, message=None):
super(Error, self).__init__(message)

View File

@ -148,6 +148,33 @@ class CLITestAuthKeystone(testtools.TestCase):
self.mox.ReplayAll()
self.client.do_request('/resource', 'GET')
def test_refresh_token_no_auth_url(self):
self.mox.StubOutWithMock(self.client, "request")
self.client.auth_url = None
self.client.auth_token = TOKEN
self.client.endpoint_url = ENDPOINT_URL
res401 = self.mox.CreateMock(httplib2.Response)
res401.status = 401
# If a token is expired, neutron server returns 401
self.client.request(
mox.StrContains(ENDPOINT_URL + '/resource'), 'GET',
headers=mox.ContainsKeyValue('X-Auth-Token', TOKEN)
).AndReturn((res401, ''))
self.mox.ReplayAll()
self.assertRaises(exceptions.NoAuthURLProvided,
self.client.do_request,
'/resource',
'GET')
def test_get_endpoint_url_with_invalid_auth_url(self):
# Handle the case when auth_url is not provided
self.client.auth_url = None
self.assertRaises(exceptions.NoAuthURLProvided,
self.client._get_endpoint_url)
def test_get_endpoint_url(self):
self.mox.StubOutWithMock(self.client, "request")