Exemplo n.º 1
0
    def test_grandchild_targeted_message(self):
        target_cell = 'api-cell!child-cell2!grandchild-cell1'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        call_info = {}

        def our_fake_method(message, **kwargs):
            call_info['context'] = message.ctxt
            call_info['routing_path'] = message.routing_path
            call_info['kwargs'] = kwargs

        fakes.stub_tgt_method(self, 'grandchild-cell1', 'our_fake_method',
                our_fake_method)

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                  self.ctxt, method,
                                                  method_kwargs, direction,
                                                  target_cell)
        tgt_message.process()

        self.assertEqual(self.ctxt, call_info['context'])
        self.assertEqual(method_kwargs, call_info['kwargs'])
        self.assertEqual(target_cell, call_info['routing_path'])
Exemplo n.º 2
0
    def test_send_message_to_cell_cast(self):
        msg_runner = fakes.get_message_runner('api-cell')
        cell_state = fakes.get_cell_state('api-cell', 'child-cell2')
        message = messaging._TargetedMessage(msg_runner,
                self.ctxt, 'fake', {}, 'down', cell_state, fanout=False)

        expected_server_params = {'hostname': 'rpc_host2',
                                  'password': '******',
                                  'port': 3092,
                                  'username': '******',
                                  'virtual_host': 'rpc_vhost2'}
        expected_url = ('rabbit://%(username)s:%(password)s@'
                        '%(hostname)s:%(port)d/%(virtual_host)s' %
                        expected_server_params)

        def check_transport_url(cell_state):
            return cell_state.db_info['transport_url'] == expected_url

        rpcapi = self.driver.intercell_rpcapi
        rpcclient = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(rpcapi, '_get_client')
        rpcapi._get_client(
            mox.Func(check_transport_url),
            'cells.intercell.targeted').AndReturn(rpcclient)

        rpcclient.cast(mox.IgnoreArg(), 'process_message',
                       message=message.to_json())

        self.mox.ReplayAll()

        self.driver.send_message_to_cell(cell_state, message)
Exemplo n.º 3
0
    def test_grandchild_targeted_message_with_response(self):
        target_cell = 'api-cell!child-cell2!grandchild-cell1'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        call_info = {}

        def our_fake_method(message, **kwargs):
            call_info['context'] = message.ctxt
            call_info['routing_path'] = message.routing_path
            call_info['kwargs'] = kwargs
            return 'our_fake_response'

        fakes.stub_tgt_method(self, 'grandchild-cell1', 'our_fake_method',
                our_fake_method)

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                  self.ctxt, method,
                                                  method_kwargs, direction,
                                                  target_cell,
                                                  need_response=True)
        response = tgt_message.process()

        self.assertEqual(self.ctxt, call_info['context'])
        self.assertEqual(method_kwargs, call_info['kwargs'])
        self.assertEqual(target_cell, call_info['routing_path'])
        self.assertFalse(response.failure)
        self.assertTrue(response.value_or_raise(), 'our_fake_response')
    def test_send_message_to_cell_fanout_cast(self):
        msg_runner = fakes.get_message_runner('api-cell')
        cell_state = fakes.get_cell_state('api-cell', 'child-cell2')
        message = messaging._TargetedMessage(msg_runner,
                self.ctxt, 'fake', {}, 'down', cell_state, fanout=True)

        expected_server_params = {'hostname': 'rpc_host2',
                                  'password': '******',
                                  'port': 3092,
                                  'username': '******',
                                  'virtual_host': 'rpc_vhost2'}
        expected_url = ('rabbit://%(username)s:%(password)s@'
                        '%(hostname)s:%(port)d/%(virtual_host)s' %
                        expected_server_params)

        rpcapi = self.driver.intercell_rpcapi
        rpcclient = mock.Mock()

        with mock.patch.object(rpcapi, '_get_client') as m_get_client:
            m_get_client.return_value = rpcclient

            rpcclient.return_value = rpcclient
            rpcclient.prepare.return_value = rpcclient

            self.driver.send_message_to_cell(cell_state, message)
            m_get_client.assert_called_with(cell_state,
                                            'cells.intercell.targeted')
            self.assertEqual(expected_url,
                             cell_state.db_info['transport_url'])
            rpcclient.prepare.assert_called_with(fanout=True)
            rpcclient.cast.assert_called_with(mock.ANY,
                                              'process_message',
                                              message=message.to_json())
