Merge "reset task_state after select_destinations failed."

This commit is contained in:
Jenkins 2016-02-18 17:56:32 +00:00 committed by Gerrit Code Review
commit d51c5670d8
5 changed files with 40 additions and 4 deletions

View File

@ -318,7 +318,8 @@ class ComputeTaskManager(base.Base):
exception.HypervisorUnavailable,
exception.InstanceInvalidState,
exception.MigrationPreCheckError,
exception.LiveMigrationWithOldNovaNotSafe) as ex:
exception.LiveMigrationWithOldNovaNotSafe,
exception.MigrationSchedulerRPCError) as ex:
with excutils.save_and_reraise_exception():
# TODO(johngarbutt) - eventually need instance actions here
_set_vm_state(context, instance, ex, instance.vm_state)

View File

@ -13,6 +13,7 @@
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
import six
from nova.compute import power_state
from nova.conductor.tasks import base
@ -177,8 +178,17 @@ class LiveMigrationTask(base.TaskBase):
# scheduler.utils methods to directly use the RequestSpec object
spec_obj = objects.RequestSpec.from_primitives(
self.context, request_spec, filter_properties)
host = self.scheduler_client.select_destinations(self.context,
spec_obj)[0]['host']
try:
host = self.scheduler_client.select_destinations(self.context,
spec_obj)[0]['host']
except messaging.RemoteError as ex:
# TODO(ShaoHe Feng) There maybe multi-scheduler, and the
# scheduling algorithm is R-R, we can let other scheduler try.
# Note(ShaoHe Feng) There are types of RemoteError, such as
# NoSuchMethod, UnsupportedVersion, we can distinguish it by
# ex.exc_type.
raise exception.MigrationSchedulerRPCError(
reason=six.text_type(ex))
try:
self._check_compatible_with_source_hypervisor(host)
self._call_livem_checks_on_host(host)

View File

@ -1321,6 +1321,10 @@ class MigrationPreCheckError(MigrationError):
msg_fmt = _("Migration pre-check error: %(reason)s")
class MigrationSchedulerRPCError(MigrationError):
msg_fmt = _("Migration select destinations error: %(reason)s")
class MalformedRequestBody(NovaException):
msg_fmt = _("Malformed message body: %(reason)s")

View File

@ -16,6 +16,7 @@ import oslo_messaging as messaging
from nova.compute import power_state
from nova.compute import rpcapi as compute_rpcapi
from nova.compute import vm_states
from nova.conductor.tasks import live_migrate
from nova import exception
from nova import objects
@ -38,6 +39,7 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
host=self.instance_host,
uuid=self.instance_uuid,
power_state=power_state.RUNNING,
vm_state = vm_states.ACTIVE,
memory_mb=512,
image_ref=self.instance_image)
self.instance = objects.Instance._from_db_object(
@ -501,6 +503,24 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
self.mox.ReplayAll()
self.assertRaises(exception.NoValidHost, self.task._find_destination)
@mock.patch("nova.utils.get_image_from_system_metadata")
@mock.patch("nova.scheduler.utils.build_request_spec")
@mock.patch("nova.scheduler.utils.setup_instance_group")
@mock.patch("nova.objects.RequestSpec.from_primitives")
def test_find_destination_with_remoteError(self,
m_from_primitives, m_setup_instance_group,
m_build_request_spec, m_get_image_from_system_metadata):
m_get_image_from_system_metadata.return_value = {'properties': {}}
m_build_request_spec.return_value = {}
fake_spec = objects.RequestSpec()
m_from_primitives.return_value = fake_spec
with mock.patch.object(self.task.scheduler_client,
'select_destinations') as m_select_destinations:
error = messaging.RemoteError()
m_select_destinations.side_effect = error
self.assertRaises(exception.MigrationSchedulerRPCError,
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',

View File

@ -1109,7 +1109,8 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
exc.InvalidHypervisorType(),
exc.InvalidCPUInfo(reason='dummy'),
exc.UnableToMigrateToSelf(instance_id='dummy', host='dummy'),
exc.InvalidLocalStorage(path='dummy', reason='dummy')]
exc.InvalidLocalStorage(path='dummy', reason='dummy'),
exc.MigrationSchedulerRPCError(reason='dummy')]
for ex in exs:
self._test_migrate_server_deals_with_expected_exceptions(ex)