diff --git a/glance/notifier.py b/glance/notifier.py index d14e49d66a..1eaadbf94d 100644 --- a/glance/notifier.py +++ b/glance/notifier.py @@ -77,10 +77,20 @@ class Notifier(object): publisher_id = CONF.default_publisher_id - # NOTE(flaper87): Assume the user has configured - # the transport url. - self._transport = messaging.get_transport(CONF, - aliases=_ALIASES) + try: + # NOTE(flaper87): Assume the user has configured + # the transport url. + self._transport = messaging.get_transport(CONF, + aliases=_ALIASES) + except messaging.DriverLoadFailure: + # NOTE(flaper87): Catch driver load failures and re-raise + # them *just* if the `transport_url` option was set. This + # step is intended to keep backwards compatibility and avoid + # weird behaviors (like exceptions on missing dependencies) + # when the old notifier options are used. + if CONF.transport_url is not None: + with excutils.save_and_reraise_exception(): + LOG.exception(_('Error loading the notifier')) # NOTE(flaper87): This needs to be checked # here because the `get_transport` call diff --git a/glance/tests/unit/test_notifier.py b/glance/tests/unit/test_notifier.py index da7566202f..0b2a9252a4 100644 --- a/glance/tests/unit/test_notifier.py +++ b/glance/tests/unit/test_notifier.py @@ -103,11 +103,12 @@ class TestNotifier(utils.BaseTestCase): self.assertEqual(str(nfier._transport._driver._url), 'qpid:///') - def test_custom_strategy(self): - st = "glance.notifier.notify_noop.NoopStrategy" - self.config(notifier_strategy=st) - #NOTE(bcwaldon): the fact that Notifier is instantiated means we're ok - notifier.Notifier() + def test_notifier_strategy(self): + self.config(notifier_strategy='qpid') + nfier = notifier.Notifier() + self.assertIsNotNone(nfier._transport) + self.assertEqual(str(nfier._transport._driver._url), + 'qpid:///') def test_transport_url(self): transport_url = "qpid://superhost:5672/"