def test_update_sequences(self):
     """ Test the sequencing of the update_sequences method. """
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     application = ApplicationStatus('ApplicationTest', self.supvisors.logger)
     # add processes to the application
     for info in database_copy():
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info)
         # set random sequence to process
         process.rules.start_sequence = random.randint(0, 2)
         process.rules.stop_sequence = random.randint(0, 2)
         application.add_process(process)
     # call the sequencer
     application.update_sequences()
     # check the sequencing of the starting
     sequences = sorted({process.rules.start_sequence for process in application.processes.values()})
     # as key is an integer, the sequence dictionary should be sorted but pypy doesn't...
     for sequence, processes in sorted(application.start_sequence.items()):
         self.assertEqual(sequence, sequences.pop(0))
         self.assertListEqual(sorted(processes, key=lambda x: x.process_name),
             sorted([proc for proc in application.processes.values() if sequence == proc.rules.start_sequence], key=lambda x: x.process_name))
     # check the sequencing of the stopping
     sequences = sorted({process.rules.stop_sequence for process in application.processes.values()})
     # as key is an integer, the sequence dictionary should be sorted but pypy doesn't...
     for sequence, processes in sorted(application.stop_sequence.items()):
         self.assertEqual(sequence, sequences.pop(0))
         self.assertListEqual(sorted(processes, key=lambda x: x.process_name),
             sorted([proc for proc in application.processes.values() if sequence == proc.rules.stop_sequence], key=lambda x: x.process_name))
Beispiel #2
0
 def test_update_sequences(self):
     """ Test the sequencing of the deployment method. """
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     application = ApplicationStatus('ApplicationTest', self.supvisors.logger)
     # add processes to the application
     for info in ProcessInfoDatabase:
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info.copy())
         # set random sequence to process
         process.rules.start_sequence = random.randint(0, 2)
         process.rules.stop_sequence = random.randint(0, 2)
         application.add_process(process)
     # call the sequencer
     application.update_sequences()
     # check the sequencing of the starting
     sequences = sorted({process.rules.start_sequence for process in application.processes.values()})
     # as key is an integer, the sequence dictionary should be sorted but pypy doesn't...
     for sequence, processes in sorted(application.start_sequence.items()):
         self.assertEqual(sequence, sequences.pop(0))
         self.assertListEqual(sorted(processes, key=lambda x: x.process_name),
             sorted([proc for proc in application.processes.values() if sequence == proc.rules.start_sequence], key=lambda x: x.process_name))
     # check the sequencing of the stopping
     sequences = sorted({process.rules.stop_sequence for process in application.processes.values()})
     # as key is an integer, the sequence dictionary should be sorted but pypy doesn't...
     for sequence, processes in sorted(application.stop_sequence.items()):
         self.assertEqual(sequence, sequences.pop(0))
         self.assertListEqual(sorted(processes, key=lambda x: x.process_name),
             sorted([proc for proc in application.processes.values() if sequence == proc.rules.stop_sequence], key=lambda x: x.process_name))
 def test_add_process(self):
     """ Test the add_process method. """
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     application = ApplicationStatus('ApplicationTest', self.supvisors.logger)
     # add a process to the application
     info = any_process_info()
     process = ProcessStatus(info['group'], info['name'], self.supvisors)
     process.add_info('10.0.0.1', info)
     application.add_process(process)
     # check that process is stored
     self.assertIn(process.process_name, application.processes.keys())
     self.assertIs(process, application.processes[process.process_name])
Beispiel #4
0
 def test_add_process(self):
     """ Test the add_process method. """
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     application = ApplicationStatus('ApplicationTest', self.supvisors.logger)
     # add a process to the application
     info = any_process_info()
     process = ProcessStatus(info['group'], info['name'], self.supvisors)
     process.add_info('10.0.0.1', info)
     application.add_process(process)
     # check that process is stored
     self.assertIn(process.process_name, application.processes.keys())
     self.assertIs(process, application.processes[process.process_name])
 def test_running(self):
     """ Test the running method. """
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     application = ApplicationStatus('ApplicationTest', self.supvisors.logger)
     self.assertFalse(application.running())
     # add a stopped process
     info = any_stopped_process_info()
     process = ProcessStatus(info['group'], info['name'], self.supvisors)
     process.add_info('10.0.0.1', info)
     application.add_process(process)
     application.update_status()
     self.assertFalse(application.running())
     # add a running process
     info = any_running_process_info()
     process = ProcessStatus(info['group'], info['name'], self.supvisors)
     process.add_info('10.0.0.1', info)
     application.add_process(process)
     application.update_status()
     self.assertTrue(application.running())
