diff --git a/swh/scheduler/api/server.py b/swh/scheduler/api/server.py --- a/swh/scheduler/api/server.py +++ b/swh/scheduler/api/server.py @@ -1,10 +1,11 @@ -# Copyright (C) 2018-2019 The Software Heritage developers +# Copyright (C) 2018-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import logging import os +from typing import Dict from swh.core import config from swh.core.api import JSONFormatter, MsgpackFormatter, RPCServerApp @@ -82,14 +83,14 @@ return links -def load_and_check_config(config_path, type="local"): +def load_and_check_config(config_path: str, type: str = "postgresql") -> Dict: """Check the minimal configuration is set to run the api or raise an error explanation. Args: - config_path (str): Path to the configuration file to load - type (str): configuration type. For 'local' type, more - checks are done. + config_path: Configuration file path to load + type: Configuration type, for 'postgresql' type (the default), more checks are + done. Raises: Error if the setup is not as expected @@ -110,7 +111,7 @@ if not vcfg: raise KeyError("Missing '%scheduler' configuration") - if type == "local": + if type == "postgresql": cls = vcfg.get("cls") if cls not in ("local", "postgresql"): raise ValueError( diff --git a/swh/scheduler/tests/test_server.py b/swh/scheduler/tests/test_server.py --- a/swh/scheduler/tests/test_server.py +++ b/swh/scheduler/tests/test_server.py @@ -54,14 +54,10 @@ def test_load_and_check_config_remote_config_local_type_raise(tmpdir): - """Configuration without 'local' storage is rejected""" - config = {"scheduler": {"cls": "remote"}} - config_path = prepare_config_file(tmpdir, config) - expected_error = ( - "The scheduler backend can only be started with a 'postgresql'" " configuration" - ) - with pytest.raises(ValueError, match=expected_error): - load_and_check_config(config_path, type="local") + """Configuration without 'postgresql' storage is rejected""" + config_path = prepare_config_file(tmpdir, {"scheduler": {"cls": "remote"}}) + with pytest.raises(ValueError, match="'postgresql'"): + load_and_check_config(config_path) def test_load_and_check_config_local_incomplete_configuration(tmpdir): @@ -79,16 +75,17 @@ load_and_check_config(config_path) -def test_load_and_check_config_local_config_fine(tmpdir): +@pytest.mark.parametrize("clazz", ["local", "postgresql"]) +def test_load_and_check_config_local_config_fine(tmpdir, clazz): """Local configuration is fine""" config = { "scheduler": { - "cls": "postgresql", + "cls": clazz, "db": "db", } } config_path = prepare_config_file(tmpdir, config) - cfg = load_and_check_config(config_path, type="local") + cfg = load_and_check_config(config_path, type="postgresql") assert cfg == config