]> arthur.barton.de Git - bup.git/commitdiff
test-save-errors: add tests for inaccessible metadata
authorJohannes Berg <johannes@sipsolutions.net>
Sat, 25 Jan 2020 21:21:24 +0000 (22:21 +0100)
committerRob Browning <rlb@defaultvalue.org>
Sat, 25 Apr 2020 19:24:17 +0000 (14:24 -0500)
Add test cases for when metadata for a file and directory cannot
be read (causing an IOError instead).

Note that this test fails if the previous two patches aren't
applied.

Note also that if such an error ever happened without the patch
to save, the repository is essentially corrupt and there no way
to figure out _which_ file didn't get metadata.

Note that this uses some python trickery to force an IOError in
metadata reading.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
[rlb@defaultvalue.org: name test in commit summary line]
Tested-by: Rob Browning <rlb@defaultvalue.org>
(cherry picked from commit 19b3b1b7acda5e507a4ec053cff6a2e139c24f31)
[rlb@defaultvalue.org: adjust bup-save test overrides for 0.3x]
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
Makefile
t/test-save-errors [new file with mode: 0755]

index 38e0ee4b4f08774ce43af89158c356d74f032be1..77dae0b71801551efa2132fc9c65d456615379bf 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -153,6 +153,7 @@ runtests-python: all t/tmp
 cmdline_tests := \
   t/test-ftp \
   t/test-save-restore \
+  t/test-save-errors \
   t/test-packsizelimit \
   t/test-prune-older \
   t/test-web.sh \
diff --git a/t/test-save-errors b/t/test-save-errors
new file mode 100755 (executable)
index 0000000..2578256
--- /dev/null
@@ -0,0 +1,106 @@
+#!/usr/bin/env bash
+. wvtest.sh
+. wvtest-bup.sh
+. t/lib.sh
+
+set -o pipefail
+
+top="$(WVPASS pwd)" || exit $?
+tmpdir="$(WVPASS wvmktempdir)" || exit $?
+export BUP_DIR="$tmpdir/bup"
+
+bup() { "$top/bup" "$@"; }
+
+WVPASS cd "$tmpdir"
+
+# necessary for 0 == 1970-01-01 00:00
+export TZ=UTC
+
+WVSTART "init"
+WVPASS bup init
+
+mkdir "$tmpdir/save"
+for f in $(seq 9) ; do
+    touch -t 200${f}01010000 "$tmpdir/save/$f"
+done
+mkdir "$tmpdir/save/a"
+touch -t 199901010000 "$tmpdir/save/a/1"
+
+WVSTART "metadata read error for a file"
+WVPASS bup index "$tmpdir/save"
+
+# now do a hack to inject save errors while reading metadata
+# essentially, we create a bup-save command for ourselves
+# that gets an error for the .../5 file in metadata.from_path()
+cat > "$tmpdir/bup-save" << EOF
+#!/bin/sh
+"""": # -*-python-*-
+export PYTHONPATH="$top/lib"
+exec "$top/cmd/bup-python" "\$0" \${1+"\$@"}
+"""
+from bup import metadata
+orig_from_path = metadata.from_path
+def from_path(path, *args, **kw):
+    if path.endswith(b'/5'):
+        raise IOError('intentionally failing metadata read for .../5')
+    return orig_from_path(path, *args, **kw)
+metadata.from_path = from_path
+
+exec(open("$top/cmd/bup-save", "rb").read())
+EOF
+chmod +x "$tmpdir/bup-save"
+
+# use it to save the data
+"$tmpdir/bup-save" -n test "$tmpdir/save"
+
+# this should work anyway
+WVPASS bup ls -l "test/latest/$tmpdir/save"
+# also check the *right* data was returned
+lsout="$(bup ls -l "test/latest/$tmpdir/save")"
+for f in 1 2 3 4   6 7 8 9 ; do
+    if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
+        WVFAIL echo incorrect date for $f
+    fi
+done
+# and ensure we actually failed, and the above script/hack didn't break
+if ! echo "$lsout" | grep "1970-01-01 00:00 5" ; then
+    WVFAIL echo unexpected date for file 5
+fi
+
+
+WVSTART "metadata read error for a folder"
+WVPASS bup index --clear
+WVPASS bup index "$tmpdir/save"
+
+cat > "$tmpdir/bup-save" << EOF
+#!/bin/sh
+"""": # -*-python-*-
+export PYTHONPATH="$top/lib"
+exec "$top/cmd/bup-python" "\$0" \${1+"\$@"}
+"""
+from bup import metadata
+orig_from_path = metadata.from_path
+def from_path(path, *args, **kw):
+    if path.endswith(b'/a'):
+        raise IOError('intentionally failing metadata read for .../a')
+    return orig_from_path(path, *args, **kw)
+metadata.from_path = from_path
+
+exec(open("$top/cmd/bup-save", "rb").read())
+EOF
+chmod +x "$tmpdir/bup-save"
+
+# use it to save the data
+"$tmpdir/bup-save" -n test "$tmpdir/save"
+
+# this should work anyway
+WVPASS bup ls -l "test/latest/$tmpdir/save"
+if ! bup ls -l "test/latest/$tmpdir/save/a" | grep '1999-01-01 00:00 1' ; then
+    WVFAIL unexpected date for file a/1
+fi
+# and ensure we actually failed, and the above script/hack didn't break
+if ! bup ls -l "test/latest/$tmpdir/save" | grep "1970-01-01 00:00 a" ; then
+    WVFAIL unexpected date for directory a
+fi
+
+WVPASS rm -rf "$tmpdir"