Exemplo n.º 5
0
 def test_targeted_message(self):
     self.flags(max_hop_count=99, group='cells')
     target_cell = 'api-cell!child-cell2!grandchild-cell1'
     method = 'fake_method'
     method_kwargs = dict(arg1=1, arg2=2)
     direction = 'down'
     tgt_message = messaging._TargetedMessage(self.msg_runner,
                                               self.ctxt, method,
                                               method_kwargs, direction,
                                               target_cell)
     self.assertEqual(self.ctxt, tgt_message.ctxt)
     self.assertEqual(method, tgt_message.method_name)
     self.assertEqual(method_kwargs, tgt_message.method_kwargs)
     self.assertEqual(direction, tgt_message.direction)
     self.assertEqual(target_cell, target_cell)
     self.assertFalse(tgt_message.fanout)
     self.assertFalse(tgt_message.need_response)
     self.assertEqual(self.our_name, tgt_message.routing_path)
     self.assertEqual(1, tgt_message.hop_count)
     self.assertEqual(99, tgt_message.max_hop_count)
     self.assertFalse(tgt_message.is_broadcast)
     # Correct next hop?
     next_hop = tgt_message._get_next_hop()
     child_cell = self.state_manager.get_child_cell('child-cell2')
     self.assertEqual(child_cell, next_hop)
Exemplo n.º 6
0
 def test_create_targeted_message_with_response(self):
     self.flags(max_hop_count=99, group='cells')
     our_name = 'child-cell1'
     target_cell = 'child-cell1!api-cell'
     msg_runner = fakes.get_message_runner(our_name)
     method = 'fake_method'
     method_kwargs = dict(arg1=1, arg2=2)
     direction = 'up'
     tgt_message = messaging._TargetedMessage(msg_runner,
                                               self.ctxt, method,
                                               method_kwargs, direction,
                                               target_cell,
                                               need_response=True)
     self.assertEqual(self.ctxt, tgt_message.ctxt)
     self.assertEqual(method, tgt_message.method_name)
     self.assertEqual(method_kwargs, tgt_message.method_kwargs)
     self.assertEqual(direction, tgt_message.direction)
     self.assertEqual(target_cell, target_cell)
     self.assertFalse(tgt_message.fanout)
     self.assertTrue(tgt_message.need_response)
     self.assertEqual(our_name, tgt_message.routing_path)
     self.assertEqual(1, tgt_message.hop_count)
     self.assertEqual(99, tgt_message.max_hop_count)
     self.assertFalse(tgt_message.is_broadcast)
     # Correct next hop?
     next_hop = tgt_message._get_next_hop()
     parent_cell = msg_runner.state_manager.get_parent_cell('api-cell')
     self.assertEqual(parent_cell, next_hop)
Exemplo n.º 7
0
    def test_grandchild_targeted_message_with_response(self):
        target_cell = 'api-cell!child-cell2!grandchild-cell1'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        call_info = {}

        def our_fake_method(message, **kwargs):
            call_info['context'] = message.ctxt
            call_info['routing_path'] = message.routing_path
            call_info['kwargs'] = kwargs
            return 'our_fake_response'

        fakes.stub_tgt_method(self, 'grandchild-cell1', 'our_fake_method',
                              our_fake_method)

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                 self.ctxt,
                                                 method,
                                                 method_kwargs,
                                                 direction,
                                                 target_cell,
                                                 need_response=True)
        response = tgt_message.process()

        self.assertEqual(self.ctxt, call_info['context'])
        self.assertEqual(method_kwargs, call_info['kwargs'])
        self.assertEqual(target_cell, call_info['routing_path'])
        self.assertFalse(response.failure)
        self.assertTrue(response.value_or_raise(), 'our_fake_response')
Exemplo n.º 8
0
    def test_grandchild_targeted_message(self):
        target_cell = 'api-cell!child-cell2!grandchild-cell1'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        call_info = {}

        def our_fake_method(message, **kwargs):
            call_info['context'] = message.ctxt
            call_info['routing_path'] = message.routing_path
            call_info['kwargs'] = kwargs

        fakes.stub_tgt_method(self, 'grandchild-cell1', 'our_fake_method',
                our_fake_method)

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                  self.ctxt, method,
                                                  method_kwargs, direction,
                                                  target_cell)
        tgt_message.process()

        self.assertEqual(self.ctxt, call_info['context'])
        self.assertEqual(method_kwargs, call_info['kwargs'])
        self.assertEqual(target_cell, call_info['routing_path'])
