Пример #1
0
    def _test_service_get_all(self, fake_filters, **kwargs):
        service_attrs = dict(test_service.fake_service)
        del service_attrs['version']
        services = [
            cells_utils.ServiceProxy(
                objects.Service(**dict(
                    service_attrs, id=1, topic='compute', host='host1')),
                'cell1'),
            cells_utils.ServiceProxy(
                objects.Service(**dict(
                    service_attrs, id=2, topic='compute', host='host2')),
                'cell1')
        ]
        exp_services = []
        for service in services:
            exp_service = copy.copy(service)
            exp_service.update({'availability_zone': 'nova'})
            exp_services.append(exp_service)

        @mock.patch.object(self.host_api.cells_rpcapi, 'service_get_all')
        def _do_test(mock_service_get_all):
            mock_service_get_all.return_value = services
            result = self.host_api.service_get_all(self.ctxt,
                                                   filters=fake_filters,
                                                   **kwargs)
            mock_service_get_all.assert_called_once_with(self.ctxt,
                                                         filters=fake_filters)
            self.assertEqual(jsonutils.to_primitive(exp_services),
                             jsonutils.to_primitive(result))

        _do_test()
    def _test_service_get_all(self, fake_filters, **kwargs):
        service_attrs = dict(test_service.fake_service)
        del service_attrs['version']
        services = [
            cells_utils.ServiceProxy(
                objects.Service(**dict(
                    service_attrs, id=1, topic='compute', host='host1')),
                'cell1'),
            cells_utils.ServiceProxy(
                objects.Service(**dict(
                    service_attrs, id=2, topic='compute', host='host2')),
                'cell1')
        ]
        exp_services = []
        for service in services:
            exp_service = copy.copy(service)
            exp_service.update({'availability_zone': 'nova'})
            exp_services.append(exp_service)

        self.mox.StubOutWithMock(self.host_api.cells_rpcapi, 'service_get_all')
        self.host_api.cells_rpcapi.service_get_all(
            self.ctxt, filters=fake_filters).AndReturn(services)
        self.mox.ReplayAll()
        result = self.host_api.service_get_all(self.ctxt,
                                               filters=fake_filters,
                                               **kwargs)
        self.mox.VerifyAll()
        self.assertEqual(jsonutils.to_primitive(exp_services),
                         jsonutils.to_primitive(result))
    def test_service_get_all_no_zones(self):
        services = [
            cells_utils.ServiceProxy(
                objects.Service(id=1, topic='compute', host='host1'), 'cell1'),
            cells_utils.ServiceProxy(
                objects.Service(id=2, topic='compute', host='host2'), 'cell1')
        ]

        fake_filters = {'host': 'host1'}
        self.mox.StubOutWithMock(self.host_api.cells_rpcapi, 'service_get_all')
        self.host_api.cells_rpcapi.service_get_all(
            self.ctxt, filters=fake_filters).AndReturn(services)
        self.mox.ReplayAll()
        result = self.host_api.service_get_all(self.ctxt, filters=fake_filters)
        self.assertEqual(services, result)
Пример #4
0
    def test_service_get_all(self):
        responses = []
        expected_response = []
        # 3 cells... so 3 responses.  Each response is a list of services.
        # Manager should turn these into a single list of responses.
        for i in range(3):
            cell_name = 'path!to!cell%i' % i
            services = []
            for service in FAKE_SERVICES:
                fake_service = objects.Service(**service)
                services.append(fake_service)
                expected_service = cells_utils.ServiceProxy(
                    fake_service, cell_name)
                expected_response.append(
                    (cell_name, expected_service, fake_service))
            response = messaging.Response(self.ctxt, cell_name, services,
                                          False)
            responses.append(response)

        self.mox.StubOutWithMock(self.msg_runner, 'service_get_all')
        self.mox.StubOutWithMock(cells_utils, 'add_cell_to_service')
        self.msg_runner.service_get_all(self.ctxt,
                                        'fake-filters').AndReturn(responses)
        # Calls are done by cells, so we need to sort the list by the cell name
        expected_response.sort(key=lambda k: k[0])
        for cell_name, service_proxy, service in expected_response:
            cells_utils.add_cell_to_service(service,
                                            cell_name).AndReturn(service_proxy)
        self.mox.ReplayAll()
        response = self.cells_manager.service_get_all(self.ctxt,
                                                      filters='fake-filters')
        self.assertEqual([proxy for cell, proxy, service in expected_response],
                         response)
