From 7ae6145cb511d6021b75a61028b211874fb0787a Mon Sep 17 00:00:00 2001 From: gordon chung Date: Thu, 12 Feb 2015 16:51:43 -0500 Subject: [PATCH] unicode error in event converter it's possible that a unicode error be thrown when attempting to convert notification to event. this patch uses six to handle this issue. Closes-Bug: #1421430 Change-Id: Icf450792fd2921344c2a432e5a72be18dda33ac9 --- ceilometer/event/storage/models.py | 5 +++-- ceilometer/event/trait_plugins.py | 2 +- ceilometer/tests/storage/test_models.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ceilometer/event/storage/models.py b/ceilometer/event/storage/models.py index 480643e6..2e3a3371 100644 --- a/ceilometer/event/storage/models.py +++ b/ceilometer/event/storage/models.py @@ -13,6 +13,7 @@ """Model classes for use in the events storage API. """ from oslo_utils import timeutils +import six from ceilometer.storage import base @@ -51,7 +52,7 @@ class Event(base.Model): def __repr__(self): trait_list = [] if self.traits: - trait_list = [str(trait) for trait in self.traits] + trait_list = [six.text_type(trait) for trait in self.traits] return ("" % (self.message_id, self.event_type, self.generated, " ".join(trait_list))) @@ -117,4 +118,4 @@ class Trait(base.Model): return float(value) if trait_type is cls.DATETIME_TYPE: return timeutils.normalize_time(timeutils.parse_isotime(value)) - return str(value) + return six.text_type(value) diff --git a/ceilometer/event/trait_plugins.py b/ceilometer/event/trait_plugins.py index 2b8c8e4f..912788fe 100644 --- a/ceilometer/event/trait_plugins.py +++ b/ceilometer/event/trait_plugins.py @@ -110,7 +110,7 @@ class SplitterTraitPlugin(TraitPluginBase): def trait_value(self, match_list): if not match_list: return None - value = str(match_list[0][1]) + value = six.text_type(match_list[0][1]) if self.max_split is not None: values = value.split(self.separator, self.max_split) else: diff --git a/ceilometer/tests/storage/test_models.py b/ceilometer/tests/storage/test_models.py index 2115ba4f..5c28a85f 100644 --- a/ceilometer/tests/storage/test_models.py +++ b/ceilometer/tests/storage/test_models.py @@ -16,6 +16,7 @@ import datetime from oslotest import base as testbase +import six from ceilometer.alarm.storage import models as alarm_models from ceilometer.event.storage import models as event_models @@ -109,7 +110,7 @@ class TestTraitModel(testbase.BaseTestCase): v = event_models.Trait.convert_value( event_models.Trait.TEXT_TYPE, 10) self.assertEqual("10", v) - self.assertIsInstance(v, str) + self.assertIsInstance(v, six.text_type) class TestClassModel(testbase.BaseTestCase):