コード例 #1
0
def test_sending_rpc_call_to_nova(connection):
    class Proxy(object):
        def testmethod(self, context, foo):
            return {
                'foo': foo,
            }

    novaconn = rpc.create_connection()
    novaconn.create_consumer('test', Proxy())

    gt = eventlet.spawn(novaconn.consume)
    try:
        eventlet.sleep(0)

        with connection as newconn:
            resp = sending.send_rpc(newconn,
                                    context.get_admin_context(),
                                    exchange=flags.FLAGS.control_exchange,
                                    topic='test',
                                    method='testmethod',
                                    args={
                                        'foo': 'bar',
                                    },
                                    timeout=2)
            assert resp == {
                'foo': 'bar',
            }
    finally:
        gt.kill()
        novaconn.close()
コード例 #2
0
def test_send_rpc(get_connection):
    def response_greenthread():
        with get_connection() as conn:
            with conn.channel() as chan:
                queue = entities.get_topic_queue('test_rpc',
                                                 'test',
                                                 channel=chan)
                queue.declare()
                msg = ifirst(
                    consuming.queue_iterator(queue, no_ack=True, timeout=2))
                msgid, ctx, method, args = context.parse_message(msg.payload)
                sending.reply(conn, msgid, args)

    g = eventlet.spawn_n(response_greenthread)
    eventlet.sleep(0)

    with get_connection() as conn:
        ctx = context.get_admin_context()
        resp = sending.send_rpc(conn,
                                context=ctx,
                                exchange='test_rpc',
                                topic='test',
                                method='test_method',
                                args={
                                    'foo': 'bar',
                                },
                                timeout=3)
        #resp.ack()
        assert resp == {
            'foo': 'bar',
        }

    assert not g
    # check consumefrom has removed entry
    assert not consuming._conndrainers
コード例 #3
0
ファイル: test_sending.py プロジェクト: edwardgeorge/newrpc
def test_send_rpc(get_connection):
    def response_greenthread():
        with get_connection() as conn:
            with conn.channel() as chan:
                queue = entities.get_topic_queue('test_rpc', 'test', channel=chan)
                queue.declare()
                msg = ifirst(consuming.queue_iterator(queue, no_ack=True, timeout=2))
                msgid, ctx, method, args = context.parse_message(msg.payload)
                sending.reply(conn, msgid, args)

    g = eventlet.spawn_n(response_greenthread)
    eventlet.sleep(0)

    with get_connection() as conn:
        ctx = context.get_admin_context()
        resp = sending.send_rpc(conn,
                context=ctx,
                exchange='test_rpc',
                topic='test',
                method='test_method',
                args={'foo': 'bar', },
                timeout=3)
        #resp.ack()
        assert resp == {'foo': 'bar', }

    assert not g
    # check consumefrom has removed entry
    assert not consuming._conndrainers
コード例 #4
0
ファイル: nova.py プロジェクト: edwardgeorge/newrpc
def fanout_cast(connection, context, topic, msg, options=None):
    return sending.send_rpc(connection,
        context=context,
        exchange=None,
        topic=topic,
        method=msg['method'],
        args=msg['args'],
        fanout=True)
コード例 #5
0
ファイル: test_service.py プロジェクト: edwardgeorge/newrpc
def test_exceptions(connection, get_connection):
    class Controller(object):
        def test_method(self, context, **kwargs):
            raise KeyError("foo")

    srv = service.Service(Controller, connection=connection, exchange="testrpc", topic="test")
    srv.start()
    eventlet.sleep(0)

    try:
        ctx = context.get_admin_context()
        with get_connection() as conn:
            with pytest.raises(exceptions.RemoteError):
                sending.send_rpc(conn, ctx, "testrpc", "test", "test_method", args={})
    finally:
        srv.kill()
        connection.release()
コード例 #6
0
ファイル: nova.py プロジェクト: edwardgeorge/newrpc
def fanout_cast(connection, context, topic, msg, options=None):
    return sending.send_rpc(connection,
                            context=context,
                            exchange=None,
                            topic=topic,
                            method=msg['method'],
                            args=msg['args'],
                            fanout=True)
コード例 #7
0
ファイル: nova.py プロジェクト: edwardgeorge/newrpc
def cast(connection, context, topic, msg, options=None):
    exchange = _get_exchange(options)
    return sending.send_rpc(connection,
        context=context,
        exchange=exchange,
        topic=topic,
        method=msg['method'],
        args=msg['args'],
        noreply=True)
コード例 #8
0
ファイル: nova.py プロジェクト: edwardgeorge/newrpc
def cast(connection, context, topic, msg, options=None):
    exchange = _get_exchange(options)
    return sending.send_rpc(connection,
                            context=context,
                            exchange=exchange,
                            topic=topic,
                            method=msg['method'],
                            args=msg['args'],
                            noreply=True)