Exemplo n.º 9
0
 def test_create_targeted_message_with_response(self):
     self.flags(max_hop_count=99, group='cells')
     our_name = 'child-cell1'
     target_cell = 'child-cell1!api-cell'
     msg_runner = fakes.get_message_runner(our_name)
     method = 'fake_method'
     method_kwargs = dict(arg1=1, arg2=2)
     direction = 'up'
     tgt_message = messaging._TargetedMessage(msg_runner,
                                              self.ctxt,
                                              method,
                                              method_kwargs,
                                              direction,
                                              target_cell,
                                              need_response=True)
     self.assertEqual(self.ctxt, tgt_message.ctxt)
     self.assertEqual(method, tgt_message.method_name)
     self.assertEqual(method_kwargs, tgt_message.method_kwargs)
     self.assertEqual(direction, tgt_message.direction)
     self.assertEqual(target_cell, target_cell)
     self.assertFalse(tgt_message.fanout)
     self.assertTrue(tgt_message.need_response)
     self.assertEqual(our_name, tgt_message.routing_path)
     self.assertEqual(1, tgt_message.hop_count)
     self.assertEqual(99, tgt_message.max_hop_count)
     self.assertFalse(tgt_message.is_broadcast)
     # Correct next hop?
     next_hop = tgt_message._get_next_hop()
     parent_cell = msg_runner.state_manager.get_parent_cell('api-cell')
     self.assertEqual(parent_cell, next_hop)
Exemplo n.º 10
0
    def test_send_message_to_cell_cast(self):
        msg_runner = fakes.get_message_runner("api-cell")
        cell_state = fakes.get_cell_state("api-cell", "child-cell2")
        message = messaging._TargetedMessage(msg_runner, self.ctxt, "fake", {}, "down", cell_state, fanout=False)

        expected_server_params = {
            "hostname": "rpc_host2",
            "password": "******",
            "port": 3092,
            "username": "******",
            "virtual_host": "rpc_vhost2",
        }
        expected_url = (
            "rabbit://%(username)s:%(password)s@" "%(hostname)s:%(port)d/%(virtual_host)s" % expected_server_params
        )

        def check_transport_url(cell_state):
            return cell_state.db_info["transport_url"] == expected_url

        rpcapi = self.driver.intercell_rpcapi
        rpcclient = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(rpcapi, "_get_client")
        rpcapi._get_client(mox.Func(check_transport_url), "cells.intercell.targeted").AndReturn(rpcclient)

        rpcclient.cast(mox.IgnoreArg(), "process_message", message=message.to_json())

        self.mox.ReplayAll()

        self.driver.send_message_to_cell(cell_state, message)
Exemplo n.º 11
0
 def test_targeted_message(self):
     self.flags(max_hop_count=99, group='cells')
     target_cell = 'api-cell!child-cell2!grandchild-cell1'
     method = 'fake_method'
     method_kwargs = dict(arg1=1, arg2=2)
     direction = 'down'
     tgt_message = messaging._TargetedMessage(self.msg_runner,
                                               self.ctxt, method,
                                               method_kwargs, direction,
                                               target_cell)
     self.assertEqual(self.ctxt, tgt_message.ctxt)
     self.assertEqual(method, tgt_message.method_name)
     self.assertEqual(method_kwargs, tgt_message.method_kwargs)
     self.assertEqual(direction, tgt_message.direction)
     self.assertEqual(target_cell, target_cell)
     self.assertFalse(tgt_message.fanout)
     self.assertFalse(tgt_message.need_response)
     self.assertEqual(self.our_name, tgt_message.routing_path)
     self.assertEqual(1, tgt_message.hop_count)
     self.assertEqual(99, tgt_message.max_hop_count)
     self.assertFalse(tgt_message.is_broadcast)
     # Correct next hop?
     next_hop = tgt_message._get_next_hop()
     child_cell = self.state_manager.get_child_cell('child-cell2')
     self.assertEqual(child_cell, next_hop)
