Skip to content

Commit 15502dd

Browse files
SeanMooneyauniyal61
authored andcommitted
[compute] always set instance.host in post_livemigration
This change add a new _post_live_migration_update_host function that wraps _post_live_migration and just ensures that if we exit due to an exception instance.host is set to the destination host. when we are in _post_live_migration the guest has already started running on the destination host and we cannot revert. Sometimes admins or users will hard reboot the instance expecting that to fix everything when the vm enters the error state after the failed migrations. Previously this would end up recreating the instance on the source node leading to possible data corruption if the instance used shared storage. Change-Id: Ibc4bc7edf1c8d1e841c72c9188a0a62836e9f153 Partial-Bug: #1628606 (cherry picked from commit 8449b7c) (cherry picked from commit 643b0c7) (cherry picked from commit 17ae907)
1 parent 5efcc3f commit 15502dd

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

nova/compute/manager.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8472,8 +8472,9 @@ def _do_live_migration(self, context, dest, instance, block_migration,
84728472
# host attachment. We fetch BDMs before that to retain connection_info
84738473
# and attachment_id relating to the source host for post migration
84748474
# cleanup.
8475-
post_live_migration = functools.partial(self._post_live_migration,
8476-
source_bdms=source_bdms)
8475+
post_live_migration = functools.partial(
8476+
self._post_live_migration_update_host, source_bdms=source_bdms
8477+
)
84778478
rollback_live_migration = functools.partial(
84788479
self._rollback_live_migration, source_bdms=source_bdms)
84798480

@@ -8745,6 +8746,42 @@ def _post_live_migration_remove_source_vol_connections(
87458746
bdm.attachment_id, self.host,
87468747
str(e), instance=instance)
87478748

8749+
# TODO(sean-k-mooney): add typing
8750+
def _post_live_migration_update_host(
8751+
self, ctxt, instance, dest, block_migration=False,
8752+
migrate_data=None, source_bdms=None
8753+
):
8754+
try:
8755+
self._post_live_migration(
8756+
ctxt, instance, dest, block_migration, migrate_data,
8757+
source_bdms)
8758+
except Exception:
8759+
# Restore the instance object
8760+
node_name = None
8761+
try:
8762+
# get node name of compute, where instance will be
8763+
# running after migration, that is destination host
8764+
compute_node = self._get_compute_info(ctxt, dest)
8765+
node_name = compute_node.hypervisor_hostname
8766+
except exception.ComputeHostNotFound:
8767+
LOG.exception('Failed to get compute_info for %s', dest)
8768+
8769+
# we can never rollback from post live migration and we can only
8770+
# get here if the instance is running on the dest so we ensure
8771+
# the instance.host is set correctly and reraise the original
8772+
# exception unmodified.
8773+
if instance.host != dest:
8774+
# apply saves the new fields while drop actually removes the
8775+
# migration context from the instance, so migration persists.
8776+
instance.apply_migration_context()
8777+
instance.drop_migration_context()
8778+
instance.host = dest
8779+
instance.task_state = None
8780+
instance.node = node_name
8781+
instance.progress = 0
8782+
instance.save()
8783+
raise
8784+
87488785
@wrap_exception()
87498786
@wrap_instance_fault
87508787
def _post_live_migration(self, ctxt, instance, dest,
@@ -8756,7 +8793,7 @@ def _post_live_migration(self, ctxt, instance, dest,
87568793
and mainly updating database record.
87578794

87588795
:param ctxt: security context
8759-
:param instance: instance dict
8796+
:param instance: instance object
87608797
:param dest: destination host
87618798
:param block_migration: if true, prepare for block migration
87628799
:param migrate_data: if not None, it is a dict which has data

nova/tests/functional/regressions/test_bug_1628606.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,5 @@ def test_post_live_migration(self, mock_migration):
5656
server = self._live_migrate(
5757
server, migration_expected_state='error',
5858
server_expected_state='ERROR')
59-
# FIXME(amit): this should point to the dest as after migration
60-
# but does not because of bug 1628606
61-
self.assertEqual(self.src.host, server['OS-EXT-SRV-ATTR:host'])
59+
60+
self.assertEqual(self.dest.host, server['OS-EXT-SRV-ATTR:host'])

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9952,6 +9952,27 @@ def test_post_live_migration_new_allocations(self):
99529952
self.instance,
99539953
migration)
99549954

9955+
def test_post_live_migration_update_host(self):
9956+
@mock.patch.object(self.compute, '_get_compute_info')
9957+
def _test_post_live_migration(_get_compute_info):
9958+
dest_host = 'dest'
9959+
cn = objects.ComputeNode(hypervisor_hostname=dest_host)
9960+
_get_compute_info.return_value = cn
9961+
instance = fake_instance.fake_instance_obj(self.context,
9962+
node='src',
9963+
uuid=uuids.instance)
9964+
with mock.patch.object(self.compute, "_post_live_migration"
9965+
) as plm, mock.patch.object(instance, "save") as save:
9966+
error = ValueError("some failure")
9967+
plm.side_effect = error
9968+
self.assertRaises(
9969+
ValueError, self.compute._post_live_migration_update_host,
9970+
self.context, instance, dest_host)
9971+
save.assert_called_once()
9972+
self.assertEqual(instance.host, dest_host)
9973+
9974+
_test_post_live_migration()
9975+
99559976
def test_post_live_migration_cinder_pre_344_api(self):
99569977
# Because live migration has
99579978
# succeeded,_post_live_migration_remove_source_vol_connections()

0 commit comments

Comments
 (0)