Beispiel #1
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)
Beispiel #2
0
    def test_rpc_topic_uses_message_type(self):
        self.flags(rpc_driver_queue_base='cells.intercell42', group='cells')
        msg_runner = fakes.get_message_runner('api-cell')
        cell_state = fakes.get_cell_state('api-cell', 'child-cell2')
        message = messaging._BroadcastMessage(msg_runner,
                self.ctxt, 'fake', {}, 'down', fanout=True)
        message.message_type = 'fake-message-type'

        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.intercell42.fake-message-type').AndReturn(rpcclient)

        rpcclient.prepare(fanout=True).AndReturn(rpcclient)
        rpcclient.cast(mox.IgnoreArg(), 'process_message',
                       message=message.to_json())

        self.mox.ReplayAll()

        self.driver.send_message_to_cell(cell_state, message)
Beispiel #3
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'])
    def test_rpc_topic_uses_message_type(self):
        self.flags(rpc_driver_queue_base='cells.intercell42', group='cells')
        msg_runner = fakes.get_message_runner('api-cell')
        cell_state = fakes.get_cell_state('api-cell', 'child-cell2')
        message = messaging._BroadcastMessage(msg_runner,
                self.ctxt, 'fake', 'fake', 'down', fanout=True)
        message.message_type = 'fake-message-type'

        call_info = {}

        def _fake_fanout_cast_to_server(*args, **kwargs):
            call_info['topic'] = kwargs.get('topic')

        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)
        self.assertEqual('cells.intercell42.fake-message-type',
                         call_info['topic'])
Beispiel #5
0
    def test_rpc_topic_uses_message_type(self):
        self.flags(rpc_driver_queue_base='cells.intercell42', group='cells')
        msg_runner = fakes.get_message_runner('api-cell')
        cell_state = fakes.get_cell_state('api-cell', 'child-cell2')
        message = messaging._BroadcastMessage(msg_runner,
                                              self.ctxt,
                                              'fake', {},
                                              'down',
                                              fanout=True)
        message.message_type = 'fake-message-type'

        call_info = {}

        def _fake_fanout_cast_to_server(*args, **kwargs):
            call_info['topic'] = kwargs.get('topic')

        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)
        self.assertEqual('cells.intercell42.fake-message-type',
                         call_info['topic'])
    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'])