Beispiel #1
0
 def test_RunningFailureStrategies(self):
     """ Test the RunningFailureStrategies enumeration. """
     from supvisors.ttypes import RunningFailureStrategies
     self.assertEqual('CONTINUE', RunningFailureStrategies._to_string(RunningFailureStrategies.CONTINUE))
     self.assertEqual('RESTART_PROCESS', RunningFailureStrategies._to_string(RunningFailureStrategies.RESTART_PROCESS))
     self.assertEqual('STOP_APPLICATION', RunningFailureStrategies._to_string(RunningFailureStrategies.STOP_APPLICATION))
     self.assertEqual('RESTART_APPLICATION', RunningFailureStrategies._to_string(RunningFailureStrategies.RESTART_APPLICATION))
Beispiel #2
0
 def load_application_rules(self, application):
     # find application element
     self.logger.trace('searching application element for {}'.format(application.application_name))
     application_elt = self.root.find("./application[@name='{}']".format(application.application_name))
     if application_elt is not None:
         # get start_sequence rule
         value = application_elt.findtext('start_sequence')
         application.rules.start_sequence = int(value) if value and int(value)>0 else 0
         # get stop_sequence rule
         value = application_elt.findtext('stop_sequence')
         application.rules.stop_sequence = int(value) if value and int(value)>0 else 0
         # get starting_failure_strategy rule
         value = application_elt.findtext('starting_failure_strategy')
         if value:
             strategy = StartingFailureStrategies._from_string(value)
             if strategy:
                 application.rules.starting_failure_strategy = strategy
         # get running_failure_strategy rule
         value = application_elt.findtext('running_failure_strategy')
         if value:
             strategy = RunningFailureStrategies._from_string(value)
             if strategy:
                 application.rules.running_failure_strategy = strategy
         # final print
         self.logger.debug('application {} - rules {}'.format(application.application_name, application.rules))
Beispiel #3
0
 def __str__(self):
     """ Contents as string. """
     return 'start_sequence={} stop_sequence={} starting_failure_strategy={}'\
         ' running_failure_strategy={}'.format(
             self.start_sequence, self.stop_sequence,
             StartingFailureStrategies._to_string(self.starting_failure_strategy),
             RunningFailureStrategies._to_string(self.running_failure_strategy))
Beispiel #4
0
    def check_dependencies(self, namespec):
        """ Update rules after they have been read from the rules file.

        A required process that is not in the starting sequence is forced to
        optional.
        If addresses are not defined, all addresses are applicable.
        Supervisor autorestart is not compatible with RunningFailureStrategy
        STOP / RESTART.
        """
        # required MUST have start_sequence, so force to optional if
        # start_sequence is not set
        if self.required and self.start_sequence == 0:
            self.logger.warn('{} - required forced to False because'
                ' no start_sequence defined'.format(namespec))
            self.required = False
        # if no addresses, consider all addresses
        if not self.addresses:
            self.addresses = ['*']
            self.logger.warn('{} - no address defined so all Supvisors'
                ' addresses are applicable'.format(namespec))
        # disable autorestart when RunningFailureStrategies is not CONTINUE
        if self.running_failure_strategy != RunningFailureStrategies.CONTINUE:
            if self.info_source.autorestart(namespec):
                self.info_source.disable_autorestart(namespec)
                self.logger.warn('{} - autorestart disabled due to running failure'
                    ' strategy {}'.format(namespec,
                    RunningFailureStrategies._to_string(self.running_failure_strategy)))
Beispiel #5
0
 def __str__(self):
     """ Contents as string. """
     return 'start_sequence={} stop_sequence={} starting_failure_strategy={}'\
         ' running_failure_strategy={}'.format(
             self.start_sequence, self.stop_sequence,
             StartingFailureStrategies._to_string(self.starting_failure_strategy),
             RunningFailureStrategies._to_string(self.running_failure_strategy))
Beispiel #6
0
 def __str__(self):
     """ Contents as string. """
     return 'addresses={} start_sequence={} stop_sequence={} required={}' \
         ' wait_exit={} expected_loading={} running_failure_strategy={}'.\
         format(self.addresses,
             self.start_sequence, self.stop_sequence, self.required,
             self.wait_exit, self.expected_loading,
             RunningFailureStrategies._to_string(self.running_failure_strategy))
Beispiel #7
0
 def serial(self):
     """ Return a serializable form of the ApplicationRules. """
     return {'start_sequence': self.start_sequence,
         'stop_sequence': self.stop_sequence,
         'starting_failure_strategy':
             StartingFailureStrategies._to_string(self.starting_failure_strategy),
         'running_failure_strategy':
             RunningFailureStrategies._to_string(self.running_failure_strategy)}
Beispiel #8
0
 def __str__(self):
     """ Contents as string. """
     return 'addresses={} start_sequence={} stop_sequence={} required={}' \
         ' wait_exit={} expected_loading={} running_failure_strategy={}'.\
         format(self.addresses,
             self.start_sequence, self.stop_sequence, self.required,
             self.wait_exit, self.expected_loading,
             RunningFailureStrategies._to_string(
                 self.running_failure_strategy))
Beispiel #9
0
 def serial(self):
     """ Return a serializable form of the ProcessRules. """
     return {'addresses': self.addresses,
         'start_sequence': self.start_sequence,
         'stop_sequence': self.stop_sequence,
         'required': self.required,
         'wait_exit': self.wait_exit,
         'expected_loading': self.expected_loading,
         'running_failure_strategy':
             RunningFailureStrategies._to_string(
                 self.running_failure_strategy)}
