Skip to content

Commit

Permalink
Merge "reset task_state after select_destinations failed."
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Feb 18, 2016
2 parents 4fade90 + 30d5d80 commit d51c567
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
3 changes: 2 additions & 1 deletion nova/conductor/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ def _set_vm_state(context, instance, ex, vm_state=None,
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)
Expand Down
14 changes: 12 additions & 2 deletions nova/conductor/tasks/live_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -177,8 +178,17 @@ def _find_destination(self):
# 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)
Expand Down
4 changes: 4 additions & 0 deletions nova/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
20 changes: 20 additions & 0 deletions nova/tests/unit/conductor/tasks/test_live_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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
Expand All @@ -38,6 +39,7 @@ def setUp(self):
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(
Expand Down Expand Up @@ -501,6 +503,24 @@ def test_find_destination_when_runs_out_of_hosts(self):
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',
Expand Down
3 changes: 2 additions & 1 deletion nova/tests/unit/conductor/test_conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,8 @@ def test_migrate_server_deals_with_expected_exception(self):
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)

Expand Down

0 comments on commit d51c567

Please sign in to comment.