Merge "New exception when auth_url is not specified"
This commit is contained in:
@@ -226,6 +226,9 @@ class HTTPClient(httplib2.Http):
|
|||||||
'password': self.password, },
|
'password': self.password, },
|
||||||
'tenantName': self.tenant_name, }, }
|
'tenantName': self.tenant_name, }, }
|
||||||
|
|
||||||
|
if self.auth_url is None:
|
||||||
|
raise exceptions.NoAuthURLProvided()
|
||||||
|
|
||||||
token_url = self.auth_url + "/tokens"
|
token_url = self.auth_url + "/tokens"
|
||||||
|
|
||||||
# Make sure we follow redirects when trying to reach Keystone
|
# Make sure we follow redirects when trying to reach Keystone
|
||||||
@@ -250,6 +253,9 @@ class HTTPClient(httplib2.Http):
|
|||||||
self._extract_service_catalog(resp_body)
|
self._extract_service_catalog(resp_body)
|
||||||
|
|
||||||
def _get_endpoint_url(self):
|
def _get_endpoint_url(self):
|
||||||
|
if self.auth_url is None:
|
||||||
|
raise exceptions.NoAuthURLProvided()
|
||||||
|
|
||||||
url = self.auth_url + '/tokens/%s/endpoints' % self.auth_token
|
url = self.auth_url + '/tokens/%s/endpoints' % self.auth_token
|
||||||
try:
|
try:
|
||||||
resp, body = self._cs_request(url, "GET")
|
resp, body = self._cs_request(url, "GET")
|
||||||
|
|||||||
@@ -151,6 +151,10 @@ class BadInputError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NoAuthURLProvided(BadInputError):
|
||||||
|
message = _("auth_url was not provided to the Neutron client")
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
def __init__(self, message=None):
|
def __init__(self, message=None):
|
||||||
super(Error, self).__init__(message)
|
super(Error, self).__init__(message)
|
||||||
|
|||||||
@@ -148,6 +148,33 @@ class CLITestAuthKeystone(testtools.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
self.client.do_request('/resource', 'GET')
|
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):
|
def test_get_endpoint_url(self):
|
||||||
self.mox.StubOutWithMock(self.client, "request")
|
self.mox.StubOutWithMock(self.client, "request")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user