diff --git a/swh/vault/api/server.py b/swh/vault/api/server.py --- a/swh/vault/api/server.py +++ b/swh/vault/api/server.py @@ -27,7 +27,7 @@ def get_vault(): global vault if not vault: - vault = get_swhvault(**app.config["vault"]) + vault = get_swhvault(**app.config) return vault @@ -106,7 +106,7 @@ if not os.path.isfile(config_path): raise ValueError(f"Configuration path {config_path} should exist.") - app_config = read_raw_config(config_basepath(config_path)) + app_config = read_raw_config(config_basepath(config_path))["vault"] app.config.update(merge_configs(DEFAULT_CONFIG, app_config)) return app diff --git a/swh/vault/backend.py b/swh/vault/backend.py --- a/swh/vault/backend.py +++ b/swh/vault/backend.py @@ -72,7 +72,7 @@ def __init__(self, **config): self.config = config - self.cache = VaultCache(**config["cache"]) + self.cache = VaultCache(**self.config["cache"]) self.scheduler = get_scheduler(**config["scheduler"]) self.storage = get_storage(**config["storage"]) self.smtp_server = smtplib.SMTP(**config.get("smtp", {})) diff --git a/swh/vault/tests/conftest.py b/swh/vault/tests/conftest.py --- a/swh/vault/tests/conftest.py +++ b/swh/vault/tests/conftest.py @@ -57,31 +57,29 @@ @pytest.fixture -def swh_vault_config(postgres_vault, postgres_storage, tmp_path) -> Dict[str, Any]: +def swh_local_vault_config( + postgres_vault, postgres_storage, tmp_path +) -> Dict[str, Any]: tmp_path = str(tmp_path) return { - "db": postgres_vault.dsn, - "storage": { - "cls": "postgresql", - "db": postgres_storage.dsn, - "objstorage": { + "vault": { + "cls": "local", + "db": postgres_vault.dsn, + "cache": { "cls": "pathslicing", - "args": {"root": tmp_path, "slicing": "0:1/1:5",}, + "args": {"root": tmp_path, "slicing": "0:1/1:5", "allow_delete": True}, }, - }, - "cache": { - "cls": "pathslicing", - "args": {"root": tmp_path, "slicing": "0:1/1:5", "allow_delete": True}, - }, - "scheduler": {"cls": "remote", "url": "http://swh-scheduler:5008",}, - } - - -@pytest.fixture -def swh_local_vault_config(swh_vault_config: Dict[str, Any]) -> Dict[str, Any]: - return { - "vault": {"cls": "local", **swh_vault_config}, - "client_max_size": 1024 ** 3, + "client_max_size": 1024 ** 3, + "storage": { + "cls": "postgresql", + "db": postgres_storage.dsn, + "objstorage": { + "cls": "pathslicing", + "args": {"root": tmp_path, "slicing": "0:1/1:5",}, + }, + }, + "scheduler": {"cls": "remote", "url": "http://swh-scheduler:5008",}, + } } @@ -95,8 +93,8 @@ @pytest.fixture -def swh_vault(swh_vault_config): - return get_vault("local", **swh_vault_config) +def swh_vault(swh_local_vault_config): + return get_vault(**swh_local_vault_config["vault"]) @pytest.fixture diff --git a/swh/vault/tests/test_init.py b/swh/vault/tests/test_init.py --- a/swh/vault/tests/test_init.py +++ b/swh/vault/tests/test_init.py @@ -50,6 +50,6 @@ assert isinstance(concrete_vault, expected_class) -def test_init_get_vault_ok(swh_vault_config): - concrete_vault = get_vault("local", **swh_vault_config) +def test_init_get_vault_ok(swh_local_vault_config): + concrete_vault = get_vault(**swh_local_vault_config["vault"]) assert isinstance(concrete_vault, VaultBackend) diff --git a/swh/vault/tests/test_server.py b/swh/vault/tests/test_server.py --- a/swh/vault/tests/test_server.py +++ b/swh/vault/tests/test_server.py @@ -37,10 +37,7 @@ """ app = make_app_from_configfile() assert app is not None - assert "vault" in app.config - # Cleanup app - del app.config["vault"] swh.vault.api.server.vault = None @@ -54,10 +51,7 @@ app = make_app_from_configfile(conf_path) assert app is not None - assert "vault" in app.config - # Cleanup app - del app.config["vault"] swh.vault.api.server.vault = None @@ -68,8 +62,6 @@ yield app - # Cleanup app - del app.config["vault"] swh.vault.api.server.vault = None @@ -152,9 +144,9 @@ @pytest.mark.parametrize("missing_key", ["storage", "cache", "scheduler"]) -def test_check_config_missing_key(missing_key, swh_vault_config) -> None: +def test_check_config_missing_key(missing_key, swh_local_vault_config) -> None: """Any other configuration than 'local' (the default) is rejected""" - config_ok = {"vault": {"cls": "local", **swh_vault_config}} + config_ok = swh_local_vault_config config_ko = copy.deepcopy(config_ok) config_ko["vault"].pop(missing_key, None) @@ -163,8 +155,6 @@ check_config(config_ko) -@pytest.mark.parametrize("missing_key", ["storage", "cache", "scheduler"]) -def test_check_config_ok(missing_key, swh_vault_config) -> None: +def test_check_config_ok(swh_local_vault_config) -> None: """Any other configuration than 'local' (the default) is rejected""" - config_ok = {"vault": {"cls": "local", **swh_vault_config}} - assert check_config(config_ok) is not None + assert check_config(swh_local_vault_config) is not None