Ejemplo n.º 1
0
    def _setup_attrs(self, up=True):
        mid_cell = 'child-cell2'
        if up:
            src_cell = 'grandchild-cell1'
            tgt_cell = 'api-cell'
        else:
            src_cell = 'api-cell'
            tgt_cell = 'grandchild-cell1'

        self.src_msg_runner = fakes.get_message_runner(src_cell)
        methods_cls = self.src_msg_runner.methods_by_type['broadcast']
        self.src_methods_cls = methods_cls
        self.src_db_inst = methods_cls.db
        self.src_compute_api = methods_cls.compute_api

        self.mid_msg_runner = fakes.get_message_runner(mid_cell)
        methods_cls = self.mid_msg_runner.methods_by_type['broadcast']
        self.mid_methods_cls = methods_cls
        self.mid_db_inst = methods_cls.db
        self.mid_compute_api = methods_cls.compute_api

        self.tgt_msg_runner = fakes.get_message_runner(tgt_cell)
        methods_cls = self.tgt_msg_runner.methods_by_type['broadcast']
        self.tgt_methods_cls = methods_cls
        self.tgt_db_inst = methods_cls.db
        self.tgt_compute_api = methods_cls.compute_api
Ejemplo n.º 2
0
    def _setup_attrs(self, up=True):
        mid_cell = 'child-cell2'
        if up:
            src_cell = 'grandchild-cell1'
            tgt_cell = 'api-cell'
        else:
            src_cell = 'api-cell'
            tgt_cell = 'grandchild-cell1'

        self.src_msg_runner = fakes.get_message_runner(src_cell)
        methods_cls = self.src_msg_runner.methods_by_type['broadcast']
        self.src_methods_cls = methods_cls
        self.src_db_inst = methods_cls.db
        self.src_compute_api = methods_cls.compute_api

        self.mid_msg_runner = fakes.get_message_runner(mid_cell)
        methods_cls = self.mid_msg_runner.methods_by_type['broadcast']
        self.mid_methods_cls = methods_cls
        self.mid_db_inst = methods_cls.db
        self.mid_compute_api = methods_cls.compute_api

        self.tgt_msg_runner = fakes.get_message_runner(tgt_cell)
        methods_cls = self.tgt_msg_runner.methods_by_type['broadcast']
        self.tgt_methods_cls = methods_cls
        self.tgt_db_inst = methods_cls.db
        self.tgt_compute_api = methods_cls.compute_api
Ejemplo n.º 3
0
    def _setup_attrs(self, up=True):
        mid_cell = 'child-cell2'
        if up:
            src_cell = 'grandchild-cell1'
            tgt_cell = 'api-cell'
        else:
            src_cell = 'api-cell'
            tgt_cell = 'grandchild-cell1'

        self.src_msg_runner = fakes.get_message_runner(src_cell)
        methods_cls = self.src_msg_runner.methods_by_type['broadcast']
        self.src_methods_cls = methods_cls
        self.src_db_inst = methods_cls.db
        self.src_compute_api = methods_cls.compute_api

        if not up:
            # fudge things so we only have 1 child to broadcast to
            state_manager = self.src_msg_runner.state_manager
            for cell in state_manager.get_child_cells():
                if cell.name != 'child-cell2':
                    del state_manager.child_cells[cell.name]

        self.mid_msg_runner = fakes.get_message_runner(mid_cell)
        methods_cls = self.mid_msg_runner.methods_by_type['broadcast']
        self.mid_methods_cls = methods_cls
        self.mid_db_inst = methods_cls.db
        self.mid_compute_api = methods_cls.compute_api

        self.tgt_msg_runner = fakes.get_message_runner(tgt_cell)
        methods_cls = self.tgt_msg_runner.methods_by_type['broadcast']
        self.tgt_methods_cls = methods_cls
        self.tgt_db_inst = methods_cls.db
        self.tgt_compute_api = methods_cls.compute_api
