def test_publisher_init(self):
     with mock.patch.dict(config.conf, {"tls": self.tls_conf}):
         publisher = _session.PublisherSession()
     self.assertEqual(publisher._parameters.host, "localhost")
     self.assertEqual(publisher._parameters.port, 5672)
     self.assertEqual(publisher._parameters.virtual_host, "/")
     self.assertIsNone(publisher._parameters.ssl_options)
 def test_plain_auth(self):
     """Assert when there's no key or certfile, plain authentication is used"""
     with mock.patch.dict(config.conf, {"tls": self.tls_conf}):
         publisher = _session.PublisherSession(
             "amqps://*****:*****@rabbit.example.com/vhost")
     self.assertIsInstance(publisher._parameters.credentials,
                           credentials.PlainCredentials)
 def test_publish_init_custom_url(self):
     """Assert a custom URL can be provided to the publisher session."""
     with mock.patch.dict(config.conf, {"tls": self.tls_conf}):
         publisher = _session.PublisherSession(
             "amqps://*****:*****@rabbit.example.com/vhost")
     self.assertEqual(publisher._parameters.host, "rabbit.example.com")
     self.assertEqual(publisher._parameters.port, 5671)
     self.assertEqual(publisher._parameters.virtual_host, "vhost")
     self.assertIsNotNone(publisher._parameters.ssl_options)
 def test_external_auth(self):
     """Assert when there's both a key and certfile, external auth is used"""
     tls_conf = {
         "keyfile": os.path.join(FIXTURES_DIR, "key.pem"),
         "certfile": os.path.join(FIXTURES_DIR, "cert.pem"),
         "ca_cert": os.path.join(FIXTURES_DIR, "ca_bundle.pem"),
     }
     with mock.patch.dict(config.conf, {"tls": tls_conf}):
         publisher = _session.PublisherSession(
             "amqps://*****:*****@rabbit.example.com/vhost")
     self.assertIsInstance(publisher._parameters.credentials,
                           credentials.ExternalCredentials)
 def setUp(self):
     self.publisher = _session.PublisherSession()
     self.publisher._connection = mock.Mock()
     self.publisher._channel = mock.Mock()
     self.message = mock.Mock()
     self.message.headers = {}
     self.message.topic = "test.topic"
     self.message.body = "test body"
     self.message.schema_version = 1
     self.tls_conf = {
         'keyfile': None,
         'certfile': None,
         'ca_cert': os.path.join(FIXTURES_DIR, 'ca_bundle.pem'),
     }
 def setUp(self):
     self.publisher = _session.PublisherSession()
     self.publisher._connection = mock.Mock()
     self.publisher._channel = mock.Mock()
     self.message = mock.Mock()
     self.message._headers = {}
     self.message.topic = "test.topic"
     self.message._encoded_routing_key = b"test.topic"
     self.message._body = "test body"
     self.message._encoded_body = b'"test body"'
     self.tls_conf = {
         "keyfile": None,
         "certfile": None,
         "ca_cert": os.path.join(FIXTURES_DIR, "ca_bundle.pem"),
     }
Beispiel #7
0
 def setUp(self):
     self.publisher = _session.PublisherSession()
     self.publisher._connection = mock.Mock()
     self.publisher._channel = mock.Mock()
     if _session._pika_version < pkg_resources.parse_version("1.0.0b1"):
         self.publisher_channel_publish = self.publisher._channel.publish
     else:
         self.publisher_channel_publish = self.publisher._channel.basic_publish
     self.message = mock.Mock()
     self.message._headers = {}
     self.message.topic = "test.topic"
     self.message._encoded_routing_key = b"test.topic"
     self.message.body = "test body"
     self.message._encoded_body = b'"test body"'
     self.tls_conf = {
         "keyfile": None,
         "certfile": None,
         "ca_cert": os.path.join(FIXTURES_DIR, "ca_bundle.pem"),
     }
Beispiel #8
0
def create_queues_with_bindings(queues):
    """
    Create a queue synchronously with bindings.

    Args:
        queues (list): A list of queues to create. Any associated bindings will
            be created with them.
    """
    sesh = _session.PublisherSession()
    queue_args = {}
    if config.conf["queue_expires"]:
        queue_args["x-expires"] = config.conf["queue_expires"]
    if config.conf["queue_max_length"]:
        queue_args["x-max-length"] = config.conf["queue_max_lenth"]
    if config.conf["queue_max_size"]:
        queue_args["x-max-length-bytes"] = config.conf["queue_max_size"]

    for queue in queues:
        try:
            sesh.queue_declare(str(queue.id),
                               durable=True,
                               arguments=queue_args)
            for b in queue.topic_bindings:
                sesh.queue_bind(str(queue.id),
                                "amq.topic",
                                routing_key=b.topic,
                                arguments={})
            for b in queue.header_bindings:
                for match in b.binding_arguments():
                    sesh.queue_bind(str(queue.id),
                                    "amq.match",
                                    routing_key=None,
                                    arguments=match)
        except fml_exceptions.ConnectionException as e:
            # Probably raise something that turns into a 50...2? Service unavailable
            _log.warning("Failed to create the %r queue with bindings: %s",
                         queue.id, str(e))