summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-07-30 11:26:25 -0400
committerRussell Bryant <rbryant@redhat.com>2012-07-30 20:18:38 -0400
commit564def16ba2b684c0fbdaef1861b5fddd9ed4b5c (patch)
treecc909b0d204956fc9ad4e1a2bddd0c87ddb23410
parent9302771de4324ac86aad4a8ec0dfe13d4ec3a0cc (diff)
Send a full instance in resume_instance.
Change the resume_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: I57789eab047de7ff9b84e2bb5367139a9a7b8e40
-rw-r--r--nova/compute/manager.py17
-rw-r--r--nova/compute/rpcapi.py7
-rw-r--r--nova/tests/compute/test_compute.py7
-rw-r--r--nova/tests/compute/test_rpcapi.py6
4 files changed, 20 insertions, 17 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 9ce1e1c47..ff6723f9f 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -272,7 +272,7 @@ def _get_image_meta(context, image_ref):
class ComputeManager(manager.SchedulerDependentManager):
"""Manages the running instances from creation to destruction."""
- RPC_API_VERSION = '1.29'
+ RPC_API_VERSION = '1.30'
def __init__(self, compute_driver=None, *args, **kwargs):
"""Load configuration options and connect to the hypervisor."""
@@ -1804,22 +1804,23 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
@checks_instance_lock
@wrap_instance_fault
- def resume_instance(self, context, instance_uuid):
+ def resume_instance(self, context, instance=None, instance_uuid=None):
"""Resume the given suspended 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(_('Resuming'), context=context, instance=instance_ref)
- self.driver.resume(instance_ref)
+ LOG.audit(_('Resuming'), context=context, instance=instance)
+ self.driver.resume(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.ACTIVE,
task_state=None)
- self._notify_about_instance_usage(context, instance_ref, 'resume')
+ self._notify_about_instance_usage(context, instance, 'resume')
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
@wrap_instance_fault
diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py
index 4b982b6fb..b09211d1a 100644
--- a/nova/compute/rpcapi.py
+++ b/nova/compute/rpcapi.py
@@ -100,6 +100,7 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
rescue_instance()
1.28 - Remove instance_uuid, add instance argument to reset_network()
1.29 - Remove instance_uuid, add instance argument to resize_instance()
+ 1.30 - Remove instance_uuid, add instance argument to resume_instance()
'''
BASE_RPC_API_VERSION = '1.0'
@@ -370,9 +371,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
image=image), topic, version='1.29')
def resume_instance(self, ctxt, instance):
+ instance_p = jsonutils.to_primitive(instance)
self.cast(ctxt, self.make_msg('resume_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.30')
def revert_resize(self, ctxt, instance, migration_id, host):
self.cast(ctxt, self.make_msg('revert_resize',
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 831763f13..4e1c57201 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -499,12 +499,11 @@ class ComputeTestCase(BaseTestCase):
def test_suspend(self):
"""ensure instance can be suspended and resumed"""
- instance = self._create_fake_instance()
+ instance = jsonutils.to_primitive(self._create_fake_instance())
instance_uuid = instance['uuid']
self.compute.run_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.suspend_instance(self.context, instance=instance)
+ self.compute.resume_instance(self.context, instance=instance)
self.compute.terminate_instance(self.context, instance_uuid)
def test_suspend_error(self):
diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py
index 8defc7608..f47d081be 100644
--- a/nova/tests/compute/test_rpcapi.py
+++ b/nova/tests/compute/test_rpcapi.py
@@ -59,8 +59,8 @@ class ComputeRpcAPITestCase(test.TestCase):
'power_on_instance', 'pre_live_migration', 'reboot_instance',
'rebuild_instance', 'remove_fixed_ip_from_instance',
'remove_volume_connection', 'rescue_instance', 'reset_network',
- 'resize_instance', 'start_instance', 'stop_instance',
- 'suspend_instance', 'unpause_instance'
+ 'resize_instance', 'resume_instance', 'start_instance',
+ 'stop_instance', 'suspend_instance', 'unpause_instance'
]
if 'rpcapi_class' in kwargs:
@@ -281,7 +281,7 @@ class ComputeRpcAPITestCase(test.TestCase):
def test_resume_instance(self):
self._test_compute_api('resume_instance', 'cast',
- instance=self.fake_instance)
+ instance=self.fake_instance, version='1.30')
def test_revert_resize(self):
self._test_compute_api('revert_resize', 'cast',