Ejemplo n.º 4
0
    def test_process_message(self):
        msg_runner = fakes.get_message_runner('api-cell')
        dispatcher = rpc_driver.InterCellRPCDispatcher(msg_runner)
        message = messaging._BroadcastMessage(msg_runner,
                                              self.ctxt,
                                              'fake', {},
                                              'down',
                                              fanout=True)

        call_info = {}

        def _fake_message_from_json(json_message):
            call_info['json_message'] = json_message
            self.assertEqual(message.to_json(), json_message)
            return message

        def _fake_process():
            call_info['process_called'] = True

        self.stubs.Set(msg_runner, 'message_from_json',
                       _fake_message_from_json)
        self.stubs.Set(message, 'process', _fake_process)

        dispatcher.process_message(self.ctxt, message.to_json())
        self.assertEqual(message.to_json(), call_info['json_message'])
        self.assertTrue(call_info['process_called'])
Ejemplo n.º 5
0
 def test_create_broadcast_message_with_response(self):
     self.flags(max_hop_count=99, group='cells')
     our_name = 'child-cell1'
     msg_runner = fakes.get_message_runner(our_name)
     method = 'fake_method'
     method_kwargs = dict(arg1=1, arg2=2)
     direction = 'up'
     bcast_message = messaging._BroadcastMessage(msg_runner,
                                                 self.ctxt,
                                                 method,
                                                 method_kwargs,
                                                 direction,
                                                 need_response=True)
     self.assertEqual(self.ctxt, bcast_message.ctxt)
     self.assertEqual(method, bcast_message.method_name)
     self.assertEqual(method_kwargs, bcast_message.method_kwargs)
     self.assertEqual(direction, bcast_message.direction)
     self.assertFalse(bcast_message.fanout)
     self.assertTrue(bcast_message.need_response)
     self.assertEqual(our_name, bcast_message.routing_path)
     self.assertEqual(1, bcast_message.hop_count)
     self.assertEqual(99, bcast_message.max_hop_count)
     self.assertTrue(bcast_message.is_broadcast)
     # Correct next hops?
     next_hops = bcast_message._get_next_hops()
     parent_cells = msg_runner.state_manager.get_parent_cells()
     self.assertEqual(parent_cells, next_hops)
Ejemplo n.º 6
0
 def _init_cells_scheduler(self):
     fakes.init(self)
     self.msg_runner = fakes.get_message_runner('api-cell')
     self.scheduler = self.msg_runner.scheduler
     self.state_manager = self.msg_runner.state_manager
     self.my_cell_state = self.state_manager.get_my_state()
     self.ctxt = context.RequestContext('fake', 'fake')
     instance_uuids = []
     for x in xrange(3):
         instance_uuids.append(uuidutils.generate_uuid())
     self.instance_uuids = instance_uuids
     self.instances = [{'uuid': uuid} for uuid in instance_uuids]
     self.request_spec = {
             'instance_uuids': instance_uuids,
             'instance_properties': 'fake_properties',
             'instance_type': 'fake_type',
             'image': 'fake_image',
             'security_group': 'fake_sec_groups',
             'block_device_mapping': 'fake_bdm'}
     self.build_inst_kwargs = {
             'instances': self.instances,
             'image': 'fake_image',
             'filter_properties': {'instance_type': 'fake_type'},
             'security_groups': 'fake_sec_groups',
             'block_device_mapping': 'fake_bdm'}
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
 def _init_cells_scheduler(self):
     fakes.init(self)
     self.msg_runner = fakes.get_message_runner('api-cell')
     self.scheduler = self.msg_runner.scheduler
     self.state_manager = self.msg_runner.state_manager
     self.my_cell_state = self.state_manager.get_my_state()
     self.ctxt = context.RequestContext('fake', 'fake')
     instance_uuids = []
     for x in xrange(3):
         instance_uuids.append(uuidutils.generate_uuid())
     self.instance_uuids = instance_uuids
     self.instances = [{'uuid': uuid} for uuid in instance_uuids]
     self.request_spec = {
         'instance_uuids': instance_uuids,
         'instance_properties': 'fake_properties',
         'instance_type': 'fake_type',
         'image': 'fake_image',
         'security_group': 'fake_sec_groups',
         'block_device_mapping': 'fake_bdm'
     }
     self.build_inst_kwargs = {
         'instances': self.instances,
         'image': 'fake_image',
         'filter_properties': {
             'instance_type': 'fake_type'
         },
         'security_groups': 'fake_sec_groups',
         'block_device_mapping': 'fake_bdm'
     }
