From e5b3988c7cb01d2230f67c41aa76935a11b0e42a Mon Sep 17 00:00:00 2001 From: Rohit Jaiswal Date: Wed, 24 Jun 2015 22:15:02 +0000 Subject: [PATCH] Update alarm history only if change in alarm property When alarm's property is updated with the same value, an empty record is added to the alarm history output. This fix omits the update to alarm history if there no changes to any alarm property. Change-Id: Ib860f371979896c7eedd41a25c3b640bb6dbee31 Closes-Bug: 1465550 --- ceilometer/api/controllers/v2/alarms.py | 2 ++ .../tests/api/v2/test_alarm_scenarios.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ceilometer/api/controllers/v2/alarms.py b/ceilometer/api/controllers/v2/alarms.py index 5408a694..d36529b1 100644 --- a/ceilometer/api/controllers/v2/alarms.py +++ b/ceilometer/api/controllers/v2/alarms.py @@ -459,6 +459,8 @@ class AlarmController(rest.RestController): def _record_change(self, data, now, on_behalf_of=None, type=None): if not cfg.CONF.alarm.record_history: return + if not data: + return type = type or alarm_models.AlarmChange.RULE_CHANGE scrubbed_data = utils.stringify_timestamps(data) detail = json.dumps(scrubbed_data) diff --git a/ceilometer/tests/api/v2/test_alarm_scenarios.py b/ceilometer/tests/api/v2/test_alarm_scenarios.py index 6cd33fde..86e92184 100644 --- a/ceilometer/tests/api/v2/test_alarm_scenarios.py +++ b/ceilometer/tests/api/v2/test_alarm_scenarios.py @@ -2182,6 +2182,28 @@ class TestAlarms(v2.FunctionalTest, history[0]['detail']) self.assertEqual('low', new_alarm['severity']) + def test_redundant_update_alarm_property_no_history_change(self): + alarm = self._get_alarm('a') + history = self._get_alarm_history(alarm) + self.assertEqual([], history) + self.assertEqual('critical', alarm['severity']) + + self._update_alarm(alarm, dict(severity='low')) + new_alarm = self._get_alarm('a') + history = self._get_alarm_history(alarm) + self.assertEqual(1, len(history)) + self.assertEqual(jsonutils.dumps({'severity': 'low'}), + history[0]['detail']) + self.assertEqual('low', new_alarm['severity']) + + self._update_alarm(alarm, dict(severity='low')) + updated_alarm = self._get_alarm('a') + updated_history = self._get_alarm_history(updated_alarm) + self.assertEqual(1, len(updated_history)) + self.assertEqual(jsonutils.dumps({'severity': 'low'}), + updated_history[0]['detail']) + self.assertEqual(history, updated_history) + def test_get_recorded_alarm_history_on_create(self): new_alarm = { 'name': 'new_alarm',