Merge "Update logging according oslo.i18n recommendations"

This commit is contained in:
Jenkins 2015-07-01 07:18:07 +00:00 committed by Gerrit Code Review
commit 10e291b2c3
15 changed files with 33 additions and 34 deletions

View File

@ -57,7 +57,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(_LI("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

View File

@ -141,7 +141,7 @@ class CloudNetwork(resource.Resource):
try: try:
network.delete() network.delete()
except NetworkInUse: except NetworkInUse:
LOG.warn("Network '%s' still in use." % network.id) LOG.warn(_LW("Network '%s' still in use."), network.id)
else: else:
network_info['delete_issued'] = True network_info['delete_issued'] = True
return False return False

View File

@ -292,7 +292,7 @@ class StackController(object):
not_tags=not_tags, not_tags=not_tags,
not_tags_any=not_tags_any) not_tags_any=not_tags_any)
except AttributeError as ex: except AttributeError as ex:
LOG.warn(_LW("Old Engine Version: %s") % ex) LOG.warn(_LW("Old Engine Version: %s"), ex)
return stacks_view.collection(req, stacks=stacks, count=count, return stacks_view.collection(req, stacks=stacks, count=count,
tenant_safe=tenant_safe) tenant_safe=tenant_safe)

View File

@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging
from keystoneclient import exceptions as keystone_exceptions from keystoneclient import exceptions as keystone_exceptions
from keystoneclient import session from keystoneclient import session
from oslo_config import cfg from oslo_config import cfg
@ -24,9 +22,6 @@ from webob import exc
from heat.common import context from heat.common import context
LOG = logging.getLogger(__name__)
class KeystonePasswordAuthProtocol(object): class KeystonePasswordAuthProtocol(object):
""" """
Alternative authentication middleware that uses username and password Alternative authentication middleware that uses username and password

View File

@ -114,7 +114,8 @@ class HeatException(Exception):
# log the issue and the kwargs # log the issue and the kwargs
LOG.exception(_LE('Exception in string format operation')) LOG.exception(_LE('Exception in string format operation'))
for name, value in six.iteritems(kwargs): for name, value in six.iteritems(kwargs):
LOG.error("%s: %s" % (name, value)) # noqa LOG.error(_LE("%(name)s: %(value)s"),
{'name': name, 'value': value}) # noqa
if _FATAL_EXCEPTION_FORMAT_ERRORS: if _FATAL_EXCEPTION_FORMAT_ERRORS:
raise_(exc_info[0], exc_info[1], exc_info[2]) raise_(exc_info[0], exc_info[1], exc_info[2])

View File

@ -442,7 +442,7 @@ class KeystoneClientV3(object):
return return
except kc_exception.Forbidden: except kc_exception.Forbidden:
LOG.warning(_LW('Unable to get details for project %s, ' LOG.warning(_LW('Unable to get details for project %s, '
'not deleting') % project_id) 'not deleting'), project_id)
return return
if project.domain_id != self.stack_domain_id: if project.domain_id != self.stack_domain_id:

View File

