Catch loading failures if transport_url is not set
The current implementation always tries to get a transport from
oslo.messaging assuming the transport_url option has been set. This is
done to keep backwards compatibility. However, since the default
`rpc_backend` is rabbit, it'll always try to load such driver. The
problem raises when `kombu` is not installed and the `notifier_strategy`
is set to qpid. This will make glance-api fail because it'll try to load
the rabbit driver *before* loading the qpid one.
This patch puts the first load attempt in a try / except block. The
error caught (if any) will be re-raised *just* if transport_url has been
configured, otherwise it'll move forward and try to load the notifier
driver using the old configuration options.
The patch also removes an obsolete test.
Change-Id: I00e653704463ea8245e2960050e0d5e6839f278a
Closes-bug: #1302661
(cherry picked from commit 164d1ab46f
)
This commit is contained in:
parent
5fa3d2ef95
commit
69fdd19cf1
|
@ -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
|
||||
|
|
|
@ -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/"
|
||||
|
|
Loading…
Reference in New Issue