From a4a3b18f89dae5aa4e08797f1ee5ee4a2dcfea67 Mon Sep 17 00:00:00 2001 From: OpenStack Proposal Bot Date: Sun, 25 Sep 2016 10:03:02 +0000 Subject: [PATCH] Remove enable_notifications option In the oslo.messaging to enable or disable notifications uses the 'notification_driver' option. This approach used in many Openstack projects. By default the option is empty, that means no notification will be send. To enable notification needs to set the value with one of supported drivers (e.g. messagingv2). Change-Id: Ifdc38d56a4fa3a1755fff72d4bef88937c0170ed --- devstack/plugin.sh | 1 - ...le_notifications_opt-4c0d46e8e79eb06f.yaml | 6 +++++ sahara/tests/unit/base.py | 3 ++- .../unit/utils/notification/test_sender.py | 2 -- sahara/tests/unit/utils/test_rpc.py | 21 +----------------- sahara/utils/notification/sender.py | 11 +--------- sahara/utils/rpc.py | 22 ++++--------------- 7 files changed, 14 insertions(+), 52 deletions(-) create mode 100644 releasenotes/notes/remove_enable_notifications_opt-4c0d46e8e79eb06f.yaml diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 787dc59332..d88f0513ca 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -81,7 +81,6 @@ function configure_sahara { # Set configuration to send notifications if is_service_enabled ceilometer; then - iniset $SAHARA_CONF_FILE oslo_messaging_notifications enable "true" iniset $SAHARA_CONF_FILE oslo_messaging_notifications driver "messaging" fi diff --git a/releasenotes/notes/remove_enable_notifications_opt-4c0d46e8e79eb06f.yaml b/releasenotes/notes/remove_enable_notifications_opt-4c0d46e8e79eb06f.yaml new file mode 100644 index 0000000000..b7605c4501 --- /dev/null +++ b/releasenotes/notes/remove_enable_notifications_opt-4c0d46e8e79eb06f.yaml @@ -0,0 +1,6 @@ +--- +deprecations: + - The 'enable' option of the 'oslo_messaging_notifications' section + has been removed. To enable notifications now please specify the + 'driver' option in the same section. + diff --git a/sahara/tests/unit/base.py b/sahara/tests/unit/base.py index 8099a8e3da..84e8316015 100644 --- a/sahara/tests/unit/base.py +++ b/sahara/tests/unit/base.py @@ -19,14 +19,15 @@ from oslotest import base from sahara import context from sahara.db import api as db_api from sahara import main +from sahara.utils import rpc class SaharaTestCase(base.BaseTestCase): def setUp(self): super(SaharaTestCase, self).setUp() - self.setup_context() + rpc.setup('all-in-one') def setup_context(self, username="test_user", tenant_id="tenant_1", auth_token="test_auth_token", tenant_name='test_tenant', diff --git a/sahara/tests/unit/utils/notification/test_sender.py b/sahara/tests/unit/utils/notification/test_sender.py index 9e049b4123..5f68aea353 100644 --- a/sahara/tests/unit/utils/notification/test_sender.py +++ b/sahara/tests/unit/utils/notification/test_sender.py @@ -27,8 +27,6 @@ class NotificationTest(base.SaharaTestCase): def info(self, *args): self.call = args - self.override_config("enable", True, - group='oslo_messaging_notifications') notifier = FakeNotifier() mock_notify.return_value = notifier ctx = context.ctx() diff --git a/sahara/tests/unit/utils/test_rpc.py b/sahara/tests/unit/utils/test_rpc.py index 846e645329..4cb6c8acee 100644 --- a/sahara/tests/unit/utils/test_rpc.py +++ b/sahara/tests/unit/utils/test_rpc.py @@ -56,10 +56,8 @@ class TestMessagingSetup(base.SaharaTestCase): super(TestMessagingSetup, self).tearDown() def test_set_defaults(self): - self.override_config('enable', True, - group='oslo_messaging_notifications') - messaging.setup('distributed') + self.assertIsNotNone(messaging.MESSAGING_TRANSPORT) self.assertIsNotNone(messaging.NOTIFICATION_TRANSPORT) self.assertIsNotNone(messaging.NOTIFIER) @@ -77,8 +75,6 @@ class TestMessagingSetup(base.SaharaTestCase): self.assertEqual(1, self.notifier_init.call_count) def test_fallback(self): - self.override_config('enable', True, - group='oslo_messaging_notifications') self.get_notify_transport.side_effect = ValueError() messaging.setup('distributed') @@ -100,22 +96,7 @@ class TestMessagingSetup(base.SaharaTestCase): self.get_notify_transport.call_args_list) self.assertEqual(1, self.notifier_init.call_count) - def test_no_messaging(self): - messaging.setup('all-in-one') - - self.assertEqual(0, self.get_notify_transport.call_count) - self.assertEqual(0, self.get_transport.call_count) - def test_only_notifications(self): - self.override_config('enable', True, - group='oslo_messaging_notifications') - messaging.setup('all-in-one') self.assertEqual(0, self.get_transport.call_count) self.assertEqual(1, self.get_notify_transport.call_count) - - def test_only_service_messaging(self): - messaging.setup('distributed') - - self.assertEqual(1, self.get_transport.call_count) - self.assertEqual(0, self.get_notify_transport.call_count) diff --git a/sahara/utils/notification/sender.py b/sahara/utils/notification/sender.py index 61bdebd590..9fa5a9496c 100644 --- a/sahara/utils/notification/sender.py +++ b/sahara/utils/notification/sender.py @@ -33,13 +33,7 @@ notifier_opts = [ help='Notification level for outgoing notifications'), cfg.StrOpt('publisher_id', deprecated_name='notification_publisher_id', - deprecated_group='DEFAULT', - help='Notification publisher_id for outgoing notifications'), - cfg.BoolOpt('enable', - deprecated_name='enable_notifications', - deprecated_group='DEFAULT', - default=False, - help='Enables sending notifications to Ceilometer') + deprecated_group='DEFAULT') ] notifier_opts_group = 'oslo_messaging_notifications' @@ -56,9 +50,6 @@ def _get_publisher(): def _notify(event_type, body): - if not cfg.CONF.oslo_messaging_notifications.enable: - return - LOG.debug("Notification about cluster is going to be sent. Notification " "type={type}".format(type=event_type)) ctx = context.ctx() diff --git a/sahara/utils/rpc.py b/sahara/utils/rpc.py index 46cb7fda52..7cbc14abbb 100644 --- a/sahara/utils/rpc.py +++ b/sahara/utils/rpc.py @@ -21,7 +21,6 @@ from oslo_serialization import jsonutils from sahara import context from sahara.i18n import _LE -from sahara.i18n import _LI MESSAGING_TRANSPORT = None @@ -105,37 +104,24 @@ def setup_service_messaging(): def setup_notifications(): global NOTIFICATION_TRANSPORT, NOTIFIER, MESSAGING_TRANSPORT - if not cfg.CONF.oslo_messaging_notifications.enable: - LOG.info(_LI("Notifications disabled")) - return - try: - NOTIFICATION_TRANSPORT = messaging.get_notification_transport( - cfg.CONF, aliases=_ALIASES) + NOTIFICATION_TRANSPORT = \ + messaging.get_notification_transport(cfg.CONF, aliases=_ALIASES) except Exception: LOG.error(_LE("Unable to setup notification transport. Reusing " "service transport for that.")) - setup_service_messaging() - NOTIFICATION_TRANSPORT = MESSAGING_TRANSPORT serializer = ContextSerializer(JsonPayloadSerializer()) - NOTIFIER = messaging.Notifier( - NOTIFICATION_TRANSPORT, serializer=serializer) - LOG.info(_LI("Notifications enabled")) + NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT, + serializer=serializer) def setup(service_name): """Initialise the oslo_messaging layer.""" - global MESSAGING_TRANSPORT, NOTIFICATION_TRANSPORT, NOTIFIER - if (service_name == 'all-in-one' and - not cfg.CONF.oslo_messaging_notifications.enable): - LOG.info(_LI("Notifications disabled")) - return messaging.set_transport_defaults('sahara') - setup_notifications() if service_name != 'all-in-one': setup_service_messaging()