def _get_global_config(config_file, options):
    global_config = None
    try:
        global_config = ValidConfig.ValidConfig(config_file)
    except Exception as msg:
        sys.exit(f"Failed to load configuration {config_file}\n{msg}")

    global_config.update({
        'server_address': ['localhost', options.port]  # Use Jsonnet-supported schema (i.e. not a tuple)
    })
    return global_config
Пример #2
0
def _get_global_config(config_file, options):
    global_config = None
    try:
        global_config = ValidConfig.ValidConfig(config_file)
    except Exception as msg:  # pragma: no cover
        sys.exit(f"Failed to load configuration {config_file}\n{msg}")

    global_config.update(
        # Use Jsonnet-supported schema (i.e. not a tuple)
        {"server_address": ["localhost", options.port]})

    if options.no_webserver:
        global_config.update({"no_webserver": True})

    return global_config
Пример #3
0
    def _load_channel(self, channel_name, path):
        channel_config = None
        self.logger.debug(f"Loading channel {channel_name} from {path}.")
        try:
            channel_config = ValidConfig.ValidConfig(path)
        except Exception as msg:
            return (False, f"Failed to open channel configuration file {path} "
                    f"contains error\n-> {msg}\nSKIPPING channel")

        try:
            _check_keys(channel_config)
        except Exception as msg:
            return (False, f"The channel configuration file {path} contains a "
                    f"validation error\n{msg}\nSKIPPING channel")
        self.logger.debug(f"Channel {channel_name} config is valid.")

        self.channels[channel_name] = channel_config
        return (True, channel_config)
Пример #4
0
def test_wrong_type_config():
    with pytest.raises(RuntimeError):
        ValidConfig._convert_to_json(_global_config_file('wrong_type.conf'))
Пример #5
0
def test_invalid_config():
    with pytest.raises(RuntimeError):
        ValidConfig._convert_to_json(_global_config_file('invalid.jsonnet'))
Пример #6
0
def test_empty_config():
    with pytest.raises(RuntimeError):
        ValidConfig._convert_to_json(_global_config_file('empty.conf'))
Пример #7
0
def test_no_such_file():
    with pytest.raises(RuntimeError):
        ValidConfig._convert_to_json('/this/file/really/shouldnt/exist')