summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-12-03 15:57:27 +0000
committerGerrit Code Review <review@openstack.org>2014-12-03 15:57:27 +0000
commit61ca6900f4f4f583c43015306ac28f949f44fbad (patch)
tree81332e9fc85f33cd5b9557aa0ee47bca3fb8b0aa
parent5e40bcf29043ed8cbbc77380e2c96a6b3842f236 (diff)
parent3489129cb5a412457650add59cd7198095b6b27c (diff)
downloadceilometer-61ca6900f4f4f583c43015306ac28f949f44fbad.tar.gz
Merge "Fix signature validation failure when using qpid message queue" into stable/juno
-rw-r--r--ceilometer/tests/test_utils.py12
-rw-r--r--ceilometer/utils.py38
2 files changed, 26 insertions, 24 deletions
diff --git a/ceilometer/tests/test_utils.py b/ceilometer/tests/test_utils.py
index bda3de19..b7741018 100644
--- a/ceilometer/tests/test_utils.py
+++ b/ceilometer/tests/test_utils.py
@@ -72,7 +72,7 @@ class TestUtils(base.BaseTestCase):
big = 1 << 64
expected = [('a', 'A'),
('b', 'B'),
- ('nested:list', ['{%d: 99, %d: 42}' % (small, big)])]
+ ('nested:list', [{small: 99, big: 42}])]
data = {'a': 'A',
'b': 'B',
'nested': {'list': [{small: 99, big: 42}]}}
@@ -82,14 +82,8 @@ class TestUtils(base.BaseTestCase):
# the keys 1 and 1<<64 cause a hash collision on 64bit platforms
if k == 'nested:list':
self.assertIn(v,
- [[('{%d: 99, %d: 42}'
- % (small, big)).encode('ascii')],
- [('{%d: 99, %dL: 42}'
- % (small, big)).encode('ascii')],
- [('{%d: 42, %d: 99}'
- % (big, small)).encode('ascii')],
- [('{%dL: 42, %d: 99}'
- % (big, small)).encode('ascii')]])
+ [[{small: 99, big: 42}],
+ [{big: 42, small: 99}]])
else:
self.assertIn((k, v), expected)
diff --git a/ceilometer/utils.py b/ceilometer/utils.py
index 016fb8a3..6b2ab15b 100644
--- a/ceilometer/utils.py
+++ b/ceilometer/utils.py
@@ -33,7 +33,6 @@ from oslo.utils import timeutils
from oslo.utils import units
import six
-
rootwrap_conf = cfg.StrOpt('rootwrap_config',
default="/etc/ceilometer/rootwrap.conf",
help='Path to the rootwrap configuration file to'
@@ -53,6 +52,28 @@ def execute(*cmd, **kwargs):
return processutils.execute(*cmd, **kwargs)
+def decode_unicode(input):
+ """Decode the unicode of the message, and encode it into utf-8."""
+ if isinstance(input, dict):
+ temp = {}
+ # If the input data is a dict, create an equivalent dict with a
+ # predictable insertion order to avoid inconsistencies in the
+ # message signature computation for equivalent payloads modulo
+ # ordering
+ for key, value in sorted(six.iteritems(input)):
+ temp[decode_unicode(key)] = decode_unicode(value)
+ return temp
+ elif isinstance(input, (tuple, list)):
+ # When doing a pair of JSON encode/decode operations to the tuple,
+ # the tuple would become list. So we have to generate the value as
+ # list here.
+ return [decode_unicode(element) for element in input]
+ elif isinstance(input, six.text_type):
+ return input.encode('utf-8')
+ else:
+ return input
+
+
def recursive_keypairs(d, separator=':'):
"""Generator that produces sequence of keypairs for nested dictionaries."""
for name, value in sorted(six.iteritems(d)):
@@ -60,20 +81,7 @@ def recursive_keypairs(d, separator=':'):
for subname, subvalue in recursive_keypairs(value, separator):
yield ('%s%s%s' % (name, separator, subname), subvalue)
elif isinstance(value, (tuple, list)):
- # When doing a pair of JSON encode/decode operations to the tuple,
- # the tuple would become list. So we have to generate the value as
- # list here.
-
- # in the special case of the list item itself being a dict,
- # create an equivalent dict with a predictable insertion order
- # to avoid inconsistencies in the message signature computation
- # for equivalent payloads modulo ordering
- first = lambda i: i[0]
- m = map(lambda x: six.text_type(dict(sorted(x.items(), key=first))
- if isinstance(x, dict)
- else x).encode('utf-8'),
- value)
- yield name, list(m)
+ yield name, decode_unicode(value)
else:
yield name, value