Ejemplo n.º 10
0
 def _init_cells_scheduler(self):
     fakes.init(self)
     self.msg_runner = fakes.get_message_runner("api-cell")
     self.scheduler = self.msg_runner.scheduler
     self.state_manager = self.msg_runner.state_manager
     self.my_cell_state = self.state_manager.get_my_state()
     self.ctxt = context.RequestContext("fake", "fake")
     instance_uuids = []
     for x in xrange(3):
         instance_uuids.append(uuidutils.generate_uuid())
     self.instance_uuids = instance_uuids
     self.instances = [{"uuid": uuid} for uuid in instance_uuids]
     self.request_spec = {
         "instance_uuids": instance_uuids,
         "instance_properties": "fake_properties",
         "instance_type": "fake_type",
         "image": "fake_image",
         "security_group": "fake_sec_groups",
         "block_device_mapping": "fake_bdm",
     }
     self.build_inst_kwargs = {
         "instances": self.instances,
         "image": "fake_image",
         "filter_properties": {"instance_type": "fake_type"},
         "security_groups": "fake_sec_groups",
         "block_device_mapping": "fake_bdm",
     }
Ejemplo n.º 11
0
    def test_broadcast_routing_up(self):
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'up'
        msg_runner = fakes.get_message_runner('grandchild-cell3')

        cells = set()

        def our_fake_method(message, **kwargs):
            cells.add(message.routing_path)

        fakes.stub_bcast_methods(self, 'our_fake_method', our_fake_method)

        bcast_message = messaging._BroadcastMessage(msg_runner,
                                                    self.ctxt,
                                                    method,
                                                    method_kwargs,
                                                    direction,
                                                    run_locally=True)
        bcast_message.process()
        # Paths are reversed, since going 'up'
        expected = set([
            'grandchild-cell3', 'grandchild-cell3!child-cell3',
            'grandchild-cell3!child-cell3!api-cell'
        ])
        self.assertEqual(expected, cells)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
 def setUp(self):
     super(_FilterTestClass, self).setUp()
     fakes.init(self)
     self.msg_runner = fakes.get_message_runner("api-cell")
     self.scheduler = self.msg_runner.scheduler
     self.my_cell_state = self.msg_runner.state_manager.get_my_state()
     self.filter_handler = filters.CellFilterHandler()
     self.filter_classes = self.filter_handler.get_matching_classes([self.filter_cls_name])
     self.context = context.RequestContext("fake", "fake", is_admin=True)
Ejemplo n.º 15
0
 def setUp(self):
     super(_FilterTestClass, self).setUp()
     fakes.init(self)
     self.msg_runner = fakes.get_message_runner('api-cell')
     self.scheduler = self.msg_runner.scheduler
     self.my_cell_state = self.msg_runner.state_manager.get_my_state()
     self.filter_handler = filters.CellFilterHandler()
     self.filter_classes = self.filter_handler.get_matching_classes(
         [self.filter_cls_name])
     self.context = context.RequestContext('fake', 'fake', is_admin=True)
Ejemplo n.º 16
0
 def setUp(self):
     super(CellsMessageClassesTestCase, self).setUp()
     fakes.init(self)
     self.ctxt = context.RequestContext('fake', 'fake')
     # Need to be able to deserialize test.TestingException.
     allowed_modules = CONF.allowed_rpc_exception_modules
     allowed_modules.append('nova.test')
     self.flags(allowed_rpc_exception_modules=allowed_modules)
     self.our_name = 'api-cell'
     self.msg_runner = fakes.get_message_runner(self.our_name)
     self.state_manager = self.msg_runner.state_manager
