Merge "api: handle case where metadata is None"
This commit is contained in:
@@ -194,9 +194,11 @@ def _flatten_metadata(metadata):
|
|||||||
"""Return flattened resource metadata without nested structures
|
"""Return flattened resource metadata without nested structures
|
||||||
and with all values converted to unicode strings.
|
and with all values converted to unicode strings.
|
||||||
"""
|
"""
|
||||||
|
if metadata:
|
||||||
return dict((k, unicode(v))
|
return dict((k, unicode(v))
|
||||||
for k, v in metadata.iteritems()
|
for k, v in metadata.iteritems()
|
||||||
if type(v) not in set([list, dict, set]))
|
if type(v) not in set([list, dict, set]))
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
class Sample(wtypes.Base):
|
class Sample(wtypes.Base):
|
||||||
|
|||||||
@@ -39,6 +39,27 @@ class TestListResources(FunctionalTest):
|
|||||||
data = self.get_json('/resources')
|
data = self.get_json('/resources')
|
||||||
self.assertEquals([], data)
|
self.assertEquals([], data)
|
||||||
|
|
||||||
|
def test_instance_no_metadata(self):
|
||||||
|
counter1 = counter.Counter(
|
||||||
|
'instance',
|
||||||
|
'cumulative',
|
||||||
|
'',
|
||||||
|
1,
|
||||||
|
'user-id',
|
||||||
|
'project-id',
|
||||||
|
'resource-id',
|
||||||
|
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
|
||||||
|
resource_metadata=None
|
||||||
|
)
|
||||||
|
msg = meter.meter_message_from_counter(counter1,
|
||||||
|
cfg.CONF.metering_secret,
|
||||||
|
'test',
|
||||||
|
)
|
||||||
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
|
data = self.get_json('/resources')
|
||||||
|
self.assertEquals(1, len(data))
|
||||||
|
|
||||||
def test_instances(self):
|
def test_instances(self):
|
||||||
counter1 = counter.Counter(
|
counter1 = counter.Counter(
|
||||||
'instance',
|
'instance',
|
||||||
|
|||||||
Reference in New Issue
Block a user