Handle MessageTimeout to MigrationPreCheckError

There are a few checks before live-migration, if any of the
check failed, the live-migration can't be done. However
during _call_livem_checks_on_host check, because it's a
RPC call ,so it might result in a MessageTimeout exception.
If this occurs, we should safely revert its state,
since no real opperation occured.

This patch translates the MessageTimeout to
MigrationPreCheckError and leverage existing MigrationPreCheckError
processing to revert instance to normal state instead of error

Closes-Bug: 1435633

Change-Id: I8b484abb6650e14e2d225ca5e476d1fa7a6ee990
This commit is contained in:
jichenjc 2015-03-23 00:36:43 +08:00
parent 5e61bc6d83
commit c0d0e5ccf6
2 changed files with 17 additions and 3 deletions

View File

@ -12,6 +12,7 @@
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from nova.compute import power_state
from nova.conductor.tasks import base
@ -141,9 +142,14 @@ class LiveMigrationTask(base.TaskBase):
raise exception.DestinationHypervisorTooOld()
def _call_livem_checks_on_host(self, destination):
self.migrate_data = self.compute_rpcapi.\
check_can_live_migrate_destination(self.context, self.instance,
destination, self.block_migration, self.disk_over_commit)
try:
self.migrate_data = self.compute_rpcapi.\
check_can_live_migrate_destination(self.context, self.instance,
destination, self.block_migration, self.disk_over_commit)
except messaging.MessagingTimeout:
msg = _("Timeout while checking if we can live migrate to host: "
"%s") % destination
raise exception.MigrationPreCheckError(msg)
def _find_destination(self):
# TODO(johngarbutt) this retry loop should be shared

View File

@ -12,6 +12,7 @@
import mock
from mox3 import mox
import oslo_messaging as messaging
from nova.compute import power_state
from nova.compute import rpcapi as compute_rpcapi
@ -445,3 +446,10 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
self.mox.ReplayAll()
self.assertRaises(exception.NoValidHost, self.task._find_destination)
def test_call_livem_checks_on_host(self):
with mock.patch.object(self.task.compute_rpcapi,
'check_can_live_migrate_destination',
side_effect=messaging.MessagingTimeout):
self.assertRaises(exception.MigrationPreCheckError,
self.task._call_livem_checks_on_host, {})