How to use the amqp.exceptions.AccessRefused function in amqp

To help you get started, we’ve selected a few amqp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polyaxon / polyaxon / tests / test_checks / test_rabbitmq_check.py View on Github external
def test_broker_access_refused(self, mocked_connection):
        mocked_conn = mock.MagicMock()
        mocked_connection.return_value.__enter__.return_value = mocked_conn
        mocked_conn.connect.side_effect = AccessRefused('Access Refused')

        results = RabbitMQCheck.run()
        assert results['RABBITMQ'].is_healthy is False
        assert results['RABBITMQ'].severity == Result.ERROR
        mocked_connection.assert_called_once_with('broker_url')
github polyaxon / polyaxon / tests / test_checks / test_rabbitmq_check.py View on Github external
def test_broker_connection_upon_none_url(self, mocked_connection):
        mocked_conn = mock.MagicMock()
        mocked_connection.return_value.__enter__.return_value = mocked_conn
        mocked_conn.connect.side_effect = AccessRefused('Connection Refused')

        results = RabbitMQCheck.run()
        assert results['RABBITMQ'].is_healthy is False
        assert results['RABBITMQ'].severity == Result.ERROR
        mocked_connection.assert_called_once_with(None)
github polyaxon / polyaxon / polyaxon / checks / rabbitmq.py View on Github external
def check() -> Result:
        """Open and close the broker channel."""
        if conf.get(CELERY_BROKER_BACKEND) == 'redis':
            return Result()
        try:
            # Context to release connection
            with Connection(conf.get(CELERY_BROKER_URL)) as conn:
                conn.connect()
        except ConnectionRefusedError:
            return Result(message='Service unable to connect, "Connection was refused".',
                          severity=Result.ERROR)

        except AccessRefused:
            return Result(message='Service unable to connect, "Authentication error".',
                          severity=Result.ERROR)

        except IOError:
            return Result(message='Service has an "IOError".', severity=Result.ERROR)

        except Exception as e:
            return Result(message='Service has an "{}" error.'.format(e), severity=Result.ERROR)
        else:
            return Result()
github KristianOellegaard / django-health-check / health_check / contrib / rabbitmq / backends.py View on Github external
"""Check RabbitMQ service by opening and closing a broker channel."""
        logger.debug("Checking for a broker_url on django settings...")

        broker_url = getattr(settings, "BROKER_URL", None)

        logger.debug("Got %s as the broker_url. Connecting to rabbit...", broker_url)

        logger.debug("Attempting to connect to rabbit...")
        try:
            # conn is used as a context to release opened resources later
            with Connection(broker_url) as conn:
                conn.connect()  # exceptions may be raised upon calling connect
        except ConnectionRefusedError as e:
            self.add_error(ServiceUnavailable("Unable to connect to RabbitMQ: Connection was refused."), e)

        except AccessRefused as e:
            self.add_error(ServiceUnavailable("Unable to connect to RabbitMQ: Authentication error."), e)

        except IOError as e:
            self.add_error(ServiceUnavailable("IOError"), e)

        except BaseException as e:
            self.add_error(ServiceUnavailable("Unknown error"), e)
        else:
            logger.debug("Connection established. RabbitMQ is healthy.")