Esempio n. 1
0
 def to_port_num(value):
     """ Convert a string into a port number. """
     value = integer(value)
     if 0 < value <= 65535:
         return value
     raise ValueError('invalid value for port: %d. expected in [1;65535]' %
                      value)
Esempio n. 2
0
 def server_configs_from_parser(self, parser):
     """ The following has nothing to deal with Supervisor's server configurations.
     It gets Supvisors configuration.
     Supervisor's ServerOptions has not been designed to be specialized.
     This method is overriden just to have an access point to the Supervisor parser. """
     configs = ServerOptions.server_configs_from_parser(self, parser)
     # set section
     if not parser.has_section(SupvisorsServerOptions._Section):
         raise ValueError('.ini file ({}) does not include a [{}] section'.format(self.configfile, self._Section))
     temp, parser.mysection = parser.mysection, self._Section
     # get values
     opt = self.supvisors_options
     opt.address_list = list(OrderedDict.fromkeys(filter(None, list_of_strings(parser.getdefault('address_list', gethostname())))))
     opt.rules_file = parser.getdefault('rules_file', None)
     if opt.rules_file:
         opt.rules_file = existing_dirpath(opt.rules_file)
     opt.internal_port = self.to_port_num(parser.getdefault('internal_port', '65001'))
     opt.event_port = self.to_port_num(parser.getdefault('event_port', '65002'))
     opt.auto_fence = boolean(parser.getdefault('auto_fence', 'false'))
     opt.synchro_timeout = self.to_timeout(parser.getdefault('synchro_timeout', '15'))
     opt.conciliation_strategy = self.to_conciliation_strategy(parser.getdefault('conciliation_strategy', 'USER'))
     opt.starting_strategy = self.to_starting_strategy(parser.getdefault('starting_strategy', 'CONFIG'))
     # configure statistics
     opt.stats_periods = self.to_periods(list_of_strings(parser.getdefault('stats_periods', '10')))
     opt.stats_histo = self.to_histo(parser.getdefault('stats_histo', 200))
     opt.stats_irix_mode = boolean(parser.getdefault('stats_irix_mode', 'false'))
     # configure logger
     opt.logfile = existing_dirpath(parser.getdefault('logfile', '{}.log'.format(SupvisorsServerOptions._Section)))
     opt.logfile_maxbytes = byte_size(parser.getdefault('logfile_maxbytes', '50MB'))
     opt.logfile_backups = integer(parser.getdefault('logfile_backups', 10))
     opt.loglevel = logging_level(parser.getdefault('loglevel', 'info'))
     # reset mysection and return original result
     parser.mysection = temp
     return configs
Esempio n. 3
0
 def to_histo(value):
     """ Convert a string into a value of historic depth. """
     histo = integer(value)
     if 10 <= histo <= 1500:
         return histo
     raise ValueError(
         'invalid value for stats_histo: {}. expected in [10;1500] (seconds)'
         .format(value))
Esempio n. 4
0
 def to_timeout(value):
     """ Convert a string into a timeout value. """
     value = integer(value)
     if 0 < value <= 1000:
         return value
     raise ValueError(
         'invalid value for synchro_timeout: %d. expected in [1;1000] (seconds)'
         % value)
