Support list/tuple as meter message value.

Support generating meter signatures for meter messages with values of
list/tuple type.

Also fixed bug #1130601.

Change-Id: Iee1951196983c1e4f941fc0c6303c3c1bd3dcc0d
This commit is contained in:
Lianhao Lu 2013-02-21 17:44:02 +08:00
parent 8bca547c0e
commit 1fc532371d
3 changed files with 22 additions and 1 deletions

View File

@ -48,6 +48,12 @@ def recursive_keypairs(d):
if isinstance(value, dict):
for subname, subvalue in recursive_keypairs(value):
yield ('%s:%s' % (name, 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.
yield name, list(map(lambda x: unicode(x).encode('utf-8'),
value))
else:
yield name, value

View File

@ -210,7 +210,7 @@ class NetPollster(plugin.ComputePollster):
resource_metadata = dict(zip(metadata._fields, metadata))
resource_metadata['instance_id'] = instance.id
resource_metadata['instance_type'] = \
instance.flavor['id'] if instance.flavor else None,
instance.flavor['id'] if instance.flavor else None
return counter.Counter(
name=name,

View File

@ -20,6 +20,7 @@
from ceilometer.collector import meter
from ceilometer import counter
from ceilometer.openstack.common import jsonutils
def test_compute_signature_change_key():
@ -99,6 +100,20 @@ def test_verify_signature_nested():
assert meter.verify_signature(data, 'not-so-secret')
def test_verify_signature_nested_json():
data = {'a': 'A',
'b': 'B',
'nested': {'a': 'A',
'b': 'B',
'c': ('c',),
'd': ['d']
},
}
data['message_signature'] = meter.compute_signature(data, 'not-so-secret')
jsondata = jsonutils.loads(jsonutils.dumps(data))
assert meter.verify_signature(jsondata, 'not-so-secret')
TEST_COUNTER = counter.Counter(name='name',
type='typ',
unit='',