Beispiel #10
0
 def load_process_rules(self, process):
     self.logger.trace('searching program element for {}'.format(
         process.namespec()))
     program_elt = self.get_program_element(process)
     rules = process.rules
     if program_elt is not None:
         # get addresses rule
         self.get_program_addresses(program_elt, rules)
         # get start_sequence rule
         value = program_elt.findtext('start_sequence')
         try:
             rules.start_sequence = int(value)
             if rules.start_sequence < 0:
                 raise
         except:
             rules.start_sequence = 0
         # get stop_sequence rule
         value = program_elt.findtext('stop_sequence')
         try:
             rules.stop_sequence = int(value)
             if rules.stop_sequence < 0:
                 raise
         except:
             rules.stop_sequence = 0
         # get required rule
         value = program_elt.findtext('required')
         try:
             rules.required = boolean(value)
         except:
             rules.required = False
         # get wait_exit rule
         value = program_elt.findtext('wait_exit')
         try:
             rules.wait_exit = boolean(value)
         except:
             rules.wait_exit = False
         # get expected_loading rule
         value = program_elt.findtext('expected_loading')
         try:
             rules.expected_loading = int(value)
             if not 0 <= rules.expected_loading <= 100:
                 raise
         except:
             rules.expected_loading = 1
         # get running_failure_strategy rule
         value = program_elt.findtext('running_failure_strategy')
         if value:
             strategy = RunningFailureStrategies._from_string(value)
             if strategy:
                 rules.running_failure_strategy = strategy
         # check that rules are compliant with dependencies
         rules.check_dependencies(process.namespec())
         self.logger.debug('process {} - rules {}'.format(
             process.namespec(), rules))
Beispiel #11
0
 def load_process_rules(self, process):
     self.logger.trace('searching program element for {}'.format(process.namespec()))
     program_elt = self.get_program_element(process)
     rules = process.rules
     if program_elt is not None:
         # get addresses rule
         self.get_program_addresses(program_elt, rules)
         # get start_sequence rule
         value = program_elt.findtext('start_sequence')
         try:
             rules.start_sequence = int(value)
             if rules.start_sequence < 0:
                 raise
         except:
             rules.start_sequence = 0
         # get stop_sequence rule
         value = program_elt.findtext('stop_sequence')
         try:
             rules.stop_sequence = int(value)
             if rules.stop_sequence < 0:
                 raise
         except:
             rules.stop_sequence = 0
         # get required rule
         value = program_elt.findtext('required')
         try:
             rules.required = boolean(value)
         except:
             rules.required = False
         # get wait_exit rule
         value = program_elt.findtext('wait_exit')
         try:
             rules.wait_exit = boolean(value)
         except:
             rules.wait_exit = False
         # get expected_loading rule
         value = program_elt.findtext('expected_loading')
         try:
             rules.expected_loading = int(value)
             if not 0 <= rules.expected_loading <= 100:
                 raise
         except:
             rules.expected_loading = 1
         # get running_failure_strategy rule
         value = program_elt.findtext('running_failure_strategy')
         if value:
             strategy = RunningFailureStrategies._from_string(value)
             if strategy:
                 rules.running_failure_strategy = strategy
         # check that rules are compliant with dependencies
         rules.check_dependencies(process.namespec())
         self.logger.debug('process {} - rules {}'.format(process.namespec(), rules))
Beispiel #12
0
 def serial(self):
     """ Return a serializable form of the ApplicationRules. """
     return {
         'start_sequence':
         self.start_sequence,
         'stop_sequence':
         self.stop_sequence,
         'starting_failure_strategy':
         StartingFailureStrategies._to_string(
             self.starting_failure_strategy),
         'running_failure_strategy':
         RunningFailureStrategies._to_string(self.running_failure_strategy)
     }
Beispiel #13
0
 def test_dependency_rules_running_failure(self):
     """ Test the dependency related to running failure strategy in process rules.
     Done in a separate test as it impacts the supervisor internal model. """
     from supvisors.process import ProcessRules
     from supvisors.ttypes import RunningFailureStrategies
     rules = ProcessRules(self.supvisors)
     # test that only the CONTINUE strategy keeps the autorestart
     mocked_disable = self.supvisors.info_source.disable_autorestart
     for strategy in RunningFailureStrategies._values():
         rules.running_failure_strategy = strategy
         rules.check_dependencies('dummy_process_1')
         if strategy == RunningFailureStrategies.CONTINUE:
             self.assertEqual(0, mocked_disable.call_count)
         else:
             self.assertEqual([call('dummy_process_1')], mocked_disable.call_args_list)
             mocked_disable.reset_mock()
Beispiel #14
0
 def test_dependency_rules_running_failure(self):
     """ Test the dependency related to running failure strategy in process rules.
     Done in a separate test as it impacts the supervisor internal model. """
     from supvisors.process import ProcessRules
     from supvisors.ttypes import RunningFailureStrategies
     rules = ProcessRules(self.supvisors)
     # test that only the CONTINUE strategy keeps the autorestart
     mocked_disable = self.supvisors.info_source.disable_autorestart
     for strategy in RunningFailureStrategies._values():
         rules.running_failure_strategy = strategy
         rules.check_dependencies('dummy_process_1')
         if strategy == RunningFailureStrategies.CONTINUE:
             self.assertEqual(0, mocked_disable.call_count)
         else:
             self.assertEqual([call('dummy_process_1')],
                              mocked_disable.call_args_list)
             mocked_disable.reset_mock()