diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-04-24 14:00:25 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-04-24 14:00:25 +0000 |
| commit | 276c320b105a8527291bb695bccdb34e135f3395 (patch) | |
| tree | 9729a3cd358c866ae04de1dc61d1e16321ab7135 /nova/tests | |
| parent | 77253569750b5a6a83cbb410eaa43f5df6d187de (diff) | |
| parent | 732bcdb9502aca5c6b38966bd1e53c79236300da (diff) | |
Merge "Make os.services.update work with cells"
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/cells/test_cells_manager.py | 20 | ||||
| -rw-r--r-- | nova/tests/cells/test_cells_messaging.py | 37 | ||||
| -rw-r--r-- | nova/tests/cells/test_cells_rpcapi.py | 14 | ||||
| -rw-r--r-- | nova/tests/compute/test_host_api.py | 39 |
4 files changed, 110 insertions, 0 deletions
diff --git a/nova/tests/cells/test_cells_manager.py b/nova/tests/cells/test_cells_manager.py index 74a7e9834..137d48ff6 100644 --- a/nova/tests/cells/test_cells_manager.py +++ b/nova/tests/cells/test_cells_manager.py @@ -294,6 +294,26 @@ class CellsManagerClassTestCase(test.TestCase): host_name=cell_and_host) 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) + def test_proxy_rpc_to_manager(self): self.mox.StubOutWithMock(self.msg_runner, 'proxy_rpc_to_manager') diff --git a/nova/tests/cells/test_cells_messaging.py b/nova/tests/cells/test_cells_messaging.py index bed27085f..728856006 100644 --- a/nova/tests/cells/test_cells_messaging.py +++ b/nova/tests/cells/test_cells_messaging.py @@ -20,6 +20,7 @@ from oslo.config import cfg from nova.cells import messaging from nova.cells import utils as cells_utils from nova import context +from nova import db from nova import exception from nova.openstack.common import rpc from nova.openstack.common import timeutils @@ -745,6 +746,42 @@ class CellsTargetedMethodsTestCase(test.TestCase): result = response.value_or_raise() self.assertEqual('fake-service', result) + def test_service_update(self): + binary = 'nova-compute' + fake_service = dict(id=42, host='fake_host', binary='nova-compute', + topic='compute') + fake_compute = dict( + id=7116, service_id=42, host='fake_host', vcpus=0, memory_mb=0, + local_gb=0, vcpus_used=0, memory_mb_used=0, local_gb_used=0, + hypervisor_type=0, hypervisor_version=0, hypervisor_hostname=0, + free_ram_mb=0, free_disk_gb=0, current_workload=0, running_vms=0, + cpu_info='HAL', disk_available_least=0) + params_to_update = {'disabled': True, 'report_count': 13} + + ctxt = context.RequestContext('fake_user', 'fake_project', + is_admin=True) + # We use the real DB for this test, as it's too hard to reach the + # host_api to mock out its DB methods + db.service_create(ctxt, fake_service) + db.compute_node_create(ctxt, fake_compute) + + self.mox.ReplayAll() + + response = self.src_msg_runner.service_update( + ctxt, self.tgt_cell_name, + 'fake_host', binary, params_to_update) + result = response.value_or_raise() + result.pop('created_at', None) + result.pop('updated_at', None) + expected_result = dict( + deleted=0, deleted_at=None, + binary=fake_service['binary'], + disabled=True, # We just updated this.. + report_count=13, # ..and this + host='fake_host', id=42, + topic='compute') + self.assertEqual(expected_result, result) + def test_proxy_rpc_to_manager_call(self): fake_topic = 'fake-topic' fake_rpc_message = 'fake-rpc-message' diff --git a/nova/tests/cells/test_cells_rpcapi.py b/nova/tests/cells/test_cells_rpcapi.py index 0a5c6a71b..76c9f05d3 100644 --- a/nova/tests/cells/test_cells_rpcapi.py +++ b/nova/tests/cells/test_cells_rpcapi.py @@ -248,6 +248,20 @@ class CellsAPITestCase(test.TestCase): version='1.2') self.assertEqual(result, 'fake_response') + def test_service_update(self): + call_info = self._stub_rpc_method('call', 'fake_response') + result = self.cells_rpcapi.service_update( + self.fake_context, host_name='fake-host-name', + binary='nova-api', params_to_update={'disabled': True}) + expected_args = { + 'host_name': 'fake-host-name', + 'binary': 'nova-api', + 'params_to_update': {'disabled': True}} + self._check_result(call_info, 'service_update', + expected_args, + version='1.7') + self.assertEqual(result, 'fake_response') + def test_proxy_rpc_to_manager(self): call_info = self._stub_rpc_method('call', 'fake_response') result = self.cells_rpcapi.proxy_rpc_to_manager( diff --git a/nova/tests/compute/test_host_api.py b/nova/tests/compute/test_host_api.py index 66dd1d739..6a87205ae 100644 --- a/nova/tests/compute/test_host_api.py +++ b/nova/tests/compute/test_host_api.py @@ -205,6 +205,27 @@ class ComputeHostAPITestCase(test.TestCase): 'fake-host') self.assertEqual('fake-response', result) + def test_service_update(self): + host_name = 'fake-host' + binary = 'nova-compute' + params_to_update = dict(disabled=True) + service_id = 42 + expected_result = {'id': service_id} + + self.mox.StubOutWithMock(self.host_api.db, 'service_get_by_args') + self.host_api.db.service_get_by_args(self.ctxt, + host_name, binary).AndReturn({'id': service_id}) + + self.mox.StubOutWithMock(self.host_api.db, 'service_update') + self.host_api.db.service_update( + self.ctxt, service_id, params_to_update).AndReturn(expected_result) + + self.mox.ReplayAll() + + result = self.host_api.service_update( + self.ctxt, host_name, binary, params_to_update) + self.assertEqual(expected_result, result) + def test_instance_get_all_by_host(self): self.mox.StubOutWithMock(self.host_api.db, 'instance_get_all_by_host') @@ -312,6 +333,24 @@ class ComputeHostAPICellsTestCase(ComputeHostAPITestCase): 'fake-host') self.assertEqual('fake-response', result) + def test_service_update(self): + host_name = 'fake-host' + binary = 'nova-compute' + params_to_update = dict(disabled=True) + service_id = 42 + expected_result = {'id': service_id} + + 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(expected_result) + + self.mox.ReplayAll() + + result = self.host_api.service_update( + self.ctxt, host_name, binary, params_to_update) + self.assertEqual(expected_result, result) + 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'), |
