Ejemplo n.º 1
0
 def test_compute_node_get_all(self):
     responses = []
     expected_response = []
     # 3 cells... so 3 responses.  Each response is a list of computes.
     # Manager should turn these into a single list of responses.
     for i in range(3):
         cell_name = 'path!to!cell%i' % i
         compute_nodes = []
         for compute_node in FAKE_COMPUTE_NODES:
             fake_compute = objects.ComputeNode(**compute_node)
             fake_compute._cached_service = None
             compute_nodes.append(fake_compute)
             expected_compute_node = cells_utils.ComputeNodeProxy(
                 fake_compute, cell_name)
             expected_response.append(
                 (cell_name, expected_compute_node, fake_compute))
         response = messaging.Response(self.ctxt, cell_name, compute_nodes,
                                       False)
         responses.append(response)
     self.mox.StubOutWithMock(self.msg_runner, 'compute_node_get_all')
     self.mox.StubOutWithMock(cells_utils, 'add_cell_to_compute_node')
     self.msg_runner.compute_node_get_all(
         self.ctxt, hypervisor_match='fake-match').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, compute_proxy, compute_node in expected_response:
         cells_utils.add_cell_to_compute_node(
             compute_node, cell_name).AndReturn(compute_proxy)
     self.mox.ReplayAll()
     response = self.cells_manager.compute_node_get_all(
         self.ctxt, hypervisor_match='fake-match')
     self.assertEqual([proxy for cell, proxy, compute in expected_response],
                      response)
Ejemplo n.º 2
0
    def test_proxy_object_serializer_to_primitive(self):
        obj = objects.ComputeNode(id=1, host='fake')
        obj_proxy = cells_utils.ComputeNodeProxy(obj, 'fake_path')
        serializer = cells_utils.ProxyObjectSerializer()

        primitive = serializer.serialize_entity('ctx', obj_proxy)
        self.assertIsInstance(primitive, dict)
        class_name = primitive.pop('cell_proxy.class_name')
        cell_path = primitive.pop('cell_proxy.cell_path')
        self.assertEqual('ComputeNodeProxy', class_name)
        self.assertEqual('fake_path', cell_path)
        self.assertEqual(obj.obj_to_primitive(), primitive)
Ejemplo n.º 3
0
    def test_compute_node_get(self):
        fake_cell = 'fake-cell'
        fake_compute = objects.ComputeNode(**FAKE_COMPUTE_NODES[0])
        fake_compute._cached_service = None
        fake_response = messaging.Response(self.ctxt, fake_cell, fake_compute,
                                           False)

        expected_response = cells_utils.ComputeNodeProxy(
            fake_compute, fake_cell)
        cell_and_id = cells_utils.cell_with_item(fake_cell, 'fake-id')
        self.mox.StubOutWithMock(self.msg_runner, 'compute_node_get')
        self.mox.StubOutWithMock(cells_utils, 'add_cell_to_compute_node')
        self.msg_runner.compute_node_get(self.ctxt, 'fake-cell',
                                         'fake-id').AndReturn(fake_response)
        cells_utils.add_cell_to_compute_node(
            fake_compute, fake_cell).AndReturn(expected_response)
        self.mox.ReplayAll()
        response = self.cells_manager.compute_node_get(self.ctxt,
                                                       compute_id=cell_and_id)
        self.assertEqual(expected_response, response)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)