コード例 #1
0
ファイル: conditions.py プロジェクト: yasirz/DIRBS-Core
    def __init__(self, *, ignore_env, **cond_config):
        """Constructor which parses the condition config."""
        super(ConditionConfig, self).__init__(ignore_env=ignore_env, **cond_config)
        self.label = self._parse_string('label', max_len=64)

        # Check that condition name contains only letters, underscores and digits(0-9)
        bad_symbol_error_message = 'Condition label {0} must contain only letters, underscores or digits(0-9)!'
        parse_alphanum(self.label.lower(), bad_symbol_error_message)

        self.grace_period = self._parse_positive_int('grace_period_days')
        self.blocking = self._parse_bool('blocking')
        self.sticky = self._parse_bool('sticky')
        self.reason = self._parse_string('reason')
        self.max_allowed_matching_ratio = self._parse_float_ratio('max_allowed_matching_ratio')
        self.amnesty_eligible = self._parse_bool('amnesty_eligible')
        if self.reason.find('|') != -1:
            msg = 'Illegal pipe character in reason string for condition: {0}'.format(self.label)
            _logger.error(msg)
            raise ConfigParseException(msg)

        dimensions = self.raw_config['dimensions']
        if not isinstance(dimensions, list):
            msg = 'Dimensions not a list type!'
            _logger.error('{0}: {1}'.format(self.section_name, msg))
            raise ConfigParseException(msg)
        self.dimensions = [DimensionConfig(ignore_env=ignore_env, **d) for d in dimensions]

        if self.amnesty_eligible and not self.blocking:
            msg = 'Informational conditions cannot have amnesty_eligible flag set to True.'
            _logger.error('{0}: {1}'.format(self.section_name, msg))
            raise ConfigParseException(msg)
コード例 #2
0
ファイル: region.py プロジェクト: joaquimkalala/DIRBS-Core
    def __init__(self, **operator_config):
        """Constructor which parses the operator config."""
        super(OperatorConfig, self).__init__(**operator_config)
        self.id = self._parse_string('id', max_len=16)

        if self.id != self.id.lower():
            _logger.warning('operator_id: {0} has been changed to '
                            'lower case: {1}'.format(self.id, self.id.lower()))
            self.id = self.id.lower()

        # Check that operator_ids contains only letters, underscores and digits(0-9)
        bad_symbol_error_message = 'Operator_id {0} must contain only letters, underscores or digits(0-9)!'
        parse_alphanum(self.id, bad_symbol_error_message)

        self.name = self._parse_string('name')
        if self.id == self.COUNTRY_OPERATOR_NAME:
            msg = "Invalid use of reserved operator name \'__all__\' in config!"
            _logger.error(msg)
            raise ConfigParseException(msg)

        # Make sure mcc_mnc key is there and is a list
        if 'mcc_mnc_pairs' not in operator_config or type(
                operator_config['mcc_mnc_pairs']) is not list:
            msg = 'Missing (or non-list) {0} in config for operator ID {1}!'.format(
                'mcc_mnc_pairs', self.id)
            _logger.error(msg)
            raise ConfigParseException(msg)

        # Validate each MCC/MNC pair
        for mcc_mnc in self.raw_config['mcc_mnc_pairs']:
            for key in ['mcc', 'mnc']:
                try:
                    int(mcc_mnc[key])
                except (ValueError, KeyError):
                    msg = 'Non-existent or non integer {0} in config for operator ID {1}!'.format(
                        key, self.id)
                    _logger.error(msg)
                    raise ConfigParseException(msg)

        # Make sure we stringify mcc and mnc values in case they were interpreted as ints by YAML parser
        self.mcc_mnc_pairs = \
            [{'mcc': str(x['mcc']), 'mnc': str(x['mnc'])} for x in self.raw_config['mcc_mnc_pairs']]

        if self.mcc_mnc_pairs is None or len(self.mcc_mnc_pairs) <= 0:
            msg = 'At least one valid MCC-MNC pair must be provided for operator ID {0}.'.format(
                self.id)
            _logger.error(msg)
            raise ConfigParseException(msg)
コード例 #3
0
    def __init__(self, **operator_config):
        """Constructor which parses the operator config."""
        super(BrokerOperatorConfig, self).__init__(**operator_config)
        self.id = self._parse_string('id', max_len=16)

        if self.id != self.id.lower():
            _logger.warning('operator_id: {0} has been changed to '
                            'lower case: {1}'.format(self.id, self.id.lower()))
            self.id = self.id.lower()

        # Check that operator_ids contains only letters, underscores and digits(0-9)
        bad_symbol_error_message = 'Operator_id {0} must contain only letters, underscores or digits(0-9)!'
        parse_alphanum(self.id, bad_symbol_error_message)

        self.name = self._parse_string('name')
        if self.id == self.COUNTRY_OPERATOR_NAME:
            msg = "Invalid use of reserved operator name \'__all__\' in config!"
            _logger.error(msg)
            raise ConfigParseException(msg)
        self.topic = self._parse_string('topic')