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:
parent
28fba9c262
commit
8a0f567848
|
@ -451,7 +451,7 @@ def _load_log_config(log_config_append):
|
||||||
logging.config.fileConfig(log_config_append,
|
logging.config.fileConfig(log_config_append,
|
||||||
disable_existing_loggers=False)
|
disable_existing_loggers=False)
|
||||||
except moves.configparser.Error as exc:
|
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'):
|
def setup(product_name, version='unknown'):
|
||||||
|
|
|
@ -224,7 +224,7 @@ def trycmd(*args, **kwargs):
|
||||||
out, err = execute(*args, **kwargs)
|
out, err = execute(*args, **kwargs)
|
||||||
failed = False
|
failed = False
|
||||||
except ProcessExecutionError as exn:
|
except ProcessExecutionError as exn:
|
||||||
out, err = '', str(exn)
|
out, err = '', six.text_type(exn)
|
||||||
failed = True
|
failed = True
|
||||||
|
|
||||||
if not failed and discard_warnings and err:
|
if not failed and discard_warnings and err:
|
||||||
|
|
|
@ -84,7 +84,7 @@ class QuotaException(Exception):
|
||||||
|
|
||||||
|
|
||||||
class QuotaError(QuotaException):
|
class QuotaError(QuotaException):
|
||||||
msg_fmt = _("Quota exceeded") + ": code=%(code)s"
|
msg_fmt = _("Quota exceeded: code=%(code)s")
|
||||||
code = 413
|
code = 413
|
||||||
headers = {'Retry-After': 0}
|
headers = {'Retry-After': 0}
|
||||||
safe = True
|
safe = True
|
||||||
|
|
|
@ -202,7 +202,7 @@ class ReplyProxy(ConnectionContext):
|
||||||
LOG.warn(_('No calling threads waiting for msg_id : %(msg_id)s'
|
LOG.warn(_('No calling threads waiting for msg_id : %(msg_id)s'
|
||||||
', message : %(data)s'), {'msg_id': msg_id,
|
', message : %(data)s'), {'msg_id': msg_id,
|
||||||
'data': message_data})
|
'data': message_data})
|
||||||
LOG.warn(_('_call_waiters: %s') % str(self._call_waiters))
|
LOG.warn(_('_call_waiters: %s') % self._call_waiters)
|
||||||
else:
|
else:
|
||||||
waiter.put(message_data)
|
waiter.put(message_data)
|
||||||
|
|
||||||
|
|
|
@ -549,7 +549,7 @@ class Connection(object):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
log_info = {}
|
log_info = {}
|
||||||
log_info['err_str'] = str(e)
|
log_info['err_str'] = e
|
||||||
log_info['max_retries'] = self.max_retries
|
log_info['max_retries'] = self.max_retries
|
||||||
log_info.update(params)
|
log_info.update(params)
|
||||||
|
|
||||||
|
@ -621,7 +621,7 @@ class Connection(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _connect_error(exc):
|
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': "
|
LOG.error(_LE("Failed to declare consumer for topic '%(topic)s': "
|
||||||
"%(err_str)s") % log_info)
|
"%(err_str)s") % log_info)
|
||||||
|
|
||||||
|
@ -641,11 +641,11 @@ class Connection(object):
|
||||||
def _error_callback(exc):
|
def _error_callback(exc):
|
||||||
if isinstance(exc, socket.timeout):
|
if isinstance(exc, socket.timeout):
|
||||||
LOG.debug('Timed out waiting for RPC response: %s' %
|
LOG.debug('Timed out waiting for RPC response: %s' %
|
||||||
str(exc))
|
exc)
|
||||||
raise rpc_common.Timeout()
|
raise rpc_common.Timeout()
|
||||||
else:
|
else:
|
||||||
LOG.exception(_LE('Failed to consume message from queue: %s') %
|
LOG.exception(_LE('Failed to consume message from queue: %s') %
|
||||||
str(exc))
|
exc)
|
||||||
info['do_consume'] = True
|
info['do_consume'] = True
|
||||||
|
|
||||||
def _consume():
|
def _consume():
|
||||||
|
@ -682,7 +682,7 @@ class Connection(object):
|
||||||
"""Send to a publisher based on the publisher class."""
|
"""Send to a publisher based on the publisher class."""
|
||||||
|
|
||||||
def _error_callback(exc):
|
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 "
|
LOG.exception(_LE("Failed to publish message to topic "
|
||||||
"'%(topic)s': %(err_str)s") % log_info)
|
"'%(topic)s': %(err_str)s") % log_info)
|
||||||
|
|
||||||
|
|
|
@ -571,7 +571,7 @@ class Connection(object):
|
||||||
add it to our list of consumers
|
add it to our list of consumers
|
||||||
"""
|
"""
|
||||||
def _connect_error(exc):
|
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': "
|
LOG.error(_LE("Failed to declare consumer for topic '%(topic)s': "
|
||||||
"%(err_str)s") % log_info)
|
"%(err_str)s") % log_info)
|
||||||
|
|
||||||
|
@ -588,11 +588,11 @@ class Connection(object):
|
||||||
def _error_callback(exc):
|
def _error_callback(exc):
|
||||||
if isinstance(exc, qpid_exceptions.Empty):
|
if isinstance(exc, qpid_exceptions.Empty):
|
||||||
LOG.debug('Timed out waiting for RPC response: %s' %
|
LOG.debug('Timed out waiting for RPC response: %s' %
|
||||||
str(exc))
|
exc)
|
||||||
raise rpc_common.Timeout()
|
raise rpc_common.Timeout()
|
||||||
else:
|
else:
|
||||||
LOG.exception(_LE('Failed to consume message from queue: %s') %
|
LOG.exception(_LE('Failed to consume message from queue: %s') %
|
||||||
str(exc))
|
exc)
|
||||||
|
|
||||||
def _consume():
|
def _consume():
|
||||||
nxt_receiver = self.session.next_receiver(timeout=timeout)
|
nxt_receiver = self.session.next_receiver(timeout=timeout)
|
||||||
|
@ -625,7 +625,7 @@ class Connection(object):
|
||||||
"""Send to a publisher based on the publisher class."""
|
"""Send to a publisher based on the publisher class."""
|
||||||
|
|
||||||
def _connect_error(exc):
|
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 "
|
LOG.exception(_LE("Failed to publish message to topic "
|
||||||
"'%(topic)s': %(err_str)s") % log_info)
|
"'%(topic)s': %(err_str)s") % log_info)
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ def bool_from_string(subject, strict=False, default=False):
|
||||||
Strings yielding False are 'f', 'false', 'off', 'n', 'no', or '0'.
|
Strings yielding False are 'f', 'false', 'off', 'n', 'no', or '0'.
|
||||||
"""
|
"""
|
||||||
if not isinstance(subject, six.string_types):
|
if not isinstance(subject, six.string_types):
|
||||||
subject = str(subject)
|
subject = six.text_type(subject)
|
||||||
|
|
||||||
lowered = subject.strip().lower()
|
lowered = subject.strip().lower()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue