@@ -933,14 +933,41 @@ def _update_available_resource(self, context, resources, startup=False):
933933 'flavor' , 'migration_context' ,
934934 'resources' ])
935935
936- # Now calculate usage based on instance utilization:
937- instance_by_uuid = self ._update_usage_from_instances (
938- context , instances , nodename )
939-
940936 # Grab all in-progress migrations and error migrations:
941937 migrations = objects .MigrationList .get_in_progress_and_error (
942938 context , self .host , nodename )
943939
940+ # Check for tracked instances with in-progress, incoming, but not
941+ # finished migrations. For those instance the migration context
942+ # is not applied yet (it will be during finish_resize when the
943+ # migration goes to finished state). We need to manually and
944+ # temporary apply the migration context here when the resource usage is
945+ # updated. See bug 1953359 for more details.
946+ instance_by_uuid = {instance .uuid : instance for instance in instances }
947+ for migration in migrations :
948+ if (
949+ migration .instance_uuid in instance_by_uuid and
950+ migration .dest_compute == self .host and
951+ migration .dest_node == nodename
952+ ):
953+ # we does not check for the 'post-migrating' migration status
954+ # as applying the migration context for an instance already
955+ # in finished migration status is a no-op anyhow.
956+ instance = instance_by_uuid [migration .instance_uuid ]
957+ LOG .debug (
958+ 'Applying migration context for instance %s as it has an '
959+ 'incoming, in-progress migration %s. '
960+ 'Migration status is %s' ,
961+ migration .instance_uuid , migration .uuid , migration .status
962+ )
963+ # It is OK not to revert the migration context at the end of
964+ # the periodic as the instance is not saved during the periodic
965+ instance .apply_migration_context ()
966+
967+ # Now calculate usage based on instance utilization:
968+ instance_by_uuid = self ._update_usage_from_instances (
969+ context , instances , nodename )
970+
944971 self ._pair_instances_to_migrations (migrations , instance_by_uuid )
945972 self ._update_usage_from_migrations (context , migrations , nodename )
946973
0 commit comments