Beispiel #1
0
    def test_add_cell_to_compute_node(self):
        fake_compute = objects.ComputeNode(id=1, host='fake')
        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)
    def test_add_cell_to_compute_node(self):
        fake_compute = objects.ComputeNode(id=1, host='fake')
        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)
Beispiel #3
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')
Beispiel #4
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')
Beispiel #5
0
    def test_add_cell_to_service_no_compute_node(self, mock_get_by_id):
        fake_service = objects.Service(id=1, host='fake')
        mock_get_by_id.side_effect = exception.ServiceNotFound(service_id=1)
        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')
Beispiel #6
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')
Beispiel #7
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)
Beispiel #8
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)
 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)
Beispiel #10
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)
Beispiel #11
0
 def test_compute_node_get_not_found(self):
     cell_compute_uuid = cells_utils.cell_with_item('cell1', uuids.cn_uuid)
     with mock.patch.object(self.host_api.cells_rpcapi, 'compute_node_get',
                            side_effect=exception.CellRoutingInconsistency(
                                reason='because_cells_v1')):
         self.assertRaises(exception.ComputeHostNotFound,
                           self.host_api.compute_node_get,
                           self.ctxt, cell_compute_uuid)
Beispiel #12
0
 def test_compute_node_get_not_found(self):
     cell_compute_uuid = cells_utils.cell_with_item('cell1', uuids.cn_uuid)
     with mock.patch.object(self.host_api.cells_rpcapi, 'compute_node_get',
                            side_effect=exception.CellRoutingInconsistency(
                                reason='because_cells_v1')):
         self.assertRaises(exception.ComputeHostNotFound,
                           self.host_api.compute_node_get,
                           self.ctxt, cell_compute_uuid)
Beispiel #13
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)
Beispiel #14
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)
 def test_compute_node_get(self):
     fake_cell = "fake-cell"
     fake_response = messaging.Response(fake_cell, FAKE_COMPUTE_NODES[0], False)
     expected_response = copy.deepcopy(FAKE_COMPUTE_NODES[0])
     cells_utils.add_cell_to_compute_node(expected_response, fake_cell)
     cell_and_id = cells_utils.cell_with_item(fake_cell, "fake-id")
     self.mox.StubOutWithMock(self.msg_runner, "compute_node_get")
     self.msg_runner.compute_node_get(self.ctxt, "fake-cell", "fake-id").AndReturn(fake_response)
     self.mox.ReplayAll()
     response = self.cells_manager.compute_node_get(self.ctxt, compute_id=cell_and_id)
     self.assertEqual(expected_response, response)
class CellHypervisorsTestV2(HypervisorsTestV2, CellHypervisorsTestV21):
    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()
Beispiel #17
0
    def test_instance_get_all_by_host(self, mock_get):
        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')]

        mock_get.return_value = instances
        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)
Beispiel #18
0
    def test_instance_get_all_by_host(self, mock_get):
        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')]

        mock_get.return_value = instances
        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)
Beispiel #19
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)
    def test_service_get_by_compute_host(self):
        self.mox.StubOutWithMock(self.msg_runner, "service_get_by_compute_host")
        fake_cell = "fake-cell"
        fake_response = messaging.Response(fake_cell, FAKE_SERVICES[0], False)
        expected_response = copy.deepcopy(FAKE_SERVICES[0])
        cells_utils.add_cell_to_service(expected_response, fake_cell)

        cell_and_host = cells_utils.cell_with_item("fake-cell", "fake-host")
        self.msg_runner.service_get_by_compute_host(self.ctxt, fake_cell, "fake-host").AndReturn(fake_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)
Beispiel #21
0
    def test_instance_get_all_by_host(self, mock_get):
        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"),
        ]

        mock_get.return_value = instances
        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)
