Skip to content

Commit 643b0c7

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)
1 parent 74a618a commit 643b0c7

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
@@ -8761,8 +8761,9 @@ def _do_live_migration(self, context, dest, instance, block_migration,
87618761
# host attachment. We fetch BDMs before that to retain connection_info
87628762
# and attachment_id relating to the source host for post migration
87638763
# cleanup.
8764-
post_live_migration = functools.partial(self._post_live_migration,
8765-
source_bdms=source_bdms)
8764+
post_live_migration = functools.partial(
8765+
self._post_live_migration_update_host, source_bdms=source_bdms
8766+
)
87668767
rollback_live_migration = functools.partial(
87678768
self._rollback_live_migration, source_bdms=source_bdms)
87688769

@@ -9037,6 +9038,42 @@ def _post_live_migration_remove_source_vol_connections(
90379038
bdm.attachment_id, self.host,
90389039
str(e), instance=instance)
90399040

9041+
# TODO(sean-k-mooney): add typing
9042+
def _post_live_migration_update_host(
9043+
self, ctxt, instance, dest, block_migration=False,
9044+
migrate_data=None, source_bdms=None
9045+
):
9046+
try:
9047+
self._post_live_migration(
9048+
ctxt, instance, dest, block_migration, migrate_data,
9049+
source_bdms)
9050+
except Exception:
9051+
# Restore the instance object
9052+
node_name = None
9053+
try:
9054+
# get node name of compute, where instance will be
9055+
# running after migration, that is destination host
9056+
compute_node = self._get_compute_info(ctxt, dest)
9057+
node_name = compute_node.hypervisor_hostname
9058+
except exception.ComputeHostNotFound:
9059+
LOG.exception('Failed to get compute_info for %s', dest)
9060+
9061+
# we can never rollback from post live migration and we can only
9062+
# get here if the instance is running on the dest so we ensure
9063+
# the instance.host is set correctly and reraise the original
9064+
# exception unmodified.
9065+
if instance.host != dest:
9066+
# apply saves the new fields while drop actually removes the
9067+
# migration context from the instance, so migration persists.
9068+
instance.apply_migration_context()
9069+
instance.drop_migration_context()
9070+
instance.host = dest
9071+
instance.task_state = None
9072+
instance.node = node_name
9073+
instance.progress = 0
9074+
instance.save()
9075+
raise
9076+
90409077
@wrap_exception()
90419078
@wrap_instance_fault
90429079
def _post_live_migration(self, ctxt, instance, dest,
@@ -9048,7 +9085,7 @@ def _post_live_migration(self, ctxt, instance, dest,
90489085
and mainly updating database record.
90499086

90509087
:param ctxt: security context
9051-
:param instance: instance dict
9088+
:param instance: instance object
90529089
:param dest: destination host
90539090
:param block_migration: if true, prepare for block migration
90549091
: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
@@ -10209,6 +10209,27 @@ def test_post_live_migration_new_allocations(self):
1020910209
self.instance,
1021010210
migration)
1021110211

10212+
def test_post_live_migration_update_host(self):
10213+
@mock.patch.object(self.compute, '_get_compute_info')
10214+
def _test_post_live_migration(_get_compute_info):
10215+
dest_host = 'dest'
10216+
cn = objects.ComputeNode(hypervisor_hostname=dest_host)
10217+
_get_compute_info.return_value = cn
10218+
instance = fake_instance.fake_instance_obj(self.context,
10219+
node='src',
10220+
uuid=uuids.instance)
10221+
with mock.patch.object(self.compute, "_post_live_migration"
10222+
) as plm, mock.patch.object(instance, "save") as save:
10223+
error = ValueError("some failure")
10224+
plm.side_effect = error
10225+
self.assertRaises(
10226+
ValueError, self.compute._post_live_migration_update_host,
10227+
self.context, instance, dest_host)
10228+
save.assert_called_once()
10229+
self.assertEqual(instance.host, dest_host)
10230+
10231+
_test_post_live_migration()
10232+
1021210233
def test_post_live_migration_cinder_pre_344_api(self):
1021310234
# Because live migration has
1021410235
# succeeded,_post_live_migration_remove_source_vol_connections()

0 commit comments

Comments
 (0)