summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-08-03 23:11:03 -0400
committerRussell Bryant <rbryant@redhat.com>2012-08-06 15:09:33 -0400
commitabe509fae061f7c14d6b02e9718031e90cfb3ffa (patch)
treec66549e9ee5cc9fc835f9f852513c10ec0ab7ba4
parent2ed2c411a982e297d6b756f8a21939fadb2a0a93 (diff)
Send full instance to compute live_migration.
Remove the instance_id parameter and send a full instance to live_migration in the compute manager. This cuts down on database access required by the compute manager. Part of blueprint no-db-messaging. Change-Id: Ic21f061702704ddeaa6925aac4ecad69b0e8de18
-rw-r--r--nova/compute/manager.py28
-rw-r--r--nova/compute/rpcapi.py8
-rw-r--r--nova/scheduler/driver.py8
-rw-r--r--nova/tests/compute/test_compute.py8
-rw-r--r--nova/tests/compute/test_rpcapi.py5
-rw-r--r--nova/tests/scheduler/test_scheduler.py14
6 files changed, 42 insertions, 29 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index e57881e88..0da0e7319 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -273,7 +273,7 @@ def _get_image_meta(context, image_ref):
class ComputeManager(manager.SchedulerDependentManager):
"""Manages the running instances from creation to destruction."""
- RPC_API_VERSION = '1.39'
+ RPC_API_VERSION = '1.40'
def __init__(self, compute_driver=None, *args, **kwargs):
"""Load configuration options and connect to the hypervisor."""
@@ -2201,48 +2201,50 @@ class ComputeManager(manager.SchedulerDependentManager):
if block_migration:
self.driver.pre_block_migration(context, instance, disk)
- def live_migration(self, context, instance_id,
- dest, block_migration=False):
+ def live_migration(self, context, dest, block_migration=False,
+ instance=None, instance_id=None):
"""Executing live migration.
:param context: security context
- :param instance_id: nova.db.sqlalchemy.models.Instance.Id
+ :param instance_id: (deprecated) nova.db.sqlalchemy.models.Instance.Id
+ :param instance: instance dict
:param dest: destination host
:param block_migration: if true, prepare for block migration
"""
# Get instance for error handling.
- instance_ref = self.db.instance_get(context, instance_id)
+ if not instance:
+ instance = self.db.instance_get(context, instance_id)
try:
# Checking volume node is working correctly when any volumes
# are attached to instances.
- if self._get_instance_volume_bdms(context, instance_ref['uuid']):
+ if self._get_instance_volume_bdms(context, instance['uuid']):
rpc.call(context,
FLAGS.volume_topic,
{'method': 'check_for_export',
- 'args': {'instance_id': instance_id}})
+ 'args': {'instance_id': instance['id']}})
if block_migration:
- disk = self.driver.get_instance_disk_info(instance_ref.name)
+ disk = self.driver.get_instance_disk_info(instance['name'])
else:
disk = None
- self.compute_rpcapi.pre_live_migration(context, instance_ref,
+ self.compute_rpcapi.pre_live_migration(context, instance,
block_migration, disk, dest)
except Exception:
with excutils.save_and_reraise_exception():
- instance_uuid = instance_ref['uuid']
+ instance_uuid = instance['uuid']
LOG.exception(_('Pre live migration failed at %(dest)s'),
- locals(), instance=instance_ref)
- self.rollback_live_migration(context, instance_ref, dest,
+ locals(), instance=instance)
+ self.rollback_live_migration(context, instance, dest,
block_migration)
# Executing live migration
# live_migration might raises exceptions, but
# nothing must be recovered in this version.
- self.driver.live_migration(context, instance_ref, dest,
+ self.driver.live_migration(context, instance, dest,
self._post_live_migration,
self.rollback_live_migration,
block_migration)
diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py
index 72babd380..9b98f2ef5 100644
--- a/nova/compute/rpcapi.py
+++ b/nova/compute/rpcapi.py
@@ -118,6 +118,7 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
- remove instance_type_id, add instance_type
- remove topic, it was unused
1.39 - Remove instance_uuid, add instance argument to run_instance()
+ 1.40 - Remove instance_id, add instance argument to live_migration()
'''
BASE_RPC_API_VERSION = '1.0'
@@ -275,6 +276,13 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
topic=_compute_topic(self.topic, ctxt, None, instance),
version='1.19')
+ def live_migration(self, ctxt, instance, dest, block_migration, host):
+ instance_p = jsonutils.to_primitive(instance)
+ self.cast(ctxt, self.make_msg('live_migration', instance=instance_p,
+ dest=dest, block_migration=block_migration),
+ topic=_compute_topic(self.topic, ctxt, host, None),
+ version='1.40')
+
def pause_instance(self, ctxt, instance):
instance_p = jsonutils.to_primitive(instance)
self.cast(ctxt, self.make_msg('pause_instance',
diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py
index 6494957e2..3461ea508 100644
--- a/nova/scheduler/driver.py
+++ b/nova/scheduler/driver.py
@@ -238,11 +238,9 @@ class Scheduler(object):
# Perform migration
src = instance['host']
- cast_to_compute_host(context, src, 'live_migration',
- update_db=False,
- instance_id=instance['id'],
- dest=dest,
- block_migration=block_migration)
+ self.compute_rpcapi.live_migration(context, host=src,
+ instance=new_instance_ref, dest=dest,
+ block_migration=block_migration)
def _live_migration_src_check(self, context, instance_ref):
"""Live migration check routine (for src host).
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 8561d5124..5c6bc00d4 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -1663,7 +1663,7 @@ class ComputeTestCase(BaseTestCase):
self.mox.StubOutWithMock(self.compute.compute_rpcapi,
'pre_live_migration')
self.compute.compute_rpcapi.pre_live_migration(c,
- mox.IsA(instance_ref), True, None, instance['host']).AndRaise(
+ mox.IsA(instance), True, None, instance['host']).AndRaise(
rpc.common.RemoteError('', '', ''))
# mocks for rollback
@@ -1687,7 +1687,8 @@ class ComputeTestCase(BaseTestCase):
self.mox.ReplayAll()
self.assertRaises(rpc_common.RemoteError,
self.compute.live_migration,
- c, inst_id, instance['host'], True)
+ c, dest=instance['host'], block_migration=True,
+ instance=rpcinst)
# cleanup
for bdms in db.block_device_mapping_get_all_by_instance(
@@ -1719,7 +1720,8 @@ class ComputeTestCase(BaseTestCase):
# start test
self.mox.ReplayAll()
- ret = self.compute.live_migration(c, inst_id, instance['host'])
+ ret = self.compute.live_migration(c, dest=instance['host'],
+ instance=instance)
self.assertEqual(ret, None)
# cleanup
diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py
index ef9064a39..cfd00d505 100644
--- a/nova/tests/compute/test_rpcapi.py
+++ b/nova/tests/compute/test_rpcapi.py
@@ -188,6 +188,11 @@ class ComputeRpcAPITestCase(test.TestCase):
self._test_compute_api('inject_network_info', 'cast',
instance=self.fake_instance, version='1.19')
+ def test_live_migration(self):
+ self._test_compute_api('live_migration', 'cast',
+ instance=self.fake_instance, dest='dest',
+ block_migration='blockity_block', host='tsoh', version='1.40')
+
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',
diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py
index 3950d1ef6..cfb6d862d 100644
--- a/nova/tests/scheduler/test_scheduler.py
+++ b/nova/tests/scheduler/test_scheduler.py
@@ -409,7 +409,7 @@ class SchedulerTestCase(test.TestCase):
self.mox.StubOutWithMock(self.driver.compute_rpcapi,
'check_can_live_migrate_destination')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
- self.mox.StubOutWithMock(driver, 'cast_to_compute_host')
+ self.mox.StubOutWithMock(compute_rpcapi.ComputeAPI, 'live_migration')
self.mox.StubOutWithMock(notifications, 'send_update')
dest = 'fake_host2'
@@ -431,9 +431,8 @@ class SchedulerTestCase(test.TestCase):
notifications.send_update(self.context, instance, instance,
service="scheduler")
- driver.cast_to_compute_host(self.context, instance['host'],
- 'live_migration', update_db=False,
- instance_id=instance['id'], dest=dest,
+ compute_rpcapi.ComputeAPI.live_migration(self.context,
+ host=instance['host'], instance=instance, dest=dest,
block_migration=block_migration)
self.mox.ReplayAll()
@@ -451,7 +450,7 @@ class SchedulerTestCase(test.TestCase):
self.mox.StubOutWithMock(rpc, 'call')
self.mox.StubOutWithMock(rpc, 'cast')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
- self.mox.StubOutWithMock(driver, 'cast_to_compute_host')
+ self.mox.StubOutWithMock(compute_rpcapi.ComputeAPI, 'live_migration')
dest = 'fake_host2'
block_migration = True
@@ -498,9 +497,8 @@ class SchedulerTestCase(test.TestCase):
{"task_state": task_states.MIGRATING}).AndReturn(
(instance, instance))
- driver.cast_to_compute_host(self.context, instance['host'],
- 'live_migration', update_db=False,
- instance_id=instance_id, dest=dest,
+ compute_rpcapi.ComputeAPI.live_migration(self.context,
+ host=instance['host'], instance=instance, dest=dest,
block_migration=block_migration)
self.mox.ReplayAll()