Log translation hint for Heat.contrib

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: I8dbb5430507283038939b5665d67615c46b1f72e
This commit is contained in:
liu-sheng 2014-07-25 11:56:30 +08:00
parent d971917560
commit 7a786674f7
7 changed files with 31 additions and 24 deletions

View File

@ -17,6 +17,7 @@
import six import six
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common.i18n import _LW
from heat.engine import attributes from heat.engine import attributes
from heat.engine import properties from heat.engine import properties
from heat.engine import resource from heat.engine import resource
@ -346,5 +347,5 @@ def available_resource_mapping():
if DOCKER_INSTALLED: if DOCKER_INSTALLED:
return resource_mapping() return resource_mapping()
else: else:
LOG.warn(_("Docker plug-in loaded, but docker lib not installed.")) LOG.warn(_LW("Docker plug-in loaded, but docker lib not installed."))
return {} return {}

View File

@ -20,11 +20,13 @@ from oslo.config import cfg
from oslo.utils import importutils from oslo.utils import importutils
from heat.common import exception from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _LE
from heat.common.i18n import _LI
from heat.common.i18n import _LW
from heat.openstack.common import log as logging from heat.openstack.common import log as logging
LOG = logging.getLogger('heat.common.keystoneclient') LOG = logging.getLogger('heat.common.keystoneclient')
LOG.info(_("Keystone V2 loaded")) LOG.info(_LI("Keystone V2 loaded"))
class KeystoneClientV2(object): class KeystoneClientV2(object):
@ -87,8 +89,8 @@ class KeystoneClientV2(object):
kwargs['tenant_name'] = self.context.tenant kwargs['tenant_name'] = self.context.tenant
kwargs['tenant_id'] = self.context.tenant_id kwargs['tenant_id'] = self.context.tenant_id
else: else:
LOG.error(_("Keystone v2 API connection failed, no password " LOG.error(_LE("Keystone v2 API connection failed, no password "
"or auth_token!")) "or auth_token!"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
kwargs['cacert'] = self._get_client_option('ca_file') kwargs['cacert'] = self._get_client_option('ca_file')
kwargs['insecure'] = self._get_client_option('insecure') kwargs['insecure'] = self._get_client_option('insecure')
@ -102,7 +104,7 @@ class KeystoneClientV2(object):
if auth_kwargs: if auth_kwargs:
# Sanity check # Sanity check
if not client.auth_ref.trust_scoped: if not client.auth_ref.trust_scoped:
LOG.error(_("v2 trust token re-scoping failed!")) LOG.error(_LE("v2 trust token re-scoping failed!"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
# All OK so update the context with the token # All OK so update the context with the token
self.context.auth_token = client.auth_ref.auth_token self.context.auth_token = client.auth_ref.auth_token
@ -110,8 +112,8 @@ class KeystoneClientV2(object):
# Ensure the v2 API we're using is not impacted by keystone # Ensure the v2 API we're using is not impacted by keystone
# bug #1239303, otherwise we can't trust the user_id # bug #1239303, otherwise we can't trust the user_id
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, bug #1239303 " LOG.error(_LE("Trust impersonation failed, bug #1239303 "
"suspected, you may need a newer keystone")) "suspected, you may need a newer keystone"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
return client return client
@ -147,8 +149,8 @@ class KeystoneClientV2(object):
Returns the keystone ID of the resulting user Returns the keystone ID of the resulting user
""" """
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
username = username[-64:] username = username[-64:]
user = self.client.users.create(username, user = self.client.users.create(username,
@ -171,10 +173,10 @@ class KeystoneClientV2(object):
self.client.roles.add_user_role(user.id, role_id, self.client.roles.add_user_role(user.id, role_id,
self.context.tenant_id) 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})
return user.id return user.id

View File

@ -11,7 +11,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from heat.common.i18n 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__)
@ -30,7 +30,7 @@ class ZaqarClientPlugin(client_plugin.ClientPlugin):
con = self.context con = self.context
if self.auth_token is None: if self.auth_token is None:
LOG.error(_("Zaqar connection failed, no auth_token!")) LOG.error(_LE("Zaqar connection failed, no auth_token!"))
return None return None
opts = { opts = {

View File

@ -21,7 +21,8 @@ import urlparse
from oslo.config import cfg from oslo.config import cfg
from heat.common import exception from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _LI
from heat.common.i18n import _LW
from heat.engine.clients import client_plugin from heat.engine.clients import client_plugin
from heat.engine.clients.os import cinder from heat.engine.clients.os import cinder
from heat.engine.clients.os import glance from heat.engine.clients.os import glance
@ -57,7 +58,7 @@ class RackspaceClientPlugin(client_plugin.ClientPlugin):
"""Create an authenticated client context.""" """Create an authenticated client context."""
self.pyrax = pyrax.create_context("rackspace") self.pyrax = pyrax.create_context("rackspace")
self.pyrax.auth_endpoint = self.context.auth_url self.pyrax.auth_endpoint = self.context.auth_url
LOG.info(_("Authenticating username: %s") % LOG.info(_LI("Authenticating username: %s") %
self.context.username) self.context.username)
tenant = self.context.tenant_id tenant = self.context.tenant_id
tenant_name = self.context.tenant tenant_name = self.context.tenant
@ -65,9 +66,9 @@ class RackspaceClientPlugin(client_plugin.ClientPlugin):
tenant_id=tenant, tenant_id=tenant,
tenant_name=tenant_name) tenant_name=tenant_name)
if not self.pyrax.authenticated: if not self.pyrax.authenticated:
LOG.warn(_("Pyrax Authentication Failed.")) LOG.warn(_LW("Pyrax Authentication Failed."))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
LOG.info(_("User %s authenticated successfully."), LOG.info(_LI("User %s authenticated successfully."),
self.context.username) self.context.username)

View File

@ -18,6 +18,7 @@ import six
from heat.common import exception from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common.i18n import _LI
from heat.engine import attributes from heat.engine import attributes
from heat.engine import constraints from heat.engine import constraints
from heat.engine import function from heat.engine import function
@ -672,7 +673,7 @@ class CloudLoadBalancer(resource.Resource):
raise exception.InvalidTemplateAttribute(resource=self.name, raise exception.InvalidTemplateAttribute(resource=self.name,
key=key) key=key)
function = attribute_function[key] function = attribute_function[key]
LOG.info(_('%(name)s.GetAtt(%(key)s) == %(function)s'), LOG.info(_LI('%(name)s.GetAtt(%(key)s) == %(function)s'),
{'name': self.name, 'key': key, 'function': function}) {'name': self.name, 'key': key, 'function': function})
return function return function

View File

@ -15,6 +15,7 @@ import copy
from heat.common import exception from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common.i18n import _LW
from heat.engine import attributes from heat.engine import attributes
from heat.engine import properties from heat.engine import properties
from heat.engine.resources import server from heat.engine.resources import server
@ -181,7 +182,7 @@ class CloudServer(server.Server):
reason = server.metadata.get('rackconnect_unprocessable_reason', reason = server.metadata.get('rackconnect_unprocessable_reason',
None) None)
if reason is not None: if reason is not None:
LOG.warning(_("RackConnect unprocessable reason: %s") % reason) LOG.warn(_LW("RackConnect unprocessable reason: %s"), reason)
msg = _("RackConnect automation has completed") msg = _("RackConnect automation has completed")
self._add_event(self.action, self.status, msg) self._add_event(self.action, self.status, msg)

View File

@ -15,6 +15,7 @@ import netaddr
from heat.common import exception from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common.i18n import _LW
from heat.engine import attributes from heat.engine import attributes
from heat.engine import constraints from heat.engine import constraints
from heat.engine import properties from heat.engine import properties
@ -93,8 +94,8 @@ class CloudNetwork(resource.Resource):
try: try:
self._network = self.cloud_networks().get(self.resource_id) self._network = self.cloud_networks().get(self.resource_id)
except NotFound: except NotFound:
LOG.warn(_("Could not find network %s but resource id is set.") LOG.warn(_LW("Could not find network %s but resource id is"
% self.resource_id) " set."), self.resource_id)
return self._network return self._network
def cloud_networks(self): def cloud_networks(self):