Beispiel #6
0
 def test_stopped(self):
     """ Test the stopped method. """
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     application = ApplicationStatus('ApplicationTest', self.supvisors.logger)
     self.assertTrue(application.stopped())
     # add a stopped process
     info = any_stopped_process_info()
     process = ProcessStatus(info['group'], info['name'], self.supvisors)
     process.add_info('10.0.0.1', info)
     application.add_process(process)
     application.update_status()
     self.assertTrue(application.stopped())
     # add a running process
     info = any_running_process_info()
     process = ProcessStatus(info['group'], info['name'], self.supvisors)
     process.add_info('10.0.0.1', info)
     application.add_process(process)
     application.update_status()
     self.assertFalse(application.stopped())
 def test_update_status(self):
     """ Test the rules to update the status of the application method. """
     from supervisor.states import ProcessStates
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     from supvisors.ttypes import ApplicationStates
     application = ApplicationStatus('ApplicationTest', self.supvisors.logger)
     # add processes to the application
     for info in database_copy():
         process = ProcessStatus(info['group'], info['name'], self.supvisors)
         process.add_info('10.0.0.1', info)
         application.add_process(process)
     # init status
     # there are lots of states but the 'strongest' is STARTING
     # STARTING is a 'running' state so major/minor failures are applicable
     application.update_status()
     self.assertEqual(ApplicationStates.STARTING, application.state)
     # there is a FATAL state in the process database
     # no rule is set for processes, so there are only minor failures
     self.assertFalse(application.major_failure)
     self.assertTrue(application.minor_failure)
     # set FATAL process to major
     fatal_process = next((process for process in application.processes.values() if process.state == ProcessStates.FATAL), None)
     fatal_process.rules.required = True
     # update status. major failure is now expected
     application.update_status()
     self.assertEqual(ApplicationStates.STARTING, application.state)
     self.assertTrue(application.major_failure)
     self.assertFalse(application.minor_failure)
     # set STARTING process to RUNNING
     starting_process = next((process for process in application.processes.values() if process.state == ProcessStates.STARTING), None)
     starting_process.state = ProcessStates.RUNNING
     # update status. there is still one BACKOFF process leading to STARTING application
     application.update_status()
     self.assertEqual(ApplicationStates.STARTING, application.state)
     self.assertTrue(application.major_failure)
     self.assertFalse(application.minor_failure)
     # set BACKOFF process to EXITED
     backoff_process = next((process for process in application.processes.values() if process.state == ProcessStates.BACKOFF), None)
     backoff_process.state = ProcessStates.EXITED
     # update status. the 'strongest' state is now STOPPING
     # as STOPPING is not a 'running' state, failures are not applicable
     application.update_status()
     self.assertEqual(ApplicationStates.STOPPING, application.state)
     self.assertFalse(application.major_failure)
     self.assertFalse(application.minor_failure)
     # set STOPPING process to STOPPED
     stopping_process = next((process for process in application.processes.values() if process.state == ProcessStates.STOPPING), None)
     stopping_process.state = ProcessStates.STOPPED
     # update status. the 'strongest' state is now RUNNING
     # failures are applicable again
     application.update_status()
     self.assertEqual(ApplicationStates.RUNNING, application.state)
     self.assertTrue(application.major_failure)
     self.assertFalse(application.minor_failure)
     # set RUNNING processes to STOPPED
     for process in application.processes.values():
         if process.state == ProcessStates.RUNNING:
             process.state = ProcessStates.STOPPED
     # update status. the 'strongest' state is now RUNNING
     # failures are not applicable anymore
     application.update_status()
     self.assertEqual(ApplicationStates.STOPPED, application.state)
     self.assertFalse(application.major_failure)
     self.assertFalse(application.minor_failure)
