Fix host validity check for live-migration
When live migrating instance to invalid host, live migration fails
with host not found and sets instance task state to migrating.
This change handles host validity in API layer before changing instance
task_state to 'MIGRATING' and raise proper exception on invalid host.
Change-Id: I7c5e80298b9adf1bd53cc6c464a3744b5397b7e8
Related-Bug: #1643623
Closes-Bug: #1785031
(cherry picked from commit c7aed3d139
)
This commit is contained in:
parent
b0f6ff4da0
commit
0a60496ddb
|
@ -4258,6 +4258,11 @@ class API(base.Base):
|
|||
LOG.debug("Going to try to live migrate instance to %s",
|
||||
host_name or "another host", instance=instance)
|
||||
|
||||
if host_name:
|
||||
# Validate the specified host before changing the instance task
|
||||
# state.
|
||||
nodes = objects.ComputeNodeList.get_all_by_host(context, host_name)
|
||||
|
||||
instance.task_state = task_states.MIGRATING
|
||||
instance.save(expected_task_state=[None])
|
||||
|
||||
|
@ -4277,7 +4282,6 @@ class API(base.Base):
|
|||
|
||||
# NOTE(sbauza): Force is a boolean by the new related API version
|
||||
if force is False and host_name:
|
||||
nodes = objects.ComputeNodeList.get_all_by_host(context, host_name)
|
||||
# Unset the host to make sure we call the scheduler
|
||||
# from the conductor LiveMigrationTask. Yes this is tightly-coupled
|
||||
# to behavior in conductor and not great.
|
||||
|
|
|
@ -2471,21 +2471,25 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
self.compute_api.get_instance_diagnostics,
|
||||
self.context, instance)
|
||||
|
||||
def test_live_migrate_active_vm_state(self):
|
||||
@mock.patch.object(objects.ComputeNodeList, 'get_all_by_host')
|
||||
def test_live_migrate_active_vm_state(self, mock_nodelist):
|
||||
instance = self._create_instance_obj()
|
||||
self._live_migrate_instance(instance)
|
||||
|
||||
def test_live_migrate_paused_vm_state(self):
|
||||
@mock.patch.object(objects.ComputeNodeList, 'get_all_by_host')
|
||||
def test_live_migrate_paused_vm_state(self, mock_nodelist):
|
||||
paused_state = dict(vm_state=vm_states.PAUSED)
|
||||
instance = self._create_instance_obj(params=paused_state)
|
||||
self._live_migrate_instance(instance)
|
||||
|
||||
@mock.patch.object(objects.ComputeNodeList, 'get_all_by_host')
|
||||
@mock.patch.object(compute_utils, 'add_instance_fault_from_exc')
|
||||
@mock.patch.object(objects.RequestSpec, 'get_by_instance_uuid')
|
||||
@mock.patch.object(objects.InstanceAction, 'action_start')
|
||||
@mock.patch.object(objects.Instance, 'save')
|
||||
def test_live_migrate_messaging_timeout(self, _save, _action, get_spec,
|
||||
add_instance_fault_from_exc):
|
||||
add_instance_fault_from_exc,
|
||||
mock_nodelist):
|
||||
instance = self._create_instance_obj()
|
||||
if self.cell_type == 'api':
|
||||
api = self.compute_api.cells_rpcapi
|
||||
|
@ -2504,6 +2508,23 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
instance,
|
||||
mock.ANY)
|
||||
|
||||
@mock.patch.object(objects.RequestSpec, 'get_by_instance_uuid')
|
||||
@mock.patch.object(objects.InstanceAction, 'action_start')
|
||||
@mock.patch.object(objects.ComputeNodeList, 'get_all_by_host',
|
||||
side_effect=exception.ComputeHostNotFound(
|
||||
host='fake_host'))
|
||||
def test_live_migrate_computehost_notfound(self, mock_nodelist,
|
||||
mock_action,
|
||||
mock_get_spec):
|
||||
instance = self._create_instance_obj()
|
||||
self.assertRaises(exception.ComputeHostNotFound,
|
||||
self.compute_api.live_migrate,
|
||||
self.context, instance,
|
||||
host_name='fake_host',
|
||||
block_migration='auto',
|
||||
disk_over_commit=False)
|
||||
self.assertIsNone(instance.task_state)
|
||||
|
||||
@mock.patch.object(objects.RequestSpec, 'get_by_instance_uuid')
|
||||
@mock.patch.object(objects.Instance, 'save')
|
||||
@mock.patch.object(objects.InstanceAction, 'action_start')
|
||||
|
|
|
@ -671,10 +671,12 @@ class CellsConductorAPIRPCRedirect(test.NoDBTestCase):
|
|||
self.compute_api.resize(self.context, instance)
|
||||
self.assertTrue(self.cells_rpcapi.resize_instance.called)
|
||||
|
||||
@mock.patch.object(objects.ComputeNodeList, 'get_all_by_host')
|
||||
@mock.patch.object(objects.RequestSpec, 'get_by_instance_uuid')
|
||||
@mock.patch.object(compute_api.API, '_record_action_start')
|
||||
@mock.patch.object(objects.Instance, 'save')
|
||||
def test_live_migrate_instance(self, instance_save, _record, _get_spec):
|
||||
def test_live_migrate_instance(self, instance_save, _record, _get_spec,
|
||||
mock_nodelist):
|
||||
orig_system_metadata = {}
|
||||
instance = fake_instance.fake_instance_obj(self.context,
|
||||
vm_state=vm_states.ACTIVE, cell_name='fake-cell',
|
||||
|
|
Loading…
Reference in New Issue