@@ -8460,8 +8460,9 @@ def _do_live_migration(self, context, dest, instance, block_migration,
8460
8460
# host attachment. We fetch BDMs before that to retain connection_info
8461
8461
# and attachment_id relating to the source host for post migration
8462
8462
# 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
+ )
8465
8466
rollback_live_migration = functools.partial(
8466
8467
self._rollback_live_migration, source_bdms=source_bdms)
8467
8468
@@ -8707,6 +8708,42 @@ def _post_live_migration_remove_source_vol_connections(
8707
8708
bdm.attachment_id, self.host,
8708
8709
str(e), instance=instance)
8709
8710
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
+
8710
8747
@wrap_exception()
8711
8748
@wrap_instance_fault
8712
8749
def _post_live_migration(self, ctxt, instance, dest,
@@ -8718,7 +8755,7 @@ def _post_live_migration(self, ctxt, instance, dest,
8718
8755
and mainly updating database record.
8719
8756
8720
8757
:param ctxt: security context
8721
- :param instance: instance dict
8758
+ :param instance: instance object
8722
8759
:param dest: destination host
8723
8760
:param block_migration: if true, prepare for block migration
8724
8761
:param migrate_data: if not None, it is a dict which has data
0 commit comments