Move notifications options into oslo_messaging_notifications

In order to make the notifications configuration clearer, let's put
its options into "oslo_messaging_notifications" group just like what
oslo_messaging did.

Closes-Bug: #1536034
Depends-On: I4c9f4de73e7732cb90cb742c94daddf8d2d5e398
Change-Id: I0ba6348ecbc1852e24c9eb7b5f0fa9f3e5922463
This commit is contained in:
Javeme 2016-01-20 16:33:27 +08:00
parent 3a1cd0f6b5
commit 24be6c081d
9 changed files with 33 additions and 17 deletions

View File

@ -81,7 +81,7 @@ function configure_sahara {
# Set configuration to send notifications # Set configuration to send notifications
if is_service_enabled ceilometer; then if is_service_enabled ceilometer; then
iniset $SAHARA_CONF_FILE DEFAULT enable_notifications "true" iniset $SAHARA_CONF_FILE oslo_messaging_notifications enable "true"
iniset $SAHARA_CONF_FILE oslo_messaging_notifications driver "messaging" iniset $SAHARA_CONF_FILE oslo_messaging_notifications driver "messaging"
fi fi

View File

@ -135,12 +135,14 @@ Notifications configuration
--------------------------- ---------------------------
Sahara can be configured to send notifications to the OpenStack Sahara can be configured to send notifications to the OpenStack
Telemetry module. To enable this functionality the following parameters Telemetry module. To enable this functionality the following parameter
should be set in the ``[DEFAULT]`` section of the configuration file: ``enable`` should be set in the ``[oslo_messaging_notifications]`` section
of the configuration file:
.. sourcecode:: cfg .. sourcecode:: cfg
enable_notifications = true [oslo_messaging_notifications]
enable = true
.. ..
And the following parameter ``driver`` should be set in the And the following parameter ``driver`` should be set in the

View File

@ -0,0 +1,3 @@
---
upgrade:
- Move notifications options into oslo_messaging_notifications

View File

@ -152,7 +152,6 @@ def list_opts():
db_opts, db_opts,
plugins_base.opts, plugins_base.opts,
topology_helper.opts, topology_helper.opts,
sender.notifier_opts,
keystone.opts, keystone.opts,
remote.ssh_opts, remote.ssh_opts,
sahara_main.opts, sahara_main.opts,
@ -187,7 +186,8 @@ def list_opts():
(swift_helper.public_endpoint_cert_group.name, (swift_helper.public_endpoint_cert_group.name,
itertools.chain(swift_helper.opts)), itertools.chain(swift_helper.opts)),
(castellan.castellan_group.name, (castellan.castellan_group.name,
itertools.chain(castellan.castellan_opts)) itertools.chain(castellan.castellan_opts)),
(sender.notifier_opts_group, sender.notifier_opts)
] ]

View File

@ -85,7 +85,8 @@ def setup_common(possible_topdir, service_name):
cinder.validate_config() cinder.validate_config()
castellan.validate_config() castellan.validate_config()
if service_name != 'all-in-one' or cfg.CONF.enable_notifications: if (service_name != 'all-in-one' or
CONF.oslo_messaging_notifications.enable):
messaging.setup() messaging.setup()
plugins_base.setup_plugins() plugins_base.setup_plugins()

View File

@ -51,7 +51,8 @@ class NotificationTest(base.SaharaTestCase):
@mock.patch('oslo_messaging.notify.notifier.Notifier.info') @mock.patch('oslo_messaging.notify.notifier.Notifier.info')
def test_update_cluster(self, mock_notify): def test_update_cluster(self, mock_notify):
self.override_config("enable_notifications", True) self.override_config("enable", True,
group='oslo_messaging_notifications')
messaging.setup() messaging.setup()
self._make_sample() self._make_sample()

View File

@ -30,7 +30,8 @@ class TestMessagingSetup(base.SaharaTestCase):
def setUp(self): def setUp(self):
super(TestMessagingSetup, self).setUp() super(TestMessagingSetup, self).setUp()
self.override_config('enable_notifications', True) self.override_config('enable', True,
group='oslo_messaging_notifications')
def _install(self): def _install(self):
messaging.setup() messaging.setup()

View File

@ -24,22 +24,30 @@ SERVICE = 'sahara'
EVENT_TEMPLATE = "sahara.cluster.%s" EVENT_TEMPLATE = "sahara.cluster.%s"
notifier_opts = [ notifier_opts = [
cfg.StrOpt('notification_level', cfg.StrOpt('level',
default='INFO', default='INFO',
deprecated_name='notification_level',
deprecated_group='DEFAULT',
help='Notification level for outgoing notifications'), help='Notification level for outgoing notifications'),
cfg.StrOpt('notification_publisher_id', cfg.StrOpt('publisher_id',
deprecated_name='notification_publisher_id',
deprecated_group='DEFAULT',
help='Notification publisher_id for outgoing notifications'), help='Notification publisher_id for outgoing notifications'),
cfg.BoolOpt('enable_notifications', cfg.BoolOpt('enable',
deprecated_name='enable_notifications',
deprecated_group='DEFAULT',
default=False, default=False,
help='Enables sending notifications to Ceilometer') help='Enables sending notifications to Ceilometer')
] ]
notifier_opts_group = 'oslo_messaging_notifications'
CONF = cfg.CONF CONF = cfg.CONF
CONF.register_opts(notifier_opts) CONF.register_opts(notifier_opts, group=notifier_opts_group)
def _get_publisher(): def _get_publisher():
publisher_id = CONF.notification_publisher_id publisher_id = CONF.oslo_messaging_notifications.publisher_id
if publisher_id is None: if publisher_id is None:
publisher_id = SERVICE publisher_id = SERVICE
return publisher_id return publisher_id
@ -70,14 +78,14 @@ def _body(
def notify(context, cluster_id, cluster_name, cluster_status, ev_type): def notify(context, cluster_id, cluster_name, cluster_status, ev_type):
"""Sends notification about creating/updating/deleting cluster.""" """Sends notification about creating/updating/deleting cluster."""
if not cfg.CONF.enable_notifications: if not cfg.CONF.oslo_messaging_notifications.enable:
return return
LOG.debug("Notification about cluster is going to be sent. Notification " LOG.debug("Notification about cluster is going to be sent. Notification "
"type={type}, cluster status = {status}" "type={type}, cluster status = {status}"
.format(type=ev_type, status=cluster_status)) .format(type=ev_type, status=cluster_status))
level = CONF.notification_level level = CONF.oslo_messaging_notifications.level
_notify(context, EVENT_TEMPLATE % ev_type, level, _notify(context, EVENT_TEMPLATE % ev_type, level,
_body(cluster_id, cluster_name, cluster_status, context.tenant_id, _body(cluster_id, cluster_name, cluster_status, context.tenant_id,

View File

@ -101,7 +101,7 @@ def setup():
TRANSPORT = messaging.get_transport(cfg.CONF, aliases=_ALIASES) TRANSPORT = messaging.get_transport(cfg.CONF, aliases=_ALIASES)
if not cfg.CONF.enable_notifications: if not cfg.CONF.oslo_messaging_notifications.enable:
LOG.info(_LI("Notifications disabled")) LOG.info(_LI("Notifications disabled"))
return return
LOG.info(_LI("Notifications enabled")) LOG.info(_LI("Notifications enabled"))