Ejemplo n.º 17
0
 def setUp(self):
     super(CellsMessageClassesTestCase, self).setUp()
     fakes.init(self)
     self.ctxt = context.RequestContext('fake', 'fake')
     # Need to be able to deserialize test.TestingException.
     allowed_modules = CONF.allowed_rpc_exception_modules
     allowed_modules.append('nova.test')
     self.flags(allowed_rpc_exception_modules=allowed_modules)
     self.our_name = 'api-cell'
     self.msg_runner = fakes.get_message_runner(self.our_name)
     self.state_manager = self.msg_runner.state_manager
Ejemplo n.º 18
0
 def _init_cells_scheduler(self):
     fakes.init(self)
     self.msg_runner = fakes.get_message_runner("api-cell")
     self.scheduler = self.msg_runner.scheduler
     self.state_manager = self.msg_runner.state_manager
     self.my_cell_state = self.state_manager.get_my_state()
     self.ctxt = context.RequestContext("fake", "fake")
     instance_uuids = []
     for x in xrange(3):
         instance_uuids.append(uuidutils.generate_uuid())
     self.instance_uuids = instance_uuids
     self.request_spec = {"instance_uuids": instance_uuids, "other": "stuff"}
Ejemplo n.º 19
0
 def _setup_attrs(self, source_cell, target_cell):
     self.tgt_cell_name = target_cell
     self.src_msg_runner = fakes.get_message_runner(source_cell)
     self.src_state_manager = self.src_msg_runner.state_manager
     tgt_shortname = target_cell.split('!')[-1]
     self.tgt_cell_mgr = fakes.get_cells_manager(tgt_shortname)
     self.tgt_msg_runner = self.tgt_cell_mgr.msg_runner
     self.tgt_scheduler = self.tgt_msg_runner.scheduler
     self.tgt_state_manager = self.tgt_msg_runner.state_manager
     methods_cls = self.tgt_msg_runner.methods_by_type['targeted']
     self.tgt_methods_cls = methods_cls
     self.tgt_compute_api = methods_cls.compute_api
     self.tgt_db_inst = methods_cls.db
Ejemplo n.º 20
0
 def _setup_attrs(self, source_cell, target_cell):
     self.tgt_cell_name = target_cell
     self.src_msg_runner = fakes.get_message_runner(source_cell)
     self.src_state_manager = self.src_msg_runner.state_manager
     tgt_shortname = target_cell.split('!')[-1]
     self.tgt_cell_mgr = fakes.get_cells_manager(tgt_shortname)
     self.tgt_msg_runner = self.tgt_cell_mgr.msg_runner
     self.tgt_scheduler = self.tgt_msg_runner.scheduler
     self.tgt_state_manager = self.tgt_msg_runner.state_manager
     methods_cls = self.tgt_msg_runner.methods_by_type['targeted']
     self.tgt_methods_cls = methods_cls
     self.tgt_compute_api = methods_cls.compute_api
     self.tgt_db_inst = methods_cls.db
Ejemplo n.º 21
0
 def setUp(self):
     super(CellsSchedulerTestCase, self).setUp()
     fakes.init(self)
     self.msg_runner = fakes.get_message_runner('api-cell')
     self.scheduler = self.msg_runner.scheduler
     self.state_manager = self.msg_runner.state_manager
     self.my_cell_state = self.state_manager.get_my_state()
     self.ctxt = context.RequestContext('fake', 'fake')
     instance_uuids = []
     for x in xrange(3):
         instance_uuids.append(uuidutils.generate_uuid())
     self.instance_uuids = instance_uuids
     self.request_spec = {'instance_uuids': instance_uuids,
                          'other': 'stuff'}
