Merge "virt: handle unicode when logging LifecycleEvents"

This commit is contained in:
Jenkins
2016-09-09 22:53:34 +00:00
committed by Gerrit Code Review
2 changed files with 15 additions and 2 deletions

View File

@@ -800,6 +800,18 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
self.connection.emit_event(event1)
def test_emit_unicode_event(self):
"""Tests that we do not fail on translated unicode events."""
started_event = virtevent.LifecycleEvent(
"cef19ce0-0ca2-11df-855d-b19fbce37686",
virtevent.EVENT_LIFECYCLE_STARTED)
callback = mock.Mock()
self.connection.register_event_listener(callback)
with mock.patch.object(started_event, 'get_name',
return_value=u'\xF0\x9F\x92\xA9'):
self.connection.emit_event(started_event)
callback.assert_called_once_with(started_event)
def test_set_bootable(self):
self.assertRaises(NotImplementedError, self.connection.set_bootable,
'instance', True)

View File

@@ -24,6 +24,7 @@ import sys
from oslo_log import log as logging
from oslo_utils import importutils
import six
import nova.conf
from nova.i18n import _, _LE, _LI
@@ -1428,7 +1429,7 @@ class ComputeDriver(object):
"""
if not self._compute_event_callback:
LOG.debug("Discarding event %s", str(event))
LOG.debug("Discarding event %s", six.text_type(event))
return
if not isinstance(event, virtevent.Event):
@@ -1436,7 +1437,7 @@ class ComputeDriver(object):
_("Event must be an instance of nova.virt.event.Event"))
try:
LOG.debug("Emitting event %s", str(event))
LOG.debug("Emitting event %s", six.text_type(event))
self._compute_event_callback(event)
except Exception as ex:
LOG.error(_LE("Exception dispatching event %(event)s: %(ex)s"),