Merge "Catch exception when evaluate single alarm"
This commit is contained in:
commit
de29b78119
@ -113,7 +113,10 @@ class AlarmService(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
LOG.debug(_('evaluating alarm %s') % alarm.alarm_id)
|
LOG.debug(_('evaluating alarm %s') % alarm.alarm_id)
|
||||||
|
try:
|
||||||
self.evaluators[alarm.type].obj.evaluate(alarm)
|
self.evaluators[alarm.type].obj.evaluate(alarm)
|
||||||
|
except Exception:
|
||||||
|
LOG.exception(_('Failed to evaluate alarm %s'), alarm.alarm_id)
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def _assigned_alarms(self):
|
def _assigned_alarms(self):
|
||||||
|
@ -107,6 +107,22 @@ class TestAlarmEvaluationService(tests_base.BaseTestCase):
|
|||||||
self.svc.PARTITIONING_GROUP_NAME, [alarm])
|
self.svc.PARTITIONING_GROUP_NAME, [alarm])
|
||||||
self.threshold_eval.evaluate.assert_called_once_with(alarm)
|
self.threshold_eval.evaluate.assert_called_once_with(alarm)
|
||||||
|
|
||||||
|
def test_evaluation_cycle_with_bad_alarm(self):
|
||||||
|
alarms = [
|
||||||
|
mock.Mock(type='threshold', name='bad'),
|
||||||
|
mock.Mock(type='threshold', name='good'),
|
||||||
|
]
|
||||||
|
self.api_client.alarms.list.return_value = alarms
|
||||||
|
self.threshold_eval.evaluate.side_effect = [Exception('Boom!'), None]
|
||||||
|
with mock.patch('ceilometerclient.client.get_client',
|
||||||
|
return_value=self.api_client):
|
||||||
|
p_coord_mock = self.svc.partition_coordinator
|
||||||
|
p_coord_mock.extract_my_subset.return_value = alarms
|
||||||
|
|
||||||
|
self.svc._evaluate_assigned_alarms()
|
||||||
|
self.assertEqual([mock.call(alarms[0]), mock.call(alarms[1])],
|
||||||
|
self.threshold_eval.evaluate.call_args_list)
|
||||||
|
|
||||||
def test_unknown_extension_skipped(self):
|
def test_unknown_extension_skipped(self):
|
||||||
alarms = [
|
alarms = [
|
||||||
mock.Mock(type='not_existing_type'),
|
mock.Mock(type='not_existing_type'),
|
||||||
|
@ -71,6 +71,19 @@ class TestSingletonAlarmService(tests_base.BaseTestCase):
|
|||||||
self.singleton._evaluate_assigned_alarms()
|
self.singleton._evaluate_assigned_alarms()
|
||||||
self.threshold_eval.evaluate.assert_called_once_with(alarm)
|
self.threshold_eval.evaluate.assert_called_once_with(alarm)
|
||||||
|
|
||||||
|
def test_evaluation_cycle_with_bad_alarm(self):
|
||||||
|
alarms = [
|
||||||
|
mock.Mock(type='threshold', name='bad'),
|
||||||
|
mock.Mock(type='threshold', name='good'),
|
||||||
|
]
|
||||||
|
self.threshold_eval.evaluate.side_effect = [Exception('Boom!'), None]
|
||||||
|
self.api_client.alarms.list.return_value = alarms
|
||||||
|
with mock.patch('ceilometerclient.client.get_client',
|
||||||
|
return_value=self.api_client):
|
||||||
|
self.singleton._evaluate_assigned_alarms()
|
||||||
|
self.assertEqual([mock.call(alarms[0]), mock.call(alarms[1])],
|
||||||
|
self.threshold_eval.evaluate.call_args_list)
|
||||||
|
|
||||||
def test_unknown_extension_skipped(self):
|
def test_unknown_extension_skipped(self):
|
||||||
alarms = [
|
alarms = [
|
||||||
mock.Mock(type='not_existing_type'),
|
mock.Mock(type='not_existing_type'),
|
||||||
|
Loading…
Reference in New Issue
Block a user