Exemplo n.º 12
0
 def test_targeted_message_when_target_cell_state_is_me(self):
     method = 'fake_method'
     method_kwargs = dict(arg1=1, arg2=2)
     direction = 'down'
     target_cell = self.state_manager.get_my_state()
     tgt_message = messaging._TargetedMessage(self.msg_runner, self.ctxt,
                                              method, method_kwargs,
                                              direction, target_cell)
     self.assertEqual('api-cell', tgt_message.target_cell)
     # Correct next hop?
     next_hop = tgt_message._get_next_hop()
     self.assertEqual(target_cell, next_hop)
Exemplo n.º 13
0
 def test_targeted_message_when_target_cell_state_is_me(self):
     method = 'fake_method'
     method_kwargs = dict(arg1=1, arg2=2)
     direction = 'down'
     target_cell = self.state_manager.get_my_state()
     tgt_message = messaging._TargetedMessage(self.msg_runner,
                                               self.ctxt, method,
                                               method_kwargs, direction,
                                               target_cell)
     self.assertEqual('api-cell', tgt_message.target_cell)
     # Correct next hop?
     next_hop = tgt_message._get_next_hop()
     self.assertEqual(target_cell, next_hop)
Exemplo n.º 14
0
    def test_targeted_message_invalid_cell2(self):
        target_cell = 'unknown-cell!child-cell2'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                  self.ctxt, method,
                                                  method_kwargs, direction,
                                                  target_cell,
                                                  need_response=True)
        response = tgt_message.process()
        self.assertTrue(response.failure)
        self.assertRaises(exception.CellRoutingInconsistency,
                response.value_or_raise)
Exemplo n.º 15
0
    def test_targeted_message_invalid_cell2(self):
        target_cell = 'unknown-cell!child-cell2'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                  self.ctxt, method,
                                                  method_kwargs, direction,
                                                  target_cell,
                                                  need_response=True)
        response = tgt_message.process()
        self.assertTrue(response.failure)
        self.assertRaises(exception.CellRoutingInconsistency,
                response.value_or_raise)
Exemplo n.º 16
0
    def test_send_message_to_cell_fanout_cast(self):
        msg_runner = fakes.get_message_runner('api-cell')
        cell_state = fakes.get_cell_state('api-cell', 'child-cell2')
        message = messaging._TargetedMessage(msg_runner,
                                             self.ctxt,
                                             'fake',
                                             'fake',
                                             'down',
                                             cell_state,
                                             fanout=True)

        call_info = {}

        def _fake_make_msg(method, **kwargs):
            call_info['rpc_method'] = method
            call_info['rpc_kwargs'] = kwargs
            return 'fake-message'

        def _fake_fanout_cast_to_server(*args, **kwargs):
            call_info['cast_args'] = args
            call_info['cast_kwargs'] = kwargs

        self.stubs.Set(rpc, 'fanout_cast_to_server',
                       _fake_fanout_cast_to_server)
        self.stubs.Set(self.driver.intercell_rpcapi, 'make_msg',
                       _fake_make_msg)
        self.stubs.Set(self.driver.intercell_rpcapi, 'fanout_cast_to_server',
                       _fake_fanout_cast_to_server)

        self.driver.send_message_to_cell(cell_state, message)
        expected_server_params = {
            'hostname': 'rpc_host2',
            'password': '******',
            'port': 'rpc_port2',
            'username': '******',
            'virtual_host': 'rpc_vhost2'
        }
        expected_cast_args = (self.ctxt, expected_server_params,
                              'fake-message')
        expected_cast_kwargs = {'topic': 'cells.intercell.targeted'}
        expected_rpc_kwargs = {'message': message.to_json()}
        self.assertEqual(expected_cast_args, call_info['cast_args'])
        self.assertEqual(expected_cast_kwargs, call_info['cast_kwargs'])
        self.assertEqual('process_message', call_info['rpc_method'])
        self.assertEqual(expected_rpc_kwargs, call_info['rpc_kwargs'])
Exemplo n.º 17
0
    def test_grandchild_targeted_message_with_error(self):
        target_cell = 'api-cell!child-cell2!grandchild-cell1'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        def our_fake_method(message, **kwargs):
            raise test.TestingException('this should be returned')

        fakes.stub_tgt_method(self, 'grandchild-cell1', 'our_fake_method',
                our_fake_method)

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                  self.ctxt, method,
                                                  method_kwargs, direction,
                                                  target_cell,
                                                  need_response=True)
        response = tgt_message.process()
        self.assertTrue(response.failure)
        self.assertRaises(test.TestingException, response.value_or_raise)