Ejemplo n.º 22
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'])
Ejemplo n.º 23
0
    def test_start_consumers(self):
        self.flags(rpc_driver_queue_base='cells.intercell42', group='cells')
        rpc_consumers = []
        rpc_conns = []
        fake_msg_runner = fakes.get_message_runner('api-cell')
        call_info = {}

        class FakeInterCellRPCDispatcher(object):
            def __init__(_self, msg_runner):
                self.assertEqual(fake_msg_runner, msg_runner)
                call_info['intercell_dispatcher'] = _self

        class FakeRPCDispatcher(object):
            def __init__(_self, proxy_objs):
                self.assertEqual([call_info['intercell_dispatcher']],
                                 proxy_objs)
                call_info['rpc_dispatcher'] = _self

        class FakeRPCConn(object):
            def create_consumer(_self, topic, proxy_obj, **kwargs):
                self.assertEqual(call_info['rpc_dispatcher'], proxy_obj)
                rpc_consumers.append((topic, kwargs))

            def consume_in_thread(_self):
                pass

        def _fake_create_connection(new):
            self.assertTrue(new)
            fake_conn = FakeRPCConn()
            rpc_conns.append(fake_conn)
            return fake_conn

        self.stubs.Set(rpc, 'create_connection', _fake_create_connection)
        self.stubs.Set(rpc_driver, 'InterCellRPCDispatcher',
                       FakeInterCellRPCDispatcher)
        self.stubs.Set(rpc_dispatcher, 'RpcDispatcher', FakeRPCDispatcher)

        self.driver.start_consumers(fake_msg_runner)

        for message_type in ['broadcast', 'response', 'targeted']:
            topic = 'cells.intercell42.' + message_type
            self.assertIn((topic, {'fanout': True}), rpc_consumers)
            self.assertIn((topic, {'fanout': False}), rpc_consumers)
        self.assertEqual(rpc_conns, self.driver.rpc_connections)
Ejemplo n.º 24
0
    def test_start_consumers(self):
        self.flags(rpc_driver_queue_base='cells.intercell42', group='cells')
        rpc_consumers = []
        rpc_conns = []
        fake_msg_runner = fakes.get_message_runner('api-cell')
        call_info = {}

        class FakeInterCellRPCDispatcher(object):
            def __init__(_self, msg_runner):
                self.assertEqual(fake_msg_runner, msg_runner)
                call_info['intercell_dispatcher'] = _self

        class FakeRPCDispatcher(object):
            def __init__(_self, proxy_objs):
                self.assertEqual([call_info['intercell_dispatcher']],
                                 proxy_objs)
                call_info['rpc_dispatcher'] = _self

        class FakeRPCConn(object):
            def create_consumer(_self, topic, proxy_obj, **kwargs):
                self.assertEqual(call_info['rpc_dispatcher'], proxy_obj)
                rpc_consumers.append((topic, kwargs))

            def consume_in_thread(_self):
                pass

        def _fake_create_connection(new):
            self.assertTrue(new)
            fake_conn = FakeRPCConn()
            rpc_conns.append(fake_conn)
            return fake_conn

        self.stubs.Set(rpc, 'create_connection', _fake_create_connection)
        self.stubs.Set(rpc_driver, 'InterCellRPCDispatcher',
                       FakeInterCellRPCDispatcher)
        self.stubs.Set(rpc_dispatcher, 'RpcDispatcher', FakeRPCDispatcher)

        self.driver.start_consumers(fake_msg_runner)

        for message_type in ['broadcast', 'response', 'targeted']:
            topic = 'cells.intercell42.' + message_type
            self.assertIn((topic, {'fanout': True}), rpc_consumers)
            self.assertIn((topic, {'fanout': False}), rpc_consumers)
        self.assertEqual(rpc_conns, self.driver.rpc_connections)
