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:
parent
059d6b20e4
commit
7ae6145cb5
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user