summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-07-26 16:45:22 -0400
committerRussell Bryant <rbryant@redhat.com>2012-07-26 18:46:32 -0400
commitd5c3271b1159ea3dfce3c0bf56b75006784ee439 (patch)
treef1a07d430f26990985c7b4f94e213751a6ac1f04
parent2203249e190535aff7799a689effff77743fba61 (diff)
Send a full instance via rpc for post_live_migration_at_destination.
Change the post_live_migration_at_destination 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. The method got moved in rpcapi.py, but that was just to restore alphabetical order. Part of blueprint no-db-messaging. Change-Id: Ib36cb065f838f644e97b6e82b39409737df15558
-rw-r--r--nova/compute/manager.py24
-rw-r--r--nova/compute/rpcapi.py18
-rw-r--r--nova/tests/compute/test_compute.py8
-rw-r--r--nova/tests/compute/test_rpcapi.py13
4 files changed, 32 insertions, 31 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index ae47b6caa..7e555b010 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -298,7 +298,7 @@ def _get_additional_capabilities():
class ComputeManager(manager.SchedulerDependentManager):
"""Manages the running instances from creation to destruction."""
- RPC_API_VERSION = '1.19'
+ RPC_API_VERSION = '1.20'
def __init__(self, compute_driver=None, *args, **kwargs):
"""Load configuration options and connect to the hypervisor."""
@@ -2338,7 +2338,8 @@ class ComputeManager(manager.SchedulerDependentManager):
"This error can be safely ignored."),
instance=instance_ref)
- def post_live_migration_at_destination(self, context, instance_id,
+ def post_live_migration_at_destination(self, context, instance=None,
+ instance_id=None,
block_migration=False):
"""Post operations for live migration .
@@ -2347,34 +2348,33 @@ class ComputeManager(manager.SchedulerDependentManager):
:param block_migration: if true, prepare for block migration
"""
- instance_ref = self.db.instance_get(context, instance_id)
+ if not instance:
+ instance = self.db.instance_get(context, instance_id)
LOG.info(_('Post operation of migraton started'),
- instance=instance_ref)
+ instance=instance)
# NOTE(tr3buchet): setup networks on destination host
# this is called a second time because
# multi_host does not create the bridge in
# plug_vifs
- self.network_api.setup_networks_on_host(context, instance_ref,
+ self.network_api.setup_networks_on_host(context, instance,
self.host)
- network_info = self._get_instance_nw_info(context, instance_ref)
- self.driver.post_live_migration_at_destination(context, instance_ref,
+ network_info = self._get_instance_nw_info(context, instance)
+ self.driver.post_live_migration_at_destination(context, instance,
self._legacy_nw_info(network_info),
block_migration)
# Restore instance state
- 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'],
host=self.host,
power_state=current_power_state,
vm_state=vm_states.ACTIVE,
task_state=None)
# NOTE(vish): this is necessary to update dhcp
- self.network_api.setup_networks_on_host(context,
- instance_ref,
- self.host)
+ self.network_api.setup_networks_on_host(context, instance, self.host)
def rollback_live_migration(self, context, instance_ref,
dest, block_migration):
diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py
index 4b012de78..7243e37c5 100644
--- a/nova/compute/rpcapi.py
+++ b/nova/compute/rpcapi.py
@@ -82,6 +82,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.18 - Remove instance_uuid, add instance argument to inject_file()
1.19 - Remove instance_uuid, add instance argument to
inject_network_info()
+ 1.20 - Remove instance_id, add instance argument to
+ post_live_migration_at_destination()
'''
BASE_RPC_API_VERSION = '1.0'
@@ -232,13 +234,6 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
topic=_compute_topic(self.topic, ctxt, None, instance),
version='1.19')
- def post_live_migration_at_destination(self, ctxt, instance,
- block_migration, host):
- return self.call(ctxt,
- self.make_msg('post_live_migration_at_destination',
- instance_id=instance['id'], block_migration=block_migration),
- _compute_topic(self.topic, ctxt, host, None))
-
def pause_instance(self, ctxt, instance):
instance_p = jsonutils.to_primitive(instance)
self.cast(ctxt, self.make_msg('pause_instance',
@@ -246,6 +241,15 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
topic=_compute_topic(self.topic, ctxt, None, instance),
version='1.5')
+ def post_live_migration_at_destination(self, ctxt, instance,
+ block_migration, host):
+ instance_p = jsonutils.to_primitive(instance)
+ return self.call(ctxt,
+ self.make_msg('post_live_migration_at_destination',
+ instance=instance_p, block_migration=block_migration),
+ _compute_topic(self.topic, ctxt, host, None),
+ version='1.20')
+
def power_off_instance(self, ctxt, instance):
self.cast(ctxt, self.make_msg('power_off_instance',
instance_uuid=instance['uuid']),
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 76b3666a7..9fcb004a4 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -1658,9 +1658,9 @@ class ComputeTestCase(BaseTestCase):
# creating testdata
c = context.get_admin_context()
- inst_ref = self._create_fake_instance({
+ inst_ref = jsonutils.to_primitive(self._create_fake_instance({
'state_description': 'migrating',
- 'state': power_state.PAUSED})
+ 'state': power_state.PAUSED}))
inst_uuid = inst_ref['uuid']
inst_id = inst_ref['id']
@@ -1680,8 +1680,8 @@ class ComputeTestCase(BaseTestCase):
self.mox.StubOutWithMock(rpc, 'call')
rpc.call(c, rpc.queue_get_for(c, FLAGS.compute_topic, dest),
{"method": "post_live_migration_at_destination",
- "args": {'instance_id': inst_id, 'block_migration': False},
- "version": "1.0"}, None)
+ "args": {'instance': inst_ref, 'block_migration': False},
+ "version": "1.20"}, None)
self.mox.StubOutWithMock(self.compute.driver, 'unplug_vifs')
self.compute.driver.unplug_vifs(inst_ref, [])
rpc.call(c, 'network', {'method': 'setup_networks_on_host',
diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py
index 181fbfa91..9644ce8d8 100644
--- a/nova/tests/compute/test_rpcapi.py
+++ b/nova/tests/compute/test_rpcapi.py
@@ -54,9 +54,9 @@ class ComputeRpcAPITestCase(test.TestCase):
'check_can_live_migrate_source', 'confirm_resize',
'detach_volume', 'finish_resize', 'finish_revert_resize',
'get_console_output', 'get_diagnostics', 'get_vnc_console',
- 'inject_file', 'inject_network_info',
- 'pause_instance', 'reboot_instance', 'suspend_instance',
- 'unpause_instance'
+ 'inject_file', 'inject_network_info', 'pause_instance',
+ 'post_live_migration_at_destination', 'reboot_instance',
+ 'suspend_instance', 'unpause_instance'
]
if 'rpcapi_class' in kwargs:
@@ -82,10 +82,7 @@ class ComputeRpcAPITestCase(test.TestCase):
instance = expected_msg['args']['instance']
del expected_msg['args']['instance']
if method in ['rollback_live_migration_at_destination',
- 'pre_live_migration', 'remove_volume_connection',
- 'post_live_migration_at_destination',
- 'check_can_live_migrate_destination',
- 'check_can_live_migrate_source']:
+ 'pre_live_migration', 'remove_volume_connection']:
expected_msg['args']['instance_id'] = instance['id']
else:
expected_msg['args']['instance_uuid'] = instance['uuid']
@@ -209,7 +206,7 @@ class ComputeRpcAPITestCase(test.TestCase):
def test_post_live_migration_at_destination(self):
self._test_compute_api('post_live_migration_at_destination', 'call',
instance=self.fake_instance, block_migration='block_migration',
- host='host')
+ host='host', version='1.20')
def test_pause_instance(self):
self._test_compute_api('pause_instance', 'cast',