diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 51b2818f3c44..4d0a73544c76 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -860,10 +860,8 @@ class ComputeManager(manager.Manager): # again, then we've just become a hard reboot. That means the # task state for the instance needs to change so that we're in one # of the expected task states for a hard reboot. - soft_types = [task_states.REBOOT_STARTED, - task_states.REBOOT_PENDING, - task_states.REBOOTING] - if instance.task_state in soft_types and reboot_type == 'HARD': + if (instance.task_state in task_states.soft_reboot_states and + reboot_type == 'HARD'): instance.task_state = task_states.REBOOT_PENDING_HARD instance.save() @@ -3017,14 +3015,11 @@ class ComputeManager(manager.Manager): # acknowledge the request made it to the manager if reboot_type == "SOFT": instance.task_state = task_states.REBOOT_PENDING - expected_states = (task_states.REBOOTING, - task_states.REBOOT_PENDING, - task_states.REBOOT_STARTED) + expected_states = task_states.soft_reboot_states else: instance.task_state = task_states.REBOOT_PENDING_HARD - expected_states = (task_states.REBOOTING_HARD, - task_states.REBOOT_PENDING_HARD, - task_states.REBOOT_STARTED_HARD) + expected_states = task_states.hard_reboot_states + context = context.elevated() LOG.info("Rebooting instance", instance=instance) diff --git a/nova/compute/task_states.py b/nova/compute/task_states.py index 2b793aebb3bf..b247d8696ffd 100644 --- a/nova/compute/task_states.py +++ b/nova/compute/task_states.py @@ -119,3 +119,7 @@ UNSHELVING = fields.InstanceTaskState.UNSHELVING ALLOW_REBOOT = [None, REBOOTING, REBOOT_PENDING, REBOOT_STARTED, RESUMING, REBOOTING_HARD, UNPAUSING, PAUSING, SUSPENDING] + +# These states indicate a reboot +soft_reboot_states = (REBOOTING, REBOOT_PENDING, REBOOT_STARTED) +hard_reboot_states = (REBOOTING_HARD, REBOOT_PENDING_HARD, REBOOT_STARTED_HARD) diff --git a/nova/compute/utils.py b/nova/compute/utils.py index d89ed1863c5b..529647ac7516 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -601,10 +601,9 @@ def get_reboot_type(task_state, current_power_state): """Checks if the current instance state requires a HARD reboot.""" if current_power_state != power_state.RUNNING: return 'HARD' - soft_types = [task_states.REBOOT_STARTED, task_states.REBOOT_PENDING, - task_states.REBOOTING] - reboot_type = 'SOFT' if task_state in soft_types else 'HARD' - return reboot_type + if task_state in task_states.soft_reboot_states: + return 'SOFT' + return 'HARD' def get_machine_ips():