Ejemplo n.º 25
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', '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'])
Ejemplo n.º 26
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'])
Ejemplo n.º 27
0
    def test_broadcast_routing_up(self):
        method = 'our_fake_method'
        method_kwargs = dict(arg1=1, arg2=2)
        direction = 'up'
        msg_runner = fakes.get_message_runner('grandchild-cell3')

        cells = set()

        def our_fake_method(message, **kwargs):
            cells.add(message.routing_path)

        fakes.stub_bcast_methods(self, 'our_fake_method', our_fake_method)

        bcast_message = messaging._BroadcastMessage(msg_runner, self.ctxt,
                                                    method, method_kwargs,
                                                    direction,
                                                    run_locally=True)
        bcast_message.process()
        # Paths are reversed, since going 'up'
        expected = set(['grandchild-cell3', 'grandchild-cell3!child-cell3',
                        'grandchild-cell3!child-cell3!api-cell'])
        self.assertEqual(expected, cells)
Ejemplo n.º 28
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'])
Ejemplo n.º 29
0
    def test_process_message(self):
        msg_runner = fakes.get_message_runner('api-cell')
        dispatcher = rpc_driver.InterCellRPCDispatcher(msg_runner)
        message = messaging._BroadcastMessage(msg_runner,
                self.ctxt, 'fake', {}, 'down', fanout=True)

        call_info = {}

        def _fake_message_from_json(json_message):
            call_info['json_message'] = json_message
            self.assertEqual(message.to_json(), json_message)
            return message

        def _fake_process():
            call_info['process_called'] = True

        self.stubs.Set(msg_runner, 'message_from_json',
                _fake_message_from_json)
        self.stubs.Set(message, 'process', _fake_process)

        dispatcher.process_message(self.ctxt, message.to_json())
        self.assertEqual(message.to_json(), call_info['json_message'])
        self.assertTrue(call_info['process_called'])
Ejemplo n.º 30
0
 def test_create_broadcast_message_with_response(self):
     self.flags(max_hop_count=99, group='cells')
     our_name = 'child-cell1'
     msg_runner = fakes.get_message_runner(our_name)
     method = 'fake_method'
     method_kwargs = dict(arg1=1, arg2=2)
     direction = 'up'
     bcast_message = messaging._BroadcastMessage(msg_runner, self.ctxt,
             method, method_kwargs, direction, need_response=True)
     self.assertEqual(self.ctxt, bcast_message.ctxt)
     self.assertEqual(method, bcast_message.method_name)
     self.assertEqual(method_kwargs, bcast_message.method_kwargs)
     self.assertEqual(direction, bcast_message.direction)
     self.assertFalse(bcast_message.fanout)
     self.assertTrue(bcast_message.need_response)
     self.assertEqual(our_name, bcast_message.routing_path)
     self.assertEqual(1, bcast_message.hop_count)
     self.assertEqual(99, bcast_message.max_hop_count)
     self.assertTrue(bcast_message.is_broadcast)
     # Correct next hops?
     next_hops = bcast_message._get_next_hops()
     parent_cells = msg_runner.state_manager.get_parent_cells()
     self.assertEqual(parent_cells, next_hops)
Ejemplo n.º 31
0
    def test_start_servers(self):
        self.flags(rpc_driver_queue_base='cells.intercell42', group='cells')
        fake_msg_runner = fakes.get_message_runner('api-cell')

        class FakeInterCellRPCDispatcher(object):
            def __init__(_self, msg_runner):
                self.assertEqual(fake_msg_runner, msg_runner)

        self.stubs.Set(rpc_driver, 'InterCellRPCDispatcher',
                       FakeInterCellRPCDispatcher)
        self.mox.StubOutWithMock(rpc, 'get_server')

        for message_type in messaging.MessageRunner.get_message_types():
            topic = 'cells.intercell42.' + message_type
            target = oslo_messaging.Target(topic=topic, server=CONF.host)
            endpoints = [mox.IsA(FakeInterCellRPCDispatcher)]

            rpcserver = self.mox.CreateMockAnything()
            rpc.get_server(target, endpoints=endpoints).AndReturn(rpcserver)
            rpcserver.start()

        self.mox.ReplayAll()

        self.driver.start_servers(fake_msg_runner)