From 1238049886ca1b57c4c273937115b7e67688d59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radoslav=20Bod=C3=B3?= <bodik@cesnet.cz> Date: Tue, 16 Apr 2024 14:46:19 +0200 Subject: [PATCH] rwm: add backup exclusive lock to support cron use-cases (fix ci tests, gitlab-runner does not have access to /var/run) --- tests/test_rwm.py | 17 +++++++++++------ tests/test_storage.py | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/test_rwm.py b/tests/test_rwm.py index 70dd160..a351cce 100644 --- a/tests/test_rwm.py +++ b/tests/test_rwm.py @@ -133,7 +133,8 @@ def test_backup(tmpworkdir: str, motoserver: str): # pylint: disable=unused-arg }, "retention": { "keep-daily": "1" - } + }, + "lock_path": f"{tmpworkdir}/rwm.lock", }) Path("testdatadir").mkdir() @@ -164,7 +165,8 @@ def test_backup_excludes(tmpworkdir: str, motoserver: str): # pylint: disable=u "excludes": ["testdatadir/proc/*", "*.ignored"], "extras": ["--tag", "dummytag"], } - } + }, + "lock_path": f"{tmpworkdir}/rwm.lock", }) Path("testdatadir").mkdir() @@ -202,7 +204,8 @@ def test_backup_error_handling(tmpworkdir: str): # pylint: disable=unused-argum "restic_bucket": "restictest", "backups": { "dummycfg": {"filesdirs": ["dummydir"]} - } + }, + "lock_path": f"{tmpworkdir}/rwm.lock", } mock_true = Mock(return_value=True) @@ -275,7 +278,8 @@ def test_storage_delete(tmpworkdir: str, radosuser_admin: rwm.StorageManager): "restic_password": "dummydummydummydummy", "backups": { "testcfg": {"filesdirs": ["testdatadir/"]} - } + }, + "lock_path": f"{tmpworkdir}/rwm.lock", }) bucket_name = trwm.config.restic_bucket @@ -350,7 +354,8 @@ def test_storage_restore_state_restic(tmpworkdir: str, radosuser_admin: rwm.Stor "testcfg": { "filesdirs": ["testdatadir/"], } - } + }, + "lock_path": f"{tmpworkdir}/rwm.lock", }) # create and initialize storage @@ -394,7 +399,7 @@ def test_storage_restore_state_restic(tmpworkdir: str, radosuser_admin: rwm.Stor def test_locks(tmpworkdir: str): # pylint: disable=unused-argument """test LockManager""" - lock_path = "./test.lock" + lock_path = f"{tmpworkdir}/rwm.lock" locker1 = rwm.LockManager(lock_path) locker1.lock() diff --git a/tests/test_storage.py b/tests/test_storage.py index 3e08529..90185b8 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -134,7 +134,8 @@ def test_storage_backup_usage( "restic_password": "dummydummydummydummy", "backups": { "dummy": {"filesdirs": ["testdir"]} - } + }, + "lock_path": f"{tmpworkdir}/rwm.lock", }) assert trwm.restic_cmd(["init"]).returncode == 0 assert trwm.backup("dummy") == 0 -- GitLab