summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorMatthew Sherborne <msherborne@gmail.com>2013-03-15 13:46:12 +1000
committerMatthew Sherborne <msherborne@gmail.com>2013-04-23 22:04:01 +1000
commit732bcdb9502aca5c6b38966bd1e53c79236300da (patch)
treee7a5ab2c4fd2fad84c66d64548833f3bc2309236 /nova/tests
parentbfc3a3ccb2811cc8a96a15987528e6639ec029bf (diff)
Make os.services.update work with cells
In the nova.api.openstack.compute.contrib.services: * Make update (enable/disable) service work In nova.compute.api.api.HostAPI: Add - service_update - Used by openstack api's services.py In nova.compute.api.cells_api.HostAPI: Add - service_update - Used by openstack api's services.py In cells: * Increase API version from 1.6 to 1.7 * Add service_update Fixes bug #1150499 Change-Id: I5651bd5bc328692df82f4d9da27d390a8c95e03f
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/cells/test_cells_manager.py20
-rw-r--r--nova/tests/cells/test_cells_messaging.py37
-rw-r--r--nova/tests/cells/test_cells_rpcapi.py14
-rw-r--r--nova/tests/compute/test_host_api.py39
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'),