Merge "Support list/tuple as meter message value."
This commit is contained in:
commit
ce3dca922f
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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='',
|
||||
|
Loading…
Reference in New Issue
Block a user