← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1348244] [NEW] debug log messages need to be unicode

 

Public bug reported:

Debug logs should be:
  
    LOG.debug("message")  should be LOG.debug(u"message")

Before the translation of debug log messages was removed, the
translation was returning unicode.   Now that they are no longer
translated they need to be explicitly marked as unicode.

This was confirmed by discussion with dhellman.   See
2014-07-23T13:48:23 in this log http://eavesdrop.openstack.org/irclogs
/%23openstack-oslo/%23openstack-oslo.2014-07-23.log

The problem was discovered when an exception was used as replacement
text in a debug log message:

       LOG.debug("Failed to mount image %(ex)s)", {'ex': e})

In particular it was discovered as part of enabling lazy translation,
where the exception message is replaced with an object that does not
support str().   Note that this would also fail without lazy enabled, if
a translation for the exception message was provided that was unicode.


Example trace: 

 Traceback (most recent call last):
  File "nova/tests/virt/disk/test_api.py", line 78, in test_can_resize_need_fs_type_specified
    self.assertFalse(api.is_image_partitionless(imgfile, use_cow=True))
  File "nova/virt/disk/api.py", line 208, in is_image_partitionless
    fs.setup()
  File "nova/virt/disk/vfs/localfs.py", line 80, in setup
    LOG.debug("Failed to mount image %(ex)s)", {'ex': e})
  File "/usr/lib/python2.7/logging/__init__.py", line 1412, in debug
    self.logger.debug(msg, *args, **kwargs)
  File "/usr/lib/python2.7/logging/__init__.py", line 1128, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/usr/lib/python2.7/logging/__init__.py", line 1258, in _log
    self.handle(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1268, in handle
    self.callHandlers(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1308, in callHandlers
    hdlr.handle(record)
  File "nova/test.py", line 212, in handle
    self.format(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 723, in format
    return fmt.format(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 464, in format
    record.message = record.getMessage()
  File "/usr/lib/python2.7/logging/__init__.py", line 328, in getMessage
    msg = msg % self.args
  File "/opt/stack/nova/.tox/py27/local/lib/python2.7/site-packages/oslo/i18n/_message.py", line 167, in __str__
    raise UnicodeError(msg)
UnicodeError: Message objects do not support str() because they may contain non-ascii characters. Please use unicode() or translate() instead.
======================================================================
FAIL: nova.tests.virt.disk.test_api.APITestCase.test_resize2fs_e2fsck_fails
tags: worker-3

** Affects: nova
     Importance: Undecided
     Assignee: James Carey (jecarey)
         Status: New

** Changed in: nova
     Assignee: (unassigned) => James Carey (jecarey)

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1348244

Title:
  debug log messages need to be unicode

Status in OpenStack Compute (Nova):
  New

Bug description:
  Debug logs should be:
    
      LOG.debug("message")  should be LOG.debug(u"message")

  Before the translation of debug log messages was removed, the
  translation was returning unicode.   Now that they are no longer
  translated they need to be explicitly marked as unicode.

  This was confirmed by discussion with dhellman.   See
  2014-07-23T13:48:23 in this log http://eavesdrop.openstack.org/irclogs
  /%23openstack-oslo/%23openstack-oslo.2014-07-23.log

  The problem was discovered when an exception was used as replacement
  text in a debug log message:

         LOG.debug("Failed to mount image %(ex)s)", {'ex': e})

  In particular it was discovered as part of enabling lazy translation,
  where the exception message is replaced with an object that does not
  support str().   Note that this would also fail without lazy enabled,
  if a translation for the exception message was provided that was
  unicode.

  
  Example trace: 

   Traceback (most recent call last):
    File "nova/tests/virt/disk/test_api.py", line 78, in test_can_resize_need_fs_type_specified
      self.assertFalse(api.is_image_partitionless(imgfile, use_cow=True))
    File "nova/virt/disk/api.py", line 208, in is_image_partitionless
      fs.setup()
    File "nova/virt/disk/vfs/localfs.py", line 80, in setup
      LOG.debug("Failed to mount image %(ex)s)", {'ex': e})
    File "/usr/lib/python2.7/logging/__init__.py", line 1412, in debug
      self.logger.debug(msg, *args, **kwargs)
    File "/usr/lib/python2.7/logging/__init__.py", line 1128, in debug
      self._log(DEBUG, msg, args, **kwargs)
    File "/usr/lib/python2.7/logging/__init__.py", line 1258, in _log
      self.handle(record)
    File "/usr/lib/python2.7/logging/__init__.py", line 1268, in handle
      self.callHandlers(record)
    File "/usr/lib/python2.7/logging/__init__.py", line 1308, in callHandlers
      hdlr.handle(record)
    File "nova/test.py", line 212, in handle
      self.format(record)
    File "/usr/lib/python2.7/logging/__init__.py", line 723, in format
      return fmt.format(record)
    File "/usr/lib/python2.7/logging/__init__.py", line 464, in format
      record.message = record.getMessage()
    File "/usr/lib/python2.7/logging/__init__.py", line 328, in getMessage
      msg = msg % self.args
    File "/opt/stack/nova/.tox/py27/local/lib/python2.7/site-packages/oslo/i18n/_message.py", line 167, in __str__
      raise UnicodeError(msg)
  UnicodeError: Message objects do not support str() because they may contain non-ascii characters. Please use unicode() or translate() instead.
  ======================================================================
  FAIL: nova.tests.virt.disk.test_api.APITestCase.test_resize2fs_e2fsck_fails
  tags: worker-3

To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1348244/+subscriptions


Follow ups

References