From a019a9007d09d190ebd3005b4c13ba78e1ec0536 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 16 Jan 2013 18:49:56 +0000 Subject: Cells: Add cells support to hypervisors extension This removes the DB calls from the extension and moves them into HostAPI(). The cells version of HostAPI() proxies them to the appropriate cell or cells. Change-Id: I17ff10e62d2f10b85a557edcc1509ca3b0d15a29 --- .../openstack/compute/contrib/test_hypervisors.py | 4 +- nova/tests/cells/test_cells_manager.py | 58 +++++++++++++ nova/tests/cells/test_cells_messaging.py | 96 ++++++++++++++++++++++ nova/tests/cells/test_cells_rpcapi.py | 27 ++++++ 4 files changed, 183 insertions(+), 2 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/contrib/test_hypervisors.py b/nova/tests/api/openstack/compute/contrib/test_hypervisors.py index 4e4d214cc..f93c64487 100644 --- a/nova/tests/api/openstack/compute/contrib/test_hypervisors.py +++ b/nova/tests/api/openstack/compute/contrib/test_hypervisors.py @@ -267,7 +267,7 @@ class HypervisorsTest(test.TestCase): def fake_get_host_uptime(context, hyp): raise exc.HTTPNotImplemented() - self.stubs.Set(self.controller.api, 'get_host_uptime', + self.stubs.Set(self.controller.host_api, 'get_host_uptime', fake_get_host_uptime) req = fakes.HTTPRequest.blank('/v2/fake/os-hypervisors/1') @@ -278,7 +278,7 @@ class HypervisorsTest(test.TestCase): def fake_get_host_uptime(context, hyp): return "fake uptime" - self.stubs.Set(self.controller.api, 'get_host_uptime', + self.stubs.Set(self.controller.host_api, 'get_host_uptime', fake_get_host_uptime) req = fakes.HTTPRequest.blank('/v2/fake/os-hypervisors/1') diff --git a/nova/tests/cells/test_cells_manager.py b/nova/tests/cells/test_cells_manager.py index df670b91f..1ebbc407d 100644 --- a/nova/tests/cells/test_cells_manager.py +++ b/nova/tests/cells/test_cells_manager.py @@ -370,3 +370,61 @@ class CellsManagerClassTestCase(test.TestCase): period_beginning='fake-begin', period_ending='fake-end', host=cell_and_host, state='fake-state') self.assertEqual(expected_response, response) + + 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 xrange(3): + cell_name = 'path!to!cell%i' % i + compute_nodes = [] + for compute_node in FAKE_COMPUTE_NODES: + compute_nodes.append(copy.deepcopy(compute_node)) + expected_compute_node = copy.deepcopy(compute_node) + cells_utils.add_cell_to_compute_node(expected_compute_node, + cell_name) + expected_response.append(expected_compute_node) + response = messaging.Response(cell_name, compute_nodes, False) + responses.append(response) + self.mox.StubOutWithMock(self.msg_runner, + 'compute_node_get_all') + self.msg_runner.compute_node_get_all(self.ctxt, + hypervisor_match='fake-match').AndReturn(responses) + self.mox.ReplayAll() + response = self.cells_manager.compute_node_get_all(self.ctxt, + hypervisor_match='fake-match') + self.assertEqual(expected_response, response) + + def test_compute_node_stats(self): + raw_resp1 = {'key1': 1, 'key2': 2} + raw_resp2 = {'key2': 1, 'key3': 2} + raw_resp3 = {'key3': 1, 'key4': 2} + responses = [messaging.Response('cell1', raw_resp1, False), + messaging.Response('cell2', raw_resp2, False), + messaging.Response('cell2', raw_resp3, False)] + expected_resp = {'key1': 1, 'key2': 3, 'key3': 3, 'key4': 2} + + self.mox.StubOutWithMock(self.msg_runner, + 'compute_node_stats') + self.msg_runner.compute_node_stats(self.ctxt).AndReturn(responses) + self.mox.ReplayAll() + response = self.cells_manager.compute_node_stats(self.ctxt) + self.assertEqual(expected_resp, response) + + 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) diff --git a/nova/tests/cells/test_cells_messaging.py b/nova/tests/cells/test_cells_messaging.py index b505ea4f6..811ad17fd 100644 --- a/nova/tests/cells/test_cells_messaging.py +++ b/nova/tests/cells/test_cells_messaging.py @@ -811,6 +811,19 @@ class CellsTargetedMethodsTestCase(test.TestCase): result = response[0].value_or_raise() self.assertEqual(['fake_result'], result) + def test_compute_node_get(self): + compute_id = 'fake-id' + self.mox.StubOutWithMock(self.tgt_db_inst, 'compute_node_get') + self.tgt_db_inst.compute_node_get(self.ctxt, + compute_id).AndReturn('fake_result') + + self.mox.ReplayAll() + + response = self.src_msg_runner.compute_node_get(self.ctxt, + self.tgt_cell_name, compute_id) + result = response.value_or_raise() + self.assertEqual('fake_result', result) + class CellsBroadcastMethodsTestCase(test.TestCase): """Test case for _BroadcastMessageMethods class. Most of these @@ -1140,3 +1153,86 @@ class CellsBroadcastMethodsTestCase(test.TestCase): ('api-cell!child-cell2', [3]), ('api-cell', [1, 2])] self.assertEqual(expected, response_values) + + def test_compute_node_get_all(self): + # Reset this, as this is a broadcast down. + self._setup_attrs(up=False) + + ctxt = self.ctxt.elevated() + + self.mox.StubOutWithMock(self.src_db_inst, 'compute_node_get_all') + self.mox.StubOutWithMock(self.mid_db_inst, 'compute_node_get_all') + self.mox.StubOutWithMock(self.tgt_db_inst, 'compute_node_get_all') + + self.src_db_inst.compute_node_get_all(ctxt).AndReturn([1, 2]) + self.mid_db_inst.compute_node_get_all(ctxt).AndReturn([3]) + self.tgt_db_inst.compute_node_get_all(ctxt).AndReturn([4, 5]) + + self.mox.ReplayAll() + + responses = self.src_msg_runner.compute_node_get_all(ctxt) + response_values = [(resp.cell_name, resp.value_or_raise()) + for resp in responses] + expected = [('api-cell!child-cell2!grandchild-cell1', [4, 5]), + ('api-cell!child-cell2', [3]), + ('api-cell', [1, 2])] + self.assertEqual(expected, response_values) + + def test_compute_node_get_all_with_hyp_match(self): + # Reset this, as this is a broadcast down. + self._setup_attrs(up=False) + hypervisor_match = 'meow' + + ctxt = self.ctxt.elevated() + + self.mox.StubOutWithMock(self.src_db_inst, + 'compute_node_search_by_hypervisor') + self.mox.StubOutWithMock(self.mid_db_inst, + 'compute_node_search_by_hypervisor') + self.mox.StubOutWithMock(self.tgt_db_inst, + 'compute_node_search_by_hypervisor') + + self.src_db_inst.compute_node_search_by_hypervisor(ctxt, + hypervisor_match).AndReturn([1, 2]) + self.mid_db_inst.compute_node_search_by_hypervisor(ctxt, + hypervisor_match).AndReturn([3]) + self.tgt_db_inst.compute_node_search_by_hypervisor(ctxt, + hypervisor_match).AndReturn([4, 5]) + + self.mox.ReplayAll() + + responses = self.src_msg_runner.compute_node_get_all(ctxt, + hypervisor_match=hypervisor_match) + response_values = [(resp.cell_name, resp.value_or_raise()) + for resp in responses] + expected = [('api-cell!child-cell2!grandchild-cell1', [4, 5]), + ('api-cell!child-cell2', [3]), + ('api-cell', [1, 2])] + self.assertEqual(expected, response_values) + + def test_compute_node_stats(self): + # Reset this, as this is a broadcast down. + self._setup_attrs(up=False) + + ctxt = self.ctxt.elevated() + + self.mox.StubOutWithMock(self.src_db_inst, + 'compute_node_statistics') + self.mox.StubOutWithMock(self.mid_db_inst, + 'compute_node_statistics') + self.mox.StubOutWithMock(self.tgt_db_inst, + 'compute_node_statistics') + + self.src_db_inst.compute_node_statistics(ctxt).AndReturn([1, 2]) + self.mid_db_inst.compute_node_statistics(ctxt).AndReturn([3]) + self.tgt_db_inst.compute_node_statistics(ctxt).AndReturn([4, 5]) + + self.mox.ReplayAll() + + responses = self.src_msg_runner.compute_node_stats(ctxt) + response_values = [(resp.cell_name, resp.value_or_raise()) + for resp in responses] + expected = [('api-cell!child-cell2!grandchild-cell1', [4, 5]), + ('api-cell!child-cell2', [3]), + ('api-cell', [1, 2])] + self.assertEqual(expected, response_values) diff --git a/nova/tests/cells/test_cells_rpcapi.py b/nova/tests/cells/test_cells_rpcapi.py index c1e9b5ca8..d19ce5b2b 100644 --- a/nova/tests/cells/test_cells_rpcapi.py +++ b/nova/tests/cells/test_cells_rpcapi.py @@ -277,3 +277,30 @@ class CellsAPITestCase(test.TestCase): self._check_result(call_info, 'task_log_get_all', expected_args, version='1.3') self.assertEqual(result, 'fake_response') + + def test_compute_node_get_all(self): + call_info = self._stub_rpc_method('call', 'fake_response') + result = self.cells_rpcapi.compute_node_get_all(self.fake_context, + hypervisor_match='fake-match') + + expected_args = {'hypervisor_match': 'fake-match'} + self._check_result(call_info, 'compute_node_get_all', expected_args, + version='1.4') + self.assertEqual(result, 'fake_response') + + def test_compute_node_stats(self): + call_info = self._stub_rpc_method('call', 'fake_response') + result = self.cells_rpcapi.compute_node_stats(self.fake_context) + expected_args = {} + self._check_result(call_info, 'compute_node_stats', + expected_args, version='1.4') + self.assertEqual(result, 'fake_response') + + def test_compute_node_get(self): + call_info = self._stub_rpc_method('call', 'fake_response') + result = self.cells_rpcapi.compute_node_get(self.fake_context, + 'fake_compute_id') + expected_args = {'compute_id': 'fake_compute_id'} + self._check_result(call_info, 'compute_node_get', + expected_args, version='1.4') + self.assertEqual(result, 'fake_response') -- cgit