Merge "unicode error in event converter"

This commit is contained in:
Jenkins 2015-02-18 19:49:28 +00:00 committed by Gerrit Code Review
commit 7f725d8724
3 changed files with 6 additions and 4 deletions

View File

@ -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 ("<Event: %s, %s, %s, %s>" %
(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)

View File

@ -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:

View File

@ -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):