Don't load into alarms evaluators disabled alarms
With this patch, alarm evaluators query the ceilometer API with only enabled alarms inteads of loading all alarms and skip the disabled one. Related to bug #1231328 Change-Id: I7121c1d2703f2f82a7d910431696aa31cbf7fbe6
This commit is contained in:
parent
3cfac4c51a
commit
ac9bb779bf
@ -301,7 +301,8 @@ class PartitionCoordinator(object):
|
||||
try:
|
||||
LOG.debug(_('%(this)s alarms for evaluation: %(alarms)s') %
|
||||
dict(this=self.this, alarms=self.assignment))
|
||||
return [a for a in api_client.alarms.list()
|
||||
return [a for a in api_client.alarms.list(q=[{'field': 'enabled',
|
||||
'value': True}])
|
||||
if a.alarm_id in self.assignment]
|
||||
except Exception:
|
||||
LOG.exception(_('assignment retrieval failed'))
|
||||
|
@ -102,10 +102,6 @@ class AlarmService(object):
|
||||
|
||||
def _evaluate_alarm(self, alarm):
|
||||
"""Evaluate the alarms assigned to this evaluator."""
|
||||
if not alarm.enabled:
|
||||
LOG.debug(_('skipping alarm %s: alarm disabled') %
|
||||
alarm.alarm_id)
|
||||
return
|
||||
if alarm.type not in self.supported_evaluators:
|
||||
LOG.debug(_('skipping alarm %s: type unsupported') %
|
||||
alarm.alarm_id)
|
||||
@ -138,7 +134,8 @@ class SingletonAlarmService(AlarmService, os_service.Service):
|
||||
self.tg.add_timer(604800, lambda: None)
|
||||
|
||||
def _assigned_alarms(self):
|
||||
return self._client.alarms.list()
|
||||
return self._client.alarms.list(q=[{'field': 'enabled',
|
||||
'value': True}])
|
||||
|
||||
|
||||
def alarm_evaluator():
|
||||
|
@ -64,29 +64,13 @@ class TestSingletonAlarmService(base.TestCase):
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_evaluation_cycle(self):
|
||||
alarm = mock.Mock(enabled=True,
|
||||
type='threshold')
|
||||
alarm = mock.Mock(type='threshold')
|
||||
self.api_client.alarms.list.return_value = [alarm]
|
||||
with mock.patch('ceilometerclient.client.get_client',
|
||||
return_value=self.api_client):
|
||||
self.singleton._evaluate_assigned_alarms()
|
||||
self.threshold_eval.evaluate.assert_called_once_with(alarm)
|
||||
|
||||
def test_disabled_is_skipped(self):
|
||||
alarms = [
|
||||
mock.Mock(enabled=False,
|
||||
type='threshold'),
|
||||
mock.Mock(enabled=True,
|
||||
type='threshold'),
|
||||
]
|
||||
|
||||
self.api_client.alarms.list.return_value = alarms
|
||||
with mock.patch('ceilometerclient.client.get_client',
|
||||
return_value=self.api_client):
|
||||
self.singleton.start()
|
||||
self.singleton._evaluate_assigned_alarms()
|
||||
self.threshold_eval.evaluate.assert_called_once_with(alarms[1])
|
||||
|
||||
def test_unknown_extention_skipped(self):
|
||||
alarms = [
|
||||
mock.Mock(type='not_existing_type'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user