diff --git a/keystonemiddleware/audit.py b/keystonemiddleware/audit.py index bfe6b219..88d295dd 100644 --- a/keystonemiddleware/audit.py +++ b/keystonemiddleware/audit.py @@ -46,6 +46,7 @@ from pycadf import reporterstep from pycadf import resource from pycadf import tag from pycadf import timestamp +import six from six.moves import configparser from six.moves.urllib import parse as urlparse import webob.dec @@ -79,6 +80,16 @@ AuditMap = collections.namedtuple('AuditMap', 'default_target_endpoint_type']) +# NOTE(blk-u): Compatibility for Python 2. SafeConfigParser and +# SafeConfigParser.readfp are deprecated in Python 3. Remove this when we drop +# support for Python 2. +if six.PY2: + class ConfigParser(configparser.SafeConfigParser): + read_file = configparser.SafeConfigParser.readfp +else: + ConfigParser = configparser.ConfigParser + + class OpenStackAuditApi(object): def __init__(self, cfg_file): @@ -90,8 +101,8 @@ class OpenStackAuditApi(object): if cfg_file: try: - map_conf = configparser.SafeConfigParser() - map_conf.readfp(open(cfg_file)) + map_conf = ConfigParser() + map_conf.read_file(open(cfg_file)) try: default_target_endpoint_type = map_conf.get( diff --git a/keystonemiddleware/auth_token/__init__.py b/keystonemiddleware/auth_token/__init__.py index e0956230..79e2425f 100644 --- a/keystonemiddleware/auth_token/__init__.py +++ b/keystonemiddleware/auth_token/__init__.py @@ -735,11 +735,11 @@ class AuthProtocol(object): verified = self._verify_signed_token(token, token_hashes) except exceptions.CertificateConfigError: - self._LOG.warn(_LW('Fetch certificate config failed, ' - 'fallback to online validation.')) + self._LOG.warning(_LW('Fetch certificate config failed, ' + 'fallback to online validation.')) except exc.RevocationListError: - self._LOG.warn(_LW('Fetch revocation list failed, ' - 'fallback to online validation.')) + self._LOG.warning(_LW('Fetch revocation list failed, ' + 'fallback to online validation.')) if verified is not None: data = jsonutils.loads(verified) @@ -764,7 +764,7 @@ class AuthProtocol(object): return auth_ref, data except (exceptions.ConnectionRefused, exceptions.RequestTimeout): self._LOG.debug('Token validation failure.', exc_info=True) - self._LOG.warn(_LW('Authorization failed for token')) + self._LOG.warning(_LW('Authorization failed for token')) raise exc.InvalidToken(_('Token authorization failed')) except exc.ServiceError: raise @@ -772,7 +772,7 @@ class AuthProtocol(object): self._LOG.debug('Token validation failure.', exc_info=True) if token_hashes: self._token_cache.store_invalid(token_hashes[0]) - self._LOG.warn(_LW('Authorization failed for token')) + self._LOG.warning(_LW('Authorization failed for token')) raise exc.InvalidToken(_('Token authorization failed')) def _build_user_headers(self, auth_ref):