Пример #5
0
    def test_service_get_all_no_zones(self):
        services = [
            cells_utils.ServiceProxy(
                objects.Service(id=1, topic='compute', host='host1'), 'cell1'),
            cells_utils.ServiceProxy(
                objects.Service(id=2, topic='compute', host='host2'), 'cell1')
        ]

        fake_filters = {'host': 'host1'}

        @mock.patch.object(self.host_api.cells_rpcapi, 'service_get_all')
        def _do_test(mock_service_get_all):
            mock_service_get_all.return_value = services
            result = self.host_api.service_get_all(self.ctxt,
                                                   filters=fake_filters)
            self.assertEqual(services, result)

        _do_test()
    def test_service_get_by_compute_host(self):
        self.mox.StubOutWithMock(self.host_api.cells_rpcapi,
                                 'service_get_by_compute_host')

        obj = objects.Service(id=1, host='fake')
        fake_service = cells_utils.ServiceProxy(obj, 'cell1')

        self.host_api.cells_rpcapi.service_get_by_compute_host(
            self.ctxt, 'fake-host').AndReturn(fake_service)
        self.mox.ReplayAll()
        result = self.host_api.service_get_by_compute_host(
            self.ctxt, 'fake-host')
        self.assertEqual(fake_service, result)
Пример #7
0
    def test_service_get_by_compute_host(self):
        obj = objects.Service(id=1, host='fake')
        fake_service = cells_utils.ServiceProxy(obj, 'cell1')

        @mock.patch.object(self.host_api.cells_rpcapi,
                           'service_get_by_compute_host')
        def _do_test(mock_service_get_by_compute_host):
            mock_service_get_by_compute_host.return_value = fake_service
            result = self.host_api.service_get_by_compute_host(
                self.ctxt, 'fake-host')
            self.assertEqual(fake_service, result)

        _do_test()
Пример #8
0
    def service_get_all(self,
                        context,
                        filters=None,
                        set_zones=False,
                        all_cells=False,
                        cell_down_support=False):
        """Get all services.

        Note that this is the cellsv1 variant, which means we ignore the
        "all_cells" parameter.
        """
        if filters is None:
            filters = {}
        if 'availability_zone' in filters:
            zone_filter = filters.pop('availability_zone')
            set_zones = True
        else:
            zone_filter = None
        services = self.cells_rpcapi.service_get_all(context, filters=filters)
        if set_zones:
            # TODO(sbauza): set_availability_zones returns flat dicts,
            # we should rather modify the RPC API to amend service_get_all by
            # adding a set_zones argument
            services = availability_zones.set_availability_zones(
                context, services)
            if zone_filter is not None:
                services = [
                    s for s in services
                    if s['availability_zone'] == zone_filter
                ]

            # NOTE(sbauza): As services is a list of flat dicts, we need to
            # rehydrate the corresponding ServiceProxy objects
            cell_paths = []
            for service in services:
                cell_path, id = cells_utils.split_cell_and_item(service['id'])
                cell_path, host = cells_utils.split_cell_and_item(
                    service['host'])
                service['id'] = id
                service['host'] = host
                cell_paths.append(cell_path)
            services = obj_base.obj_make_list(context, objects.ServiceList(),
                                              objects.Service, services)
            services = [
                cells_utils.ServiceProxy(s, c)
                for s, c in zip(services, cell_paths)
            ]

        return services
