nova/nova/cells
melanie witt 62a5b4bd20 Use six.text_type() when logging Instance object
We're seeing a trace in gate jobs, for example:

  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
  402: ordinal not in range(128)

when attempting to log an Instance object with a unicode display name.

This resurfaced relatively recently because of the change in devstack
to use the new OSJournalHandler with use_journal=True which is
suspected of causing some deadlock issues [1] unrelated to this bug.

The problem occurs in code that logs an entire Instance object when
the object has a field with unicode characters in it (display_name).
When the object is sent to logging, the UnicodeDecodeError is raised
while formatting the log record here [2]. This implies an implicit
conversion attempt to unicode at this point.

I found that with the Instance object, the conversion to unicode fails
with the UnicodeDecodeError unless the encoding 'utf-8' is explicitly
specified to six.text_type(). And when specifying an encoding to
six.text_type(), the argument to convert must be a string, not an
Instance object, so this does the conversion in two steps as a utility
function:

  1. Get the string representation of the Instance with repr()
  2. Call six.text_type(instance_repr, 'utf-8') passing the encoding
     if not six.PY3

Closes-Bug: #1580728

[1] https://review.openstack.org/#/c/462163
[2] https://github.com/python/cpython/blob/2e576f5/Lib/logging/__init__.py#L338

Change-Id: I0fc3ae02cb2e401b3240faf0d8b6aa5dc52b91fc
(cherry picked from commit 564958dba6)
2017-05-22 10:57:28 +00:00
..
filters policy: clean-up 2016-06-30 19:56:14 +00:00
weights Config options: centralize section "cells" 2016-01-27 16:10:42 +02:00
__init__.py Remove vi modelines 2014-02-03 14:19:44 +00:00
driver.py Port to oslo.messaging 2014-02-01 09:53:24 +00:00
manager.py [2/3]Replace six.iteritems() with .items() 2017-01-09 09:11:00 +00:00
messaging.py Use six.text_type() when logging Instance object 2017-05-22 10:57:28 +00:00
opts.py Improve the help text for cells options (7) 2016-06-09 08:39:46 +03:00
rpc_driver.py Config options: centralize section "cells" 2016-01-27 16:10:42 +02:00
rpcapi.py Integrate OSProfiler and Nova 2017-01-18 15:00:14 +07:00
scheduler.py Refactor block_device_mapping handling during boot 2016-07-05 14:38:21 -04:00
state.py Remove straggling use of main db flavors in cellsv1 code 2017-02-11 18:54:48 +00:00
utils.py [TrivialFix] Fix comment typo error 2016-12-22 15:11:45 +08:00