diff --git a/swh/objstorage/api/server.py b/swh/objstorage/api/server.py --- a/swh/objstorage/api/server.py +++ b/swh/objstorage/api/server.py @@ -1,9 +1,10 @@ -# Copyright (C) 2015-2020 The Software Heritage developers +# Copyright (C) 2015-2021 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 json +import logging import os import aiohttp.web @@ -18,6 +19,8 @@ from swh.objstorage.factory import get_objstorage from swh.objstorage.objstorage import DEFAULT_LIMIT +LOGGER = logging.getLogger(__name__) + def timed(f): async def w(*a, **kw): @@ -234,6 +237,8 @@ if "objstorage" not in cfg: raise KeyError("Invalid configuration; missing objstorage config entry") + bypass_check = os.environ.get("SWH_DEV_ENVIRONMENT", 0) + missing_keys = [] vcfg = cfg["objstorage"] if "cls" not in vcfg: @@ -256,7 +261,10 @@ ) elif cls == "noop": - raise EnvironmentError("Noop implementations should not be used in production.") + msg = "Noop implementation should not be used in production." + if not bypass_check: + raise EnvironmentError(msg) + LOGGER.warning(msg) return cfg diff --git a/swh/objstorage/tests/test_server.py b/swh/objstorage/tests/test_server.py --- a/swh/objstorage/tests/test_server.py +++ b/swh/objstorage/tests/test_server.py @@ -118,8 +118,12 @@ @pytest.mark.parametrize( "config", [pytest.param({"objstorage": {"cls": "noop",}}, id="noop",),], ) -def test_load_and_check_config_raise(tmpdir, config): - """pathslicing configuration fine loads ok""" +def test_load_and_check_config_raise(tmpdir, config, monkeypatch): + """noop configuration should raise in production environment and ok in dev""" config_path = prepare_config_file(tmpdir, config) with pytest.raises(EnvironmentError, match="not be used in production"): load_and_check_config(config_path) + + # But they are fine in development environment + monkeypatch.setenv("SWH_DEV_ENVIRONMENT", 1) + load_and_check_config(config_path)