From 028fd279652dbe167b12b32dff00c6a299c4fc02 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 7 Feb 2021 17:46:06 +0200 Subject: test: add scenario for live data file being unreadable --- obnam.md | 22 ++++++++++++++++++++++ subplot/data.py | 14 ++++++++++++++ subplot/data.yaml | 6 ++++++ 3 files changed, 42 insertions(+) diff --git a/obnam.md b/obnam.md index 204d6d9..cb08f13 100644 --- a/obnam.md +++ b/obnam.md @@ -1269,6 +1269,28 @@ given a manifest of the directory live restored in rest in rest.yaml then files live.yaml and rest.yaml match ~~~ +## Unreadable file + +This scenario verifies that Obnam will back up all files of live data, +even if one of them is unreadable. By inference, we assume this means +other errors on individual files also won't end the backup +prematurely. + + +~~~scenario +given an installed obnam +and a running chunk server +and a client config based on smoke.yaml +and a file live/data.dat containing some random data +and a file live/bad.dat containing some random data +and file live/bad.dat has mode 000 +when I run obnam --config smoke.yaml backup +then backup generation is GEN +when I invoke obnam --config smoke.yaml restore rest +then file live/data.dat is restored to rest +then file live/bad.dat is not restored to rest +~~~ + ## Restore latest generation This scenario verifies that the latest backup generation can be diff --git a/subplot/data.py b/subplot/data.py index f3faf2b..f7fb903 100644 --- a/subplot/data.py +++ b/subplot/data.py @@ -54,6 +54,20 @@ def _create_manifest_of_directory(ctx, dirname=None, manifest=None): open(manifest, "w").write(stdout) +def file_is_restored(ctx, filename=None, restored=None): + filename = os.path.join(restored, "./" + filename) + exists = os.path.exists(filename) + logging.debug(f"restored? {filename} {exists}") + assert exists + + +def file_is_not_restored(ctx, filename=None, restored=None): + filename = os.path.join(restored, "./" + filename) + exists = os.path.exists(filename) + logging.debug(f"restored? {filename} {exists}") + assert not exists + + def files_match(ctx, first=None, second=None): assert_eq = globals()["assert_eq"] diff --git a/subplot/data.yaml b/subplot/data.yaml index 9538daa..1636e77 100644 --- a/subplot/data.yaml +++ b/subplot/data.yaml @@ -24,3 +24,9 @@ - then: "stdout, as JSON, matches file {filename}" function: match_stdout_to_json_file + +- then: "file {filename} is restored to {restored}" + function: file_is_restored + +- then: "file {filename} is not restored to {restored}" + function: file_is_not_restored -- cgit v1.2.1