Пример #9
0
    def test_service_update(self):
        host_name = 'fake-host'
        binary = 'nova-compute'
        params_to_update = dict(disabled=True)

        obj = objects.Service(id=42, host='fake')
        fake_service = cells_utils.ServiceProxy(obj, 'cell1')

        @mock.patch.object(self.host_api.cells_rpcapi, 'service_update')
        def _do_test(mock_service_update):
            mock_service_update.return_value = fake_service

            result = self.host_api.service_update(self.ctxt, host_name, binary,
                                                  params_to_update)
            self.assertEqual(fake_service, result)

        _do_test()
    def test_service_update(self):
        host_name = 'fake-host'
        binary = 'nova-compute'
        params_to_update = dict(disabled=True)

        obj = objects.Service(id=42, host='fake')
        fake_service = cells_utils.ServiceProxy(obj, 'cell1')

        self.mox.StubOutWithMock(self.host_api.cells_rpcapi, 'service_update')
        self.host_api.cells_rpcapi.service_update(
            self.ctxt, host_name, binary,
            params_to_update).AndReturn(fake_service)

        self.mox.ReplayAll()

        result = self.host_api.service_update(self.ctxt, host_name, binary,
                                              params_to_update)
        self.assertEqual(fake_service, result)
Пример #11
0
    def test_service_get_by_compute_host(self):
        fake_cell = 'fake-cell'
        fake_service = objects.Service(**FAKE_SERVICES[0])
        fake_response = messaging.Response(self.ctxt, fake_cell, fake_service,
                                           False)
        expected_response = cells_utils.ServiceProxy(fake_service, fake_cell)
        cell_and_host = cells_utils.cell_with_item('fake-cell', 'fake-host')

        self.mox.StubOutWithMock(self.msg_runner,
                                 'service_get_by_compute_host')
        self.mox.StubOutWithMock(cells_utils, 'add_cell_to_service')
        self.msg_runner.service_get_by_compute_host(
            self.ctxt, fake_cell, 'fake-host').AndReturn(fake_response)
        cells_utils.add_cell_to_service(fake_service,
                                        fake_cell).AndReturn(expected_response)

        self.mox.ReplayAll()
        response = self.cells_manager.service_get_by_compute_host(
            self.ctxt, host_name=cell_and_host)
        self.assertEqual(expected_response, response)
Пример #12
0
    def test_service_update(self):
        fake_cell = 'fake-cell'
        fake_service = objects.Service(**FAKE_SERVICES[0])
        fake_response = messaging.Response(
            self.ctxt, fake_cell, fake_service, False)
        expected_response = cells_utils.ServiceProxy(fake_service, fake_cell)
        cell_and_host = cells_utils.cell_with_item('fake-cell', 'fake-host')
        params_to_update = {'disabled': True}

        self.mox.StubOutWithMock(self.msg_runner, 'service_update')
        self.mox.StubOutWithMock(cells_utils, 'add_cell_to_service')
        self.msg_runner.service_update(self.ctxt,
                fake_cell, 'fake-host', 'nova-api',
                params_to_update).AndReturn(fake_response)
        cells_utils.add_cell_to_service(fake_service, fake_cell).AndReturn(
            expected_response)
        self.mox.ReplayAll()

        response = self.cells_manager.service_update(
            self.ctxt, host_name=cell_and_host, binary='nova-api',
            params_to_update=params_to_update)
        self.assertEqual(expected_response, response)
Пример #13
0
    def setUp(self):
        super(ServicesCellsTestV21, self).setUp()

        host_api = compute.cells_api.HostAPI()

        self.ext_mgr = extensions.ExtensionManager()
        self.ext_mgr.extensions = {}
        self._set_up_controller()
        self.controller.host_api = host_api

        self.useFixture(utils_fixture.TimeFixture(fake_utcnow()))

        services_list = []
        for service in fake_services_list:
            service = service.copy()
            del service['version']
            service_obj = objects.Service(**service)
            service_proxy = cells_utils.ServiceProxy(service_obj, 'cell1')
            services_list.append(service_proxy)

        host_api.cells_rpcapi.service_get_all = (mock.Mock(
            side_effect=fake_service_get_all(services_list)))
