Remove str() from LOG.* and exceptions

gettextutils is expecting to receive unicode strings
rather than basestrings.  A basestring can cause an
unhandled exception in the logging code.  To help avoid
such issues we should remove str() from LOG.* messages and
exceptions.  We have verified that the %s formatting code
properly handle getting strings to unicode where necessary.

This patch also fixes one case where a message object was
being concatenated with '+' .  This, like using str() will
cause logging to fail and needs to be fixed.

See bug https://bugs.launchpad.net/cinder/+bug/1274245 for
the original discussion of this problem.

Fix for oslo.messaging: https://review.openstack.org/90577

Change-Id: Iad7c2284c6b21322b96dc881a82bbbab4ebb208e
Closes-bug:  1286306
This commit is contained in:
Jay S. Bryant 2014-03-03 16:52:54 -06:00 committed by ChangBo Guo(gcb)
parent 28fba9c262
commit 8a0f567848
7 changed files with 14 additions and 14 deletions

View File

@ -451,7 +451,7 @@ def _load_log_config(log_config_append):
logging.config.fileConfig(log_config_append,
disable_existing_loggers=False)
except moves.configparser.Error as exc:
raise LogConfigError(log_config_append, str(exc))
raise LogConfigError(log_config_append, six.text_type(exc))
def setup(product_name, version='unknown'):

View File

@ -224,7 +224,7 @@ def trycmd(*args, **kwargs):
out, err = execute(*args, **kwargs)
failed = False
except ProcessExecutionError as exn:
out, err = '', str(exn)
out, err = '', six.text_type(exn)
failed = True
if not failed and discard_warnings and err:

View File

@ -84,7 +84,7 @@ class QuotaException(Exception):
class QuotaError(QuotaException):
msg_fmt = _("Quota exceeded") + ": code=%(code)s"
msg_fmt = _("Quota exceeded: code=%(code)s")
code = 413
headers = {'Retry-After': 0}
safe = True

View File

@ -202,7 +202,7 @@ class ReplyProxy(ConnectionContext):
LOG.warn(_('No calling threads waiting for msg_id : %(msg_id)s'
', message : %(data)s'), {'msg_id': msg_id,
'data': message_data})
LOG.warn(_('_call_waiters: %s') % str(self._call_waiters))
LOG.warn(_('_call_waiters: %s') % self._call_waiters)
else:
waiter.put(message_data)

View File

@ -549,7 +549,7 @@ class Connection(object):
raise
log_info = {}
log_info['err_str'] = str(e)
log_info['err_str'] = e
log_info['max_retries'] = self.max_retries
log_info.update(params)
@ -621,7 +621,7 @@ class Connection(object):
"""
def _connect_error(exc):
log_info = {'topic': topic, 'err_str': str(exc)}
log_info = {'topic': topic, 'err_str': exc}
LOG.error(_LE("Failed to declare consumer for topic '%(topic)s': "
"%(err_str)s") % log_info)
@ -641,11 +641,11 @@ class Connection(object):
def _error_callback(exc):
if isinstance(exc, socket.timeout):
LOG.debug('Timed out waiting for RPC response: %s' %
str(exc))
exc)
raise rpc_common.Timeout()
else:
LOG.exception(_LE('Failed to consume message from queue: %s') %
str(exc))
exc)
info['do_consume'] = True
def _consume():
@ -682,7 +682,7 @@ class Connection(object):
"""Send to a publisher based on the publisher class."""
def _error_callback(exc):
log_info = {'topic': topic, 'err_str': str(exc)}
log_info = {'topic': topic, 'err_str': exc}
LOG.exception(_LE("Failed to publish message to topic "
"'%(topic)s': %(err_str)s") % log_info)

View File

@ -571,7 +571,7 @@ class Connection(object):
add it to our list of consumers
"""
def _connect_error(exc):
log_info = {'topic': topic, 'err_str': str(exc)}
log_info = {'topic': topic, 'err_str': exc}
LOG.error(_LE("Failed to declare consumer for topic '%(topic)s': "
"%(err_str)s") % log_info)
@ -588,11 +588,11 @@ class Connection(object):
def _error_callback(exc):
if isinstance(exc, qpid_exceptions.Empty):
LOG.debug('Timed out waiting for RPC response: %s' %
str(exc))
exc)
raise rpc_common.Timeout()
else:
LOG.exception(_LE('Failed to consume message from queue: %s') %
str(exc))
exc)
def _consume():
nxt_receiver = self.session.next_receiver(timeout=timeout)
@ -625,7 +625,7 @@ class Connection(object):
"""Send to a publisher based on the publisher class."""
def _connect_error(exc):
log_info = {'topic': topic, 'err_str': str(exc)}
log_info = {'topic': topic, 'err_str': exc}
LOG.exception(_LE("Failed to publish message to topic "
"'%(topic)s': %(err_str)s") % log_info)

View File

@ -78,7 +78,7 @@ def bool_from_string(subject, strict=False, default=False):
Strings yielding False are 'f', 'false', 'off', 'n', 'no', or '0'.
"""
if not isinstance(subject, six.string_types):
subject = str(subject)
subject = six.text_type(subject)
lowered = subject.strip().lower()