Skip to content

Commit

Permalink
Merge pull request #326 from mattbennett/fix-for-rabbit-3.6.0
Browse files Browse the repository at this point in the history
rabbitmq>=3.6.0 explicitly raises NotAllowed if vhost doesn't exist
  • Loading branch information
mattbennett committed May 29, 2016
2 parents c378bc5 + 9186996 commit 68e6268
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions nameko/amqp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from __future__ import absolute_import

import amqp
import six
from amqp.exceptions import NotAllowed
from kombu import Connection
from kombu.transport.pyamqp import Transport
import six

BAD_CREDENTIALS = (
'Error connecting to broker, probably caused by invalid credentials'
)
BAD_VHOST = (
'Error connecting to broker, probably caused by using an invalid '
'or unauthorized vhost'
)


class ConnectionTester(amqp.Connection):
Expand All @@ -18,15 +27,11 @@ def __init__(self, *args, **kwargs):
if not hasattr(self, '_wait_tune_ok'):
raise
elif self._wait_tune_ok:
six.raise_from(IOError(
'Error connecting to broker, probably caused by invalid'
' credentials'
), exc)
else:
six.raise_from(IOError(
'Error connecting to broker, probably caused by using an'
' invalid or unauthorized vhost'
), exc)
six.raise_from(IOError(BAD_CREDENTIALS), exc)
else: # pragma: no cover (rabbitmq >= 3.6.0)
six.raise_from(IOError(BAD_VHOST), exc)
except NotAllowed as exc: # pragma: no cover (rabbitmq < 3.6.0)
six.raise_from(IOError(BAD_VHOST), exc)


class TestTransport(Transport):
Expand Down

0 comments on commit 68e6268

Please sign in to comment.