Have one list of reboot task_states

We now have two places we list valid task_states for a soft
reboot. Let's just have one. Do a similar thing to hard reboot
states at the time to be consistent.

Change-Id: I87932894b3b7b2b5cc86552e322611e5701297da
This commit is contained in:
Michael Still 2015-09-03 13:52:29 +10:00
parent 91addc87c6
commit 8fc69b76ce
3 changed files with 12 additions and 14 deletions

View File

@ -860,10 +860,8 @@ class ComputeManager(manager.Manager):
# again, then we've just become a hard reboot. That means the # 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 # task state for the instance needs to change so that we're in one
# of the expected task states for a hard reboot. # of the expected task states for a hard reboot.
soft_types = [task_states.REBOOT_STARTED, if (instance.task_state in task_states.soft_reboot_states and
task_states.REBOOT_PENDING, reboot_type == 'HARD'):
task_states.REBOOTING]
if instance.task_state in soft_types and reboot_type == 'HARD':
instance.task_state = task_states.REBOOT_PENDING_HARD instance.task_state = task_states.REBOOT_PENDING_HARD
instance.save() instance.save()
@ -3017,14 +3015,11 @@ class ComputeManager(manager.Manager):
# acknowledge the request made it to the manager # acknowledge the request made it to the manager
if reboot_type == "SOFT": if reboot_type == "SOFT":
instance.task_state = task_states.REBOOT_PENDING instance.task_state = task_states.REBOOT_PENDING
expected_states = (task_states.REBOOTING, expected_states = task_states.soft_reboot_states
task_states.REBOOT_PENDING,
task_states.REBOOT_STARTED)
else: else:
instance.task_state = task_states.REBOOT_PENDING_HARD instance.task_state = task_states.REBOOT_PENDING_HARD
expected_states = (task_states.REBOOTING_HARD, expected_states = task_states.hard_reboot_states
task_states.REBOOT_PENDING_HARD,
task_states.REBOOT_STARTED_HARD)
context = context.elevated() context = context.elevated()
LOG.info("Rebooting instance", instance=instance) LOG.info("Rebooting instance", instance=instance)

View File

@ -119,3 +119,7 @@ UNSHELVING = fields.InstanceTaskState.UNSHELVING
ALLOW_REBOOT = [None, REBOOTING, REBOOT_PENDING, REBOOT_STARTED, RESUMING, ALLOW_REBOOT = [None, REBOOTING, REBOOT_PENDING, REBOOT_STARTED, RESUMING,
REBOOTING_HARD, UNPAUSING, PAUSING, SUSPENDING] 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)

View File

@ -601,10 +601,9 @@ def get_reboot_type(task_state, current_power_state):
"""Checks if the current instance state requires a HARD reboot.""" """Checks if the current instance state requires a HARD reboot."""
if current_power_state != power_state.RUNNING: if current_power_state != power_state.RUNNING:
return 'HARD' return 'HARD'
soft_types = [task_states.REBOOT_STARTED, task_states.REBOOT_PENDING, if task_state in task_states.soft_reboot_states:
task_states.REBOOTING] return 'SOFT'
reboot_type = 'SOFT' if task_state in soft_types else 'HARD' return 'HARD'
return reboot_type
def get_machine_ips(): def get_machine_ips():