api: record severity change in alarm history

A useless change was done on the original alarm object when
we update the alarm. That have the side effect to hide the change
from the history.

This change fixes that

Change-Id: I9b3030dacf0da83bc0570ed4a6f9d460f178e2be
Closes-bug: #1452264
This commit is contained in:
Mehdi Abaakouk 2015-05-06 14:19:06 +02:00
parent 9f76e5b580
commit ecd4ee6566
2 changed files with 14 additions and 2 deletions

View File

@ -522,8 +522,6 @@ class AlarmController(rest.RestController):
else:
data.state_timestamp = alarm_in.state_timestamp
alarm_in.severity = data.severity
# make sure alarms are unique by name per project.
if alarm_in.name != data.name:
alarms = list(self.conn.get_alarms(name=data.name,

View File

@ -2178,6 +2178,20 @@ class TestAlarms(v2.FunctionalTest,
history = self._get_alarm_history(alarm)
self.assertEqual(1, len(history))
def test_record_alarm_history_severity(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'])
def test_get_recorded_alarm_history_on_create(self):
new_alarm = {
'name': 'new_alarm',