summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-07-20 10:56:29 -0400
committerRussell Bryant <rbryant@redhat.com>2012-07-25 19:52:14 -0400
commit6aac5f1308aa3e360204bd8f4dcfe90522f6db2e (patch)
tree46bb6eb0f526145fbf4f67e7b6544c5dc833c05e /nova
parentd030e29f5b0ba215789739e443f25ca1c80bc3da (diff)
downloadnova-6aac5f1308aa3e360204bd8f4dcfe90522f6db2e.tar.gz
nova-6aac5f1308aa3e360204bd8f4dcfe90522f6db2e.tar.xz
nova-6aac5f1308aa3e360204bd8f4dcfe90522f6db2e.zip
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
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/manager.py14
-rw-r--r--nova/compute/rpcapi.py8
-rw-r--r--nova/tests/compute/test_compute.py17
-rw-r--r--nova/tests/compute/test_rpcapi.py8
4 files changed, 29 insertions, 18 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 3e66bd20f..067bc584b 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.3'
+ RPC_API_VERSION = '1.4'
def __init__(self, compute_driver=None, *args, **kwargs):
"""Load configuration options and connect to the hypervisor."""
@@ -1090,18 +1090,19 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
@checks_instance_lock
@wrap_instance_fault
- def reboot_instance(self, context, instance_uuid, reboot_type="SOFT"):
+ def reboot_instance(self, context, instance=None, instance_uuid=None,
+ reboot_type="SOFT"):
"""Reboot an instance on this host."""
LOG.audit(_("Rebooting instance"), context=context,
instance_uuid=instance_uuid)
context = context.elevated()
- instance = self.db.instance_get_by_uuid(context, instance_uuid)
+ if not instance:
+ instance = self.db.instance_get_by_uuid(context, instance_uuid)
self._notify_about_instance_usage(context, instance, "reboot.start")
current_power_state = self._get_power_state(context, instance)
- self._instance_update(context,
- instance_uuid,
+ self._instance_update(context, instance['uuid'],
power_state=current_power_state,
vm_state=vm_states.ACTIVE)
@@ -1125,8 +1126,7 @@ class ComputeManager(manager.SchedulerDependentManager):
# Fall through and reset task_state to None
current_power_state = self._get_power_state(context, instance)
- self._instance_update(context,
- instance_uuid,
+ self._instance_update(context, instance['uuid'],
power_state=current_power_state,
vm_state=vm_states.ACTIVE,
task_state=None)
diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py
index e637c9f64..296ee476c 100644
--- a/nova/compute/rpcapi.py
+++ b/nova/compute/rpcapi.py
@@ -20,6 +20,7 @@ Client side of the compute RPC API.
from nova import exception
from nova import flags
+from nova.openstack.common import jsonutils
from nova.openstack.common import rpc
from nova.openstack.common.rpc import common as rpc_common
import nova.openstack.common.rpc.proxy
@@ -58,6 +59,7 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.1 - Adds get_host_uptime()
1.2 - Adds check_can_live_migrate_[destination|source]
1.3 - Adds change_instance_metadata()
+ 1.4 - Remove instance_uuid, add instance argument to reboot_instance()
'''
BASE_RPC_API_VERSION = '1.0'
@@ -235,9 +237,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
disk=disk), _compute_topic(self.topic, ctxt, host, None))
def reboot_instance(self, ctxt, instance, reboot_type):
+ instance_p = jsonutils.to_primitive(instance)
self.cast(ctxt, self.make_msg('reboot_instance',
- instance_uuid=instance['uuid'], reboot_type=reboot_type),
- topic=_compute_topic(self.topic, ctxt, None, instance))
+ instance=instance_p, reboot_type=reboot_type),
+ topic=_compute_topic(self.topic, ctxt, None, instance),
+ version='1.4')
def rebuild_instance(self, ctxt, instance, new_pass, injected_files,
image_ref, orig_image_ref):
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',