From e709b98201e1dfdd693064a0d96ea523084fd14e Mon Sep 17 00:00:00 2001 From: David Stanek Date: Wed, 3 Sep 2014 03:15:16 +0000 Subject: [PATCH] Adds missing log hints for level E/I/W This patch adds logging hints for the remaining logging statements. bp more-code-style-automation Change-Id: I78801d9d3187df6470b51b3ecb0f182440112d13 --- keystone/assignment/controllers.py | 12 ++++---- keystone/auth/controllers.py | 21 ++++++------- keystone/catalog/core.py | 2 +- keystone/cli.py | 12 ++++---- keystone/common/authorization.py | 4 +-- keystone/common/cache/backends/mongo.py | 10 +++---- keystone/common/cache/core.py | 6 ++-- keystone/common/controller.py | 20 ++++++------- .../common/environment/eventlet_server.py | 6 ++-- keystone/common/ldap/core.py | 4 +-- keystone/common/utils.py | 8 ++--- keystone/contrib/example/core.py | 14 ++++----- keystone/contrib/federation/utils.py | 4 +-- keystone/exception.py | 4 +-- keystone/identity/controllers.py | 8 ++--- keystone/identity/core.py | 6 ++-- keystone/middleware/core.py | 6 ++-- keystone/notifications.py | 8 ++--- keystone/tests/core.py | 4 +-- keystone/token/persistence/backends/kvs.py | 30 +++++++++---------- keystone/token/provider.py | 12 ++++---- keystone/token/providers/common.py | 12 ++++---- keystone/token/providers/pki.py | 4 +-- 23 files changed, 107 insertions(+), 110 deletions(-) diff --git a/keystone/assignment/controllers.py b/keystone/assignment/controllers.py index bd12615026..5a9f59729c 100644 --- a/keystone/assignment/controllers.py +++ b/keystone/assignment/controllers.py @@ -28,7 +28,7 @@ from keystone.common import dependency from keystone.common import validation from keystone import config from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LW from keystone.models import token_model from keystone.openstack.common import log @@ -74,7 +74,7 @@ class Tenant(controller.V2Controller): token_ref = token_model.KeystoneToken(token_id=context['token_id'], token_data=token_data) except exception.NotFound as e: - LOG.warning(_('Authentication failed: %s'), e) + LOG.warning(_LW('Authentication failed: %s'), e) raise exception.Unauthorized(e) tenant_refs = ( @@ -709,10 +709,10 @@ class RoleAssignmentV3(controller.V3Controller): if 'role' in ref and 'id' in ref['role']: role_id = ref['role']['id'] LOG.warning( - _('Group %(group)s not found for role-assignment - ' - '%(target)s with Role: %(role)s'), { - 'group': ref['group']['id'], 'target': target, - 'role': role_id}) + _LW('Group %(group)s not found for role-assignment - ' + '%(target)s with Role: %(role)s'), { + 'group': ref['group']['id'], 'target': target, + 'role': role_id}) return members def _build_user_assignment_equivalent_of_group( diff --git a/keystone/auth/controllers.py b/keystone/auth/controllers.py index 3943c1f6a6..0fb3e4999b 100644 --- a/keystone/auth/controllers.py +++ b/keystone/auth/controllers.py @@ -28,7 +28,7 @@ from keystone.common import wsgi from keystone import config from keystone.contrib import federation from keystone import exception -from keystone.i18n import _, _LI +from keystone.i18n import _, _LI, _LW from keystone.openstack.common import log @@ -438,25 +438,26 @@ class Auth(controller.V3Controller): user_ref['id'], default_project_id): auth_info.set_scope(project_id=default_project_id) else: - msg = _("User %(user_id)s doesn't have access to" - " default project %(project_id)s. The token will" - " be unscoped rather than scoped to the project.") + msg = _LW("User %(user_id)s doesn't have access to" + " default project %(project_id)s. The token" + " will be unscoped rather than scoped to the" + " project.") LOG.warning(msg, {'user_id': user_ref['id'], 'project_id': default_project_id}) else: - msg = _("User %(user_id)s's default project %(project_id)s is" - " disabled. The token will be unscoped rather than" - " scoped to the project.") + msg = _LW("User %(user_id)s's default project %(project_id)s" + " is disabled. The token will be unscoped rather" + " than scoped to the project.") LOG.warning(msg, {'user_id': user_ref['id'], 'project_id': default_project_id}) except (exception.ProjectNotFound, exception.DomainNotFound): # default project or default project domain doesn't exist, # will issue unscoped token instead - msg = _("User %(user_id)s's default project %(project_id)s not" - " found. The token will be unscoped rather than" - " scoped to the project.") + msg = _LW("User %(user_id)s's default project %(project_id)s not" + " found. The token will be unscoped rather than" + " scoped to the project.") LOG.warning(msg, {'user_id': user_ref['id'], 'project_id': default_project_id}) diff --git a/keystone/catalog/core.py b/keystone/catalog/core.py index a8fbc95431..d8d563545c 100644 --- a/keystone/catalog/core.py +++ b/keystone/catalog/core.py @@ -53,7 +53,7 @@ def format_url(url, substitutions): try: result = url.replace('$(', '%(') % substitutions except AttributeError: - LOG.error(_('Malformed endpoint - %(url)r is not a string'), + LOG.error(_LE('Malformed endpoint - %(url)r is not a string'), {"url": url}) raise exception.MalformedEndpoint(endpoint=url) except KeyError as e: diff --git a/keystone/cli.py b/keystone/cli.py index 38ba428a74..90b1e01035 100644 --- a/keystone/cli.py +++ b/keystone/cli.py @@ -25,7 +25,7 @@ from keystone.common import sql from keystone.common.sql import migration_helpers from keystone.common import utils from keystone import config -from keystone.i18n import _ +from keystone.i18n import _, _LW from keystone import identity from keystone.openstack.common import log from keystone import token @@ -141,9 +141,8 @@ class PKISetup(BaseCertificateSetup): @classmethod def main(cls): - msg = _('keystone-manage pki_setup is not recommended for production ' - 'use.') - LOG.warn(msg) + LOG.warn(_LW('keystone-manage pki_setup is not recommended for ' + 'production use.')) keystone_user_id, keystone_group_id = cls.get_user_group() conf_pki = openssl.ConfigurePKI(keystone_user_id, keystone_group_id, rebuild=CONF.command.rebuild) @@ -161,9 +160,8 @@ class SSLSetup(BaseCertificateSetup): @classmethod def main(cls): - msg = _('keystone-manage ssl_setup is not recommended for production ' - 'use.') - LOG.warn(msg) + LOG.warn(_LW('keystone-manage ssl_setup is not recommended for ' + 'production use.')) keystone_user_id, keystone_group_id = cls.get_user_group() conf_ssl = openssl.ConfigureSSL(keystone_user_id, keystone_group_id, rebuild=CONF.command.rebuild) diff --git a/keystone/common/authorization.py b/keystone/common/authorization.py index 65dae93a45..e25640d8fe 100644 --- a/keystone/common/authorization.py +++ b/keystone/common/authorization.py @@ -17,7 +17,7 @@ # under the License. from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LW from keystone.models import token_model from keystone.openstack.common import log @@ -51,7 +51,7 @@ def token_to_auth_context(token): try: auth_context['user_id'] = token.user_id except KeyError: - LOG.warning(_('RBAC: Invalid user data in token')) + LOG.warning(_LW('RBAC: Invalid user data in token')) raise exception.Unauthorized() if token.project_scoped: diff --git a/keystone/common/cache/backends/mongo.py b/keystone/common/cache/backends/mongo.py index c9d25d1aa4..199845cfa2 100644 --- a/keystone/common/cache/backends/mongo.py +++ b/keystone/common/cache/backends/mongo.py @@ -22,7 +22,7 @@ from oslo.utils import timeutils import six from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LW from keystone.openstack.common import log @@ -400,10 +400,10 @@ class MongoApi(object): existing_value = index_data['expireAfterSeconds'] fld_present = 'doc_date' in index_data['key'][0] if fld_present and existing_value > -1 and ttl_seconds < 1: - msg = _('TTL index already exists on db collection ' - '<%(c_name)s>, remove index <%(indx_name)s> first' - ' to make updated mongo_ttl_seconds value to be ' - ' effective') + msg = _LW('TTL index already exists on db collection ' + '<%(c_name)s>, remove index <%(indx_name)s> ' + 'first to make updated mongo_ttl_seconds value ' + 'to be effective') LOG.warn(msg, {'c_name': coll_name, 'indx_name': indx_name}) diff --git a/keystone/common/cache/core.py b/keystone/common/cache/core.py index 6a75e49a4b..3f7a86e384 100644 --- a/keystone/common/cache/core.py +++ b/keystone/common/cache/core.py @@ -21,7 +21,7 @@ from oslo.utils import importutils from keystone import config from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LE from keystone.openstack.common import log @@ -97,8 +97,8 @@ def build_cache_config(): try: (argname, argvalue) = argument.split(':', 1) except ValueError: - msg = _('Unable to build cache config-key. Expected format ' - '":". Skipping unknown format: %s') + msg = _LE('Unable to build cache config-key. Expected format ' + '":". Skipping unknown format: %s') LOG.error(msg, argument) continue diff --git a/keystone/common/controller.py b/keystone/common/controller.py index b25d70f6eb..4cf9554290 100644 --- a/keystone/common/controller.py +++ b/keystone/common/controller.py @@ -22,7 +22,7 @@ from keystone.common import utils from keystone.common import wsgi from keystone import config from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LW from keystone.models import token_model from keystone.openstack.common import log @@ -74,7 +74,7 @@ def _build_policy_check_credentials(self, action, context, kwargs): # backing store. wsgi.validate_token_bind(context, token_ref) except exception.TokenNotFound: - LOG.warning(_('RBAC: Invalid token')) + LOG.warning(_LW('RBAC: Invalid token')) raise exception.Unauthorized() auth_context = authorization.token_to_auth_context(token_ref) @@ -99,7 +99,7 @@ def protected(callback=None): @functools.wraps(f) def inner(self, context, *args, **kwargs): if 'is_admin' in context and context['is_admin']: - LOG.warning(_('RBAC: Bypassing authorization')) + LOG.warning(_LW('RBAC: Bypassing authorization')) elif callback is not None: prep_info = {'f_name': f.__name__, 'input_attr': kwargs} @@ -196,7 +196,7 @@ def filterprotected(*filters): LOG.debug('RBAC: Authorization granted') else: - LOG.warning(_('RBAC: Bypassing authorization')) + LOG.warning(_LW('RBAC: Bypassing authorization')) return f(self, context, filters, **kwargs) return wrapper return _filterprotected @@ -585,15 +585,15 @@ class V3Controller(wsgi.Application): _('domain_id is required as part of entity')) except (exception.TokenNotFound, exception.UnsupportedTokenVersionException): - LOG.warning(_('Invalid token found while getting domain ID ' - 'for list request')) + LOG.warning(_LW('Invalid token found while getting domain ID ' + 'for list request')) raise exception.Unauthorized() if token_ref.domain_scoped: return token_ref.domain_id else: LOG.warning( - _('No domain information specified as part of list request')) + _LW('No domain information specified as part of list request')) raise exception.Unauthorized() def _get_domain_id_from_token(self, context): @@ -620,8 +620,8 @@ class V3Controller(wsgi.Application): _('A domain-scoped token must be used')) except (exception.TokenNotFound, exception.UnsupportedTokenVersionException): - LOG.warning(_('Invalid token found while getting domain ID ' - 'for list request')) + LOG.warning(_LW('Invalid token found while getting domain ID ' + 'for list request')) raise exception.Unauthorized() if token_ref.domain_scoped: @@ -656,7 +656,7 @@ class V3Controller(wsgi.Application): """ if 'is_admin' in context and context['is_admin']: - LOG.warning(_('RBAC: Bypassing authorization')) + LOG.warning(_LW('RBAC: Bypassing authorization')) else: action = 'identity:%s' % prep_info['f_name'] # TODO(henry-nash) need to log the target attributes as well diff --git a/keystone/common/environment/eventlet_server.py b/keystone/common/environment/eventlet_server.py index fa6d58f658..fd1afd7bfc 100644 --- a/keystone/common/environment/eventlet_server.py +++ b/keystone/common/environment/eventlet_server.py @@ -26,9 +26,7 @@ import eventlet import eventlet.wsgi import greenlet -from keystone.i18n import _ -from keystone.i18n import _LE -from keystone.i18n import _LI +from keystone.i18n import _LE, _LI from keystone.openstack.common import log @@ -184,5 +182,5 @@ class Server(object): # Wait until all servers have completed running pass except Exception: - LOG.exception(_('Server error')) + LOG.exception(_LE('Server error')) raise diff --git a/keystone/common/ldap/core.py b/keystone/common/ldap/core.py index 2da70e32a0..6b3ed5700b 100644 --- a/keystone/common/ldap/core.py +++ b/keystone/common/ldap/core.py @@ -1650,8 +1650,8 @@ class BaseLdap(object): not_deleted_nodes.append(node_dn) if not_deleted_nodes: - LOG.warn(_("When deleting entries for %(search_base)s, could not" - " delete nonexistent entries %(entries)s%(dots)s"), + LOG.warn(_LW("When deleting entries for %(search_base)s, could not" + " delete nonexistent entries %(entries)s%(dots)s"), {'search_base': search_base, 'entries': not_deleted_nodes[:3], 'dots': '...' if len(not_deleted_nodes) > 3 else ''}) diff --git a/keystone/common/utils.py b/keystone/common/utils.py index d27de54b07..91f9c55b79 100644 --- a/keystone/common/utils.py +++ b/keystone/common/utils.py @@ -32,7 +32,7 @@ from six import moves from keystone.common import config from keystone.common import environment from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LE, _LW from keystone.openstack.common import log @@ -101,8 +101,8 @@ def verify_length_and_trunc_password(password): raise exception.PasswordVerificationError(size=max_length) else: LOG.warning( - _('Truncating user password to ' - '%d characters.'), max_length) + _LW('Truncating user password to ' + '%d characters.'), max_length) return password[:max_length] else: return password @@ -278,7 +278,7 @@ def setup_remote_pydev_debug(): stderrToServer=True) return True except Exception: - LOG.exception(_( + LOG.exception(_LE( 'Error setting up the debug environment. Verify that the ' 'option --debug-url has the format : and that a ' 'debugger processes is listening on that port.')) diff --git a/keystone/contrib/example/core.py b/keystone/contrib/example/core.py index d7a83c5815..76c3ca7c70 100644 --- a/keystone/contrib/example/core.py +++ b/keystone/contrib/example/core.py @@ -16,7 +16,7 @@ from keystone.common import dependency from keystone.common import manager from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _LI from keystone import notifications from keystone.openstack.common import log @@ -61,18 +61,18 @@ class ExampleManager(manager.Manager): def project_deleted_callback(self, service, resource_type, operation, payload): # The code below is merely an example. - msg = _('Received the following notification: service %(service)s, ' - 'resource_type: %(resource_type)s, operation %(operation)s ' - 'payload %(payload)s') + msg = _LI('Received the following notification: service %(service)s, ' + 'resource_type: %(resource_type)s, operation %(operation)s ' + 'payload %(payload)s') LOG.info(msg, {'service': service, 'resource_type': resource_type, 'operation': operation, 'payload': payload}) def project_created_callback(self, service, resource_type, operation, payload): # The code below is merely an example. - msg = _('Received the following notification: service %(service)s, ' - 'resource_type: %(resource_type)s, operation %(operation)s ' - 'payload %(payload)s') + msg = _LI('Received the following notification: service %(service)s, ' + 'resource_type: %(resource_type)s, operation %(operation)s ' + 'payload %(payload)s') LOG.info(msg, {'service': service, 'resource_type': resource_type, 'operation': operation, 'payload': payload}) diff --git a/keystone/contrib/federation/utils.py b/keystone/contrib/federation/utils.py index 985ceed13b..a78525c05c 100644 --- a/keystone/contrib/federation/utils.py +++ b/keystone/contrib/federation/utils.py @@ -20,7 +20,7 @@ import six from keystone.common import config from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LW from keystone.openstack.common import log @@ -255,7 +255,7 @@ class RuleProcessor(object): if 'user' in identity_value: # if a mapping outputs more than one user name, log it if user_name is not None: - LOG.warning(_('Ignoring user name %s'), + LOG.warning(_LW('Ignoring user name %s'), identity_value['user']['name']) else: user_name = identity_value['user']['name'] diff --git a/keystone/exception.py b/keystone/exception.py index 2679af64d6..7dd4586776 100644 --- a/keystone/exception.py +++ b/keystone/exception.py @@ -16,7 +16,7 @@ from oslo.utils import encodeutils import six from keystone.common import config -from keystone.i18n import _ +from keystone.i18n import _, _LW from keystone.openstack.common import log @@ -46,7 +46,7 @@ class Error(Exception): if _FATAL_EXCEPTION_FORMAT_ERRORS: raise else: - LOG.warning(_('missing exception kwargs (programmer error)')) + LOG.warning(_LW('missing exception kwargs (programmer error)')) message = self.message_format super(Error, self).__init__(message) diff --git a/keystone/identity/controllers.py b/keystone/identity/controllers.py index 525e58dab9..326b20be66 100644 --- a/keystone/identity/controllers.py +++ b/keystone/identity/controllers.py @@ -18,7 +18,7 @@ from keystone.common import controller from keystone.common import dependency from keystone import config from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LW from keystone.openstack.common import log @@ -134,8 +134,8 @@ class User(controller.V2Controller): # old tenant. This could occur if roles aren't found # or if the project is invalid or if there are no roles # for the user on that project. - msg = _('Unable to remove user %(user)s from ' - '%(tenant)s.') + msg = _LW('Unable to remove user %(user)s from ' + '%(tenant)s.') LOG.warning(msg, {'user': user_id, 'tenant': old_user_ref['tenantId']}) @@ -153,7 +153,7 @@ class User(controller.V2Controller): # that the project is invalid or roles are some how # incorrect. This shouldn't prevent the return of the # new ref. - msg = _('Unable to add user %(user)s to %(tenant)s.') + msg = _LW('Unable to add user %(user)s to %(tenant)s.') LOG.warning(msg, {'user': user_id, 'tenant': user_ref['tenantId']}) diff --git a/keystone/identity/core.py b/keystone/identity/core.py index ef0b36f6fc..e9c232cf18 100644 --- a/keystone/identity/core.py +++ b/keystone/identity/core.py @@ -29,7 +29,7 @@ from keystone.common import driver_hints from keystone.common import manager from keystone import config from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LW from keystone.identity.mapping_backends import mapping from keystone import notifications from keystone.openstack.common import log @@ -115,7 +115,7 @@ class DomainConfigs(dict): domain_ref = assignment_api.get_domain_by_name(domain_name) except exception.DomainNotFound: LOG.warning( - _('Invalid domain name (%s) found in config file name'), + _LW('Invalid domain name (%s) found in config file name'), domain_name) return @@ -141,7 +141,7 @@ class DomainConfigs(dict): conf_dir = CONF.identity.domain_config_dir if not os.path.exists(conf_dir): - LOG.warning(_('Unable to locate domain config directory: %s'), + LOG.warning(_LW('Unable to locate domain config directory: %s'), conf_dir) return diff --git a/keystone/middleware/core.py b/keystone/middleware/core.py index 83cd593dd6..8d6d60b81c 100644 --- a/keystone/middleware/core.py +++ b/keystone/middleware/core.py @@ -22,7 +22,7 @@ from keystone.common import serializer from keystone.common import utils from keystone.common import wsgi from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _LW from keystone.models import token_model from keystone.openstack.common import log from keystone.openstack.common import versionutils @@ -262,7 +262,7 @@ class AuthContextMiddleware(wsgi.Middleware): wsgi.validate_token_bind(context, token_ref) return authorization.token_to_auth_context(token_ref) except exception.TokenNotFound: - LOG.warning(_('RBAC: Invalid token')) + LOG.warning(_LW('RBAC: Invalid token')) raise exception.Unauthorized() def process_request(self, request): @@ -272,7 +272,7 @@ class AuthContextMiddleware(wsgi.Middleware): return if authorization.AUTH_CONTEXT_ENV in request.environ: - msg = _('Auth context already exists in the request environment') + msg = _LW('Auth context already exists in the request environment') LOG.warning(msg) return diff --git a/keystone/notifications.py b/keystone/notifications.py index 7457126f03..262f4a379c 100644 --- a/keystone/notifications.py +++ b/keystone/notifications.py @@ -28,7 +28,7 @@ from pycadf import credential from pycadf import eventfactory from pycadf import resource -from keystone.i18n import _ +from keystone.i18n import _, _LE from keystone.openstack.common import log @@ -220,7 +220,7 @@ def _get_notifier(): transport = messaging.get_transport(CONF) _notifier = messaging.Notifier(transport, "identity.%s" % host) except Exception: - LOG.exception(_("Failed to construct notifier")) + LOG.exception(_LE("Failed to construct notifier")) _notifier = False return _notifier @@ -264,7 +264,7 @@ def _send_notification(operation, resource_type, resource_id, public=True): try: notifier.info(context, event_type, payload) except Exception: - LOG.exception(_( + LOG.exception(_LE( 'Failed to send %(res_id)s %(event_type)s notification'), {'res_id': resource_id, 'event_type': event_type}) @@ -452,7 +452,7 @@ def _send_audit_notification(action, initiator, outcome, **kwargs): except Exception: # diaper defense: any exception that occurs while emitting the # notification should not interfere with the API request - LOG.exception(_( + LOG.exception(_LE( 'Failed to send %(action)s %(event_type)s notification'), {'action': action, 'event_type': event_type}) diff --git a/keystone/tests/core.py b/keystone/tests/core.py index faedb15e7b..b6618b33bb 100644 --- a/keystone/tests/core.py +++ b/keystone/tests/core.py @@ -49,7 +49,7 @@ from keystone.common import utils as common_utils from keystone import config from keystone import controllers from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _LW from keystone import notifications from keystone.openstack.common import log from keystone import service @@ -143,7 +143,7 @@ def checkout_vendor(repo, rev): with open(modcheck, 'w') as fd: fd.write('1') except environment.subprocess.CalledProcessError: - LOG.warning(_('Failed to checkout %s'), repo) + LOG.warning(_LW('Failed to checkout %s'), repo) os.chdir(working_dir) return revdir diff --git a/keystone/token/persistence/backends/kvs.py b/keystone/token/persistence/backends/kvs.py index af3ab3c9cc..5f4750e83d 100644 --- a/keystone/token/persistence/backends/kvs.py +++ b/keystone/token/persistence/backends/kvs.py @@ -22,7 +22,7 @@ import six from keystone.common import kvs from keystone import config from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LE, _LW from keystone.openstack.common import log from keystone import token from keystone.token import provider @@ -54,12 +54,12 @@ class Token(token.persistence.Driver): if self.__class__ == Token: # NOTE(morganfainberg): Only warn if the base KVS implementation # is instantiated. - LOG.warn(_('It is recommended to only use the base ' - 'key-value-store implementation for the token driver ' - 'for testing purposes. Please use ' - 'keystone.token.persistence.backends.memcache.Token ' - 'or keystone.token.persistence.backends.sql.Token ' - 'instead.')) + LOG.warn(_LW('It is recommended to only use the base ' + 'key-value-store implementation for the token driver ' + 'for testing purposes. Please use ' + 'keystone.token.persistence.backends.memcache.Token ' + 'or keystone.token.persistence.backends.sql.Token ' + 'instead.')) def _prefix_token_id(self, token_id): return 'token-%s' % token_id.encode('utf-8') @@ -203,8 +203,8 @@ class Token(token.persistence.Driver): expires = timeutils.normalize_time(expires) if expires < current_time: - LOG.warning(_('Token `%s` is expired, not adding to the ' - 'revocation list.'), data['id']) + LOG.warning(_LW('Token `%s` is expired, not adding to the ' + 'revocation list.'), data['id']) return revoked_token_data['expires'] = timeutils.isotime(expires, @@ -223,10 +223,10 @@ class Token(token.persistence.Driver): # be recoverable. Keystone cannot control external applications # from changing a key in some backends, however, it is possible to # gracefully handle and notify of this event. - LOG.error(_('Reinitializing revocation list due to error ' - 'in loading revocation list from backend. ' - 'Expected `list` type got `%(type)s`. Old ' - 'revocation list data: %(list)r'), + LOG.error(_LE('Reinitializing revocation list due to error ' + 'in loading revocation list from backend. ' + 'Expected `list` type got `%(type)s`. Old ' + 'revocation list data: %(list)r'), {'type': type(token_list), 'list': token_list}) token_list = [] @@ -237,8 +237,8 @@ class Token(token.persistence.Driver): expires_at = timeutils.normalize_time( timeutils.parse_isotime(token_data['expires'])) except ValueError: - LOG.warning(_('Removing `%s` from revocation list due to ' - 'invalid expires data in revocation list.'), + LOG.warning(_LW('Removing `%s` from revocation list due to ' + 'invalid expires data in revocation list.'), token_data.get('id', 'INVALID_TOKEN_DATA')) continue if expires_at > current_time: diff --git a/keystone/token/provider.py b/keystone/token/provider.py index 527ef56da2..7f0a5e5551 100644 --- a/keystone/token/provider.py +++ b/keystone/token/provider.py @@ -29,7 +29,7 @@ from keystone.common import dependency from keystone.common import manager from keystone import config from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LE, _LW from keystone.models import token_model from keystone import notifications from keystone.openstack.common import log @@ -131,9 +131,9 @@ class Manager(manager.Manager): """ if CONF.signing.token_format: - LOG.warn(_('[signing] token_format is deprecated. ' - 'Please change to setting the [token] provider ' - 'configuration value instead')) + LOG.warn(_LW('[signing] token_format is deprecated. ' + 'Please change to setting the [token] provider ' + 'configuration value instead')) try: mapped = _FORMAT_TO_PROVIDER[CONF.signing.token_format] @@ -349,8 +349,8 @@ class Manager(manager.Manager): expiry = timeutils.normalize_time( timeutils.parse_isotime(expires_at)) except Exception: - LOG.exception(_('Unexpected error or malformed token determining ' - 'token expiry: %s'), token) + LOG.exception(_LE('Unexpected error or malformed token ' + 'determining token expiry: %s'), token) raise exception.TokenNotFound(_('Failed to validate token')) if current_time < expiry: diff --git a/keystone/token/providers/common.py b/keystone/token/providers/common.py index d6f6d2e956..a1cddf896c 100644 --- a/keystone/token/providers/common.py +++ b/keystone/token/providers/common.py @@ -21,7 +21,7 @@ from keystone.common import dependency from keystone import config from keystone.contrib import federation from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LE from keystone.openstack.common import log from keystone import token from keystone.token import provider @@ -341,10 +341,10 @@ class V3TokenDataHelper(object): elif isinstance(audit_info, list): token_data['audit_ids'] = audit_info else: - msg = _('Invalid audit info data type: %(data)s (%(type)s)') - msg_subst = {'data': audit_info, 'type': type(audit_info)} - LOG.error(msg, msg_subst) - raise exception.UnexpectedError(msg % msg_subst) + msg = (_('Invalid audit info data type: %(data)s (%(type)s)') % + {'data': audit_info, 'type': type(audit_info)}) + LOG.error(msg) + raise exception.UnexpectedError(msg) def get_token_data(self, user_id, method_names, extras, domain_id=None, project_id=None, expires=None, @@ -573,7 +573,7 @@ class BaseProvider(provider.Provider): token_ref, roles_ref, catalog_ref, trust_ref) return token_data except exception.ValidationError as e: - LOG.exception(_('Failed to validate token')) + LOG.exception(_LE('Failed to validate token')) raise exception.TokenNotFound(e) def validate_v3_token(self, token_ref): diff --git a/keystone/token/providers/pki.py b/keystone/token/providers/pki.py index bf10459bd5..d4a81fd348 100644 --- a/keystone/token/providers/pki.py +++ b/keystone/token/providers/pki.py @@ -21,7 +21,7 @@ from keystone.common import environment from keystone.common import utils from keystone import config from keystone import exception -from keystone.i18n import _ +from keystone.i18n import _, _LE from keystone.openstack.common import log from keystone.token.providers import common @@ -44,6 +44,6 @@ class Provider(common.BaseProvider): CONF.signing.keyfile)) return token_id except environment.subprocess.CalledProcessError: - LOG.exception(_('Unable to sign token')) + LOG.exception(_LE('Unable to sign token')) raise exception.UnexpectedError(_( 'Unable to sign token.'))