'To attempt to address out-of-order messages, do some sanity
checking on the task states.  Add some requirements for
task_state to the instance.save() call if necessary.'

def _get_expected_task_state(self, instance):

    expected_task_state_map = {task_states.REBUILD_BLOCK_DEVICE_MAPPING: [task_states.REBUILD_BLOCK_DEVICE_MAPPING, task_states.REBUILDING], task_states.REBUILD_SPAWNING: [task_states.REBUILD_SPAWNING, task_states.REBUILD_BLOCK_DEVICE_MAPPING, task_states.REBUILDING], task_states.RESIZE_MIGRATING: [task_states.RESIZE_MIGRATING, task_states.RESIZE_PREP], task_states.RESIZE_MIGRATED: [task_states.RESIZE_MIGRATED, task_states.RESIZE_MIGRATING, task_states.RESIZE_PREP], task_states.RESIZE_FINISH: [task_states.RESIZE_FINISH, task_states.RESIZE_MIGRATED, task_states.RESIZE_MIGRATING, task_states.RESIZE_PREP]}
    if instance.obj_attr_is_set('task_state'):
        return expected_task_state_map.get(instance.task_state)
