Option group for notifications

In change Ief6f95ea906bfd95b3218a930c9db5d8a764beb9, we 
decoupled RPC and Notifications a bit. We should take another
step and separate out the options for notifications into 
its own group.

Change-Id: Ib51e2839f9035d0cc0e3f459939d9f9003a8c810
This commit is contained in:
Davanum Srinivas 2015-11-24 19:56:16 -05:00 committed by Davanum Srinivas (dims)
parent f4f40ea9a5
commit 33c1010c32
10 changed files with 65 additions and 39 deletions

View File

@ -6,7 +6,8 @@ I don't need notifications on the message bus. How do I disable them?
=====================================================================
Notification messages can be disabled using the ``noop`` notify
driver. Set ``notification_driver = noop`` in your configuration file.
driver. Set ``driver = noop`` in your configuration file under the
[oslo_messaging_notifications] section.
Why does the notification publisher create queues, too? Shouldn't the subscriber do that?
=========================================================================================
@ -26,9 +27,9 @@ notification "level". The default topic is ``notifications``, so an
info-level notification is published to the topic
``notifications.info``. A subscriber queue of the same name is created
automatically for each of these topics. To change the queue names,
change the notification topic using the ``notification_topics``
configuration option. The option accepts a list of values, so it is
possible to publish to multiple topics.
change the notification topic using the ``topics``
configuration option in ``[oslo_messaging_notifications]``. The option
accepts a list of values, so it is possible to publish to multiple topics.
What are the other choices of notification drivers available?
=============================================================

View File

@ -66,7 +66,9 @@ class ConfFixture(fixtures.Fixture):
_import_opts(self.conf, 'oslo_messaging.rpc.client', '_client_opts')
_import_opts(self.conf, 'oslo_messaging.transport', '_transport_opts')
_import_opts(self.conf,
'oslo_messaging.notify.notifier', '_notifier_opts')
'oslo_messaging.notify.notifier',
'_notifier_opts',
'oslo_messaging_notifications')
def setUp(self):
super(ConfFixture, self).setUp()

View File

@ -27,11 +27,13 @@ from oslo_messaging.notify import notifier
LOG = logging.getLogger(__name__)
router_config = cfg.StrOpt('routing_notifier_config', default='',
router_config = cfg.StrOpt('routing_config', default='',
deprecated_group='DEFAULT',
deprecated_name='routing_notifier_config',
help='RoutingNotifier configuration file location.')
CONF = cfg.CONF
CONF.register_opt(router_config)
CONF.register_opt(router_config, group='oslo_messaging_notifications')
class RoutingDriver(notifier.Driver):
@ -56,7 +58,7 @@ class RoutingDriver(notifier.Driver):
"""One-time load of notifier config file."""
self.routing_groups = {}
self.used_drivers = set()
filename = CONF.routing_notifier_config
filename = CONF.oslo_messaging_notifications.routing_config
if not filename:
return

View File

@ -27,8 +27,9 @@ class LoggingErrorNotificationHandler(logging.Handler):
publisher_id='error.publisher')
def emit(self, record):
conf = self._transport.conf
# NOTE(bnemec): Notifier registers this opt with the transport.
if ('log' in self._transport.conf.notification_driver):
if ('log' in conf.oslo_messaging_notifications.driver):
# NOTE(lbragstad): If we detect that log is one of the
# notification drivers, then return. This protects from infinite
# recursion where something bad happens, it gets logged, the log

View File

