Skip to content

Commit 0ac64bb

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) (cherry picked from commit 15502dd) (cherry picked from commit 43c0e40)
1 parent 6dda4f7 commit 0ac64bb

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
@@ -8364,8 +8364,9 @@ def _do_live_migration(self, context, dest, instance, block_migration,
83648364
# host attachment. We fetch BDMs before that to retain connection_info
83658365
# and attachment_id relating to the source host for post migration
83668366
# cleanup.
8367-
post_live_migration = functools.partial(self._post_live_migration,
8368-
source_bdms=source_bdms)
8367+
post_live_migration = functools.partial(
8368+
self._post_live_migration_update_host, source_bdms=source_bdms
8369+
)
83698370
rollback_live_migration = functools.partial(
83708371
self._rollback_live_migration, source_bdms=source_bdms)
83718372

@@ -8611,6 +8612,42 @@ def _post_live_migration_remove_source_vol_connections(
86118612
bdm.attachment_id, self.host,
86128613
six.text_type(e), instance=instance)
86138614

8615+
# TODO(sean-k-mooney): add typing
8616+
def _post_live_migration_update_host(
8617+
self, ctxt, instance, dest, block_migration=False,
8618+
migrate_data=None, source_bdms=None
8619+
):
8620+
try:
8621+
self._post_live_migration(
8622+
ctxt, instance, dest, block_migration, migrate_data,
8623+
source_bdms)
8624+
except Exception:
8625+
# Restore the instance object
8626+
node_name = None
8627+
try:
8628+
# get node name of compute, where instance will be
8629+
# running after migration, that is destination host
8630+
compute_node = self._get_compute_info(ctxt, dest)
8631+
node_name = compute_node.hypervisor_hostname
8632+
except exception.ComputeHostNotFound:
8633+
LOG.exception('Failed to get compute_info for %s', dest)
8634+
8635+
# we can never rollback from post live migration and we can only
8636+
# get here if the instance is running on the dest so we ensure
8637+
# the instance.host is set correctly and reraise the original
8638+
# exception unmodified.
8639+
if instance.host != dest:
8640+
# apply saves the new fields while drop actually removes the
8641+
# migration context from the instance, so migration persists.
8642+
instance.apply_migration_context()
8643+
instance.drop_migration_context()
8644+
instance.host = dest
8645+
instance.task_state = None
8646+
instance.node = node_name
8647+
instance.progress = 0
8648+
instance.save()
8649+
raise
8650+
86148651
@wrap_exception()
86158652
@wrap_instance_fault
86168653
def _post_live_migration(self, ctxt, instance, dest,
@@ -8622,7 +8659,7 @@ def _post_live_migration(self, ctxt, instance, dest,
86228659
and mainly updating database record.
86238660

86248661
:param ctxt: security context
8625-
:param instance: instance dict
8662+
:param instance: instance object
86268663
:param dest: destination host
86278664
:param block_migration: if true, prepare for block migration
86288665
: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
@@ -9922,6 +9922,27 @@ def test_post_live_migration_new_allocations(self):
99229922
self.instance,
99239923
migration)
99249924

9925+
def test_post_live_migration_update_host(self):
9926+
@mock.patch.object(self.compute, '_get_compute_info')
9927+
def _test_post_live_migration(_get_compute_info):
9928+
dest_host = 'dest'
9929+
cn = objects.ComputeNode(hypervisor_hostname=dest_host)
9930+
_get_compute_info.return_value = cn
9931+
instance = fake_instance.fake_instance_obj(self.context,
9932+
node='src',
9933+
uuid=uuids.instance)
9934+
with mock.patch.object(self.compute, "_post_live_migration"
9935+
) as plm, mock.patch.object(instance, "save") as save:
9936+
error = ValueError("some failure")
9937+
plm.side_effect = error
9938+
self.assertRaises(
9939+
ValueError, self.compute._post_live_migration_update_host,
9940+
self.context, instance, dest_host)
9941+
save.assert_called_once()
9942+
self.assertEqual(instance.host, dest_host)
9943+
9944+
_test_post_live_migration()
9945+
99259946
def test_post_live_migration_cinder_pre_344_api(self):
99269947
# Because live migration has
99279948
# succeeded,_post_live_migration_remove_source_vol_connections()

0 commit comments

Comments
 (0)