Make os-cache retry on an invalid token

client.authenticate doesn't actually do any rest calls if a token is present,
it just assumes the token is valid.  Instead re-authentication is done if the
request raises an Unauthorized exception, at which point we want to
unauthenticate (delete the token from in-memory) and overwrite the old token
in the keyring. Also if a password is present allways pass it into the client
so re-authentication is possible during _cs_request.

Change-Id: I86d0356d5685ffa802f1bdc97e33727ff2dd075e
This commit is contained in:
Joe Gordon 2013-10-10 08:21:48 +00:00
parent 18ad5270f4
commit 6f9d9df7df
2 changed files with 6 additions and 10 deletions

View File

@ -214,9 +214,11 @@ class HTTPClient(object):
return resp, body
except exceptions.Unauthorized as e:
try:
# frist discard auth token, to avoid the possibly expired
# first discard auth token, to avoid the possibly expired
# token being re-used in the re-authentication attempt
self.unauthenticate()
# overwrite bad token
self.keyring_saved = False
self.authenticate()
kwargs['headers']['X-Auth-Token'] = self.auth_token
resp, body = self._time_request(self.management_url + url,

View File

@ -629,15 +629,9 @@ class OpenStackComputeShell(object):
self.cs.client.tenant_id = tenant_id
self.cs.client.auth_token = auth_token
self.cs.client.management_url = management_url
# Try to auth with the given info, if it fails
# go into password mode...
try:
self.cs.authenticate()
use_pw = False
except (exc.Unauthorized, exc.AuthorizationFailure):
# Likely it expired or just didn't work...
self.cs.client.auth_token = None
self.cs.client.management_url = None
# authenticate just sets up some values in this case, no REST
# calls
self.cs.authenticate()
if use_pw:
# Auth using token must have failed or not happened
# at all, so now switch to password mode and save