Esempio n. 5
0
 def server_configs_from_parser(self, parser):
     """ The following has nothing to deal with Supervisor's server configurations.
     It gets Supvisors configuration.
     Supervisor's ServerOptions has not been designed to be specialized.
     This method is overriden just to have an access point to the Supervisor parser. """
     configs = ServerOptions.server_configs_from_parser(self, parser)
     # set section
     if not parser.has_section(SupvisorsServerOptions._Section):
         raise ValueError(
             '.ini file ({}) does not include a [{}] section'.format(
                 self.configfile, self._Section))
     temp, parser.mysection = parser.mysection, self._Section
     # get values
     opt = self.supvisors_options
     opt.address_list = list(
         OrderedDict.fromkeys(
             filter(
                 None,
                 list_of_strings(
                     parser.getdefault('address_list', gethostname())))))
     opt.deployment_file = parser.getdefault('deployment_file', None)
     if opt.deployment_file:
         opt.deployment_file = existing_dirpath(opt.deployment_file)
     opt.internal_port = self.to_port_num(
         parser.getdefault('internal_port', '65001'))
     opt.event_port = self.to_port_num(
         parser.getdefault('event_port', '65002'))
     opt.auto_fence = boolean(parser.getdefault('auto_fence', 'false'))
     opt.synchro_timeout = self.to_timeout(
         parser.getdefault('synchro_timeout', '15'))
     opt.conciliation_strategy = self.to_conciliation_strategy(
         parser.getdefault('conciliation_strategy', 'USER'))
     opt.deployment_strategy = self.to_deployment_strategy(
         parser.getdefault('deployment_strategy', 'CONFIG'))
     # configure statistics
     opt.stats_periods = self.to_periods(
         list_of_strings(parser.getdefault('stats_periods', '10')))
     opt.stats_histo = self.to_histo(parser.getdefault('stats_histo', 200))
     opt.stats_irix_mode = boolean(
         parser.getdefault('stats_irix_mode', 'false'))
     # configure logger
     opt.logfile = existing_dirpath(
         parser.getdefault('logfile', '{}.log'.format(
             SupvisorsServerOptions._Section)))
     opt.logfile_maxbytes = byte_size(
         parser.getdefault('logfile_maxbytes', '50MB'))
     opt.logfile_backups = integer(parser.getdefault('logfile_backups', 10))
     opt.loglevel = logging_level(parser.getdefault('loglevel', 'info'))
     # reset mysection and return original result
     parser.mysection = temp
     return configs
Esempio n. 6
0
 def to_periods(value):
     """ Convert a string into a list of period values. """
     if len(value) == 0:
         raise ValueError('unexpected number of stats_periods: {}. minimum is 1'.format(value))
     if len(value) > 3:
         raise ValueError('unexpected number of stats_periods: {}. maximum is 3'.format(value))
     periods = []
     for val in value:
         period = integer(val)
         if 5 > period or period > 3600:
             raise ValueError('invalid value for stats_periods: {}. expected in [5;3600] (seconds)'.format(val))
         if period % 5 != 0:
             raise ValueError('invalid value for stats_periods: %d. expected multiple of 5' % period)
         periods.append(period)
     return sorted(filter(None, periods))
Esempio n. 7
0
 def to_periods(value):
     """ Convert a string into a list of period values. """
     if len(value) > 3:
         raise ValueError(
             'unexpected number of periods: {}. maximum is 3'.format(value))
     periods = []
     for val in value:
         period = integer(val)
         if 5 > period or period > 3600:
             raise ValueError(
                 'invalid value for period: {}. expected in [5;3600] (seconds)'
                 .format(val))
         if period % 5 != 0:
             raise ValueError(
                 'invalid value for period: %d. expected multiple of 5' %
                 period)
         periods.append(period)
     return sorted(filter(None, periods))
Esempio n. 8
0
 def test_integer(self):
     from supervisor.datatypes import integer
     self.assertRaises(ValueError, integer, 'abc')
     self.assertEqual(integer('1'), 1)
     self.assertEqual(integer(str(sys.maxint + 1)), sys.maxint + 1)
Esempio n. 9
0
 def _callFUT(self, arg):
     return datatypes.integer(arg)
Esempio n. 10
0
    def test_integer(self):
        from supervisor.datatypes import integer

        self.assertRaises(ValueError, integer, "abc")
        self.assertEqual(integer("1"), 1)
        self.assertEqual(integer(str(sys.maxint + 1)), sys.maxint + 1)
Esempio n. 11
0
 def _callFUT(self, arg):
     return datatypes.integer(arg)
Esempio n. 12
0
 def to_histo(value):
     """ Convert a string into a value of historic depth. """
     histo = integer(value)
     if 10 <= histo <= 1500:
         return histo
     raise ValueError('invalid value for stats_histo: {}. expected in [10;1500] (seconds)'.format(value))
Esempio n. 13
0
 def to_timeout(value):
     """ Convert a string into a timeout value. """
     value = integer(value)
     if 0 < value <= 1000:
         return value
     raise ValueError('invalid value for synchro_timeout: %d. expected in [1;1000] (seconds)' % value)
Esempio n. 14
0
 def to_port_num(value):
     """ Convert a string into a port number. """
     value = integer(value)
     if 0 < value <= 65535:
         return value
     raise ValueError('invalid value for port: %d. expected in [1;65535]' % value)
Esempio n. 15
0
 def test_integer(self):
     from supervisor.datatypes import integer
     self.assertRaises(ValueError, integer, 'abc')
     self.assertEqual(integer('1'), 1)
     self.assertEqual(integer(str(maxint+1)), maxint+1)