From d6e1339a3c80d9d1740c944050602a8fdd5ab03f Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Tue, 24 Aug 2021 21:25:51 +1000 Subject: [PATCH] gravel/tests: fake up /var/lib/aquarium for KV store Signed-off-by: Tim Serong --- src/gravel/controllers/kv.py | 7 ++++++- src/gravel/tests/conftest.py | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/gravel/controllers/kv.py b/src/gravel/controllers/kv.py index 11aef67c1..8b838d6ff 100644 --- a/src/gravel/controllers/kv.py +++ b/src/gravel/controllers/kv.py @@ -57,7 +57,12 @@ def __init__(self): # Or, do we only open it when reading/writing in individual methods? # That would probably be better... (but would still have problems due to # simultaneous access, but we can always raise an exception in that case I guess?) - self._db = dbm.open(f"{var_lib_aquarium}/kvstore", "c") + try: + self._db = dbm.open(f"{var_lib_aquarium}/kvstore", "c") + except Exception as e: + # Only raise exceptions opening db file when *not* running unit tests + if "pytest" not in sys.modules: + raise e self._cluster: Optional[rados.Rados] = None self._connector_thread = threading.Thread(target=self._cluster_connect) self._run = True diff --git a/src/gravel/tests/conftest.py b/src/gravel/tests/conftest.py index 6acccb224..2d78a6662 100644 --- a/src/gravel/tests/conftest.py +++ b/src/gravel/tests/conftest.py @@ -169,9 +169,13 @@ async def cancel_watch(self, watch_id: int) -> None: @pytest.fixture() @pytest.mark.asyncio async def aquarium_startup( - get_data_contents: Callable[[str, str], str], mocker: MockerFixture + get_data_contents: Callable[[str, str], str], + mocker: MockerFixture, + fs: fake_filesystem.FakeFilesystem, ): + # Need the following to fake up KV mock_ceph_modules(mocker) + fs.create_dir("/var/lib/aquarium") async def startup(aquarium_app: FastAPI, aquarium_api: FastAPI): from fastapi.logger import logger as fastapi_logger