fix(backups): robustness against stale locks: everything else
continuous-integration/drone/push Build is failing Details

backups-forget
Houkime 2023-08-09 15:18:20 +00:00
parent 0eb70e1551
commit 2c9011cc87
2 changed files with 14 additions and 5 deletions

View File

@ -345,6 +345,7 @@ class ResticBackupper(AbstractBackupper):
except ValueError as error: except ValueError as error:
raise ValueError("cannot restore a snapshot: " + output) from error raise ValueError("cannot restore a snapshot: " + output) from error
@unlocked_repo
def restore_from_backup( def restore_from_backup(
self, self,
snapshot_id, snapshot_id,
@ -406,6 +407,7 @@ class ResticBackupper(AbstractBackupper):
output, output,
) )
@unlocked_repo
def forget_snapshot(self, snapshot_id) -> None: def forget_snapshot(self, snapshot_id) -> None:
""" """
Either removes snapshot or marks it for deletion later, Either removes snapshot or marks it for deletion later,
@ -441,10 +443,7 @@ class ResticBackupper(AbstractBackupper):
) # none should be impossible after communicate ) # none should be impossible after communicate
if handle.returncode != 0: if handle.returncode != 0:
raise ValueError( raise ValueError(
"forget exited with errorcode", "forget exited with errorcode", handle.returncode, ":", output, err
handle.returncode,
":",
output,
) )
def _load_snapshots(self) -> object: def _load_snapshots(self) -> object:
@ -470,8 +469,9 @@ class ResticBackupper(AbstractBackupper):
try: try:
return ResticBackupper.parse_json_output(output) return ResticBackupper.parse_json_output(output)
except ValueError as error: except ValueError as error:
raise ValueError("Cannot load snapshots: ") from error raise ValueError("Cannot load snapshots: ", output) from error
@unlocked_repo
def get_snapshots(self) -> List[Snapshot]: def get_snapshots(self) -> List[Snapshot]:
"""Get all snapshots from the repo""" """Get all snapshots from the repo"""
snapshots = [] snapshots = []

View File

@ -794,6 +794,15 @@ def test_operations_while_locked(backups, dummy_service):
Backups.provider().backupper.lock() Backups.provider().backupper.lock()
assert Backups.snapshot_restored_size(snap.id) > 0 assert Backups.snapshot_restored_size(snap.id) > 0
Backups.provider().backupper.lock()
Backups.restore_snapshot(snap)
Backups.provider().backupper.lock()
Backups.forget_snapshot(snap)
Backups.provider().backupper.lock()
assert Backups.provider().backupper.get_snapshots() == []
# check that no locks were left # check that no locks were left
Backups.provider().backupper.lock() Backups.provider().backupper.lock()
Backups.provider().backupper.unlock() Backups.provider().backupper.unlock()