Fix parsing of AMQP configuration

The deprecated notifier_strategy option is always used even if it is set
to its default value and the new notification_driver option is
explicitly set.

This change makes the notification_driver option work.

Change-Id: Icc2a063a828472132d2e2eda7f12e265db990ea1
Closes-Bug: #1271724
This commit is contained in:
Gauvain Pocentek 2014-02-14 14:30:33 +01:00
parent e98576efae
commit c4ca7a0a00
2 changed files with 22 additions and 5 deletions

View File

@ -64,16 +64,20 @@ class Notifier(object):
def __init__(self, strategy=None):
_driver = None
_strategy = strategy
if CONF.notifier_strategy != 'default':
msg = _("notifier_strategy was deprecated in "
"favor of `notification_driver`")
warnings.warn(msg, DeprecationWarning)
# NOTE(flaper87): Use this to keep backwards
# compatibility. We'll try to get an oslo.messaging
# driver from the specified strategy.
_strategy = strategy or CONF.notifier_strategy
_driver = _STRATEGY_ALIASES.get(_strategy)
# NOTE(flaper87): Use this to keep backwards
# compatibility. We'll try to get an oslo.messaging
# driver from the specified strategy.
_strategy = strategy or CONF.notifier_strategy
_driver = _STRATEGY_ALIASES.get(_strategy)
publisher_id = CONF.default_publisher_id
# NOTE(flaper87): Assume the user has configured

View File

@ -114,6 +114,19 @@ class TestNotifier(utils.BaseTestCase):
self.assertEqual(str(notify._transport._driver._url),
transport_url)
def test_notification_driver_option(self):
self.config(rpc_backend='qpid')
self.config(notification_driver='messaging')
self.config(notifier_strategy='rabbit')
notify = notifier.Notifier()
self.assertEqual(str(notify._transport._driver._url),
'rabbit:///')
self.config(notifier_strategy='default')
notify = notifier.Notifier()
self.assertEqual(str(notify._transport._driver._url),
'qpid:///')
class TestImageNotifications(utils.BaseTestCase):
"""Test Image Notifications work"""