diff --git a/monasca_api/common/repositories/model/sub_alarm_definition.py b/monasca_api/common/repositories/model/sub_alarm_definition.py index 5bfe77994..cb50f5814 100644 --- a/monasca_api/common/repositories/model/sub_alarm_definition.py +++ b/monasca_api/common/repositories/model/sub_alarm_definition.py @@ -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. diff --git a/monasca_api/tests/test_ad_repository.py b/monasca_api/tests/test_ad_repository.py index 123f8b1bf..fa2bb156c 100644 --- a/monasca_api/tests/test_ad_repository.py +++ b/monasca_api/tests/test_ad_repository.py @@ -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'))