Merge "Fix legacy alarm matching_metadata broken by recent fix."
This commit is contained in:
commit
d790a5a85e
@ -221,6 +221,11 @@ class CeilometerAlarm(resource.Resource):
|
||||
|
||||
kwargs = actions_to_urls(stack, properties)
|
||||
kwargs['type'] = 'threshold'
|
||||
if kwargs.get(self.METER_NAME) in NOVA_METERS:
|
||||
prefix = 'user_metadata.'
|
||||
else:
|
||||
prefix = 'metering.'
|
||||
|
||||
rule = {}
|
||||
for field in ['period', 'evaluation_periods', 'threshold',
|
||||
'statistic', 'comparison_operator', 'meter_name']:
|
||||
@ -230,11 +235,6 @@ class CeilometerAlarm(resource.Resource):
|
||||
mmd = properties.get(self.MATCHING_METADATA) or {}
|
||||
query = properties.get(self.QUERY) or []
|
||||
|
||||
if kwargs.get(self.METER_NAME) in NOVA_METERS:
|
||||
prefix = 'user_metadata.'
|
||||
else:
|
||||
prefix = 'metering.'
|
||||
|
||||
# make sure the matching_metadata appears in the query like this:
|
||||
# {field: metadata.$prefix.x, ...}
|
||||
for m_k, m_v in six.iteritems(mmd):
|
||||
|
@ -321,6 +321,24 @@ class CeilometerAlarmTest(common.HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_alarm_metadata_prefix(self):
|
||||
t = template_format.parse(alarm_template)
|
||||
properties = t['Resources']['MEMAlarmHigh']['Properties']
|
||||
# Test for bug/1383521, where meter_name is in NOVA_METERS
|
||||
properties[alarm.CeilometerAlarm.METER_NAME] = 'memory.usage'
|
||||
properties['matching_metadata'] =\
|
||||
{'metadata.user_metadata.groupname': 'foo'}
|
||||
|
||||
self.stack = self.create_stack(template=json.dumps(t))
|
||||
|
||||
rsrc = self.stack['MEMAlarmHigh']
|
||||
rsrc.properties.data = rsrc.cfn_to_ceilometer(self.stack, properties)
|
||||
self.assertIsNone(rsrc.properties.data.get('matching_metadata'))
|
||||
query = rsrc.properties.data['threshold_rule']['query']
|
||||
expected_query = [{'field': u'metadata.user_metadata.groupname',
|
||||
'value': u'foo', 'op': 'eq'}]
|
||||
self.assertEqual(expected_query, query)
|
||||
|
||||
def test_mem_alarm_high_correct_matching_metadata(self):
|
||||
t = template_format.parse(alarm_template)
|
||||
properties = t['Resources']['MEMAlarmHigh']['Properties']
|
||||
|
Loading…
x
Reference in New Issue
Block a user