diff options
| author | Chmouel Boudjnah <chmouel@enovance.com> | 2013-08-07 07:22:13 +0200 |
|---|---|---|
| committer | Chmouel Boudjnah <chmouel@enovance.com> | 2013-08-09 13:58:57 +0200 |
| commit | aeffdc8929e3411499cf97e531c8b5921bb72714 (patch) | |
| tree | 5c903f82b315b507649a40346221cf75e55aab6c /keystoneclient/middleware/auth_token.py | |
| parent | 648c4b5e2fe3ac2a95578b150bf7455fa8e2a5d2 (diff) | |
| download | python-keystoneclient-aeffdc8929e3411499cf97e531c8b5921bb72714.tar.gz | |
Don't cache tokens as invalid on network errors
Closes-Bug: 1172802
Change-Id: Ifc04f565b96d58a7a2f477a216b57af7f8de6a8e
Diffstat (limited to 'keystoneclient/middleware/auth_token.py')
| -rw-r--r-- | keystoneclient/middleware/auth_token.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/keystoneclient/middleware/auth_token.py b/keystoneclient/middleware/auth_token.py index 8a65dc6..1194994 100644 --- a/keystoneclient/middleware/auth_token.py +++ b/keystoneclient/middleware/auth_token.py @@ -251,6 +251,10 @@ class ConfigurationError(Exception): pass +class NetworkError(Exception): + pass + + class MiniResp(object): def __init__(self, error_message, env, headers=[]): # The HEAD method is unique: it must never return a body, even if @@ -363,6 +367,7 @@ class AuthProtocol(object): self.http_connect_timeout = (http_connect_timeout_cfg and int(http_connect_timeout_cfg)) self.auth_version = None + self.http_request_max_retries = 3 def _assert_valid_memcache_protection_config(self): if self._memcache_security_strategy: @@ -594,9 +599,8 @@ class AuthProtocol(object): """ conn = self._get_http_connection() - RETRIES = 3 + RETRIES = self.http_request_max_retries retry = 0 - while True: try: conn.request(method, path, **kwargs) @@ -606,7 +610,7 @@ class AuthProtocol(object): except Exception as e: if retry == RETRIES: self.LOG.error('HTTP connection exception: %s' % e) - raise ServiceError('Unable to communicate with keystone') + raise NetworkError('Unable to communicate with keystone') # NOTE(vish): sleep 0.5, 1, 2 self.LOG.warn('Retrying on HTTP connection exception: %s' % e) time.sleep(2.0 ** retry / 2) @@ -717,6 +721,10 @@ class AuthProtocol(object): expires = self._confirm_token_not_expired(data) self._cache_put(token_id, data, expires) return data + except NetworkError as e: + self.LOG.debug('Token validation failure.', exc_info=True) + self.LOG.warn("Authorization failed for token %s", user_token) + raise InvalidUserToken('Token authorization failed') except Exception as e: self.LOG.debug('Token validation failure.', exc_info=True) self._cache_store_invalid(user_token) |