Beispiel #8
0
 def test_deployment_state(self):
     """ Test the Deployment state of the FSM. """
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     from supvisors.statemachine import AbstractState, DeploymentState
     from supvisors.ttypes import ApplicationStates, SupvisorsStates
     state = DeploymentState(self.supvisors)
     self.assertIsInstance(state, AbstractState)
     # test enter method
     # test that start_applications is  called only when local address is the master address
     with patch.object(self.supvisors.starter,
                       'start_applications') as mocked_starter:
         self.supvisors.context.master = False
         state.enter()
         self.assertEqual(0, mocked_starter.call_count)
         # now master address is local
         self.supvisors.context.master = True
         state.enter()
         self.assertEqual(1, mocked_starter.call_count)
     # create application context
     application = ApplicationStatus('sample_test_2', self.supvisors.logger)
     self.supvisors.context.applications['sample_test_2'] = application
     for info in database_copy():
         if info['group'] == 'sample_test_2':
             process = ProcessStatus(info['group'], info['name'],
                                     self.supvisors)
             process.rules.start_sequence = len(process.namespec()) % 3
             process.rules.stop_sequence = len(process.namespec()) % 3 + 1
             process.add_info('10.0.0.1', info)
             application.add_process(process)
     # test application updates
     self.supvisors.context.master = False
     self.assertEqual(ApplicationStates.STOPPED, application.state)
     self.assertFalse(application.minor_failure)
     self.assertFalse(application.major_failure)
     self.assertDictEqual({}, application.start_sequence)
     self.assertDictEqual({}, application.stop_sequence)
     state.enter()
     application = self.supvisors.context.applications['sample_test_2']
     self.assertEqual(ApplicationStates.RUNNING, application.state)
     self.assertTrue(application.minor_failure)
     self.assertFalse(application.major_failure)
     # list order may differ, so break down
     self.assertItemsEqual([0, 1], application.start_sequence.keys())
     self.assertItemsEqual([
         application.processes['yeux_01'], application.processes['yeux_00']
     ], application.start_sequence[0])
     self.assertItemsEqual([application.processes['sleep']],
                           application.start_sequence[1])
     self.assertItemsEqual([1, 2], application.stop_sequence.keys())
     self.assertItemsEqual([
         application.processes['yeux_01'], application.processes['yeux_00']
     ], application.stop_sequence[1])
     self.assertItemsEqual([application.processes['sleep']],
                           application.stop_sequence[2])
     # test next method
     # stay in DEPLOYMENT if local is master and a deployment is in progress, whatever the conflict status
     with patch.object(self.supvisors.starter,
                       'check_starting',
                       return_value=False):
         for conflict in [True, False]:
             with patch.object(self.supvisors.context,
                               'conflicting',
                               return_value=conflict):
                 self.supvisors.context.master = True
                 result = state.next()
                 self.assertEqual(SupvisorsStates.DEPLOYMENT, result)
     # return OPERATION if local is not master and no conflict, whatever the starting status
     self.supvisors.context.master = False
     with patch.object(self.supvisors.context,
                       'conflicting',
                       return_value=False):
         for starting in [True, False]:
             with patch.object(self.supvisors.starter,
                               'check_starting',
                               return_value=starting):
                 result = state.next()
                 self.assertEqual(SupvisorsStates.OPERATION, result)
     # return OPERATION if a deployment is in progress and no conflict, whatever the master status
     with patch.object(self.supvisors.starter,
                       'check_starting',
                       return_value=True):
         with patch.object(self.supvisors.context,
                           'conflicting',
                           return_value=False):
             for master in [True, False]:
                 self.supvisors.context.master = master
                 result = state.next()
                 self.assertEqual(SupvisorsStates.OPERATION, result)
     # return CONCILIATION if local is not master and conflict detected, whatever the starting status
     self.supvisors.context.master = False
     with patch.object(self.supvisors.context,
                       'conflicting',
                       return_value=True):
         for starting in [True, False]:
             with patch.object(self.supvisors.starter,
                               'check_starting',
                               return_value=starting):
                 result = state.next()
                 self.assertEqual(SupvisorsStates.CONCILIATION, result)
     # return CONCILIATION if a deployment is in progress and conflict detected, whatever the master status
     with patch.object(self.supvisors.starter,
                       'check_starting',
                       return_value=True):
         with patch.object(self.supvisors.context,
                           'conflicting',
                           return_value=True):
             for master in [True, False]:
                 self.supvisors.context.master = master
                 result = state.next()
                 self.assertEqual(SupvisorsStates.CONCILIATION, result)
     # no exit implementation. just call it without test
     state.exit()
 def test_deployment_state(self):
     """ Test the Deployment state of the FSM. """
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     from supvisors.statemachine import AbstractState, DeploymentState
     from supvisors.ttypes import ApplicationStates, SupvisorsStates
     state = DeploymentState(self.supvisors)
     self.assertIsInstance(state, AbstractState)
     # test enter method
     # test that start_applications is  called only when local address is the master address
     with patch.object(self.supvisors.starter, 'start_applications') as mocked_starter:
         self.supvisors.context.master = False
         state.enter()
         self.assertEqual(0, mocked_starter.call_count)
         # now master address is local
         self.supvisors.context.master = True
         state.enter()
         self.assertEqual(1, mocked_starter.call_count)
     # create application context
     application = ApplicationStatus('sample_test_2', self.supvisors.logger)
     self.supvisors.context.applications['sample_test_2'] = application
     for info in database_copy():
         if info['group'] == 'sample_test_2':
             process = ProcessStatus(info['group'], info['name'], self.supvisors)
             process.rules.start_sequence = len(process.namespec()) % 3
             process.rules.stop_sequence = len(process.namespec()) % 3 + 1
             process.add_info('10.0.0.1', info)
             application.add_process(process)
     # test application updates
     self.supvisors.context.master = False
     self.assertEqual(ApplicationStates.STOPPED, application.state)
     self.assertFalse(application.minor_failure)
     self.assertFalse(application.major_failure)
     self.assertDictEqual({}, application.start_sequence)
     self.assertDictEqual({}, application.stop_sequence)
     state.enter()
     application = self.supvisors.context.applications['sample_test_2']
     self.assertEqual(ApplicationStates.RUNNING, application.state)
     self.assertTrue(application.minor_failure)
     self.assertFalse(application.major_failure)
     # list order may differ, so break down
     self.assertItemsEqual([0, 1], application.start_sequence.keys())
     self.assertItemsEqual([application.processes['yeux_01'], application.processes['yeux_00']], application.start_sequence[0])
     self.assertItemsEqual([application.processes['sleep']], application.start_sequence[1])
     self.assertItemsEqual([1, 2], application.stop_sequence.keys())
     self.assertItemsEqual([application.processes['yeux_01'], application.processes['yeux_00']], application.stop_sequence[1])
     self.assertItemsEqual([application.processes['sleep']], application.stop_sequence[2])
     # test next method
     # stay in DEPLOYMENT if local is master and a starting is in progress, whatever the conflict status
     with patch.object(self.supvisors.starter, 'check_starting', return_value=False):
         for conflict in [True, False]:
             with patch.object(self.supvisors.context, 'conflicting', return_value=conflict):
                 self.supvisors.context.master = True
                 result = state.next()
                 self.assertEqual(SupvisorsStates.DEPLOYMENT, result)
     # return OPERATION if local is not master and no conflict, whatever the starting status
     self.supvisors.context.master = False
     with patch.object(self.supvisors.context, 'conflicting', return_value=False):
         for starting in [True, False]:
             with patch.object(self.supvisors.starter, 'check_starting', return_value=starting):
                 result = state.next()
                 self.assertEqual(SupvisorsStates.OPERATION, result)
     # return OPERATION if a starting is in progress and no conflict, whatever the master status
     with patch.object(self.supvisors.starter, 'check_starting', return_value=True):
         with patch.object(self.supvisors.context, 'conflicting', return_value=False):
             for master in [True, False]:
                 self.supvisors.context.master = master
                 result = state.next()
                 self.assertEqual(SupvisorsStates.OPERATION, result)
      # return CONCILIATION if local is not master and conflict detected, whatever the starting status
     self.supvisors.context.master = False
     with patch.object(self.supvisors.context, 'conflicting', return_value=True):
         for starting in [True, False]:
             with patch.object(self.supvisors.starter, 'check_starting', return_value=starting):
                 result = state.next()
                 self.assertEqual(SupvisorsStates.CONCILIATION, result)
     # return CONCILIATION if a starting is in progress and conflict detected, whatever the master status
     with patch.object(self.supvisors.starter, 'check_starting', return_value=True):
         with patch.object(self.supvisors.context, 'conflicting', return_value=True):
             for master in [True, False]:
                 self.supvisors.context.master = master
                 result = state.next()
                 self.assertEqual(SupvisorsStates.CONCILIATION, result)
     # no exit implementation. just call it without test
     state.exit()
