def _check_state(self, states): """ Raises a BAD_SUPVISORS_STATE exception if Supvisors' state is NOT in one of the states. """ if self.fsm.state not in states: raise RPCError(Faults.BAD_SUPVISORS_STATE, 'Supvisors (state={}) not in state {} to perform request'. format(SupvisorsStates._to_string(self.supvisors.fsm.state), [SupvisorsStates._to_string(state) for state in states]))
def _check_state(self, states): """ Raises a BAD_SUPVISORS_STATE exception if Supvisors' state is NOT in one of the states. """ if self.supvisors.fsm.state not in states: raise RPCError( Faults.BAD_SUPVISORS_STATE, 'Supvisors (state={}) not in state {} to perform request'. format(SupvisorsStates._to_string(self.supvisors.fsm.state), [SupvisorsStates._to_string(state) for state in states]))
def test_serial(self): """ Test the serialization of state machine. """ from supvisors.statemachine import FiniteStateMachine from supvisors.ttypes import SupvisorsStates # create state machine instance fsm = FiniteStateMachine(self.supvisors) # test serialization for all states for state in SupvisorsStates._values(): fsm.state = state self.assertDictEqual({'statecode': state, 'statename': SupvisorsStates._to_string(state)}, fsm.serial())
def test_state_string(self): """ Test the string conversion of state machine. """ from supvisors.statemachine import FiniteStateMachine from supvisors.ttypes import SupvisorsStates # create state machine instance fsm = FiniteStateMachine(self.supvisors) # test string conversion for all states for state in SupvisorsStates._values(): fsm.state = state self.assertEqual(SupvisorsStates._to_string(state), fsm.state_string())
def test_serial(self): """ Test the serialization of state machine. """ from supvisors.statemachine import FiniteStateMachine from supvisors.ttypes import SupvisorsStates # create state machine instance fsm = FiniteStateMachine(self.supvisors) # test serialization for all states for state in SupvisorsStates._values(): fsm.state = state self.assertDictEqual( { 'statecode': state, 'statename': SupvisorsStates._to_string(state) }, fsm.serial())
def test_SupvisorsStates(self): """ Test the SupvisorsStates enumeration. """ from supvisors.ttypes import SupvisorsStates self.assertEqual('INITIALIZATION', SupvisorsStates._to_string(SupvisorsStates.INITIALIZATION)) self.assertEqual('DEPLOYMENT', SupvisorsStates._to_string(SupvisorsStates.DEPLOYMENT)) self.assertEqual('OPERATION', SupvisorsStates._to_string(SupvisorsStates.OPERATION)) self.assertEqual('CONCILIATION', SupvisorsStates._to_string(SupvisorsStates.CONCILIATION)) self.assertEqual('RESTARTING', SupvisorsStates._to_string(SupvisorsStates.RESTARTING)) self.assertEqual('SHUTTING_DOWN', SupvisorsStates._to_string(SupvisorsStates.SHUTTING_DOWN)) self.assertEqual('SHUTDOWN', SupvisorsStates._to_string(SupvisorsStates.SHUTDOWN))
def state_string(self): """ Return the supvisors state as a string. """ return SupvisorsStates._to_string(self.state)