Ejemplo n.º 1
0
    def test_mandatory_call(self):
        if not self.rpc_url.startswith("rabbit://"):
            self.skipTest("backend does not support call monitoring")

        transport = self.useFixture(
            utils.RPCTransportFixture(self.conf, self.rpc_url))
        target = oslo_messaging.Target(topic='topic_' + str(uuid.uuid4()),
                                       server='server_' + str(uuid.uuid4()))

        # test for mandatory flag using transport-options, see:
        # https://blueprints.launchpad.net/oslo.messaging/+spec/transport-options
        # first test with `at_least_once=False` raises a "MessagingTimeout"
        # error since there is no control if the queue actually exists.
        # (Default behavior)
        options = oslo_messaging.TransportOptions(at_least_once=False)
        client1 = utils.ClientStub(transport.transport,
                                   target,
                                   cast=False,
                                   timeout=1,
                                   transport_options=options)

        self.assertRaises(oslo_messaging.MessagingTimeout, client1.delay)

        # second test with `at_least_once=True` raises a "MessageUndeliverable"
        # caused by mandatory flag.
        # the MessageUndeliverable error is raised immediately without waiting
        # any timeout
        options2 = oslo_messaging.TransportOptions(at_least_once=True)
        client2 = utils.ClientStub(transport.transport,
                                   target,
                                   cast=False,
                                   timeout=60,
                                   transport_options=options2)

        self.assertRaises(oslo_messaging.MessageUndeliverable, client2.delay)
Ejemplo n.º 2
0
    def test_cast_call_with_transport_options(self):
        self.config(rpc_response_timeout=None)

        transport = oslo_messaging.get_rpc_transport(self.conf, url='fake:')

        transport_options = oslo_messaging.TransportOptions(at_least_once=True)
        client = oslo_messaging.RPCClient(transport,
                                          oslo_messaging.Target(),
                                          transport_options=transport_options)

        transport._send = mock.Mock()

        msg = dict(method='foo', args=self.args)
        kwargs = {'retry': None, 'transport_options': transport_options}
        if self.call:
            kwargs['wait_for_reply'] = True
            kwargs['timeout'] = None
            kwargs['call_monitor_timeout'] = None

        method = client.call if self.call else client.cast
        method(self.ctxt, 'foo', **self.args)

        self.assertTrue(transport_options.at_least_once)
        transport._send.assert_called_once_with(oslo_messaging.Target(),
                                                self.ctxt, msg, **kwargs)
Ejemplo n.º 3
0
def start_client(at_least_once):
    oslo_messaging.set_transport_defaults(transport_default)
    transport = oslo_messaging.get_transport(cfg.CONF)

    # in this way you can simulate the mandatory flag error
    # inside the function `call`
    # change:   options = oslo_messaging.TransportOptions(at_least_once=True)
    # to:   options = oslo_messaging.TransportOptions(at_least_once=False)
    # in this way you will see the different behaviour
    # replace 'my_not_existing_topic' value with to 'my_topic' to make it
    # working.

    target = oslo_messaging.Target(topic="my_not_existing_topic",
                                   version='2.0',
                                   namespace='test')
    # with at_least_once=False ( current default value) you will see the
    # timeout error.
    # with at_least_once=True ( so mandatory flag) you will see the excpetion raised.
    # that it is faster to raise :))!

    options = oslo_messaging.TransportOptions(at_least_once=at_least_once)
    client = oslo_messaging.RPCClient(transport,
                                      target,
                                      transport_options=options)

    for i in range(0, 1):
        time.sleep(0.1)

        try:
            r = client.call({},
                            'foo',
                            id_value=str(i),
                            test_value="ciao",
                            timeout=2)
            print("hello" + r + " - number: " + str(number))
        except oslo_messaging.exceptions.MessageUndeliverable as e:
            ### Raised when at_least_once is True, and it is reaised immediately
            prRed(
                "MessageUndeliverable error, RabbitMQ Exception: %s, routing_key: %s message: %s exchange: %s: \n"
                % (e.exception, e.routing_key, e.message.body, e.exchange))

        except oslo_messaging.exceptions.MessagingTimeout as et:
            ### Raised when at_least_once is False, you have to wait the timeout
            prRed("MessagingTimeout error: %s: \n" % (str(et)))
Ejemplo n.º 4
0
def call(transport, target, number):

    # with at_least_once=False ( current default value) you will see the
    # timeout error.
    # with at_least_once=True ( so mandatory flag) you will see the excpetion raised.
    # that it is faster to raise :))!

    options = oslo_messaging.TransportOptions(at_least_once=True)
    print("starting client")

    client = oslo_messaging.RPCClient(transport,
                                      target,
                                      transport_options=options)

    for i in range(0, 10):
        time.sleep(0.2)
        try:
            r = client.call({}, 'foo', id_value=str(i), test_value="ciao")
            print("hello" + r + " - number: " + str(number))
        except oslo_messaging.exceptions.MessageUndeliverable as e:
            print(
                "MessageUndeliverable error, RabbitMQ Exception: %s, routing_key: %s message: %s exchange: %s:"
                % (e.exception, e.routing_key, e.message.body, e.exchange))