Beispiel #10
0
 def test_update_status(self):
     """ Test the rules to update the status of the application method. """
     from supervisor.states import ProcessStates
     from supvisors.application import ApplicationStatus
     from supvisors.process import ProcessStatus
     from supvisors.ttypes import ApplicationStates
     application = ApplicationStatus('ApplicationTest',
                                     self.supvisors.logger)
     # add processes to the application
     for info in ProcessInfoDatabase:
         process = ProcessStatus(info['group'], info['name'],
                                 self.supvisors)
         process.add_info('10.0.0.1', info.copy())
         application.add_process(process)
     # init status
     # there are lots of states but the 'strongest' is STARTING
     # STARTING is a 'running' state so major/minor failures are applicable
     application.update_status()
     self.assertEqual(ApplicationStates.STARTING, application.state)
     # there is a FATAL state in the process database
     # no rule is set for processes, so there are only minor failures
     self.assertFalse(application.major_failure)
     self.assertTrue(application.minor_failure)
     # set FATAL process to major
     fatal_process = next((process
                           for process in application.processes.values()
                           if process.state == ProcessStates.FATAL), None)
     fatal_process.rules.required = True
     # update status. major failure is now expected
     application.update_status()
     self.assertEqual(ApplicationStates.STARTING, application.state)
     self.assertTrue(application.major_failure)
     self.assertFalse(application.minor_failure)
     # set STARTING process to RUNNING
     starting_process = next(
         (process for process in application.processes.values()
          if process.state == ProcessStates.STARTING), None)
     starting_process.state = ProcessStates.RUNNING
     # update status. there is still one BACKOFF process leading to STARTING application
     application.update_status()
     self.assertEqual(ApplicationStates.STARTING, application.state)
     self.assertTrue(application.major_failure)
     self.assertFalse(application.minor_failure)
     # set BACKOFF process to EXITED
     backoff_process = next(
         (process for process in application.processes.values()
          if process.state == ProcessStates.BACKOFF), None)
     backoff_process.state = ProcessStates.EXITED
     # update status. the 'strongest' state is now STOPPING
     # as STOPPING is not a 'running' state, failures are not applicable
     application.update_status()
     self.assertEqual(ApplicationStates.STOPPING, application.state)
     self.assertFalse(application.major_failure)
     self.assertFalse(application.minor_failure)
     # set STOPPING process to STOPPED
     stopping_process = next(
         (process for process in application.processes.values()
          if process.state == ProcessStates.STOPPING), None)
     stopping_process.state = ProcessStates.STOPPED
     # update status. the 'strongest' state is now RUNNING
     # failures are applicable again
     application.update_status()
     self.assertEqual(ApplicationStates.RUNNING, application.state)
     self.assertTrue(application.major_failure)
     self.assertFalse(application.minor_failure)
     # set RUNNING processes to STOPPED
     for process in application.processes.values():
         if process.state == ProcessStates.RUNNING:
             process.state = ProcessStates.STOPPED
     # update status. the 'strongest' state is now RUNNING
     # failures are not applicable anymore
     application.update_status()
     self.assertEqual(ApplicationStates.STOPPED, application.state)
     self.assertFalse(application.major_failure)
     self.assertFalse(application.minor_failure)