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:
parent
f4f40ea9a5
commit
33c1010c32
@ -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
|
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?
|
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
|
info-level notification is published to the topic
|
||||||
``notifications.info``. A subscriber queue of the same name is created
|
``notifications.info``. A subscriber queue of the same name is created
|
||||||
automatically for each of these topics. To change the queue names,
|
automatically for each of these topics. To change the queue names,
|
||||||
change the notification topic using the ``notification_topics``
|
change the notification topic using the ``topics``
|
||||||
configuration option. The option accepts a list of values, so it is
|
configuration option in ``[oslo_messaging_notifications]``. The option
|
||||||
possible to publish to multiple topics.
|
accepts a list of values, so it is possible to publish to multiple topics.
|
||||||
|
|
||||||
What are the other choices of notification drivers available?
|
What are the other choices of notification drivers available?
|
||||||
=============================================================
|
=============================================================
|
||||||
|
@ -66,7 +66,9 @@ class ConfFixture(fixtures.Fixture):
|
|||||||
_import_opts(self.conf, 'oslo_messaging.rpc.client', '_client_opts')
|
_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.transport', '_transport_opts')
|
||||||
_import_opts(self.conf,
|
_import_opts(self.conf,
|
||||||
'oslo_messaging.notify.notifier', '_notifier_opts')
|
'oslo_messaging.notify.notifier',
|
||||||
|
'_notifier_opts',
|
||||||
|
'oslo_messaging_notifications')
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ConfFixture, self).setUp()
|
super(ConfFixture, self).setUp()
|
||||||
|
@ -27,11 +27,13 @@ from oslo_messaging.notify import notifier
|
|||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
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.')
|
help='RoutingNotifier configuration file location.')
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
CONF.register_opt(router_config)
|
CONF.register_opt(router_config, group='oslo_messaging_notifications')
|
||||||
|
|
||||||
|
|
||||||
class RoutingDriver(notifier.Driver):
|
class RoutingDriver(notifier.Driver):
|
||||||
@ -56,7 +58,7 @@ class RoutingDriver(notifier.Driver):
|
|||||||
"""One-time load of notifier config file."""
|
"""One-time load of notifier config file."""
|
||||||
self.routing_groups = {}
|
self.routing_groups = {}
|
||||||
self.used_drivers = set()
|
self.used_drivers = set()
|
||||||
filename = CONF.routing_notifier_config
|
filename = CONF.oslo_messaging_notifications.routing_config
|
||||||
if not filename:
|
if not filename:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -27,8 +27,9 @@ class LoggingErrorNotificationHandler(logging.Handler):
|
|||||||
publisher_id='error.publisher')
|
publisher_id='error.publisher')
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
|
conf = self._transport.conf
|
||||||
# NOTE(bnemec): Notifier registers this opt with the transport.
|
# 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
|
# NOTE(lbragstad): If we detect that log is one of the
|
||||||
# notification drivers, then return. This protects from infinite
|
# notification drivers, then return. This protects from infinite
|
||||||
# recursion where something bad happens, it gets logged, the log
|
# recursion where something bad happens, it gets logged, the log
|
||||||
|
@ -28,19 +28,27 @@ from oslo_messaging import serializer as msg_serializer
|
|||||||
from oslo_messaging import transport as msg_transport
|
from oslo_messaging import transport as msg_transport
|
||||||
|
|
||||||
_notifier_opts = [
|
_notifier_opts = [
|
||||||
cfg.MultiStrOpt('notification_driver',
|
cfg.MultiStrOpt('driver',
|
||||||
default=[],
|
default=[],
|
||||||
|
deprecated_name='notification_driver',
|
||||||
|
deprecated_group='DEFAULT',
|
||||||
help='The Drivers(s) to handle sending notifications. '
|
help='The Drivers(s) to handle sending notifications. '
|
||||||
'Possible values are messaging, messagingv2, '
|
'Possible values are messaging, messagingv2, '
|
||||||
'routing, log, test, noop'),
|
'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 '
|
help='A URL representing the messaging driver to use for '
|
||||||
'notifications. If not set, we fall back to the same '
|
'notifications. If not set, we fall back to the same '
|
||||||
'configuration used for RPC.'),
|
'configuration used for RPC.'),
|
||||||
cfg.ListOpt('notification_topics',
|
cfg.ListOpt('topics',
|
||||||
default=['notifications', ],
|
default=['notifications', ],
|
||||||
deprecated_name='topics',
|
deprecated_opts=[
|
||||||
deprecated_group='rpc_notifier2',
|
cfg.DeprecatedOpt('topics',
|
||||||
|
group='rpc_notifier2'),
|
||||||
|
cfg.DeprecatedOpt('notification_topics',
|
||||||
|
group='DEFAULT')
|
||||||
|
],
|
||||||
help='AMQP topic used for OpenStack notifications.'),
|
help='AMQP topic used for OpenStack notifications.'),
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -83,8 +91,9 @@ class Driver(object):
|
|||||||
def get_notification_transport(conf, url=None,
|
def get_notification_transport(conf, url=None,
|
||||||
allowed_remote_exmods=None, aliases=None):
|
allowed_remote_exmods=None, aliases=None):
|
||||||
if url is None:
|
if url is None:
|
||||||
conf.register_opts(_notifier_opts)
|
conf.register_opts(_notifier_opts,
|
||||||
url = conf.notification_transport_url
|
group='oslo_messaging_notifications')
|
||||||
|
url = conf.oslo_messaging_notifications.transport_url
|
||||||
return msg_transport.get_transport(conf, url,
|
return msg_transport.get_transport(conf, url,
|
||||||
allowed_remote_exmods, aliases)
|
allowed_remote_exmods, aliases)
|
||||||
|
|
||||||
@ -111,9 +120,9 @@ class Notifier(object):
|
|||||||
notifier = messaging.Notifier(get_notification_transport(CONF),
|
notifier = messaging.Notifier(get_notification_transport(CONF),
|
||||||
'compute')
|
'compute')
|
||||||
|
|
||||||
and notifications are sent via drivers chosen with the notification_driver
|
and notifications are sent via drivers chosen with the driver
|
||||||
config option and on the topics chosen with the notification_topics config
|
config option and on the topics chosen with the topics config
|
||||||
option.
|
option in [oslo_messaging_notifications] section.
|
||||||
|
|
||||||
Alternatively, a Notifier object can be instantiated with a specific
|
Alternatively, a Notifier object can be instantiated with a specific
|
||||||
driver or topic::
|
driver or topic::
|
||||||
@ -154,24 +163,26 @@ class Notifier(object):
|
|||||||
N means N retries
|
N means N retries
|
||||||
:type retry: int
|
: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.transport = transport
|
||||||
self.publisher_id = publisher_id
|
self.publisher_id = publisher_id
|
||||||
self.retry = retry
|
self.retry = retry
|
||||||
|
|
||||||
self._driver_names = ([driver] if driver is not None
|
self._driver_names = ([driver] if driver is not None else
|
||||||
else transport.conf.notification_driver)
|
conf.oslo_messaging_notifications.driver)
|
||||||
|
|
||||||
self._topics = ([topic] if topic is not None
|
self._topics = ([topic] if topic is not None else
|
||||||
else transport.conf.notification_topics)
|
conf.oslo_messaging_notifications.topics)
|
||||||
self._serializer = serializer or msg_serializer.NoOpSerializer()
|
self._serializer = serializer or msg_serializer.NoOpSerializer()
|
||||||
|
|
||||||
self._driver_mgr = named.NamedExtensionManager(
|
self._driver_mgr = named.NamedExtensionManager(
|
||||||
'oslo.messaging.notify.drivers',
|
'oslo.messaging.notify.drivers',
|
||||||
names=self._driver_names,
|
names=self._driver_names,
|
||||||
invoke_on_load=True,
|
invoke_on_load=True,
|
||||||
invoke_args=[transport.conf],
|
invoke_args=[conf],
|
||||||
invoke_kwds={
|
invoke_kwds={
|
||||||
'topics': self._topics,
|
'topics': self._topics,
|
||||||
'transport': self.transport,
|
'transport': self.transport,
|
||||||
|
@ -51,8 +51,9 @@ class LoggingNotificationHandlerTestCase(utils.SkipIfNoTransportURL):
|
|||||||
# NOTE(gtt): Using different topic to make tests run in parallel
|
# NOTE(gtt): Using different topic to make tests run in parallel
|
||||||
topic = 'test_logging_%s_driver_%s' % (self.priority, self.driver)
|
topic = 'test_logging_%s_driver_%s' % (self.priority, self.driver)
|
||||||
|
|
||||||
self.conf.notification_driver = [self.driver]
|
self.config(driver=[self.driver],
|
||||||
self.conf.notification_topics = [topic]
|
topics=[topic],
|
||||||
|
group='oslo_messaging_notifications')
|
||||||
|
|
||||||
listener = self.useFixture(
|
listener = self.useFixture(
|
||||||
utils.NotificationFixture(self.conf, self.url, [topic]))
|
utils.NotificationFixture(self.conf, self.url, [topic]))
|
||||||
|
@ -28,7 +28,8 @@ class PublishErrorsHandlerTestCase(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
def test_emit_cfg_log_notifier_in_notifier_drivers(self):
|
def test_emit_cfg_log_notifier_in_notifier_drivers(self):
|
||||||
drivers = ['messaging', 'log']
|
drivers = ['messaging', 'log']
|
||||||
self.config(notification_driver=drivers)
|
self.config(driver=drivers,
|
||||||
|
group='oslo_messaging_notifications')
|
||||||
self.stub_flg = True
|
self.stub_flg = True
|
||||||
|
|
||||||
transport = test_notifier._FakeTransport(self.conf)
|
transport = test_notifier._FakeTransport(self.conf)
|
||||||
|
@ -49,7 +49,8 @@ class TestLogNotifier(test_utils.BaseTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestLogNotifier, self).setUp()
|
super(TestLogNotifier, self).setUp()
|
||||||
self.addCleanup(oslo_messaging.notify._impl_test.reset)
|
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
|
# NOTE(jamespage) disable thread information logging for testing
|
||||||
# as this causes test failures when zmq tests monkey_patch via
|
# as this causes test failures when zmq tests monkey_patch via
|
||||||
# eventlet
|
# eventlet
|
||||||
|
@ -156,8 +156,9 @@ class TestMessagingNotifier(test_utils.BaseTestCase):
|
|||||||
if self.v2:
|
if self.v2:
|
||||||
drivers.append('messagingv2')
|
drivers.append('messagingv2')
|
||||||
|
|
||||||
self.config(notification_driver=drivers,
|
self.config(driver=drivers,
|
||||||
notification_topics=self.topics)
|
topics=self.topics,
|
||||||
|
group='oslo_messaging_notifications')
|
||||||
|
|
||||||
transport = _FakeTransport(self.conf)
|
transport = _FakeTransport(self.conf)
|
||||||
|
|
||||||
@ -269,7 +270,8 @@ class TestLogNotifier(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
@mock.patch('oslo_utils.timeutils.utcnow')
|
@mock.patch('oslo_utils.timeutils.utcnow')
|
||||||
def test_notifier(self, mock_utcnow):
|
def test_notifier(self, mock_utcnow):
|
||||||
self.config(notification_driver=['log'])
|
self.config(driver=['log'],
|
||||||
|
group='oslo_messaging_notifications')
|
||||||
|
|
||||||
transport = _FakeTransport(self.conf)
|
transport = _FakeTransport(self.conf)
|
||||||
|
|
||||||
@ -338,7 +340,8 @@ class TestLogNotifier(test_utils.BaseTestCase):
|
|||||||
class TestRoutingNotifier(test_utils.BaseTestCase):
|
class TestRoutingNotifier(test_utils.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestRoutingNotifier, self).setUp()
|
super(TestRoutingNotifier, self).setUp()
|
||||||
self.config(notification_driver=['routing'])
|
self.config(driver=['routing'],
|
||||||
|
group='oslo_messaging_notifications')
|
||||||
|
|
||||||
transport = _FakeTransport(self.conf)
|
transport = _FakeTransport(self.conf)
|
||||||
self.notifier = oslo_messaging.Notifier(transport)
|
self.notifier = oslo_messaging.Notifier(transport)
|
||||||
@ -360,13 +363,14 @@ class TestRoutingNotifier(test_utils.BaseTestCase):
|
|||||||
self.assertTrue(self.router._should_load_plugin(ext))
|
self.assertTrue(self.router._should_load_plugin(ext))
|
||||||
|
|
||||||
def test_load_notifiers_no_config(self):
|
def test_load_notifiers_no_config(self):
|
||||||
# default routing_notifier_config=""
|
# default routing_config=""
|
||||||
self.router._load_notifiers()
|
self.router._load_notifiers()
|
||||||
self.assertEqual({}, self.router.routing_groups)
|
self.assertEqual({}, self.router.routing_groups)
|
||||||
self.assertEqual(0, len(self.router.used_drivers))
|
self.assertEqual(0, len(self.router.used_drivers))
|
||||||
|
|
||||||
def test_load_notifiers_no_extensions(self):
|
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""
|
routing_config = r""
|
||||||
config_file = mock.MagicMock()
|
config_file = mock.MagicMock()
|
||||||
config_file.return_value = routing_config
|
config_file.return_value = routing_config
|
||||||
@ -382,7 +386,8 @@ class TestRoutingNotifier(test_utils.BaseTestCase):
|
|||||||
self.assertEqual({}, self.router.routing_groups)
|
self.assertEqual({}, self.router.routing_groups)
|
||||||
|
|
||||||
def test_load_notifiers_config(self):
|
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"""
|
routing_config = r"""
|
||||||
group_1:
|
group_1:
|
||||||
rpc : foo
|
rpc : foo
|
||||||
@ -519,7 +524,8 @@ group_1:
|
|||||||
sorted(pm.map.call_args[0][6]))
|
sorted(pm.map.call_args[0][6]))
|
||||||
|
|
||||||
def test_notify_filtered(self):
|
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"""
|
routing_config = r"""
|
||||||
group_1:
|
group_1:
|
||||||
rpc:
|
rpc:
|
||||||
|
@ -283,8 +283,8 @@ def main():
|
|||||||
|
|
||||||
# oslo.config defaults
|
# oslo.config defaults
|
||||||
cfg.CONF.heartbeat_interval = 5
|
cfg.CONF.heartbeat_interval = 5
|
||||||
cfg.CONF.notification_topics = "notif"
|
cfg.CONF.oslo_messaging_notifications.topics = "notif"
|
||||||
cfg.CONF.notification_driver = "messaging"
|
cfg.CONF.oslo_messaging_notifications.driver = "messaging"
|
||||||
cfg.CONF.prog = os.path.basename(__file__)
|
cfg.CONF.prog = os.path.basename(__file__)
|
||||||
cfg.CONF.project = 'oslo.messaging'
|
cfg.CONF.project = 'oslo.messaging'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user