Log translation hint for Heat.common

Currently, Log translation is motivated by oslo's move to prioritized
translation of strings, as documented at
https://wiki.openstack.org/wiki/LoggingStandards#Log_Translation

- add log translation hints for warning, error and info levels
- move from LOG.warning to LOG.warn
- remove use of % as a string formatter, use the log functionality
  instead

Partial implements blueprint log-translation-hints

Change-Id: I715f69154bd199dabac7d537b982b875204f8b33
This commit is contained in:
liu-sheng 2014-07-25 14:36:14 +08:00
parent e70eb089a1
commit 005ebdaeca
3 changed files with 41 additions and 38 deletions

View File

@ -26,7 +26,9 @@ from oslo.config import cfg
from heat.common import context from heat.common import context
from heat.common import exception from heat.common import exception
from heat.openstack.common.gettextutils import _ from heat.common.i18n import _
from heat.common.i18n import _LE
from heat.common.i18n import _LW
from heat.openstack.common import importutils from heat.openstack.common import importutils
from heat.openstack.common import log as logging from heat.openstack.common import log as logging
@ -107,8 +109,8 @@ class KeystoneClientV3(object):
'"stack_domain_admin" and ' '"stack_domain_admin" and '
'"stack_domain_admin_password"')) '"stack_domain_admin_password"'))
else: else:
LOG.warning(_('stack_user_domain_id or stack_user_domain_name not ' LOG.warn(_LW('stack_user_domain_id or stack_user_domain_name not '
'set in heat.conf falling back to using default')) 'set in heat.conf falling back to using default'))
LOG.debug('Using stack domain %s' % self.stack_domain) LOG.debug('Using stack domain %s' % self.stack_domain)
@property @property
@ -128,7 +130,7 @@ class KeystoneClientV3(object):
if c.authenticate(): if c.authenticate():
self._admin_client = c self._admin_client = c
else: else:
LOG.error(_("Admin client authentication failed")) LOG.error(_LE("Admin client authentication failed"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
return self._admin_client return self._admin_client
@ -148,7 +150,7 @@ class KeystoneClientV3(object):
if c.authenticate(**auth_kwargs): if c.authenticate(**auth_kwargs):
self._domain_admin_client = c self._domain_admin_client = c
else: else:
LOG.error(_("Domain admin client authentication failed")) LOG.error(_LE("Domain admin client authentication failed"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
return self._domain_admin_client return self._domain_admin_client
@ -178,7 +180,7 @@ class KeystoneClientV3(object):
kwargs['auth_ref']['version'] = 'v3' kwargs['auth_ref']['version'] = 'v3'
kwargs['auth_ref']['auth_token'] = self.context.auth_token kwargs['auth_ref']['auth_token'] = self.context.auth_token
else: else:
LOG.error(_('Unknown version in auth_token_info')) LOG.error(_LE('Unknown version in auth_token_info'))
raise exception.AuthorizationFailure( raise exception.AuthorizationFailure(
_('Unknown token version')) _('Unknown token version'))
elif self.context.auth_token is not None: elif self.context.auth_token is not None:
@ -189,8 +191,8 @@ class KeystoneClientV3(object):
kwargs['password'] = self.context.password kwargs['password'] = self.context.password
kwargs['project_id'] = self.context.tenant_id kwargs['project_id'] = self.context.tenant_id
else: else:
LOG.error(_("Keystone v3 API connection failed, no password " LOG.error(_LE("Keystone v3 API connection failed, no password "
"trust or auth_token!")) "trust or auth_token!"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
kwargs.update(self._ssl_options()) kwargs.update(self._ssl_options())
client = kc_v3.Client(**kwargs) client = kc_v3.Client(**kwargs)
@ -205,11 +207,11 @@ class KeystoneClientV3(object):
if 'trust_id' in kwargs: if 'trust_id' in kwargs:
# Sanity check # Sanity check
if not client.auth_ref.trust_scoped: if not client.auth_ref.trust_scoped:
LOG.error(_("trust token re-scoping failed!")) LOG.error(_LE("trust token re-scoping failed!"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
# Sanity check that impersonation is effective # Sanity check that impersonation is effective
if self.context.trustor_user_id != client.auth_ref.user_id: if self.context.trustor_user_id != client.auth_ref.user_id:
LOG.error(_("Trust impersonation failed")) LOG.error(_LE("Trust impersonation failed"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
return client return client
@ -294,8 +296,8 @@ class KeystoneClientV3(object):
def _get_username(self, username): def _get_username(self, username):
if(len(username) > 64): if(len(username) > 64):
LOG.warning(_("Truncating the username %s to the last 64 " LOG.warn(_LW("Truncating the username %s to the last 64 "
"characters.") % username) "characters."), username)
#get the last 64 characters of the username #get the last 64 characters of the username
return username[-64:] return username[-64:]
@ -326,8 +328,8 @@ class KeystoneClientV3(object):
self.client.roles.grant(role=role_id, user=user.id, self.client.roles.grant(role=role_id, user=user.id,
project=self.context.tenant_id) project=self.context.tenant_id)
else: else:
LOG.error(_("Failed to add user %(user)s to role %(role)s, " LOG.error(_LE("Failed to add user %(user)s to role %(role)s, "
"check role exists!") % { "check role exists!"), {
'user': username, 'user': username,
'role': cfg.CONF.heat_stack_user_role}) 'role': cfg.CONF.heat_stack_user_role})
raise exception.Error(_("Can't find role %s") raise exception.Error(_("Can't find role %s")
@ -392,8 +394,8 @@ class KeystoneClientV3(object):
if not self.stack_domain: if not self.stack_domain:
# FIXME(shardy): Legacy fallback for folks using old heat.conf # FIXME(shardy): Legacy fallback for folks using old heat.conf
# files which lack domain configuration # files which lack domain configuration
LOG.warning(_('Falling back to legacy non-domain user create, ' LOG.warn(_LW('Falling back to legacy non-domain user create, '
'configure domain in heat.conf')) 'configure domain in heat.conf'))
return self.create_stack_user(username=username, password=password) return self.create_stack_user(username=username, password=password)
# We add the new user to a special keystone role # We add the new user to a special keystone role
# This role is designed to allow easier differentiation of the # This role is designed to allow easier differentiation of the
@ -413,10 +415,10 @@ class KeystoneClientV3(object):
self.domain_admin_client.roles.grant(role=role_id, user=user.id, self.domain_admin_client.roles.grant(role=role_id, user=user.id,
project=project_id) project=project_id)
else: else:
LOG.error(_("Failed to add user %(user)s to role %(role)s, " LOG.error(_LE("Failed to add user %(user)s to role %(role)s, "
"check role exists!") "check role exists!"),
% {'user': username, {'user': username,
'role': cfg.CONF.heat_stack_user_role}) 'role': cfg.CONF.heat_stack_user_role})
raise exception.Error(_("Can't find role %s") raise exception.Error(_("Can't find role %s")
% cfg.CONF.heat_stack_user_role) % cfg.CONF.heat_stack_user_role)
@ -443,8 +445,8 @@ class KeystoneClientV3(object):
if not self.stack_domain: if not self.stack_domain:
# FIXME(shardy): Legacy fallback for folks using old heat.conf # FIXME(shardy): Legacy fallback for folks using old heat.conf
# files which lack domain configuration # files which lack domain configuration
LOG.warning(_('Falling back to legacy non-domain user delete, ' LOG.warn(_LW('Falling back to legacy non-domain user delete, '
'configure domain in heat.conf')) 'configure domain in heat.conf'))
return self.delete_stack_user(user_id) return self.delete_stack_user(user_id)
try: try:
@ -464,8 +466,8 @@ class KeystoneClientV3(object):
if not self.stack_domain: if not self.stack_domain:
# FIXME(shardy): Legacy fallback for folks using old heat.conf # FIXME(shardy): Legacy fallback for folks using old heat.conf
# files which lack domain configuration # files which lack domain configuration
LOG.warning(_('Falling back to legacy non-domain project, ' LOG.warn(_LW('Falling back to legacy non-domain project, '
'configure domain in heat.conf')) 'configure domain in heat.conf'))
return self.context.tenant_id return self.context.tenant_id
# Note we use the tenant ID not name to ensure uniqueness in a multi- # Note we use the tenant ID not name to ensure uniqueness in a multi-
# domain environment (where the tenant name may not be globally unique) # domain environment (where the tenant name may not be globally unique)
@ -481,8 +483,8 @@ class KeystoneClientV3(object):
if not self.stack_domain: if not self.stack_domain:
# FIXME(shardy): Legacy fallback for folks using old heat.conf # FIXME(shardy): Legacy fallback for folks using old heat.conf
# files which lack domain configuration # files which lack domain configuration
LOG.warning(_('Falling back to legacy non-domain project, ' LOG.warn(_LW('Falling back to legacy non-domain project, '
'configure domain in heat.conf')) 'configure domain in heat.conf'))
return return
try: try:
self.domain_admin_client.projects.delete(project=project_id) self.domain_admin_client.projects.delete(project=project_id)
@ -555,8 +557,8 @@ class KeystoneClientV3(object):
if not self.stack_domain: if not self.stack_domain:
# FIXME(shardy): Legacy fallback for folks using old heat.conf # FIXME(shardy): Legacy fallback for folks using old heat.conf
# files which lack domain configuration # files which lack domain configuration
LOG.warning(_('Falling back to legacy non-domain keypair, ' LOG.warn(_LW('Falling back to legacy non-domain keypair, '
'configure domain in heat.conf')) 'configure domain in heat.conf'))
return self.create_ec2_keypair(user_id) return self.create_ec2_keypair(user_id)
data_blob = {'access': uuid.uuid4().hex, data_blob = {'access': uuid.uuid4().hex,
'secret': uuid.uuid4().hex} 'secret': uuid.uuid4().hex}
@ -572,8 +574,8 @@ class KeystoneClientV3(object):
if not self.stack_domain: if not self.stack_domain:
# FIXME(shardy): Legacy fallback for folks using old heat.conf # FIXME(shardy): Legacy fallback for folks using old heat.conf
# files which lack domain configuration # files which lack domain configuration
LOG.warning(_('Falling back to legacy non-domain keypair, ' LOG.warn(_LW('Falling back to legacy non-domain keypair, '
'configure domain in heat.conf')) 'configure domain in heat.conf'))
return self.delete_ec2_keypair(credential_id=credential_id) return self.delete_ec2_keypair(credential_id=credential_id)
self._check_stack_domain_user(user_id, project_id, 'delete_keypair') self._check_stack_domain_user(user_id, project_id, 'delete_keypair')
try: try:
@ -591,8 +593,8 @@ class KeystoneClientV3(object):
if not self.stack_domain: if not self.stack_domain:
# FIXME(shardy): Legacy fallback for folks using old heat.conf # FIXME(shardy): Legacy fallback for folks using old heat.conf
# files which lack domain configuration # files which lack domain configuration
LOG.warning(_('Falling back to legacy non-domain disable, ' LOG.warn(_LW('Falling back to legacy non-domain disable, '
'configure domain in heat.conf')) 'configure domain in heat.conf'))
return self.disable_stack_user(user_id) return self.disable_stack_user(user_id)
self._check_stack_domain_user(user_id, project_id, 'disable') self._check_stack_domain_user(user_id, project_id, 'disable')
self.domain_admin_client.users.update(user=user_id, enabled=False) self.domain_admin_client.users.update(user=user_id, enabled=False)
@ -601,8 +603,8 @@ class KeystoneClientV3(object):
if not self.stack_domain: if not self.stack_domain:
# FIXME(shardy): Legacy fallback for folks using old heat.conf # FIXME(shardy): Legacy fallback for folks using old heat.conf
# files which lack domain configuration # files which lack domain configuration
LOG.warning(_('Falling back to legacy non-domain enable, ' LOG.warn(_LW('Falling back to legacy non-domain enable, '
'configure domain in heat.conf')) 'configure domain in heat.conf'))
return self.enable_stack_user(user_id) return self.enable_stack_user(user_id)
self._check_stack_domain_user(user_id, project_id, 'enable') self._check_stack_domain_user(user_id, project_id, 'enable')
self.domain_admin_client.users.update(user=user_id, enabled=True) self.domain_admin_client.users.update(user=user_id, enabled=True)

View File

@ -23,7 +23,7 @@ import pkgutil
import sys import sys
import types import types
from heat.openstack.common.gettextutils import _ from heat.common.i18n import _LE
from heat.openstack.common import log as logging from heat.openstack.common import log as logging
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -94,7 +94,7 @@ def load_modules(package, ignore_error=False):
try: try:
module = _import_module(importer, module_name, package) module = _import_module(importer, module_name, package)
except ImportError: except ImportError:
LOG.error(_('Failed to import module %s') % module_name) LOG.error(_LE('Failed to import module %s'), module_name)
if not ignore_error: if not ignore_error:
raise raise
else: else:

View File

@ -20,7 +20,8 @@ from requests import exceptions
from six.moves import urllib from six.moves import urllib
from heat.common import exception from heat.common import exception
from heat.openstack.common.gettextutils import _ from heat.common.i18n import _
from heat.common.i18n import _LI
from heat.openstack.common import log as logging from heat.openstack.common import log as logging
cfg.CONF.import_opt('max_template_size', 'heat.common.config') cfg.CONF.import_opt('max_template_size', 'heat.common.config')
@ -40,7 +41,7 @@ def get(url, allowed_schemes=('http', 'https')):
the allowed_schemes argument. the allowed_schemes argument.
Raise an IOError if getting the data fails. Raise an IOError if getting the data fails.
""" """
LOG.info(_('Fetching data from %s') % url) LOG.info(_LI('Fetching data from %s'), url)
components = urllib.parse.urlparse(url) components = urllib.parse.urlparse(url)