@@ -8460,8 +8460,9 @@ def _do_live_migration(self, context, dest, instance, block_migration,
84608460 # host attachment. We fetch BDMs before that to retain connection_info
84618461 # and attachment_id relating to the source host for post migration
84628462 # cleanup.
8463- post_live_migration = functools.partial(self._post_live_migration,
8464- source_bdms=source_bdms)
8463+ post_live_migration = functools.partial(
8464+ self._post_live_migration_update_host, source_bdms=source_bdms
8465+ )
84658466 rollback_live_migration = functools.partial(
84668467 self._rollback_live_migration, source_bdms=source_bdms)
84678468
@@ -8707,6 +8708,42 @@ def _post_live_migration_remove_source_vol_connections(
87078708 bdm.attachment_id, self.host,
87088709 str(e), instance=instance)
87098710
8711+ # TODO(sean-k-mooney): add typing
8712+ def _post_live_migration_update_host(
8713+ self, ctxt, instance, dest, block_migration=False,
8714+ migrate_data=None, source_bdms=None
8715+ ):
8716+ try:
8717+ self._post_live_migration(
8718+ ctxt, instance, dest, block_migration, migrate_data,
8719+ source_bdms)
8720+ except Exception:
8721+ # Restore the instance object
8722+ node_name = None
8723+ try:
8724+ # get node name of compute, where instance will be
8725+ # running after migration, that is destination host
8726+ compute_node = self._get_compute_info(ctxt, dest)
8727+ node_name = compute_node.hypervisor_hostname
8728+ except exception.ComputeHostNotFound:
8729+ LOG.exception('Failed to get compute_info for %s', dest)
8730+
8731+ # we can never rollback from post live migration and we can only
8732+ # get here if the instance is running on the dest so we ensure
8733+ # the instance.host is set correctly and reraise the original
8734+ # exception unmodified.
8735+ if instance.host != dest:
8736+ # apply saves the new fields while drop actually removes the
8737+ # migration context from the instance, so migration persists.
8738+ instance.apply_migration_context()
8739+ instance.drop_migration_context()
8740+ instance.host = dest
8741+ instance.task_state = None
8742+ instance.node = node_name
8743+ instance.progress = 0
8744+ instance.save()
8745+ raise
8746+
87108747 @wrap_exception()
87118748 @wrap_instance_fault
87128749 def _post_live_migration(self, ctxt, instance, dest,
@@ -8718,7 +8755,7 @@ def _post_live_migration(self, ctxt, instance, dest,
87188755 and mainly updating database record.
87198756
87208757 :param ctxt: security context
8721- :param instance: instance dict
8758+ :param instance: instance object
87228759 :param dest: destination host
87238760 :param block_migration: if true, prepare for block migration
87248761 :param migrate_data: if not None, it is a dict which has data
0 commit comments