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
This commit is contained in:
gordon chung 2015-02-12 16:51:43 -05:00
parent 059d6b20e4
commit 7ae6145cb5
3 changed files with 6 additions and 4 deletions

View File

@ -13,6 +13,7 @@
"""Model classes for use in the events storage API. """Model classes for use in the events storage API.
""" """
from oslo_utils import timeutils from oslo_utils import timeutils
import six
from ceilometer.storage import base from ceilometer.storage import base
@ -51,7 +52,7 @@ class Event(base.Model):
def __repr__(self): def __repr__(self):
trait_list = [] trait_list = []
if self.traits: if self.traits:
trait_list = [str(trait) for trait in self.traits] trait_list = [six.text_type(trait) for trait in self.traits]
return ("<Event: %s, %s, %s, %s>" % return ("<Event: %s, %s, %s, %s>" %
(self.message_id, self.event_type, self.generated, (self.message_id, self.event_type, self.generated,
" ".join(trait_list))) " ".join(trait_list)))
@ -117,4 +118,4 @@ class Trait(base.Model):
return float(value) return float(value)
if trait_type is cls.DATETIME_TYPE: if trait_type is cls.DATETIME_TYPE:
return timeutils.normalize_time(timeutils.parse_isotime(value)) return timeutils.normalize_time(timeutils.parse_isotime(value))
return str(value) return six.text_type(value)

View File

@ -110,7 +110,7 @@ class SplitterTraitPlugin(TraitPluginBase):
def trait_value(self, match_list): def trait_value(self, match_list):
if not match_list: if not match_list:
return None return None
value = str(match_list[0][1]) value = six.text_type(match_list[0][1])
if self.max_split is not None: if self.max_split is not None:
values = value.split(self.separator, self.max_split) values = value.split(self.separator, self.max_split)
else: else:

View File

@ -16,6 +16,7 @@
import datetime import datetime
from oslotest import base as testbase from oslotest import base as testbase
import six
from ceilometer.alarm.storage import models as alarm_models from ceilometer.alarm.storage import models as alarm_models
from ceilometer.event.storage import models as event_models from ceilometer.event.storage import models as event_models
@ -109,7 +110,7 @@ class TestTraitModel(testbase.BaseTestCase):
v = event_models.Trait.convert_value( v = event_models.Trait.convert_value(
event_models.Trait.TEXT_TYPE, 10) event_models.Trait.TEXT_TYPE, 10)
self.assertEqual("10", v) self.assertEqual("10", v)
self.assertIsInstance(v, str) self.assertIsInstance(v, six.text_type)
class TestClassModel(testbase.BaseTestCase): class TestClassModel(testbase.BaseTestCase):