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