Fix for editing an Alarm Definition

This change solves the issue when: after removing the deterministic option
of an alarm definition by editing it, the alarm(s) asociated continue(s)
to behave as deterministic. Please see the story for more info.

Added Unittest.

Change-Id: I7743f2d2b8cd7c83541f77c7821f9512fb8abc36
story: 2006750
task: 37233
This commit is contained in:
Martin Chacon Piza 2019-10-23 16:18:20 +02:00
parent ce93e00050
commit 12dee6996c
2 changed files with 17 additions and 13 deletions

View File

@ -48,7 +48,7 @@ class SubAlarmDefinition(object):
self.period = row['period']
self.periods = row['periods']
self.threshold = row['threshold']
self.deterministic = str(row['is_deterministic']) == '1'
self.deterministic = row['is_deterministic']
if sub_expr:
# id is not used for compare or hash.

View File

@ -32,7 +32,7 @@ ALARM_DEF_123_FIELDS = {'actions_enabled': False,
'alarm_actions': u'29387234,77778687',
'description': None,
'expression': u'AVG(hpcs.compute{flavor_id=777, '
'image_id=888, metric_name=cpu, device=1}) > 10',
'image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'id': u'123',
'match_by': u'flavor_id,image_id',
'name': u'90% CPU',
@ -134,7 +134,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'name': '90% CPU',
'severity': 'LOW',
'expression': 'AVG(hpcs.compute{flavor_id=777,'
' image_id=888, metric_name=cpu, device=1}) > 10',
' image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'match_by': 'flavor_id,image_id',
'actions_enabled': False,
'created_at': datetime.datetime.now(),
@ -161,7 +161,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'threshold': 10,
'period': 60,
'periods': 1,
'is_deterministic': False,
'is_deterministic': True,
'created_at': datetime.datetime.now(),
'updated_at': datetime.datetime.now()},
{'id': '222',
@ -380,7 +380,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'alarm_actions': '29387234,77778687',
'description': None,
'expression': 'AVG(hpcs.compute{flavor_id=777, '
'image_id=888, metric_name=cpu, device=1}) > 10',
'image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'id': '123',
'match_by': 'flavor_id,image_id',
'name': '90% CPU',
@ -408,7 +408,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'alarm_actions': '29387234,77778687',
'description': None,
'expression': 'AVG(hpcs.compute{flavor_id=777, '
'image_id=888, metric_name=cpu, device=1}) > 10',
'image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'id': '123',
'match_by': 'flavor_id,image_id',
'name': '90% CPU',
@ -504,7 +504,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'alarm_actions': '29387234,77778687',
'description': None,
'expression': 'AVG(hpcs.compute{flavor_id=777, '
'image_id=888, metric_name=cpu, device=1}) > 10',
'image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'id': '123',
'match_by': 'flavor_id,image_id',
'name': '90% CPU',
@ -531,7 +531,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'operator': 'GT',
'period': 60,
'periods': 1,
'is_deterministic': False,
'is_deterministic': True,
'threshold': 10.0}]
self.assertEqual(len(sub_alarms), len(expected))
@ -594,7 +594,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'alarm_actions': '29387234,77778687',
'description': None,
'expression': 'AVG(hpcs.compute{flavor_id=777, '
'image_id=888, metric_name=cpu, device=1}) > 10',
'image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'id': '123',
'match_by': 'flavor_id,image_id',
'name': '90% CPU',
@ -614,7 +614,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'alarm_actions': '29387234,77778687',
'description': None,
'expression': 'AVG(hpcs.compute{flavor_id=777, '
'image_id=888, metric_name=cpu, device=1}) > 10',
'image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'id': '123',
'match_by': 'flavor_id,image_id',
'name': '90% CPU',
@ -677,7 +677,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'alarm_actions': '29387234,77778687',
'description': None,
'expression': 'AVG(hpcs.compute{flavor_id=777, '
'image_id=888, metric_name=cpu, device=1}) > 10',
'image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'id': '123',
'match_by': 'flavor_id,image_id',
'name': '90% CPU',
@ -707,7 +707,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'alarm_actions': '29387234,77778687',
'description': None,
'expression': 'AVG(hpcs.compute{flavor_id=777, '
'image_id=888, metric_name=cpu, device=1}) > 10',
'image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'id': '123',
'match_by': 'flavor_id,image_id',
'name': '90% CPU',
@ -732,7 +732,7 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
'alarm_actions': '29387234,77778687',
'description': None,
'expression': 'AVG(hpcs.compute{flavor_id=777, '
'image_id=888, metric_name=cpu, device=1}) > 10',
'image_id=888, metric_name=cpu, device=1},deterministic) > 10',
'id': '123',
'match_by': 'flavor_id,image_id',
'name': '90% CPU',
@ -820,6 +820,10 @@ class TestAlarmDefinitionRepoDB(base.BaseTestCase):
def test_should_patch_expression_threshold_change(self):
self.run_patch_test(expression=ALARM_DEF_123_FIELDS['expression'].replace(' 10', ' 20'))
def test_should_patch_expression_deterministic_change(self):
self.run_patch_test(expression=ALARM_DEF_123_FIELDS['expression'].replace(',deterministic',
''))
def test_should_patch_expression_function_change(self):
self.run_patch_test(expression=ALARM_DEF_123_FIELDS['expression'].replace('AVG', 'MAX'))