Beispiel #22
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)
Beispiel #23
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)
Beispiel #24
0
 def test_compute_node_get(self):
     fake_cell = 'fake-cell'
     fake_response = messaging.Response(fake_cell, FAKE_COMPUTE_NODES[0],
                                        False)
     expected_response = copy.deepcopy(FAKE_COMPUTE_NODES[0])
     cells_utils.add_cell_to_compute_node(expected_response, fake_cell)
     cell_and_id = cells_utils.cell_with_item(fake_cell, 'fake-id')
     self.mox.StubOutWithMock(self.msg_runner, 'compute_node_get')
     self.msg_runner.compute_node_get(self.ctxt, 'fake-cell',
                                      'fake-id').AndReturn(fake_response)
     self.mox.ReplayAll()
     response = self.cells_manager.compute_node_get(self.ctxt,
                                                    compute_id=cell_and_id)
     self.assertEqual(expected_response, response)
Beispiel #25
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)
Beispiel #26
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)
Beispiel #27
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" % (compute_rpcapi.RPC_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)
Beispiel #28
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)
Beispiel #29
0
    def test_service_get_by_compute_host(self):
        self.mox.StubOutWithMock(self.msg_runner,
                                 'service_get_by_compute_host')
        fake_cell = 'fake-cell'
        fake_response = messaging.Response(fake_cell, FAKE_SERVICES[0], False)
        expected_response = copy.deepcopy(FAKE_SERVICES[0])
        cells_utils.add_cell_to_service(expected_response, fake_cell)

        cell_and_host = cells_utils.cell_with_item('fake-cell', 'fake-host')
        self.msg_runner.service_get_by_compute_host(
            self.ctxt, fake_cell, 'fake-host').AndReturn(fake_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)
Beispiel #30
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)
Beispiel #31
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(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)
    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)
Beispiel #33
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)
Beispiel #34
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)
    def test_service_update(self):
        fake_cell = "fake-cell"
        fake_response = messaging.Response(fake_cell, FAKE_SERVICES[0], False)
        expected_response = copy.deepcopy(FAKE_SERVICES[0])
        cells_utils.add_cell_to_service(expected_response, 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.msg_runner.service_update(self.ctxt, fake_cell, "fake-host", "nova-api", params_to_update).AndReturn(
            fake_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)
Beispiel #36
0
    def test_service_update(self):
        fake_cell = 'fake-cell'
        fake_response = messaging.Response(
            fake_cell, FAKE_SERVICES[0], False)
        expected_response = copy.deepcopy(FAKE_SERVICES[0])
        cells_utils.add_cell_to_service(expected_response, 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.msg_runner.service_update(self.ctxt,
                fake_cell, 'fake-host', 'nova-api',
                params_to_update).AndReturn(fake_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)
Beispiel #37
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)
Beispiel #38
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)
Beispiel #39
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)
Beispiel #40
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)
Beispiel #41
0
 def id(self):
     return cells_utils.cell_with_item(self._cell_path, self._obj.id)
Beispiel #42
0
 def test_compute_node_get_using_uuid(self):
     cell_compute_uuid = cells_utils.cell_with_item('cell1', uuids.cn_uuid)
     with mock.patch.object(self.host_api.cells_rpcapi,
                            'compute_node_get') as compute_node_get:
         self.host_api.compute_node_get(self.ctxt, cell_compute_uuid)
     compute_node_get.assert_called_once_with(self.ctxt, cell_compute_uuid)
Beispiel #43
0
 def test_compute_node_get_using_uuid(self):
     cell_compute_uuid = cells_utils.cell_with_item('cell1', uuids.cn_uuid)
     with mock.patch.object(self.host_api.cells_rpcapi,
                            'compute_node_get') as compute_node_get:
         self.host_api.compute_node_get(self.ctxt, cell_compute_uuid)
     compute_node_get.assert_called_once_with(self.ctxt, cell_compute_uuid)
Beispiel #44
0
 def id(self):
     return cells_utils.cell_with_item(self._cell_path, self._obj.id)
Beispiel #45
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)