コード例 #9
0
ファイル: nova.py プロジェクト: edwardgeorge/newrpc
def call(connection, context, topic, msg,
        timeout=DEFAULT_RPC_TIMEOUT, options=None):
    exchange = _get_exchange(options)
    return sending.send_rpc(connection,
        context=context,
        exchange=exchange,
        topic=topic,
        method=msg['method'],
        args=msg['args'],
        timeout=timeout)
コード例 #10
0
def test_exceptions(connection, get_connection):
    class Controller(object):
        def test_method(self, context, **kwargs):
            raise KeyError('foo')

    srv = service.Service(Controller,
            connection=connection,
            exchange='testrpc', topic='test', )
    srv.start()
    eventlet.sleep(0)

    try:
        ctx = context.get_admin_context()
        with get_connection() as conn:
            with pytest.raises(exceptions.RemoteError):
                sending.send_rpc(conn, ctx,
                        'testrpc', 'test', 'test_method',
                        args={})
    finally:
        srv.kill()
        connection.release()
コード例 #11
0
ファイル: nova.py プロジェクト: edwardgeorge/newrpc
def call(connection,
         context,
         topic,
         msg,
         timeout=DEFAULT_RPC_TIMEOUT,
         options=None):
    exchange = _get_exchange(options)
    return sending.send_rpc(connection,
                            context=context,
                            exchange=exchange,
                            topic=topic,
                            method=msg['method'],
                            args=msg['args'],
                            timeout=timeout)
コード例 #12
0
def test_raising_from_error_in_nova(connection):
    class Proxy(object):
        def testmethod(self, context, **kwargs):
            raise Exception('foo')

    novaconn = rpc.create_connection()
    novaconn.create_consumer('test', Proxy())

    gt = eventlet.spawn(novaconn.consume)
    try:
        eventlet.sleep(0)

        with connection as newconn:
            with pytest.raises(exceptions.RemoteError):
                sending.send_rpc(newconn,
                        context.get_admin_context(),
                        exchange=flags.FLAGS.control_exchange,
                        topic='test',
                        method='testmethod',
                        args={},
                        timeout=2)
    finally:
        gt.kill()
        novaconn.close()
コード例 #13
0
def test_raising_from_error_in_nova(connection):
    class Proxy(object):
        def testmethod(self, context, **kwargs):
            raise Exception('foo')

    novaconn = rpc.create_connection()
    novaconn.create_consumer('test', Proxy())

    gt = eventlet.spawn(novaconn.consume)
    try:
        eventlet.sleep(0)

        with connection as newconn:
            with pytest.raises(exceptions.RemoteError):
                sending.send_rpc(newconn,
                                 context.get_admin_context(),
                                 exchange=flags.FLAGS.control_exchange,
                                 topic='test',
                                 method='testmethod',
                                 args={},
                                 timeout=2)
    finally:
        gt.kill()
        novaconn.close()
コード例 #14
0
ファイル: test_service.py プロジェクト: edwardgeorge/newrpc
def test_service(connection, get_connection):
    m = mock.Mock()
    m().test_method.side_effect = lambda context, **kwargs: kwargs

    srv = service.Service(m, connection=connection, exchange="testrpc", topic="test")
    srv.start()
    eventlet.sleep(0)

    try:
        ctx = context.get_admin_context()
        with get_connection() as conn:
            ret = sending.send_rpc(conn, ctx, "testrpc", "test", "test_method", args={"foo": "bar"}, timeout=3)
            assert m().test_method.called
            assert ret == {"foo": "bar"}
    finally:
        srv.kill()
        connection.release()
コード例 #15
0
def test_service(connection, get_connection):
    m = mock.Mock()
    m().test_method.side_effect = lambda context, **kwargs: kwargs

    srv = service.Service(m, connection=connection,
        exchange='testrpc', topic='test', )
    srv.start()
    eventlet.sleep(0)

    try:
        ctx = context.get_admin_context()
        with get_connection() as conn:
            ret = sending.send_rpc(conn, ctx,
                'testrpc', 'test', 'test_method', args={'foo': 'bar', },
                timeout=3)
            assert m().test_method.called
            assert ret == {'foo': 'bar', }
    finally:
        srv.kill()
        connection.release()
コード例 #16
0
def test_sending_rpc_call_to_nova(connection):
    class Proxy(object):
        def testmethod(self, context, foo):
            return {'foo': foo, }

    novaconn = rpc.create_connection()
    novaconn.create_consumer('test', Proxy())

    gt = eventlet.spawn(novaconn.consume)
    try:
        eventlet.sleep(0)

        with connection as newconn:
            resp = sending.send_rpc(newconn,
                    context.get_admin_context(),
                    exchange=flags.FLAGS.control_exchange,
                    topic='test',
                    method='testmethod',
                    args={'foo': 'bar', },
                    timeout=2)
            assert resp == {'foo': 'bar', }
    finally:
        gt.kill()
        novaconn.close()