From 6aac5f1308aa3e360204bd8f4dcfe90522f6db2e Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 20 Jul 2012 10:56:29 -0400 Subject: Convert reboot_instance to take a full instance. Convert the reboot_instance method in the compute rpc API to take a full instance via rpc instead of just the instance UUID. This cuts down on database access needed by nova-compute. Part of blueprint no-db-messaging. Change-Id: Id2c455f66966a9b446e5bbbe542ed3a2b0655289 --- nova/tests/compute/test_compute.py | 17 ++++++++++------- nova/tests/compute/test_rpcapi.py | 8 ++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index f6bc0ee4f..93eb644c6 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -40,6 +40,7 @@ from nova import db from nova import exception from nova import flags from nova.openstack.common import importutils +from nova.openstack.common import jsonutils from nova.openstack.common import log as logging from nova.openstack.common.notifier import test_notifier from nova.openstack.common import policy as common_policy @@ -539,8 +540,9 @@ class ComputeTestCase(BaseTestCase): {'task_state': task_states.REBOOTING}) reboot_type = "SOFT" - self.compute.reboot_instance(self.context, instance['uuid'], - reboot_type) + self.compute.reboot_instance(self.context, + instance=jsonutils.to_primitive(instance), + reboot_type=reboot_type) inst_ref = db.instance_get_by_uuid(self.context, instance['uuid']) self.assertEqual(inst_ref['power_state'], power_state.RUNNING) @@ -556,8 +558,9 @@ class ComputeTestCase(BaseTestCase): {'task_state': task_states.REBOOTING_HARD}) reboot_type = "HARD" - self.compute.reboot_instance(self.context, instance['uuid'], - reboot_type) + self.compute.reboot_instance(self.context, + instance=jsonutils.to_primitive(instance), + reboot_type=reboot_type) inst_ref = db.instance_get_by_uuid(self.context, instance['uuid']) self.assertEqual(inst_ref['power_state'], power_state.RUNNING) @@ -1018,7 +1021,7 @@ class ComputeTestCase(BaseTestCase): self.compute.terminate_instance(self.context, instance['uuid']) def test_get_lock(self): - instance = self._create_fake_instance() + instance = jsonutils.to_primitive(self._create_fake_instance()) self.assertFalse(self.compute._get_lock(self.context, instance['uuid'])) db.instance_update(self.context, instance['uuid'], {'locked': True}) @@ -1037,13 +1040,13 @@ class ComputeTestCase(BaseTestCase): # decorator should return False (fail) with locked nonadmin context self.compute.lock_instance(self.context, instance_uuid) ret_val = self.compute.reboot_instance(non_admin_context, - instance_uuid) + instance=jsonutils.to_primitive(instance)) self.assertEqual(ret_val, False) # decorator should return None (success) with unlocked nonadmin context self.compute.unlock_instance(self.context, instance_uuid) ret_val = self.compute.reboot_instance(non_admin_context, - instance_uuid) + instance=jsonutils.to_primitive(instance)) self.assertEqual(ret_val, None) self.compute.terminate_instance(self.context, instance_uuid) diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py index 96b103393..080128f47 100644 --- a/nova/tests/compute/test_rpcapi.py +++ b/nova/tests/compute/test_rpcapi.py @@ -47,6 +47,9 @@ class ComputeRpcAPITestCase(test.TestCase): def _test_compute_api(self, method, rpc_method, **kwargs): ctxt = context.RequestContext('fake_user', 'fake_project') + + methods_with_instance = ['reboot_instance'] + if 'rpcapi_class' in kwargs: rpcapi_class = kwargs['rpcapi_class'] del kwargs['rpcapi_class'] @@ -65,7 +68,8 @@ class ComputeRpcAPITestCase(test.TestCase): del expected_msg['args']['host'] if 'destination' in expected_msg['args']: del expected_msg['args']['destination'] - if 'instance' in expected_msg['args']: + if 'instance' in expected_msg['args'] and (method not in + methods_with_instance): instance = expected_msg['args']['instance'] del expected_msg['args']['instance'] if method in ['rollback_live_migration_at_destination', @@ -219,7 +223,7 @@ class ComputeRpcAPITestCase(test.TestCase): def test_reboot_instance(self): self._test_compute_api('reboot_instance', 'cast', - instance=self.fake_instance, reboot_type='type') + instance=self.fake_instance, reboot_type='type', version='1.4') def test_rebuild_instance(self): self._test_compute_api('rebuild_instance', 'cast', -- cgit