Пример #1
0
    def test_add_cell_to_compute_node_no_service(self, mock_get_by_id):
        fake_compute = objects.ComputeNode(id=1, host='fake', service_id=1)
        mock_get_by_id.side_effect = exception.ServiceNotFound(service_id=1)
        cell_path = 'fake_path'

        proxy = cells_utils.add_cell_to_compute_node(fake_compute, cell_path)

        self.assertIsInstance(proxy, cells_utils.ComputeNodeProxy)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 1), proxy.id)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake'),
                         proxy.host)
        self.assertRaises(exception.ServiceNotFound, getattr, proxy, 'service')
Пример #2
0
    def test_add_cell_to_service_with_compute_node(self):
        fake_service = objects.Service(id=1, host='fake')
        fake_service.compute_node = objects.ComputeNode(id=1, host='fake')
        cell_path = 'fake_path'

        proxy = cells_utils.add_cell_to_service(fake_service, cell_path)

        self.assertIsInstance(proxy, cells_utils.ServiceProxy)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 1), proxy.id)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake'),
                         proxy.host)
        self.assertRaises(AttributeError,
                          getattr, proxy, 'compute_node')
Пример #3
0
    def test_add_cell_to_compute_node_with_service(self, mock_get_by_id):
        fake_compute = objects.ComputeNode(id=1, host='fake', service_id=1)
        mock_get_by_id.return_value = objects.Service(id=1, host='fake-svc')
        cell_path = 'fake_path'

        proxy = cells_utils.add_cell_to_compute_node(fake_compute, cell_path)

        self.assertIsInstance(proxy, cells_utils.ComputeNodeProxy)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 1), proxy.id)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake'),
                         proxy.host)
        self.assertIsInstance(proxy.service, cells_utils.ServiceProxy)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 1),
                         proxy.service.id)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake-svc'),
                         proxy.service.host)
Пример #4
0
 def test_service_delete(self):
     cell_service_id = cells_utils.cell_with_item('cell1', 1)
     with mock.patch.object(self.host_api.cells_rpcapi,
                            'service_delete') as service_delete:
         self.host_api.service_delete(self.ctxt, cell_service_id)
         service_delete.assert_called_once_with(
             self.ctxt, cell_service_id)
Пример #5
0
    def test_service_delete(self):
        fake_cell = 'fake-cell'
        service_id = '1'
        cell_service_id = cells_utils.cell_with_item(fake_cell, service_id)

        with mock.patch.object(self.msg_runner,
                               'service_delete') as service_delete:
            self.cells_manager.service_delete(self.ctxt, cell_service_id)
            service_delete.assert_called_once_with(
                self.ctxt, fake_cell, service_id)
Пример #6
0
    def test_split_cell_and_item(self):
        path = 'australia', 'queensland', 'gold_coast'
        cell = cells_utils.PATH_CELL_SEP.join(path)
        item = 'host_5'
        together = cells_utils.cell_with_item(cell, item)
        self.assertEqual(cells_utils._CELL_ITEM_SEP.join([cell, item]),
                         together)

        # Test normal usage
        result_cell, result_item = cells_utils.split_cell_and_item(together)
        self.assertEqual(cell, result_cell)
        self.assertEqual(item, result_item)

        # Test with no cell
        cell = None
        together = cells_utils.cell_with_item(cell, item)
        self.assertEqual(item, together)
        result_cell, result_item = cells_utils.split_cell_and_item(together)
        self.assertEqual(cell, result_cell)
        self.assertEqual(item, result_item)
Пример #7
0
class CellHypervisorsTestV2(HypervisorsTestV2, CellHypervisorsTestV21):
    cell_path = 'cell1'
    DETAIL_HYPERS_DICTS = copy.deepcopy(HypervisorsTestV2.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(HypervisorsTestV2.INDEX_HYPER_DICTS)
    INDEX_HYPER_DICTS = [
        dict(hyp, id=cells_utils.cell_with_item(cell_path, hyp['id']))
        for hyp in INDEX_HYPER_DICTS
    ]

    def setUp(self):
        super(CellHypervisorsTestV2, self).setUp()
Пример #8
0
 def test_task_log_get_all_with_filters(self):
     expected_response, responses = self._build_task_log_responses(1)
     cell_and_host = cells_utils.cell_with_item('fake-cell', 'fake-host')
     self.mox.StubOutWithMock(self.msg_runner,
                              'task_log_get_all')
     self.msg_runner.task_log_get_all(self.ctxt, 'fake-cell',
             'fake-name', 'fake-begin', 'fake-end', host='fake-host',
             state='fake-state').AndReturn(responses)
     self.mox.ReplayAll()
     response = self.cells_manager.task_log_get_all(self.ctxt,
             task_name='fake-name',
             period_beginning='fake-begin', period_ending='fake-end',
             host=cell_and_host, state='fake-state')
     self.assertEqual(expected_response, response)
Пример #9
0
 def test_proxy_rpc_to_manager(self):
     self.mox.StubOutWithMock(self.msg_runner,
                              'proxy_rpc_to_manager')
     fake_response = self._get_fake_response()
     cell_and_host = cells_utils.cell_with_item('fake-cell', 'fake-host')
     topic = "%s.%s" % (CONF.compute_topic, cell_and_host)
     self.msg_runner.proxy_rpc_to_manager(self.ctxt, 'fake-cell',
             'fake-host', topic, 'fake-rpc-msg',
             True, -1).AndReturn(fake_response)
     self.mox.ReplayAll()
     response = self.cells_manager.proxy_rpc_to_manager(self.ctxt,
             topic=topic, rpc_message='fake-rpc-msg', call=True,
             timeout=-1)
     self.assertEqual('fake-response', response)
Пример #10
0
    def test_instance_get_all_by_host(self):
        instances = [dict(id=1, cell_name='cell1', host='host1'),
                     dict(id=2, cell_name='cell2', host='host1'),
                     dict(id=3, cell_name='cell1', host='host2')]

        self.mox.StubOutWithMock(self.host_api.db,
                                 'instance_get_all_by_host')

        self.host_api.db.instance_get_all_by_host(self.ctxt,
                'fake-host').AndReturn(instances)
        self.mox.ReplayAll()
        expected_result = [instances[0], instances[2]]
        cell_and_host = cells_utils.cell_with_item('cell1', 'fake-host')
        result = self.host_api.instance_get_all_by_host(self.ctxt,
                cell_and_host)
        self.assertEqual(expected_result, result)
Пример #11
0
    def test_get_host_uptime(self):
        fake_cell = 'parent!fake-cell'
        fake_host = 'fake-host'
        fake_cell_and_host = cells_utils.cell_with_item(fake_cell, fake_host)
        host_uptime = (" 08:32:11 up 93 days, 18:25, 12 users,  load average:"
                       " 0.20, 0.12, 0.14")
        fake_response = messaging.Response(self.ctxt, fake_cell, host_uptime,
                                           False)

        self.mox.StubOutWithMock(self.msg_runner,
                                 'get_host_uptime')
        self.msg_runner.get_host_uptime(self.ctxt, fake_cell, fake_host).\
            AndReturn(fake_response)
        self.mox.ReplayAll()

        response = self.cells_manager.get_host_uptime(self.ctxt,
                                                      fake_cell_and_host)
        self.assertEqual(host_uptime, response)
Пример #12
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)
Пример #13
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)
Пример #14
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', 'patron-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='patron-api',
            params_to_update=params_to_update)
        self.assertEqual(expected_response, response)
Пример #15
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)