'Test whether the desired state has been reached.
Raise an exception if a non-valid state is reached or if the
desired state is not reached within the supplied time limit.'

def reached_desired_state(self):

    try:
        existing_volume = self.volume_manager.get(self.expected_volume.id)
    except CinderClientNotFound:
        elapsed_time = (time.time() - self.start_time)
        if (elapsed_time > self.time_limit):
            raise TimeoutException(self.expected_volume, self.desired_state, elapsed_time)
        return None
    current_state = existing_volume.status
    if (current_state == self.desired_state):
        return existing_volume
    elif (current_state in self.transient_states):
        idx = self.transient_states.index(current_state)
        if (idx > 0):
            self.transient_states = self.transient_states[idx:]
    else:
        raise UnexpectedStateException(self.expected_volume, self.desired_state, current_state)
