Merge "Avoid live migrate overwriting the other task_state"

This commit is contained in:
Jenkins 2012-09-13 05:36:31 +00:00 committed by Gerrit Code Review
commit ef8d6a57a1
5 changed files with 29 additions and 22 deletions

View File

@ -1939,6 +1939,10 @@ class API(base.Base):
LOG.debug(_("Going to try to live migrate instance to %s"),
host, instance=instance)
instance = self.update(context, instance,
task_state=task_states.MIGRATING,
expected_task_state=None)
self.scheduler_rpcapi.live_migration(context, block_migration,
disk_over_commit, instance, host)

View File

@ -203,19 +203,10 @@ class Scheduler(object):
migrate_data = self.compute_rpcapi.check_can_live_migrate_destination(
context, instance, dest, block_migration, disk_over_commit)
# Change instance_state
values = {"task_state": task_states.MIGRATING}
# update instance state and notify
(old_ref, new_instance_ref) = db.instance_update_and_get_original(
context, instance['uuid'], values)
notifications.send_update(context, old_ref, new_instance_ref,
service="scheduler")
# Perform migration
src = instance['host']
self.compute_rpcapi.live_migration(context, host=src,
instance=new_instance_ref, dest=dest,
instance=instance, dest=dest,
block_migration=block_migration,
migrate_data=migrate_data)

View File

@ -139,6 +139,13 @@ class AdminActionsTest(test.TestCase):
}
})
req.content_type = 'application/json'
def fake_update(inst, context, instance,
task_state, expected_task_state):
return None
self.stubs.Set(compute.API, 'update', fake_update)
res = req.get_response(app)
self.assertEqual(res.status_int, 202)

View File

@ -80,6 +80,10 @@ class FakeSchedulerAPI(object):
filter_properties):
pass
def live_migration(self, ctxt, block_migration, disk_over_commit,
instance, dest):
pass
class BaseTestCase(test.TestCase):
@ -4483,6 +4487,19 @@ class ComputeAPITestCase(BaseTestCase):
self.security_group_api.trigger_rules_refresh(self.context, [1, 2])
def test_live_migrate(self):
instance, instance_uuid = self._run_instance()
self.compute_api.live_migrate(self.context, instance,
block_migration=True,
disk_over_commit=True,
host='fake_dest_host')
instance = db.instance_get_by_uuid(self.context, instance_uuid)
self.assertEqual(instance['task_state'], task_states.MIGRATING)
db.instance_destroy(self.context, instance['uuid'])
def fake_rpc_method(context, topic, msg, do_cast=True):
pass

View File

@ -311,10 +311,8 @@ class SchedulerTestCase(test.TestCase):
self.mox.StubOutWithMock(self.driver, '_live_migration_common_check')
self.mox.StubOutWithMock(self.driver.compute_rpcapi,
'check_can_live_migrate_destination')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
self.mox.StubOutWithMock(self.driver.compute_rpcapi,
'live_migration')
self.mox.StubOutWithMock(notifications, 'send_update')
dest = 'fake_host2'
block_migration = False
@ -330,11 +328,6 @@ class SchedulerTestCase(test.TestCase):
self.driver.compute_rpcapi.check_can_live_migrate_destination(
self.context, instance, dest, block_migration,
disk_over_commit).AndReturn({})
db.instance_update_and_get_original(self.context, instance_uuid,
{"task_state": task_states.MIGRATING}).AndReturn(
(instance, instance))
notifications.send_update(self.context, instance, instance,
service="scheduler")
self.driver.compute_rpcapi.live_migration(self.context,
host=instance['host'], instance=instance, dest=dest,
block_migration=block_migration, migrate_data={})
@ -353,7 +346,6 @@ class SchedulerTestCase(test.TestCase):
self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
self.mox.StubOutWithMock(rpc, 'call')
self.mox.StubOutWithMock(rpc, 'cast')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
self.mox.StubOutWithMock(self.driver.compute_rpcapi,
'live_migration')
@ -398,10 +390,6 @@ class SchedulerTestCase(test.TestCase):
"version": compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION},
None).AndReturn({})
db.instance_update_and_get_original(self.context, instance_uuid,
{"task_state": task_states.MIGRATING}).AndReturn(
(instance, instance))
self.driver.compute_rpcapi.live_migration(self.context,
host=instance['host'], instance=instance, dest=dest,
block_migration=block_migration, migrate_data={})