Пример #14
0
    def setUp(self):
        super(ServicesCellsTestV21, self).setUp()

        host_api = cells_api.HostAPI()

        self.ext_mgr = extensions.ExtensionManager()
        self.ext_mgr.extensions = {}
        self._set_up_controller()
        self.controller.host_api = host_api

        self.stubs.Set(timeutils, "utcnow", fake_utcnow)
        self.stubs.Set(timeutils, "utcnow_ts", fake_utcnow_ts)

        services_list = []
        for service in fake_services_list:
            service = service.copy()
            service_obj = objects.Service(**service)
            service_proxy = cells_utils.ServiceProxy(service_obj, 'cell1')
            services_list.append(service_proxy)

        self.stubs.Set(host_api.cells_rpcapi, "service_get_all",
                       fake_service_get_all(services_list))
Пример #15
0
class CellHypervisorsTestV21(HypervisorsTestV21):
    TEST_HYPERS_OBJ = [
        cells_utils.ComputeNodeProxy(obj, _CELL_PATH)
        for obj in TEST_HYPERS_OBJ
    ]
    TEST_SERVICES = [
        cells_utils.ServiceProxy(obj, _CELL_PATH) for obj in TEST_SERVICES
    ]

    TEST_SERVERS = [
        dict(server,
             host=cells_utils.cell_with_item(_CELL_PATH, server['host']))
        for server in TEST_SERVERS
    ]

    DETAIL_HYPERS_DICTS = copy.deepcopy(HypervisorsTestV21.DETAIL_HYPERS_DICTS)
    DETAIL_HYPERS_DICTS = [
        dict(hyp,
             id=cells_utils.cell_with_item(_CELL_PATH, hyp['id']),
             service=dict(
                 hyp['service'],
                 id=cells_utils.cell_with_item(_CELL_PATH,
                                               hyp['service']['id']),
                 host=cells_utils.cell_with_item(_CELL_PATH,
                                                 hyp['service']['host'])))
        for hyp in DETAIL_HYPERS_DICTS
    ]

    INDEX_HYPER_DICTS = copy.deepcopy(HypervisorsTestV21.INDEX_HYPER_DICTS)
    INDEX_HYPER_DICTS = [
        dict(hyp, id=cells_utils.cell_with_item(_CELL_PATH, hyp['id']))
        for hyp in INDEX_HYPER_DICTS
    ]

    # __deepcopy__ is added for copying an object locally in
    # _test_view_hypervisor_detail_cpuinfo_null
    cells_utils.ComputeNodeProxy.__deepcopy__ = (
        lambda self, memo: cells_utils.ComputeNodeProxy(
            copy.deepcopy(self._obj, memo), self._cell_path))

    @classmethod
    def fake_compute_node_get_all(cls, context, limit=None, marker=None):
        return cls.TEST_HYPERS_OBJ

    @classmethod
    def fake_compute_node_search_by_hypervisor(cls, context, hypervisor_re):
        return cls.TEST_HYPERS_OBJ

    @classmethod
    def fake_compute_node_get(cls, context, compute_id):
        for hyper in cls.TEST_HYPERS_OBJ:
            if hyper.id == compute_id:
                return hyper
        raise exception.ComputeHostNotFound(host=compute_id)

    @classmethod
    def fake_service_get_by_compute_host(cls, context, host):
        for service in cls.TEST_SERVICES:
            if service.host == host:
                return service

    @classmethod
    def fake_instance_get_all_by_host(cls, context, host):
        results = []
        for inst in cls.TEST_SERVERS:
            if inst['host'] == host:
                results.append(inst)
        return results

    def setUp(self):

        self.flags(enable=True, cell_type='api', group='cells')

        super(CellHypervisorsTestV21, self).setUp()

        self.stubs.Set(self.controller.host_api, 'compute_node_get_all',
                       self.fake_compute_node_get_all)
        self.stubs.Set(self.controller.host_api, 'service_get_by_compute_host',
                       self.fake_service_get_by_compute_host)
        self.stubs.Set(self.controller.host_api,
                       'compute_node_search_by_hypervisor',
                       self.fake_compute_node_search_by_hypervisor)
        self.stubs.Set(self.controller.host_api, 'compute_node_get',
                       self.fake_compute_node_get)
        self.stubs.Set(self.controller.host_api, 'compute_node_statistics',
                       fake_compute_node_statistics)
        self.stubs.Set(self.controller.host_api, 'instance_get_all_by_host',
                       self.fake_instance_get_all_by_host)
