mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-08-20 21:22:54 +00:00
ruff was never wired into this repository: no target, no CI step, no pin. It reported 45 findings across sources and tests, so nothing enforced what the codebase already mostly followed. Adds `make ruff` (check + format --check), `make ruff-fix`, and `make lint` as its alias, and makes `make test` run lint as a fourth parallel spur. The CI workflow calls `make test`, so it is covered there too. The linter is pinned in a `lint` extra: a ruff minor bump changes which rules fire, and with the suite gating on a clean run an unpinned linter would fail it on an unrelated day. The 45 findings are fixed rather than configured away. Three needed a decision instead of the mechanical fix: - The generation timestamp keeps its local wall clock (DTZ005 waived). Generations sort by that name, and UTC would order new ones before the existing ones wherever the offset is positive - "newest generation" is what every restore path selects on. - The per-volume `copy` closure now binds volume_name and vol_dir as default arguments (B023). It only worked because it is called inside the same iteration. - The two CLI top-level handlers keep their blind except (BLE001 waived): turning any failure into exit 1 is what a CLI boundary is for. The two in run.py did not need it and were narrowed to what they actually catch. Also drops the comments that restate the code: the section banners in restore/__main__.py, the filename repeated as line 1 of nine test files, step narration above the statement it narrates, and a block in app.py documenting parameters that had moved to another module. What names a trip-wire stays - the snapshot destination rule, the mysql-binary absence in MariaDB 11 images, the session-scoped FOREIGN_KEY_CHECKS, the spooled temp file for multi-GB dumps, and the negative control that loses its discriminating power if it ever passes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
"""Exercise volume_snapshot against a real filesystem, from inside a container.
|
|
|
|
Runs where loop devices exist. Prints one PASS/FAIL line per assertion and exits
|
|
non-zero on the first failure, so the calling test can surface the reason.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, "/src")
|
|
|
|
from baudolo.backup.snapshot import SnapshotError, volume_snapshot
|
|
|
|
KIND = sys.argv[1]
|
|
SUBJECT = sys.argv[2]
|
|
EXPECT = sys.argv[3]
|
|
|
|
|
|
def shell(command: str) -> list[str]:
|
|
proc = subprocess.run(
|
|
command, shell=True, capture_output=True, text=True, check=False
|
|
)
|
|
if proc.returncode != 0:
|
|
raise SnapshotError(
|
|
f"{command} exited {proc.returncode}: {proc.stderr.strip()}"
|
|
)
|
|
return proc.stdout.splitlines()
|
|
|
|
|
|
def check(label: str, condition: bool) -> None:
|
|
print(f"{'PASS' if condition else 'FAIL'} {label}", flush=True)
|
|
if not condition:
|
|
sys.exit(1)
|
|
|
|
|
|
volume = Path(SUBJECT) / "volumes" / "demo" / "_data"
|
|
volume.mkdir(parents=True, exist_ok=True)
|
|
(volume / "state").write_text("before\n")
|
|
|
|
if EXPECT == "unsupported":
|
|
try:
|
|
with volume_snapshot(KIND, SUBJECT, "e2e", run=shell):
|
|
check("snapshot on an unsupported filesystem must not succeed", False)
|
|
except SnapshotError as exc:
|
|
check(f"refused loudly: {str(exc)[:60]}", True)
|
|
sys.exit(0)
|
|
|
|
with volume_snapshot(KIND, SUBJECT, "e2e", run=shell) as resolve:
|
|
frozen = Path(resolve(str(volume))) / "state"
|
|
check("the snapshot exposes the volume", frozen.is_file())
|
|
check("the snapshot carries the content", frozen.read_text() == "before\n")
|
|
|
|
(volume / "state").write_text("after\n")
|
|
check("a later write does not reach the snapshot", frozen.read_text() == "before\n")
|
|
check("the live tree did change", (volume / "state").read_text() == "after\n")
|
|
|
|
root = Path(resolve(SUBJECT))
|
|
|
|
check(
|
|
"the snapshot is removed afterwards",
|
|
not root.exists() or not (root / "volumes").exists(),
|
|
)
|
|
print("ALL OK", flush=True)
|