@@ -3973,7 +3973,29 @@ def do_confirm_resize(context, instance, migration_id):
3973
3973
instance = instance )
3974
3974
return
3975
3975
3976
- self ._confirm_resize (context , instance , migration = migration )
3976
+ with self ._error_out_instance_on_exception (context , instance ):
3977
+ try :
3978
+ self ._confirm_resize (
3979
+ context , instance , migration = migration )
3980
+ except Exception :
3981
+ # Something failed when cleaning up the source host so
3982
+ # log a traceback and leave a hint about hard rebooting
3983
+ # the server to correct its state in the DB.
3984
+ with excutils .save_and_reraise_exception (logger = LOG ):
3985
+ LOG .exception (
3986
+ 'Confirm resize failed on source host %s. '
3987
+ 'Resource allocations in the placement service '
3988
+ 'will be removed regardless because the instance '
3989
+ 'is now on the destination host %s. You can try '
3990
+ 'hard rebooting the instance to correct its '
3991
+ 'state.' , self .host , migration .dest_compute ,
3992
+ instance = instance )
3993
+ finally :
3994
+ # Whether an error occurred or not, at this point the
3995
+ # instance is on the dest host so to avoid leaking
3996
+ # allocations in placement, delete them here.
3997
+ self ._delete_allocation_after_move (
3998
+ context , instance , migration )
3977
3999
3978
4000
do_confirm_resize (context , instance , migration .id )
3979
4001
@@ -3985,59 +4007,57 @@ def _confirm_resize(self, context, instance, migration=None):
3985
4007
self .host , action = fields .NotificationAction .RESIZE_CONFIRM ,
3986
4008
phase = fields .NotificationPhase .START )
3987
4009
3988
- with self ._error_out_instance_on_exception (context , instance ):
3989
- # NOTE(danms): delete stashed migration information
3990
- old_instance_type = instance .old_flavor
3991
- instance .old_flavor = None
3992
- instance .new_flavor = None
3993
- instance .system_metadata .pop ('old_vm_state' , None )
3994
- instance .save ()
3995
-
3996
- # NOTE(tr3buchet): tear down networks on source host
3997
- self .network_api .setup_networks_on_host (context , instance ,
3998
- migration .source_compute , teardown = True )
4010
+ # NOTE(danms): delete stashed migration information
4011
+ old_instance_type = instance .old_flavor
4012
+ instance .old_flavor = None
4013
+ instance .new_flavor = None
4014
+ instance .system_metadata .pop ('old_vm_state' , None )
4015
+ instance .save ()
3999
4016
4000
- network_info = self .network_api .get_instance_nw_info (context ,
4001
- instance )
4002
- # TODO(mriedem): Get BDMs here and pass them to the driver.
4003
- self .driver .confirm_migration (context , migration , instance ,
4004
- network_info )
4017
+ # NOTE(tr3buchet): tear down networks on source host
4018
+ self .network_api .setup_networks_on_host (context , instance ,
4019
+ migration .source_compute , teardown = True )
4005
4020
4006
- migration .status = 'confirmed'
4007
- migration .save ()
4021
+ network_info = self .network_api .get_instance_nw_info (context ,
4022
+ instance )
4023
+ # TODO(mriedem): Get BDMs here and pass them to the driver.
4024
+ self .driver .confirm_migration (context , migration , instance ,
4025
+ network_info )
4008
4026
4009
- self .rt .drop_move_claim (context , instance , migration .source_node ,
4010
- old_instance_type , prefix = 'old_' )
4011
- self ._delete_allocation_after_move (context , instance , migration )
4012
- instance .drop_migration_context ()
4027
+ migration .status = 'confirmed'
4028
+ migration .save ()
4013
4029
4014
- # NOTE(mriedem): The old_vm_state could be STOPPED but the user
4015
- # might have manually powered up the instance to confirm the
4016
- # resize/migrate, so we need to check the current power state
4017
- # on the instance and set the vm_state appropriately. We default
4018
- # to ACTIVE because if the power state is not SHUTDOWN, we
4019
- # assume _sync_instance_power_state will clean it up.
4020
- p_state = instance .power_state
4021
- vm_state = None
4022
- if p_state == power_state .SHUTDOWN :
4023
- vm_state = vm_states .STOPPED
4024
- LOG .debug ("Resized/migrated instance is powered off. "
4025
- "Setting vm_state to '%s'." , vm_state ,
4026
- instance = instance )
4027
- else :
4028
- vm_state = vm_states .ACTIVE
4030
+ self .rt .drop_move_claim (context , instance , migration .source_node ,
4031
+ old_instance_type , prefix = 'old_' )
4032
+ instance .drop_migration_context ()
4033
+
4034
+ # NOTE(mriedem): The old_vm_state could be STOPPED but the user
4035
+ # might have manually powered up the instance to confirm the
4036
+ # resize/migrate, so we need to check the current power state
4037
+ # on the instance and set the vm_state appropriately. We default
4038
+ # to ACTIVE because if the power state is not SHUTDOWN, we
4039
+ # assume _sync_instance_power_state will clean it up.
4040
+ p_state = instance .power_state
4041
+ vm_state = None
4042
+ if p_state == power_state .SHUTDOWN :
4043
+ vm_state = vm_states .STOPPED
4044
+ LOG .debug ("Resized/migrated instance is powered off. "
4045
+ "Setting vm_state to '%s'." , vm_state ,
4046
+ instance = instance )
4047
+ else :
4048
+ vm_state = vm_states .ACTIVE
4029
4049
4030
- instance .vm_state = vm_state
4031
- instance .task_state = None
4032
- instance .save (expected_task_state = [None , task_states .DELETING ,
4033
- task_states .SOFT_DELETING ])
4050
+ instance .vm_state = vm_state
4051
+ instance .task_state = None
4052
+ instance .save (expected_task_state = [None , task_states .DELETING ,
4053
+ task_states .SOFT_DELETING ])
4034
4054
4035
- self ._notify_about_instance_usage (
4036
- context , instance , "resize.confirm.end" ,
4037
- network_info = network_info )
4038
- compute_utils .notify_about_instance_action (context , instance ,
4039
- self .host , action = fields .NotificationAction .RESIZE_CONFIRM ,
4040
- phase = fields .NotificationPhase .END )
4055
+ self ._notify_about_instance_usage (
4056
+ context , instance , "resize.confirm.end" ,
4057
+ network_info = network_info )
4058
+ compute_utils .notify_about_instance_action (context , instance ,
4059
+ self .host , action = fields .NotificationAction .RESIZE_CONFIRM ,
4060
+ phase = fields .NotificationPhase .END )
4041
4061
4042
4062
def _delete_allocation_after_move (self , context , instance , migration ):
4043
4063
"""Deletes resource allocations held by the migration record against
0 commit comments