Esempio n. 1
0
    def __init__(self, *, ignore_env, **broker_config):
        """Constructor which parses the broker config."""
        super(BrokerConfig, self).__init__(ignore_env=ignore_env, **broker_config)
        self.kafka = KafkaConfig(ignore_env=ignore_env, **broker_config.get('kafka'))
        self.operators = [BrokerOperatorConfig(ignore_env=ignore_env, **o) for o in broker_config.get('operators', [])]

        # Check that operator_ids are unique and case-insensitive
        dupl_op_id_found_error_message = 'Duplicate operator_ids {0} found in config. ' \
                                         'Operator_ids are case insensitive!'
        operator_id_list = [o.id for o in self.operators]
        check_for_duplicates(operator_id_list, dupl_op_id_found_error_message)
Esempio n. 2
0
    def __init__(self, *, ignore_env, **region_config):
        """Constructor which parses the region config."""
        super(RegionConfig, self).__init__(ignore_env=ignore_env, **region_config)
        self.name = self._parse_string('name')
        self.import_msisdn_data = self._parse_bool('import_msisdn_data')
        self.import_rat_data = self._parse_bool('import_rat_data')

        # Check that country codes are strings that can be converted to ints
        try:
            [int(x) for x in self.raw_config['country_codes']]
        except ValueError:
            msg = '{0}: non-numeric value for country code!'.format(self.section_name)
            _logger.error(msg)
            raise ConfigParseException(msg)

        # Make sure we store country codes as strings
        self.country_codes = [str(x) for x in self.raw_config['country_codes']]

        if self.country_codes is None or len(self.country_codes) <= 0:
            msg = 'Country Code must be provided for "region" section in config'
            _logger.error(msg)
            raise ConfigParseException(msg)

        # Populate operators array
        self.operators = [OperatorConfig(ignore_env=ignore_env, **o) for o in region_config.get('operators', [])]

        # Check that operator_ids are unique and case-insensitive
        dupl_op_id_found_error_message = 'Duplicate operator_ids {0} found in config. ' \
                                         'Operator_ids are case insensitive!'
        operator_id_list = [o.id for o in self.operators]
        check_for_duplicates(operator_id_list, dupl_op_id_found_error_message)

        # Parse exempted device types if present
        self.exempted_device_types = [str(x) for x in self.raw_config.get('exempted_device_types', [])]

        # Check the mcc_mnc pairs are unique and that no mcc-mnc can begin with another mcc-mnc
        dupl_mcc_mnc_found_error_message = 'Duplicate MCC-MNC pairs {0} found in config. ' \
                                           'MCC-MNC pairs must be unique across all operators!'
        all_mncs = [p['mcc'] + p['mnc'] for o in self.operators for p in o.mcc_mnc_pairs]
        check_for_duplicates(all_mncs, dupl_mcc_mnc_found_error_message)
        all_mncs_set = set(all_mncs)
        substring_mcc_mnc_error_message = 'MCC-MNC pair {0} found which starts with another configured MCC-MNC pair ' \
                                          '{1}. MCC-MNC pairs must be disjoint from each other (not be prefixed by ' \
                                          'another MCC-MNC)!'
        for mcc_mnc in all_mncs_set:
            mcc_mncs_to_check = all_mncs_set.copy()
            mcc_mncs_to_check.remove(mcc_mnc)
            for other_mcc_mnc in mcc_mncs_to_check:
                if mcc_mnc.startswith(other_mcc_mnc):
                    err_msg = substring_mcc_mnc_error_message.format(mcc_mnc, other_mcc_mnc)
                    _logger.error(err_msg)
                    raise ConfigParseException(err_msg)
Esempio n. 3
0
    def __init__(self, *, ignore_env, **yaml_config):
        """Constructor performing common section parsing for config sections."""
        self.db_config = DBConfig(ignore_env=ignore_env,
                                  **(yaml_config.get('postgresql', {}) or {}))
        self.region_config = RegionConfig(ignore_env=ignore_env,
                                          **(yaml_config.get('region', {})
                                             or {}))
        self.log_config = LoggingConfig(ignore_env=ignore_env,
                                        **(yaml_config.get('logging', {})
                                           or {}))
        self.import_config = ImporterConfig(ignore_env=ignore_env,
                                            **(yaml_config.get('import', {})
                                               or {}))
        self.conditions = [
            ConditionConfig(ignore_env=ignore_env, **c)
            for c in yaml_config.get('conditions', [])
        ]
        cond_names = [c.label.lower() for c in self.conditions]

        # Check that condition names are unique and case-insensitive
        dupl_cond_name_found_error_message = 'Duplicate condition names {0} found in config. ' \
                                             'Condition names are case insensitive!'
        check_for_duplicates(cond_names, dupl_cond_name_found_error_message)

        self.operator_threshold_config = OperatorThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('operator_threshold', {}) or {}))
        self.gsma_threshold_config = GSMAThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('gsma_threshold', {}) or {}))
        self.pairing_threshold_config = PairingListThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('pairing_list_threshold', {}) or {}))
        self.subscribers_threshold_config = SubscribersListThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('subscribers_list_threshold', {}) or {}))
        self.stolen_threshold_config = StolenListThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('stolen_list_threshold', {}) or {}))
        self.import_threshold_config = \
            RegistrationListThresholdConfig(ignore_env=ignore_env,
                                            **(yaml_config.get('registration_list_threshold', {}) or {}))
        self.golden_threshold_config = GoldenListThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('golden_list_threshold', {}) or {}))
        self.barred_threshold_config = BarredListThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('barred_list_threshold', {}) or {}))
        self.monitoring_threshold_config = MonitoringListThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('monitoring_list_threshold', {}) or {}))
        self.barred_tac_threshold_config = BarredTacListThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('barred_tac_list_threshold', {}) or {}))
        self.associations_threshold_config = DeviceAssociationListThresholdConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('association_list_threshold', {}) or {}))
        self.retention_config = RetentionConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('data_retention', {}) or {}))
        self.listgen_config = ListGenerationConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('list_generation', {}) or {}))
        self.report_config = ReportGenerationConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('report_generation', {}) or {}))
        self.multiprocessing_config = MultiprocessingConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('multiprocessing', {}) or {}))
        self.statsd_config = StatsdConfig(ignore_env=ignore_env,
                                          **(yaml_config.get('statsd', {})
                                             or {}))
        self.catalog_config = CatalogConfig(ignore_env=ignore_env,
                                            **(yaml_config.get('catalog', {})
                                               or {}))
        self.amnesty_config = AmnestyConfig(ignore_env=ignore_env,
                                            **(yaml_config.get('amnesty', {})
                                               or {}))
        self.broker_config = BrokerConfig(ignore_env=ignore_env,
                                          **(yaml_config.get('broker', {})
                                             or {}))
        self.operational_config = OperationalConfig(
            ignore_env=ignore_env,
            **(yaml_config.get('operational', {}) or {}))