Merge "Alarm: Use stevedore to load the service class"

This commit is contained in:
Jenkins 2014-08-30 00:18:32 +00:00 committed by Gerrit Code Review
commit 5d0d2c9f77
4 changed files with 74 additions and 6 deletions

View File

@ -15,21 +15,23 @@
# under the License.
from oslo.config import cfg
from oslo.utils import importutils
from stevedore import driver
from ceilometer.alarm import service as alarm_service
from ceilometer.openstack.common import log
from ceilometer.openstack.common import service as os_service
from ceilometer import service
OPTS = [
cfg.StrOpt('evaluation_service',
default='ceilometer.alarm.service.SingletonAlarmService',
help='Class to launch as alarm evaluation service.'),
cfg.StrOpt('evaluation_service', default='singleton',
help='Driver to use for alarm evaluation service.'),
]
cfg.CONF.register_opts(OPTS, group='alarm')
LOG = log.getLogger(__name__)
def notifier():
service.prepare_service()
@ -38,5 +40,10 @@ def notifier():
def evaluator():
service.prepare_service()
eval_service = importutils.import_object(cfg.CONF.alarm.evaluation_service)
os_service.launch(eval_service).wait()
eval_service_mgr = driver.DriverManager(
"ceilometer.alarm.evaluator_service",
cfg.CONF.alarm.evaluation_service,
invoke_on_load=True)
LOG.debug("Alarm evaluator loaded: %s" %
eval_service_mgr.driver.__class__.__name__)
os_service.launch(eval_service_mgr.driver).wait()

View File

@ -100,6 +100,46 @@ class BinSendSampleTestCase(base.BaseTestCase):
self.assertEqual(0, subp.wait())
class BinAlarmEvaluatorServiceTestCase(base.BaseTestCase):
def _do_test(self, driver, driver_class):
pipeline_cfg_file = self.path_get('etc/ceilometer/pipeline.yaml')
content = ("[DEFAULT]\n"
"rpc_backend=fake\n"
"pipeline_cfg_file={0}\n"
"debug=true\n"
"[database]\n"
"time_to_live=1\n"
"connection=log://localhost\n".format(pipeline_cfg_file))
if driver:
content += "[alarm]\nevaluation_service=%s\n" % driver
self.tempfile = fileutils.write_to_tempfile(content=content,
prefix='ceilometer',
suffix='.conf')
self.subp = subprocess.Popen(['ceilometer-alarm-evaluator',
"--config-file=%s" % self.tempfile],
stderr=subprocess.PIPE)
err = self.subp.stderr.read(1024)
self.assertIn("Alarm evaluator loaded: %s" % driver_class, err)
def tearDown(self):
super(BinAlarmEvaluatorServiceTestCase, self).tearDown()
self.subp.kill()
self.subp.wait()
os.remove(self.tempfile)
def test_default_config(self):
self._do_test(None, "SingletonAlarmService")
def test_backward_compat(self):
self._do_test("ceilometer.alarm.service.PartitionedAlarmService",
"PartitionedAlarmService")
def test_partitioned_driver(self):
self._do_test("partitioned", "PartitionedAlarmService")
class BinApiTestCase(base.BaseTestCase):
def setUp(self):

View File

@ -193,6 +193,20 @@ drop_unmatched_notifications False If s
definitions_cfg_file event_definitions.yaml Name of event definitions config file (yaml format)
================================== ====================================== ==============================================================
Alarming
========
The following options in the [alarm] configuration section affect the configuration of alarm services
====================== ============== ====================================================================================
Parameter Default Note
====================== ============== ====================================================================================
evaluation_service singleton Driver to use for alarm evaluation service:
* singleton: All alarms are evaluated by one alarm evaluation service instance
* partitioned: All alarms are dispatched across all alarm evaluation service
instances to be evaluate
====================== ============== ====================================================================================
General options

View File

@ -224,6 +224,13 @@ ceilometer.alarm.evaluator =
threshold = ceilometer.alarm.evaluator.threshold:ThresholdEvaluator
combination = ceilometer.alarm.evaluator.combination:CombinationEvaluator
ceilometer.alarm.evaluator_service =
singleton = ceilometer.alarm.service:SingletonAlarmService
partitioned = ceilometer.alarm.service:PartitionedAlarmService
# NOTE(sileht): for backward compatibility
ceilometer.alarm.service.SingletonAlarmService = ceilometer.alarm.service:SingletonAlarmService
ceilometer.alarm.service.PartitionedAlarmService = ceilometer.alarm.service:PartitionedAlarmService
ceilometer.alarm.notifier =
log = ceilometer.alarm.notifier.log:LogAlarmNotifier
test = ceilometer.alarm.notifier.test:TestAlarmNotifier