Exemplo n.º 18
0
    def test_grandchild_targeted_message_with_error(self):
        target_cell = 'api-cell!child-cell2!grandchild-cell1'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        def our_fake_method(message, **kwargs):
            raise test.TestingException('this should be returned')

        fakes.stub_tgt_method(self, 'grandchild-cell1', 'our_fake_method',
                our_fake_method)

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                  self.ctxt, method,
                                                  method_kwargs, direction,
                                                  target_cell,
                                                  need_response=True)
        response = tgt_message.process()
        self.assertTrue(response.failure)
        self.assertRaises(test.TestingException, response.value_or_raise)
Exemplo n.º 19
0
    def test_grandchild_targeted_message_max_hops(self):
        self.flags(max_hop_count=2, group='cells')
        target_cell = 'api-cell!child-cell2!grandchild-cell1'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        def our_fake_method(message, **kwargs):
            raise test.TestingException('should not be reached')

        fakes.stub_tgt_method(self, 'grandchild-cell1', 'our_fake_method',
                our_fake_method)

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                  self.ctxt, method,
                                                  method_kwargs, direction,
                                                  target_cell,
                                                  need_response=True)
        response = tgt_message.process()
        self.assertTrue(response.failure)
        self.assertRaises(exception.CellMaxHopCountReached,
                response.value_or_raise)
Exemplo n.º 20
0
    def test_grandchild_targeted_message_max_hops(self):
        self.flags(max_hop_count=2, group='cells')
        target_cell = 'api-cell!child-cell2!grandchild-cell1'
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'down'

        def our_fake_method(message, **kwargs):
            raise test.TestingException('should not be reached')

        fakes.stub_tgt_method(self, 'grandchild-cell1', 'our_fake_method',
                our_fake_method)

        tgt_message = messaging._TargetedMessage(self.msg_runner,
                                                  self.ctxt, method,
                                                  method_kwargs, direction,
                                                  target_cell,
                                                  need_response=True)
        response = tgt_message.process()
        self.assertTrue(response.failure)
        self.assertRaises(exception.CellMaxHopCountReached,
                response.value_or_raise)
Exemplo n.º 21
0
    def test_send_message_to_cell_fanout_cast(self):
        msg_runner = fakes.get_message_runner('api-cell')
        cell_state = fakes.get_cell_state('api-cell', 'child-cell2')
        message = messaging._TargetedMessage(msg_runner,
                self.ctxt, 'fake', 'fake', 'down', cell_state, fanout=True)

        call_info = {}

        def _fake_make_msg(method, **kwargs):
            call_info['rpc_method'] = method
            call_info['rpc_kwargs'] = kwargs
            return 'fake-message'

        def _fake_fanout_cast_to_server(*args, **kwargs):
            call_info['cast_args'] = args
            call_info['cast_kwargs'] = kwargs

        self.stubs.Set(rpc, 'fanout_cast_to_server',
                       _fake_fanout_cast_to_server)
        self.stubs.Set(self.driver.intercell_rpcapi, 'make_msg',
                       _fake_make_msg)
        self.stubs.Set(self.driver.intercell_rpcapi,
                       'fanout_cast_to_server', _fake_fanout_cast_to_server)

        self.driver.send_message_to_cell(cell_state, message)
        expected_server_params = {'hostname': 'rpc_host2',
                                  'password': '******',
                                  'port': 'rpc_port2',
                                  'username': '******',
                                  'virtual_host': 'rpc_vhost2'}
        expected_cast_args = (self.ctxt, expected_server_params,
                              'fake-message')
        expected_cast_kwargs = {'topic': 'cells.intercell.targeted'}
        expected_rpc_kwargs = {'message': message.to_json()}
        self.assertEqual(expected_cast_args, call_info['cast_args'])
        self.assertEqual(expected_cast_kwargs, call_info['cast_kwargs'])
        self.assertEqual('process_message', call_info['rpc_method'])
        self.assertEqual(expected_rpc_kwargs, call_info['rpc_kwargs'])