Пример #16
0
 def fake_service_get_by_compute_host(self, context, host):
     return cells_utils.ServiceProxy(
         objects.Service(id=1,
                         host='fake-mini',
                         disabled=False,
                         disabled_reason=None), 'cell1')
Пример #17
0
class CellHypervisorsTestV21(HypervisorsTestV21):
    cell_path = 'cell1'
    TEST_HYPERS_OBJ = [
        cells_utils.ComputeNodeProxy(obj, cell_path) for obj in TEST_HYPERS_OBJ
    ]
    TEST_SERVICES = [
        cells_utils.ServiceProxy(obj, cell_path) for obj in TEST_SERVICES
    ]

    TEST_SERVERS = [
        dict(server,
             host=cells_utils.cell_with_item(cell_path, server['host']))
        for server in TEST_SERVERS
    ]

    DETAIL_HYPERS_DICTS = copy.deepcopy(HypervisorsTestV21.DETAIL_HYPERS_DICTS)
    DETAIL_HYPERS_DICTS = [
        dict(hyp,
             id=cells_utils.cell_with_item(cell_path, hyp['id']),
             service=dict(
                 hyp['service'],
                 id=cells_utils.cell_with_item(cell_path,
                                               hyp['service']['id']),
                 host=cells_utils.cell_with_item(cell_path,
                                                 hyp['service']['host'])))
        for hyp in DETAIL_HYPERS_DICTS
    ]

    INDEX_HYPER_DICTS = copy.deepcopy(HypervisorsTestV21.INDEX_HYPER_DICTS)
    INDEX_HYPER_DICTS = [
        dict(hyp, id=cells_utils.cell_with_item(cell_path, hyp['id']))
        for hyp in INDEX_HYPER_DICTS
    ]

    @classmethod
    def fake_compute_node_get_all(cls, context):
        return cls.TEST_HYPERS_OBJ

    @classmethod
    def fake_compute_node_search_by_hypervisor(cls, context, hypervisor_re):
        return cls.TEST_HYPERS_OBJ

    @classmethod
    def fake_compute_node_get(cls, context, compute_id):
        for hyper in cls.TEST_HYPERS_OBJ:
            if hyper.id == compute_id:
                return hyper
        raise exception.ComputeHostNotFound(host=compute_id)

    @classmethod
    def fake_service_get_by_compute_host(cls, context, host):
        for service in cls.TEST_SERVICES:
            if service.host == host:
                return service

    @classmethod
    def fake_instance_get_all_by_host(cls, context, host):
        results = []
        for inst in cls.TEST_SERVERS:
            if inst['host'] == host:
                results.append(inst)
        return results

    def setUp(self):

        self.flags(enable=True, cell_type='api', group='cells')

        super(CellHypervisorsTestV21, self).setUp()

        self.stubs.Set(self.controller.host_api, 'compute_node_get_all',
                       self.fake_compute_node_get_all)
        self.stubs.Set(self.controller.host_api, 'service_get_by_compute_host',
                       self.fake_service_get_by_compute_host)
        self.stubs.Set(self.controller.host_api,
                       'compute_node_search_by_hypervisor',
                       self.fake_compute_node_search_by_hypervisor)
        self.stubs.Set(self.controller.host_api, 'compute_node_get',
                       self.fake_compute_node_get)
        self.stubs.Set(self.controller.host_api, 'compute_node_statistics',
                       fake_compute_node_statistics)
        self.stubs.Set(self.controller.host_api, 'instance_get_all_by_host',
                       self.fake_instance_get_all_by_host)