@ -109,12 +109,12 @@ def _do_ops(cinstances, opname, cnxt, stack, current_stack=None, action=None,
success_count += 1 success_count += 1
except Exception as ex: except Exception as ex:
LOG.exception(_LE( LOG.exception(_LE(
"%(opname) %(ci)s failed for %(a)s on %(sid)s") % "%(opname)s %(ci)s failed for %(a)s on %(sid)s"),
{'opname': opname, 'ci': type(ci), {'opname': opname, 'ci': type(ci),
'a': action, 'sid': stack.id}) 'a': action, 'sid': stack.id})
failure = True failure = True
failure_exception_message = ex.args[0] if ex.args else str(ex) failure_exception_message = ex.args[0] if ex.args else str(ex)
break break
LOG.info(_LI("done with class=%(c)s, stackid=%(sid)s, action=%(a)s") % LOG.info(_LI("done with class=%(c)s, stackid=%(sid)s, action=%(a)s"),
{'c': type(ci), 'sid': stack.id, 'a': action}) {'c': type(ci), 'sid': stack.id, 'a': action})
return (failure, failure_exception_message, success_count) return (failure, failure_exception_message, success_count)

View File

@ -308,7 +308,7 @@ class Server(object):
self.pool.spawn_n(self._single_run, application, self.sock) self.pool.spawn_n(self._single_run, application, self.sock)
return return
LOG.info(_LI("Starting %d workers") % conf.workers) LOG.info(_LI("Starting %d workers"), conf.workers)
signal.signal(signal.SIGTERM, kill_children) signal.signal(signal.SIGTERM, kill_children)
signal.signal(signal.SIGHUP, hup) signal.signal(signal.SIGHUP, hup)
while len(self.children) < conf.workers: while len(self.children) < conf.workers:
@ -319,7 +319,7 @@ class Server(object):
try: try:
pid, status = os.wait() pid, status = os.wait()
if os.WIFEXITED(status) or os.WIFSIGNALED(status): if os.WIFEXITED(status) or os.WIFSIGNALED(status):
LOG.error(_LE('Removing dead child %s') % pid) LOG.error(_LE('Removing dead child %s'), pid)
self.children.remove(pid) self.children.remove(pid)
self.run_child() self.run_child()
except OSError as err: except OSError as err:
@ -349,10 +349,10 @@ class Server(object):
signal.signal(signal.SIGHUP, signal.SIG_DFL) signal.signal(signal.SIGHUP, signal.SIG_DFL)
signal.signal(signal.SIGTERM, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL)
self.run_server() self.run_server()
LOG.info(_LI('Child %d exiting normally') % os.getpid()) LOG.info(_LI('Child %d exiting normally'), os.getpid())
return return
else: else:
LOG.info(_LI('Started child %s') % pid) LOG.info(_LI('Started child %s'), pid)
self.children.append(pid) self.children.append(pid)
def run_server(self): def run_server(self):
@ -680,7 +680,7 @@ class Resource(object):
action_result = self.dispatch(self.controller, action, action_result = self.dispatch(self.controller, action,
request, **action_args) request, **action_args)
except TypeError as err: except TypeError as err:
LOG.error(_LE('Exception handling resource: %s') % err) LOG.error(_LE('Exception handling resource: %s'), err)
msg = _('The server could not comply with the request since ' msg = _('The server could not comply with the request since '
'it is either malformed or otherwise incorrect.') 'it is either malformed or otherwise incorrect.')
err = webob.exc.HTTPBadRequest(msg) err = webob.exc.HTTPBadRequest(msg)
@ -776,7 +776,7 @@ class Resource(object):
def log_exception(err, exc_info): def log_exception(err, exc_info):
args = {'exc_info': exc_info} if cfg.CONF.verbose or cfg.CONF.debug else {} args = {'exc_info': exc_info} if cfg.CONF.verbose or cfg.CONF.debug else {}
LOG.error(_LE("Unexpected error occurred serving API: %s") % err, LOG.error(_LE("Unexpected error occurred serving API: %s"), err,
**args) **args)

View File

@ -16,6 +16,7 @@ import collections
import six import six
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common.i18n import _LW
from heat.engine import constraints as constr from heat.engine import constraints as constr
from heat.engine import support from heat.engine import support
@ -171,23 +172,23 @@ class Attributes(collections.Mapping):
def _validate_type(self, attrib, value): def _validate_type(self, attrib, value):
if attrib.schema.type == attrib.schema.STRING: if attrib.schema.type == attrib.schema.STRING:
if not isinstance(value, six.string_types): if not isinstance(value, six.string_types):
LOG.warn(_("Attribute %(name)s is not of type %(att_type)s"), LOG.warn(_LW("Attribute %(name)s is not of type %(att_type)s"),
{'name': attrib.name, {'name': attrib.name,
'att_type': attrib.schema.STRING}) 'att_type': attrib.schema.STRING})
elif attrib.schema.type == attrib.schema.LIST: elif attrib.schema.type == attrib.schema.LIST:
if (not isinstance(value, collections.Sequence) if (not isinstance(value, collections.Sequence)
or isinstance(value, six.string_types)): or isinstance(value, six.string_types)):
LOG.warn(_("Attribute %(name)s is not of type %(att_type)s"), LOG.warn(_LW("Attribute %(name)s is not of type %(att_type)s"),
{'name': attrib.name, {'name': attrib.name,
'att_type': attrib.schema.LIST}) 'att_type': attrib.schema.LIST})
elif attrib.schema.type == attrib.schema.MAP: elif attrib.schema.type == attrib.schema.MAP:
if not isinstance(value, collections.Mapping): if not isinstance(value, collections.Mapping):
LOG.warn(_("Attribute %(name)s is not of type %(att_type)s"), LOG.warn(_LW("Attribute %(name)s is not of type %(att_type)s"),
{'name': attrib.name, {'name': attrib.name,
'att_type': attrib.schema.MAP}) 'att_type': attrib.schema.MAP})
elif attrib.schema.type == attrib.schema.INTEGER: elif attrib.schema.type == attrib.schema.INTEGER:
if not isinstance(value, int): if not isinstance(value, int):
LOG.warn(_("Attribute %(name)s is not of type %(att_type)s"), LOG.warn(_LW("Attribute %(name)s is not of type %(att_type)s"),
{'name': attrib.name, {'name': attrib.name,
'att_type': attrib.schema.INTEGER}) 'att_type': attrib.schema.INTEGER})

View File

@ -18,7 +18,7 @@ import six
from stevedore import enabled from stevedore import enabled
from heat.common import exception from heat.common import exception
from heat.common.i18n import _LE from heat.common.i18n import _
from heat.common.i18n import _LW from heat.common.i18n import _LW
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -90,8 +90,8 @@ class ClientBackend(object):
return importutils.import_object(cfg.CONF.cloud_backend, return importutils.import_object(cfg.CONF.cloud_backend,
context) context)
except (ImportError, RuntimeError) as err: except (ImportError, RuntimeError) as err:
msg = _LE('Invalid cloud_backend setting in heat.conf ' msg = _('Invalid cloud_backend setting in heat.conf '
'detected - %s') % six.text_type(err) 'detected - %s'), six.text_type(err)
LOG.error(msg) LOG.error(msg)
raise exception.Invalid(reason=msg) raise exception.Invalid(reason=msg)

View File

@ -554,7 +554,8 @@ class Resource(object):
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.debug('%s', six.text_type(ex)) LOG.debug('%s', six.text_type(ex))
except Exception as ex: except Exception as ex:
LOG.info('%(action)s: %(info)s', {"action": action, LOG.info(_LI('%(action)s: %(info)s'),
{"action": action,
"info": six.text_type(self)}, "info": six.text_type(self)},
exc_info=True) exc_info=True)
failure = exception.ResourceFailure(ex, self, action) failure = exception.ResourceFailure(ex, self, action)

View File

@ -23,6 +23,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 _LE
from heat.common.i18n import _LW from heat.common.i18n import _LW
from heat.common import identifier from heat.common import identifier
from heat.common import template_format from heat.common import template_format
@ -435,7 +436,7 @@ class StackResource(resource.Resource):
parsed_template.files, parsed_template.files,
args) args)
except Exception as ex: except Exception as ex:
LOG.exception('update_stack') LOG.exception(_LE('update_stack'))
self.raise_local_exception(ex) self.raise_local_exception(ex)
return cookie return cookie