@ -28,19 +28,27 @@ from oslo_messaging import serializer as msg_serializer
from oslo_messaging import transport as msg_transport
_notifier_opts = [
cfg.MultiStrOpt('notification_driver',
cfg.MultiStrOpt('driver',
default=[],
deprecated_name='notification_driver',
deprecated_group='DEFAULT',
help='The Drivers(s) to handle sending notifications. '
'Possible values are messaging, messagingv2, '
'routing, log, test, noop'),
cfg.StrOpt('notification_transport_url',
cfg.StrOpt('transport_url',
deprecated_name='notification_transport_url',
deprecated_group='DEFAULT',
help='A URL representing the messaging driver to use for '
'notifications. If not set, we fall back to the same '
'configuration used for RPC.'),
cfg.ListOpt('notification_topics',
cfg.ListOpt('topics',
default=['notifications', ],
deprecated_name='topics',
deprecated_group='rpc_notifier2',
deprecated_opts=[
cfg.DeprecatedOpt('topics',
group='rpc_notifier2'),
cfg.DeprecatedOpt('notification_topics',
group='DEFAULT')
],
help='AMQP topic used for OpenStack notifications.'),
]
@ -83,8 +91,9 @@ class Driver(object):
def get_notification_transport(conf, url=None,
allowed_remote_exmods=None, aliases=None):
if url is None:
conf.register_opts(_notifier_opts)
url = conf.notification_transport_url
conf.register_opts(_notifier_opts,
group='oslo_messaging_notifications')
url = conf.oslo_messaging_notifications.transport_url
return msg_transport.get_transport(conf, url,
allowed_remote_exmods, aliases)
@ -111,9 +120,9 @@ class Notifier(object):
notifier = messaging.Notifier(get_notification_transport(CONF),
'compute')
and notifications are sent via drivers chosen with the notification_driver
config option and on the topics chosen with the notification_topics config
option.
and notifications are sent via drivers chosen with the driver
config option and on the topics chosen with the topics config
option in [oslo_messaging_notifications] section.
Alternatively, a Notifier object can be instantiated with a specific
driver or topic::
@ -154,24 +163,26 @@ class Notifier(object):
N means N retries
:type retry: int
"""
transport.conf.register_opts(_notifier_opts)
conf = transport.conf
conf.register_opts(_notifier_opts,
group='oslo_messaging_notifications')
self.transport = transport
self.publisher_id = publisher_id
self.retry = retry
self._driver_names = ([driver] if driver is not None
else transport.conf.notification_driver)
self._driver_names = ([driver] if driver is not None else
conf.oslo_messaging_notifications.driver)
self._topics = ([topic] if topic is not None
else transport.conf.notification_topics)
self._topics = ([topic] if topic is not None else
conf.oslo_messaging_notifications.topics)
self._serializer = serializer or msg_serializer.NoOpSerializer()
self._driver_mgr = named.NamedExtensionManager(
'oslo.messaging.notify.drivers',
names=self._driver_names,
invoke_on_load=True,
invoke_args=[transport.conf],
invoke_args=[conf],
invoke_kwds={
'topics': self._topics,
'transport': self.transport,

View File

@ -51,8 +51,9 @@ class LoggingNotificationHandlerTestCase(utils.SkipIfNoTransportURL):
# NOTE(gtt): Using different topic to make tests run in parallel
topic = 'test_logging_%s_driver_%s' % (self.priority, self.driver)
self.conf.notification_driver = [self.driver]
self.conf.notification_topics = [topic]
self.config(driver=[self.driver],
topics=[topic],
group='oslo_messaging_notifications')
listener = self.useFixture(
utils.NotificationFixture(self.conf, self.url, [topic]))

View File

@ -28,7 +28,8 @@ class PublishErrorsHandlerTestCase(test_utils.BaseTestCase):
def test_emit_cfg_log_notifier_in_notifier_drivers(self):
drivers = ['messaging', 'log']
self.config(notification_driver=drivers)
self.config(driver=drivers,
group='oslo_messaging_notifications')
self.stub_flg = True
transport = test_notifier._FakeTransport(self.conf)

View File

@ -49,7 +49,8 @@ class TestLogNotifier(test_utils.BaseTestCase):
def setUp(self):
super(TestLogNotifier, self).setUp()
self.addCleanup(oslo_messaging.notify._impl_test.reset)
self.config(notification_driver=['test'])
self.config(driver=['test'],
group='oslo_messaging_notifications')
# NOTE(jamespage) disable thread information logging for testing
# as this causes test failures when zmq tests monkey_patch via
# eventlet

View File

@ -156,8 +156,9 @@ class TestMessagingNotifier(test_utils.BaseTestCase):
if self.v2:
drivers.append('messagingv2')
self.config(notification_driver=drivers,
notification_topics=self.topics)
self.config(driver=drivers,
topics=self.topics,
group='oslo_messaging_notifications')
transport = _FakeTransport(self.conf)
@ -269,7 +270,8 @@ class TestLogNotifier(test_utils.BaseTestCase):
@mock.patch('oslo_utils.timeutils.utcnow')
def test_notifier(self, mock_utcnow):
self.config(notification_driver=['log'])
self.config(driver=['log'],
group='oslo_messaging_notifications')
transport = _FakeTransport(self.conf)
@ -338,7 +340,8 @@ class TestLogNotifier(test_utils.BaseTestCase):
class TestRoutingNotifier(test_utils.BaseTestCase):
def setUp(self):
super(TestRoutingNotifier, self).setUp()
self.config(notification_driver=['routing'])
self.config(driver=['routing'],
group='oslo_messaging_notifications')
transport = _FakeTransport(self.conf)
self.notifier = oslo_messaging.Notifier(transport)
@ -360,13 +363,14 @@ class TestRoutingNotifier(test_utils.BaseTestCase):
self.assertTrue(self.router._should_load_plugin(ext))
def test_load_notifiers_no_config(self):
# default routing_notifier_config=""
# default routing_config=""
self.router._load_notifiers()
self.assertEqual({}, self.router.routing_groups)
self.assertEqual(0, len(self.router.used_drivers))
def test_load_notifiers_no_extensions(self):
self.config(routing_notifier_config="routing_notifier.yaml")
self.config(routing_config="routing_notifier.yaml",
group='oslo_messaging_notifications')
routing_config = r""
config_file = mock.MagicMock()
config_file.return_value = routing_config
@ -382,7 +386,8 @@ class TestRoutingNotifier(test_utils.BaseTestCase):
self.assertEqual({}, self.router.routing_groups)
def test_load_notifiers_config(self):
self.config(routing_notifier_config="routing_notifier.yaml")
self.config(routing_config="routing_notifier.yaml",
group='oslo_messaging_notifications')
routing_config = r"""
group_1:
rpc : foo
@ -519,7 +524,8 @@ group_1:
sorted(pm.map.call_args[0][6]))
def test_notify_filtered(self):
self.config(routing_notifier_config="routing_notifier.yaml")
self.config(routing_config="routing_notifier.yaml",
group='oslo_messaging_notifications')
routing_config = r"""
group_1:
rpc:

View File

@ -283,8 +283,8 @@ def main():
# oslo.config defaults
cfg.CONF.heartbeat_interval = 5
cfg.CONF.notification_topics = "notif"
cfg.CONF.notification_driver = "messaging"
cfg.CONF.oslo_messaging_notifications.topics = "notif"
cfg.CONF.oslo_messaging_notifications.driver = "messaging"
cfg.CONF.prog = os.path.basename(__file__)
cfg.CONF.project = 'oslo.messaging'