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

View File

@ -23,7 +23,7 @@ import pkgutil
import sys
import types
from heat.openstack.common.gettextutils import _
from heat.common.i18n import _LE
from heat.openstack.common import log as logging
LOG = logging.getLogger(__name__)
@ -94,7 +94,7 @@ def load_modules(package, ignore_error=False):
try:
module = _import_module(importer, module_name, package)
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:
raise
else:

View File

@ -20,7 +20,8 @@ from requests import exceptions
from six.moves import urllib
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
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.
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)