View File

@ -812,7 +812,7 @@ class EngineService(service.Service):
msg = _("Cancelling update when stack is %s" msg = _("Cancelling update when stack is %s"
) % str(current_stack.state) ) % str(current_stack.state)
raise exception.NotSupported(feature=msg) raise exception.NotSupported(feature=msg)
LOG.info(_LI('Starting cancel of updating stack %s') % db_stack.name) LOG.info(_LI('Starting cancel of updating stack %s'), db_stack.name)
# stop the running update and take the lock # stop the running update and take the lock
# as we cancel only running update, the acquire_result is # as we cancel only running update, the acquire_result is
# always some engine_id, not None # always some engine_id, not None

View File

@ -120,7 +120,7 @@ class SoftwareConfigService(service.Service):
except Exception as ex: except Exception as ex:
# ignore not-found, in case swift is not consistent yet # ignore not-found, in case swift is not consistent yet
if swift_plugin.is_not_found(ex): if swift_plugin.is_not_found(ex):
LOG.info(_LI('Signal object not found: %(c)s %(o)s') % { LOG.info(_LI('Signal object not found: %(c)s %(o)s'), {
'c': container, 'o': object_name}) 'c': container, 'o': object_name})
return sd return sd
raise ex raise ex
@ -143,7 +143,7 @@ class SoftwareConfigService(service.Service):
# ignore not-found, in case swift is not consistent yet # ignore not-found, in case swift is not consistent yet
if swift_plugin.is_not_found(ex): if swift_plugin.is_not_found(ex):
LOG.info(_LI( LOG.info(_LI(
'Signal object not found: %(c)s %(o)s') % { 'Signal object not found: %(c)s %(o)s'), {
'c': container, 'o': object_name}) 'c': container, 'o': object_name})
return sd return sd
raise ex raise ex

View File

@ -1500,7 +1500,7 @@ class Stack(collections.Mapping):
scheduler.TaskRunner(res.create)() scheduler.TaskRunner(res.create)()
except exception.ResourceFailure as ex: except exception.ResourceFailure as ex:
LOG.exception(_LE('Resource %(name)s create failed: ' LOG.exception(_LE('Resource %(name)s create failed: '
'%(ex)s') % {'name': res.name, 'ex': ex}) '%(ex)s'), {'name': res.name, 'ex': ex})
failed = True failed = True
else: else:
res.state_set(res.CREATE, res.FAILED, res.state_set(res.CREATE, res.FAILED,
@ -1585,8 +1585,8 @@ class Stack(collections.Mapping):
if traversal_id != self.current_traversal: if traversal_id != self.current_traversal:
return return
LOG.info('[%s(%s)] update traversal %s complete', LOG.info(_LI('[%(name)s(%(id)s)] update traversal %(tid)s complete'),
self.name, self.id, traversal_id) {'name': self.name, 'id': self.id, 'tid': traversal_id})
reason = 'Stack %s completed successfully' % self.action reason = 'Stack %s completed successfully' % self.action
self.state_set(self.action, self.COMPLETE, reason) self.state_set(self.action, self.COMPLETE, reason)