@@ -8229,8 +8229,9 @@ def _do_live_migration(self, context, dest, instance, block_migration,
8229
8229
# host attachment. We fetch BDMs before that to retain connection_info
8230
8230
# and attachment_id relating to the source host for post migration
8231
8231
# cleanup.
8232
- post_live_migration = functools.partial(self._post_live_migration,
8233
- source_bdms=source_bdms)
8232
+ post_live_migration = functools.partial(
8233
+ self._post_live_migration_update_host, source_bdms=source_bdms
8234
+ )
8234
8235
rollback_live_migration = functools.partial(
8235
8236
self._rollback_live_migration, source_bdms=source_bdms)
8236
8237
@@ -8479,6 +8480,42 @@ def _post_live_migration_remove_source_vol_connections(
8479
8480
bdm.attachment_id, self.host,
8480
8481
six.text_type(e), instance=instance)
8481
8482
8483
+ # TODO(sean-k-mooney): add typing
8484
+ def _post_live_migration_update_host(
8485
+ self, ctxt, instance, dest, block_migration=False,
8486
+ migrate_data=None, source_bdms=None
8487
+ ):
8488
+ try:
8489
+ self._post_live_migration(
8490
+ ctxt, instance, dest, block_migration, migrate_data,
8491
+ source_bdms)
8492
+ except Exception:
8493
+ # Restore the instance object
8494
+ node_name = None
8495
+ try:
8496
+ # get node name of compute, where instance will be
8497
+ # running after migration, that is destination host
8498
+ compute_node = self._get_compute_info(ctxt, dest)
8499
+ node_name = compute_node.hypervisor_hostname
8500
+ except exception.ComputeHostNotFound:
8501
+ LOG.exception('Failed to get compute_info for %s', dest)
8502
+
8503
+ # we can never rollback from post live migration and we can only
8504
+ # get here if the instance is running on the dest so we ensure
8505
+ # the instance.host is set correctly and reraise the original
8506
+ # exception unmodified.
8507
+ if instance.host != dest:
8508
+ # apply saves the new fields while drop actually removes the
8509
+ # migration context from the instance, so migration persists.
8510
+ instance.apply_migration_context()
8511
+ instance.drop_migration_context()
8512
+ instance.host = dest
8513
+ instance.task_state = None
8514
+ instance.node = node_name
8515
+ instance.progress = 0
8516
+ instance.save()
8517
+ raise
8518
+
8482
8519
@wrap_exception()
8483
8520
@wrap_instance_fault
8484
8521
def _post_live_migration(self, ctxt, instance, dest,
@@ -8490,7 +8527,7 @@ def _post_live_migration(self, ctxt, instance, dest,
8490
8527
and mainly updating database record.
8491
8528
8492
8529
:param ctxt: security context
8493
- :param instance: instance dict
8530
+ :param instance: instance object
8494
8531
:param dest: destination host
8495
8532
:param block_migration: if true, prepare for block migration
8496
8533
:param migrate_data: if not None, it is a dict which has data
0 commit comments