From c0046d7d0120ee18aab2f32ac6bdfca724d972ce Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Sun, 7 Jun 2015 11:39:15 -0500 Subject: [PATCH] Stop using function deprecated in Python 3 Python 3 deprecated the logger.warn method in favor of warning. DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead Change-Id: Idbd4de3c7c631fb2c235701c9b300c37a90d9538 --- keystoneclient/auth/identity/base.py | 14 ++++++----- keystoneclient/auth/identity/generic/base.py | 6 ++--- keystoneclient/middleware/auth_token.py | 23 ++++++++++--------- keystoneclient/session.py | 4 ++-- .../tests/unit/test_auth_token_middleware.py | 2 +- keystoneclient/utils.py | 2 +- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/keystoneclient/auth/identity/base.py b/keystoneclient/auth/identity/base.py index 8b8d705d..f7851926 100644 --- a/keystoneclient/auth/identity/base.py +++ b/keystoneclient/auth/identity/base.py @@ -208,9 +208,10 @@ class BaseIdentityPlugin(base.BaseAuthPlugin): else: if not service_type: - LOG.warn(_LW('Plugin cannot return an endpoint without ' - 'knowing the service type that is required. Add ' - 'service_type to endpoint filtering data.')) + LOG.warning(_LW( + 'Plugin cannot return an endpoint without knowing the ' + 'service type that is required. Add service_type to ' + 'endpoint filtering data.')) return None if not interface: @@ -243,9 +244,10 @@ class BaseIdentityPlugin(base.BaseAuthPlugin): # NOTE(jamielennox): Again if we can't contact the server we fall # back to just returning the URL from the catalog. This may not be # the best default but we need it for now. - LOG.warn(_LW('Failed to contact the endpoint at %s for discovery. ' - 'Fallback to using that endpoint as the base url.'), - url) + LOG.warning(_LW( + 'Failed to contact the endpoint at %s for discovery. Fallback ' + 'to using that endpoint as the base url.'), + url) else: url = disc.url_for(version) diff --git a/keystoneclient/auth/identity/generic/base.py b/keystoneclient/auth/identity/generic/base.py index 7e148d2c..0b87d06d 100644 --- a/keystoneclient/auth/identity/generic/base.py +++ b/keystoneclient/auth/identity/generic/base.py @@ -130,9 +130,9 @@ class BaseGenericPlugin(base.BaseIdentityPlugin): except (exceptions.DiscoveryFailure, exceptions.HTTPError, exceptions.ConnectionError): - LOG.warn(_LW('Discovering versions from the identity service ' - 'failed when creating the password plugin. ' - 'Attempting to determine version from URL.')) + LOG.warning(_LW('Discovering versions from the identity service ' + 'failed when creating the password plugin. ' + 'Attempting to determine version from URL.')) url_parts = urlparse.urlparse(self.auth_url) path = url_parts.path.lower() diff --git a/keystoneclient/middleware/auth_token.py b/keystoneclient/middleware/auth_token.py index c6a08a4f..d0fe102e 100644 --- a/keystoneclient/middleware/auth_token.py +++ b/keystoneclient/middleware/auth_token.py @@ -750,8 +750,8 @@ class AuthProtocol(object): return token else: if not self.delay_auth_decision: - self.LOG.warn('Unable to find authentication token' - ' in headers') + self.LOG.warning('Unable to find authentication token' + ' in headers') self.LOG.debug('Headers: %s', env) raise InvalidUserToken('Unable to find token in headers') @@ -804,8 +804,8 @@ class AuthProtocol(object): if self.cert_file and self.key_file: kwargs['cert'] = (self.cert_file, self.key_file) elif self.cert_file or self.key_file: - self.LOG.warn('Cannot use only a cert or key file. ' - 'Please provide both. Ignoring.') + self.LOG.warning('Cannot use only a cert or key file. ' + 'Please provide both. Ignoring.') kwargs['verify'] = self.ssl_ca_file or True if self.ssl_insecure: @@ -822,7 +822,8 @@ class AuthProtocol(object): self.LOG.error('HTTP connection exception: %s', e) raise NetworkError('Unable to communicate with keystone') # NOTE(vish): sleep 0.5, 1, 2 - self.LOG.warn('Retrying on HTTP connection exception: %s', e) + self.LOG.warning('Retrying on HTTP connection exception: %s', + e) time.sleep(2.0 ** retry / 2) retry += 1 @@ -896,12 +897,12 @@ class AuthProtocol(object): datetime_expiry = timeutils.parse_isotime(expiry) return (token, timeutils.normalize_time(datetime_expiry)) except (AssertionError, KeyError): - self.LOG.warn( + self.LOG.warning( 'Unexpected response from keystone service: %s', data) raise ServiceError('invalid json response') except (ValueError): data['access']['token']['id'] = '' - self.LOG.warn( + self.LOG.warning( 'Unable to parse expiration time from token: %s', data) raise ServiceError('invalid json response') @@ -948,13 +949,13 @@ class AuthProtocol(object): return data except NetworkError: self.LOG.debug('Token validation failure.', exc_info=True) - self.LOG.warn('Authorization failed for token') + self.LOG.warning('Authorization failed for token') raise InvalidUserToken('Token authorization failed') except Exception: self.LOG.debug('Token validation failure.', exc_info=True) if token_id: self._token_cache.store_invalid(token_id) - self.LOG.warn('Authorization failed for token') + self.LOG.warning('Authorization failed for token') raise InvalidUserToken('Token authorization failed') def _build_user_headers(self, token_info): @@ -1143,7 +1144,7 @@ class AuthProtocol(object): if response.status_code == 200: return data if response.status_code == 404: - self.LOG.warn('Authorization failed for token') + self.LOG.warning('Authorization failed for token') raise InvalidUserToken('Token authorization failed') if response.status_code == 401: self.LOG.info( @@ -1156,7 +1157,7 @@ class AuthProtocol(object): self.LOG.info('Retrying validation') return self.verify_uuid_token(user_token, False) else: - self.LOG.warn('Invalid user token. Keystone response: %s', data) + self.LOG.warning('Invalid user token. Keystone response: %s', data) raise InvalidUserToken() diff --git a/keystoneclient/session.py b/keystoneclient/session.py index 0dbc0650..73ec0226 100644 --- a/keystoneclient/session.py +++ b/keystoneclient/session.py @@ -455,8 +455,8 @@ class Session(object): try: location = resp.headers['location'] except KeyError: - logger.warn(_LW("Failed to redirect request to %s as new " - "location was not provided."), resp.url) + logger.warning(_LW("Failed to redirect request to %s as new " + "location was not provided."), resp.url) else: # NOTE(jamielennox): We don't pass through connect_retry_delay. # This request actually worked so we can reset the delay count. diff --git a/keystoneclient/tests/unit/test_auth_token_middleware.py b/keystoneclient/tests/unit/test_auth_token_middleware.py index 32a322d6..091f9561 100644 --- a/keystoneclient/tests/unit/test_auth_token_middleware.py +++ b/keystoneclient/tests/unit/test_auth_token_middleware.py @@ -927,7 +927,7 @@ class CommonAuthTokenMiddlewareTest(object): self.msg = None self.debugmsg = None - def warn(self, msg=None, *args, **kwargs): + def warning(self, msg=None, *args, **kwargs): self.msg = msg def debug(self, msg=None, *args, **kwargs): diff --git a/keystoneclient/utils.py b/keystoneclient/utils.py index ea921af8..300ca542 100644 --- a/keystoneclient/utils.py +++ b/keystoneclient/utils.py @@ -331,7 +331,7 @@ class positional(object): if self._enforcement == self.EXCEPT: raise TypeError(message) elif self._enforcement == self.WARN: - logger.warn(message) + logger.warning(message) return func(*args, **kwargs)