From 1d0362929d2bbb39a5665b0d0ce9972ca66c643b Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 20 Jul 2012 15:58:49 -0400 Subject: Send a full instance via rpc for suspend_instance. Change the suspend_instance method of the compute rpc API to take a full instance over 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: If881fb419a52a2486b2e7b85b4d58a17f72c48a6 --- nova/compute/manager.py | 17 +++++++++-------- nova/compute/rpcapi.py | 7 +++++-- nova/tests/compute/test_compute.py | 3 ++- nova/tests/compute/test_rpcapi.py | 5 +++-- 4 files changed, 19 insertions(+), 13 deletions(-) (limited to 'nova') diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 9ebfe496b..368556dea 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -297,7 +297,7 @@ def _get_additional_capabilities(): class ComputeManager(manager.SchedulerDependentManager): """Manages the running instances from creation to destruction.""" - RPC_API_VERSION = '1.5' + RPC_API_VERSION = '1.6' def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -1783,22 +1783,23 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def suspend_instance(self, context, instance_uuid): + def suspend_instance(self, context, instance=None, instance_uuid=None): """Suspend the given instance.""" context = context.elevated() - instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) + if not instance: + instance = self.db.instance_get_by_uuid(context, instance_uuid) - LOG.audit(_('Suspending'), context=context, instance=instance_ref) - self.driver.suspend(instance_ref) + LOG.audit(_('Suspending'), context=context, instance=instance) + self.driver.suspend(instance) - current_power_state = self._get_power_state(context, instance_ref) + current_power_state = self._get_power_state(context, instance) self._instance_update(context, - instance_ref['uuid'], + instance['uuid'], power_state=current_power_state, vm_state=vm_states.SUSPENDED, task_state=None) - self._notify_about_instance_usage(context, instance_ref, 'suspend') + self._notify_about_instance_usage(context, instance, 'suspend') @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index d5de04452..c893bb0d5 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -62,6 +62,7 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): 1.4 - Remove instance_uuid, add instance argument to reboot_instance() 1.5 - Remove instance_uuid, add instance argument to pause_instance(), unpause_instance() + 1.6 - Remove instance_uuid, add instance argument to suspend_instance() ''' BASE_RPC_API_VERSION = '1.0' @@ -355,9 +356,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): topic=_compute_topic(self.topic, ctxt, None, instance)) def suspend_instance(self, ctxt, instance): + instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('suspend_instance', - instance_uuid=instance['uuid']), - topic=_compute_topic(self.topic, ctxt, None, instance)) + instance=instance_p), + topic=_compute_topic(self.topic, ctxt, None, instance), + version='1.6') def terminate_instance(self, ctxt, instance): self.cast(ctxt, self.make_msg('terminate_instance', diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 0c4d07e8e..63af3813b 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -503,7 +503,8 @@ class ComputeTestCase(BaseTestCase): instance = self._create_fake_instance() instance_uuid = instance['uuid'] self.compute.run_instance(self.context, instance_uuid) - self.compute.suspend_instance(self.context, instance_uuid) + self.compute.suspend_instance(self.context, + instance=jsonutils.to_primitive(instance)) self.compute.resume_instance(self.context, instance_uuid) 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 72942d352..5c0fcd006 100644 --- a/nova/tests/compute/test_rpcapi.py +++ b/nova/tests/compute/test_rpcapi.py @@ -49,7 +49,8 @@ class ComputeRpcAPITestCase(test.TestCase): ctxt = context.RequestContext('fake_user', 'fake_project') methods_with_instance = [ - 'pause_instance', 'reboot_instance', 'unpause_instance' + 'pause_instance', 'reboot_instance', 'suspend_instance', + 'unpause_instance' ] if 'rpcapi_class' in kwargs: @@ -310,7 +311,7 @@ class ComputeRpcAPITestCase(test.TestCase): def test_suspend_instance(self): self._test_compute_api('suspend_instance', 'cast', - instance=self.fake_instance) + instance=self.fake_instance, version='1.6') def test_terminate_instance(self): self._test_compute_api('terminate_instance', 'cast', -- cgit