Test implementation =================== This chapter documents the generic, shared IMPLEMENTS sections for steps that are used in a variety of scenarios. It also discusses the shell library that may be used by all IMPLEMENTS sections. The shell library ----------------- The shell library contains shell functions and sets some shell variables that can be used by any IMPLEMENTS sections. Variables: * `REPO`: the pathname of the backup repository. Functions: * `run_obnam`: run Obnam from the source tree, ignoring any system-wide or user configuration and using only the configuration specified by the test suite itself (`--no-default-config`). Run in quiet mode (`--quiet`). The first argument to `run_obnam` is the client name. * `manifest`: run summain in a way that produces a useable manifest, which can be compared with diff with a later manifest. Live data generation -------------------- The simplest way to generate test live data is to just generate the necessary number of bytes, split over some number of files. We have the user name the directory explicitly, to avoid hidden dependencies between steps. IMPLEMENTS GIVEN (\S+) of new data in directory (\S+) genbackupdata --quiet --create "$MATCH_1" "$DATADIR/$MATCH_2" Sometimes we need an amount of data in a specific file. IMPLEMENTS GIVEN (\S+) of data in file (\S+) "$SRCDIR/mkdata" --size "$MATCH_1" "$DATADIR/$MATCH_2" We also need to generate a sparse file. A sparse file has at least one hole in it, and it may matter where the hole is: at the beginning, middle, or end of the file. Thus, we provide a way for scenarios to specify that. IMPLEMENTS GIVEN a file (\S+) in (\S+), with (.+) mkdir -p "$DATADIR/$MATCH_2" "$SRCDIR/mksparse" "$DATADIR/$MATCH_2/$MATCH_1" "$MATCH_3" Create some _interesting_ data, using the `mkfunnyfarm` utility. See the utility for details, but this is about creating files and other filesystem objects that are not the most common easy cases for backup programs (regular files with data and no holes). IMPLEMENTS GIVEN directory (\S+) with interesting filesystem objects "$SRCDIR/mkfunnyfarm" "$DATADIR/$MATCH_1" Some directories will be tagged as cache directories (see [Cache directory tagging](http://www.bford.info/cachedir/)). IMPLEMENTS GIVEN directory (\S+) is tagged as a cache directory printf 'Signature: 8a477f597d28d172789f06886806bc55' \ > "$DATADIR/$MATCH_1/CACHEDIR.TAG" Sometimes it is necessary to set the modification filestamp of a file. Actually, it's usually useful to set both `st_mtime` and `st_atime` to the same value. The timestamp is given in the "seconds after epoch" in UTC format, as is common in Unix. IMPLEMENTS GIVEN file (\S+) has Unix timestamp (-?\d+) parent=$(dirname "$MATCH_1") if [ ! -e "$DATADIR/$parent" ] then mkdir "$DATADIR/$parent" fi touch "$DATADIR/$MATCH_1" python -c ' import os filename = os.path.join( os.environ["DATADIR"], os.environ["MATCH_1"]) timestamp = int(os.environ["MATCH_2"]) os.utime(filename, (timestamp, timestamp)) ' Create a file with given permissions. IMPLEMENTS GIVEN file (\S+) with permissions (\S+) touch "$DATADIR/$MATCH_1" chmod "$MATCH_2" "$DATADIR/$MATCH_1" Create a directory with given permissions. IMPLEMENTS GIVEN directory (\S+) with permissions (\S+) install -d -m "$MATCH_2" "$DATADIR/$MATCH_1" We need to manipulate extended attributes. IMPLEMENTS GIVEN file (\S+) has extended attribute (\S+) set to (\S+) mkdir -p $(dirname "$DATADIR/$MATCH_1") setfattr --name="$MATCH_2" --value "$MATCH_3" "$DATADIR/$MATCH_1" Create a symlink. IMPLEMENTS GIVEN a symlink (\S+) pointing at (\S+) ln -s "$MATCH_2" "$DATADIR/$MATCH_1" Sometimes we need to remove a file. IMPLEMENTS WHEN user (\S+) removes file (\S+) rm -f "$DATADIR/$MATCH_2" Copy a file. IMPLEMENTS GIVEN a copy of (.+) in (.+) mkdir -p "$DATADIR/$(dirname "$MATCH_2")" cp -a "$DATADIR/$MATCH_1" "$DATADIR/$MATCH_2" Reset a repository's chunk files. IMPLEMENTS WHEN repository (.+) resets its chunks to those in (.+) r1="$DATADIR/$MATCH_1" r2="$DATADIR/$MATCH_2" if [ -e "$r1/chunks" ] then # format 6 rm -rf "$r1/chunks" cp -a "$r2/chunks" "$r1/." else rm -rf "$r1/chunk-store" cp -a "$r2/chunk-store" "$r1/." fi Manifest creation and checking ------------------------------ We make it explicit in the scenario when a manifest is generated, so that naming of the manifest is explicit. This reduces the need to debug weird test suite bugs, when an automatic or implicit manifest naming goes wrong. IMPLEMENTS GIVEN a manifest of (\S+) in (\S+) manifest "$DATADIR/$MATCH_1" > "$DATADIR/$MATCH_2" We need to check a directory tree against an existing manifest. We do this by generating a temporary manifest and diffing against that. We store the temporary manifest in a file so that if things fail, we can see what the temporary manifest actually contains. Being able to look at the actual file is easier than trying to interpret complicated diffs. We remove the restore directory prefix from the manifest (the `Name:` field that Summain outputs). This is necessary so that comparisons with **diff**(1) will work well. IMPLEMENTS THEN (\S+), restored to (\S+), matches manifest (\S+) manifest "$DATADIR/$MATCH_2/$DATADIR/$MATCH_1" | sed "s*$DATADIR/$MATCH_2/**" > "$DATADIR/temp-manifest" diff -u "$DATADIR/$MATCH_3" "$DATADIR/temp-manifest" rm -f "$DATADIR/temp-manifest" We may also need to check two manifests against each other. IMPLEMENTS THEN manifests (\S+) and (\S+) match diff -u "$DATADIR/$MATCH_1" "$DATADIR/$MATCH_2" In a special case, we may need to update the `Mtime` for the first entry in a manifest. This is used, at least, when testing cache directory exclusion: we create wanted data, then create a manifest, then add the cache directory. This invalidates the Mtime for the first entry. IMPLEMENTS GIVEN manifest (\S+) has Mtime for the first entry set from (\S+) x=$(date -r "$DATADIR/$MATCH_2" '+Mtime: %Y-%m-%d %H:%M:%S +0000') awk -v "x=$x" ' !x && /^Mtime:/ { print x; next } /^$/ { x = 1 } { print } ' "$DATADIR/$MATCH_1" > "$DATADIR/new-manifest" mv "$DATADIR/new-manifest" "$DATADIR/$MATCH_1" Sometimes we create manifests with extra stuff. This allows us to remove them afterwards. IMPLEMENTS GIVEN (\S+) is removed from manifest (\S+) awk -v skip1="$MATCH_1" -v skip2="$MATCH_1/" ' $1 == "Name:" && ($2 == skip1 || substr($2, 1, length(skip2)) == skip2) { paragraph = ""; ignore = 1; next } NF > 0 && !ignore { paragraph = paragraph $0 "\n" } NF == 0 && paragraph { printf "%s\n", paragraph; paragraph = "" } NF == 0 { ignore = 0 } END { if (paragraph) printf "%s", paragraph } ' "$DATADIR/$MATCH_2" > "$DATADIR/$MATCH_2.new" mv "$DATADIR/$MATCH_2.new" "$DATADIR/$MATCH_2" Obnam configuration management ------------------------------ In some scenarios, it is easier to maintain a configuration file than to pass in all the options to `run_obnam` every time. This section contains steps to do that. Scenarios involving encryption need to specify the encryption key to use. We store that. IMPLEMENTS GIVEN user (\S+) uses encryption key "(.*)" from (\S+) if [ ! -e "$DATADIR/$MATCH_1.gnupg" ] then mkdir "$DATADIR/$MATCH_1.gnupg" cp -a "$SRCDIR/$MATCH_3/." "$DATADIR/$MATCH_1.gnupg/." chmod -R 0700 "$DATADIR/$MATCH_1.gnupg" add_to_env "$MATCH_1" GNUPGHOME "$DATADIR/$MATCH_1.gnupg" else # Export public and secret keys from new keyring. export GNUPGHOME="$SRCDIR/$MATCH_3" gpg --export "$MATCH_2" > "$DATADIR/public.key" gpg --export-secret-keys "$MATCH_2" > "$DATADIR/secret.key" # Import into the keyring uses for tests. export GNUPGHOME="$DATADIR/$MATCH_1.gnupg" gpg --import "$DATADIR/public.key" gpg --import "$DATADIR/secret.key" fi add_to_config "$MATCH_1" encrypt-with "$MATCH_2" Scenarios involving encryption may also use a private keyring directory. IMPLEMENTS GIVEN user (\S+) separately uses encryption key "(.*)" from (\S+) if [ ! -e "$DATADIR/$MATCH_1.gnupg" ] then mkdir "$DATADIR/$MATCH_1.gnupg" cp -a "$SRCDIR/$MATCH_3/." "$DATADIR/$MATCH_1.gnupg/." add_to_config "$MATCH_1" gnupghome "$DATADIR/$MATCH_1.gnupg" else # Export public and secret keys from new keyring. export GNUPGHOME="$SRCDIR/$MATCH_3" gpg --export "$MATCH_2" > "$DATADIR/public.key" gpg --export-secret-keys "$MATCH_2" > "$DATADIR/secret.key" # Import into the keyring uses for tests. export GNUPGHOME="$DATADIR/$MATCH_1.gnupg" gpg --import "$DATADIR/public.key" gpg --import "$DATADIR/secret.key" # Use the configuration rather than the environment. add_to_config "$MATCH_1" gnupghome "$GNUPGHOME" unset GNUPGHOME fi add_to_config "$MATCH_1" encrypt-with "$MATCH_2" Encryption scenarios, at least, also need users that pretend to be someone else. IMPLEMENTS GIVEN a user (\S+) calling themselves (\S+) add_to_config "$MATCH_1" client-name "$MATCH_2" Add a setting to a client's configuration file. IMPLEMENTS GIVEN user (\S+) sets configuration (\S+) to (.*) add_to_config "$MATCH_1" "$MATCH_2" "$MATCH_3" Backing up ---------- The simplest way to run a backup, for single-client scenarios. In addition to backing up, this makes a manifest of the data. IMPLEMENTS WHEN user (\S+) backs up directory (\S+) to repository (\S+) run_obnam "$MATCH_1" backup -r "$DATADIR/$MATCH_3" "$DATADIR/$MATCH_2" A test may make a backup fail. Run without failing the test so the failure may be inspected. IMPLEMENTS WHEN user (\S+) attempts to back up directory (\S+) to repository (\S+) attempt run_obnam "$MATCH_1" \ backup -r "$DATADIR/$MATCH_3" "$DATADIR/$MATCH_2" We may also need to backup two directories at once. IMPLEMENTS WHEN user (\S+) backs up directories (\S+) and (\S+) to repository (\S+) run_obnam "$MATCH_1" backup -r "$DATADIR/$MATCH_4" \ "$DATADIR/$MATCH_2" "$DATADIR/$MATCH_3" We can also just pretend to make a backup. IMPLEMENTS WHEN user (\S+) pretends to back up directory (\S+) to repository (\S+) run_obnam "$MATCH_1" backup --pretend -r "$DATADIR/$MATCH_3" "$DATADIR/$MATCH_2" fsck'ing a repository --------------------- Verify that the repository itself is OK, by running `obnam fsck` on it. IMPLEMENTS THEN user (\S+) can fsck the repository (\S+) run_obnam "$MATCH_1" fsck -r "$DATADIR/$MATCH_2" Restoring data -------------- We need a way to restore data from a test backup repository. IMPLEMENTS WHEN user (\S+) restores their latest generation in repository (\S+) into (\S+) run_obnam "$MATCH_1" restore -r "$DATADIR/$MATCH_2" \ --to "$DATADIR/$MATCH_3" Restore a specific generation. The generation number is an ordinal in the list of generations, not the "generation id" Obnam assigns, as that is unpredictable. IMPLEMENTS WHEN user (\S+) restores generation (\d+) to (\S+) from repository (\S+) client="$MATCH_1" gen="$MATCH_2" to="$DATADIR/$MATCH_3" repo="$DATADIR/$MATCH_4" id=$(run_obnam "$client" -r "$repo" genids | awk -v "n=$gen" 'NR == n') run_obnam "$client" restore -r "$repo" \ --to "$to" --generation "$id" We may also need to attempt a restore in a situation when we expect it to fail. IMPLEMENTS WHEN user (\S+) attempts to restore their latest generation in repository (\S+) into (\S+) attempt run_obnam "$MATCH_1" restore -r "$DATADIR/$MATCH_2" \ --to "$DATADIR/$MATCH_3" We may need to restore only a single file. IMPLEMENTS WHEN user (\S+) restores file (\S+) to (\S+) from their latest generation in repository (\S+) run_obnam "$MATCH_1" ls -r "$DATADIR/$MATCH_4" run_obnam "$MATCH_1" restore -r "$DATADIR/$MATCH_4" \ --to "$DATADIR/$MATCH_3" "$DATADIR/$MATCH_2" Verifying live data ------------------- Run `obnam verify` and remember the output. IMPLEMENTS WHEN user (\S+) attempts to verify (\S+) against repository (\S+) attempt run_obnam "$MATCH_1" \ verify -r "$DATADIR/$MATCH_3" "$DATADIR/$MATCH_2" Verify a random file in live data. IMPLEMENTS WHEN user (\S+) attempts to verify a random file in (\S+) against repository (\S+) attempt run_obnam "$MATCH_1" \ verify -r "$DATADIR/$MATCH_3" --verify-randomly=1 "$DATADIR/$MATCH_2" Removing (forgetting) generations --------------------------------- Run `obnam forget` with neither a policy of what to keep, nor a specific list of generations. IMPLEMENTS WHEN user (\S+) runs obnam forget without generations or keep policy on repository (\S+) run_obnam "$MATCH_1" forget -r "$DATADIR/$MATCH_2" Remove the oldest generation. IMPLEMENTS WHEN user (\S+) forgets the oldest generation in repository (\S+) # The grep below at the end of pipeline is there to make sure # the pipeline fails if there were no generations. id=$(run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_2" genids | head -n1 | grep .) run_obnam "$MATCH_1" forget -r "$DATADIR/$MATCH_2" "$id" Remove the newest generation. IMPLEMENTS WHEN user (\S+) forgets their latest generation in repository (\S+) # The grep below at the end of pipeline is there to make sure # the pipeline fails if there were no generations. id=$(run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_2" genids | tail -n1 | grep .) run_obnam "$MATCH_1" forget -r "$DATADIR/$MATCH_2" "$id" Remove according to a `--keep` schedule. IMPLEMENTS WHEN user (\S+) forgets according to schedule (\S+) in repository (\S+) run_obnam "$MATCH_1" forget -r "$DATADIR/$MATCH_3" --keep "$MATCH_2" Pretend to forget. IMPLEMENTS WHEN user (\S+) pretends to forget according to schedule (\S+) in repository (\S+) run_obnam "$MATCH_1" \ forget --pretend -r "$DATADIR/$MATCH_3" --keep "$MATCH_2" List generations ---------------- List everything in a generation. Capture the listing in a named file. IMPLEMENTS WHEN user (\S+) lists latest generation in repository (\S+) into (\S+) run_obnam "$MATCH_1" ls -r "$DATADIR/$MATCH_2" > "$DATADIR/$MATCH_3" List only parts of a generation. Again, capture in a named file. IMPLEMENTS WHEN user (\S+) lists (\S+) in latest generation in repository (\S+) into (\S+) run_obnam "$MATCH_1" ls -r "$DATADIR/$MATCH_3" "$DATADIR/$MATCH_2" > "$DATADIR/$MATCH_4" Checks on generations --------------------- Check that number of generations is correct. IMPLEMENTS THEN user (\S+) sees (\d+) generation(s?) in repository (\S+) run_obnam "$MATCH_1" generations -r "$DATADIR/$MATCH_4" \ > "$DATADIR/generation.list" n=$(wc -l < "$DATADIR/generation.list") test "$MATCH_2" = "$n" Ditto for generation ids. IMPLEMENTS THEN user (\S+) sees (\d+) generation ids in repository (\S+) run_obnam "$MATCH_1" generations -r "$DATADIR/$MATCH_3" \ > "$DATADIR/generation-id.list" n=$(wc -l < "$DATADIR/generation-id.list") test "$MATCH_2" = "$n" Check that there are no checkpoint generations. IMPLEMENTS THEN user (\S+) sees no checkpoint generations in repository (\S+) run_obnam "$MATCH_1" generations -r "$DATADIR/$MATCH_2" \ > "$DATADIR/generation.list" if grep checkpoint "$DATADIR/generation.list" then echo "Can see checkpoint generations!" 1>&2 exit 1 fi Check timestamps of specific generations. IMPLEMENTS THEN user (\S+) has (\d+)(st|nd|rd|th) generation timestamp (.*) in repository (\S+) run_obnam "$MATCH_1" generations -r "$DATADIR/$MATCH_5" | sed -n "${MATCH_2}p" | awk -v "T=$MATCH_4" ' ($2 " " $3) != T { print "Fail to match: " $0 exit 1 } ' Diffs between generations ------------------------- Compute the difference between two generations. The generations are identified by the ordinal, not generation id, since the ids are unpredictable. IMPLEMENTS WHEN user (\S+) diffs generations (\d+) and (\d+) in repository (\S+) into (\S+) id1=$(run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_4" genids | awk -v "n=$MATCH_2" 'NR == n') id2=$(run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_4" genids | awk -v "n=$MATCH_3" 'NR == n') run_obnam "$MATCH_1" diff -r "$DATADIR/$MATCH_4" "$id1" "$id2" > "$DATADIR/$MATCH_5" Show the diff between the latest generation and the generation before that. IMPLEMENTS WHEN user (\S+) diffs latest generation in repository (\S+) into (\S+) run_obnam "$MATCH_1" diff -r "$DATADIR/$MATCH_2" latest > "$DATADIR/$MATCH_3" Encryption key management ------------------------- List clients and the encryption keys they use. IMPLEMENTS THEN user (\S+) uses key "(.+)" in repository (\S+) run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_3" client-keys | grep -x "$MATCH_1 $MATCH_2" Import a key into one user's keyring from another keyring. IMPLEMENTS WHEN user (\S+) imports public key "(.+)" from (\S+) GNUPGHOME="$SRCDIR/$MATCH_3" gpg --export --armor "$MATCH_2" | GNUPGHOME="$DATADIR/$MATCH_1.gnupg" gpg --import Add a public key to a repository, but not to the calling user, only to the shared parts. IMPLEMENTS WHEN user (\S+) adds key "(.+)" to repository (\S+) only run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_3" \ add-key --keyid "$MATCH_2" Add a public key to a repository, and the calling user. IMPLEMENTS WHEN user (\S+) adds key "(.+)" to repository (\S+) and self run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_3" \ add-key --keyid "$MATCH_2" "$MATCH_1" Remove a public key from a repository. IMPLEMENTS WHEN user (\S+) removes key "(.+)" from repository (\S+) export GNUPGHOME="$DATADIR/$MATCH_1.gnupg" keyid="$( get_fingerprint "$MATCH_2" | awk '{ print substr($0, length-16) }')" run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_3" \ remove-key --keyid "$keyid" Forget a key from the user's keyring. IMPLEMENTS WHEN user (\S+) no longer has key "(.+)" export GNUPGHOME="$DATADIR/$MATCH_1.gnupg" ls -la "$GNUPGHOME" echo fingerprints gpg --fingerprint "$MATCH_2" echo with colons gpg --fingerprint --with-colons "$MATCH_2" echo just fingeprint gpg --fingerprint --with-colons "$MATCH_2" | awk -F: '{ print } /^fpr:/ { print $10; exit }' fingerprint="$(get_fingerprint "$MATCH_2")" gpg --batch --yes --delete-secret-key "$fingerprint" Lock management --------------- We need to lock parts of the repository, and force those locks open. IMPLEMENTS WHEN user (\S+) locks repository (\S+) run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_2" _lock Force it open. IMPLEMENTS WHEN user (\S+) forces open the lock on repository (\S+) run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_2" force-lock Client management ----------------- Sometimes, even if rarely, one wants to remove a complete client from a repository. IMPLEMENTS WHEN user (\S+) removes user (\S+) from repository (\S+) run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_3" remove-client "$MATCH_2" After that, one wants to make sure the removed client isn't in the repository anymore. IMPLEMENTS THEN user (\S+) can't see user (\S+) in repository (\S+) if run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_3" clients | grep -x "$MATCH_2" then echo "Client $MATCH_2 still in repository $MATCH_3" 1>&2 exit 1 fi We may also want to make sure we do see a client. IMPLEMENTS THEN user (\S+) can see user (\S+) in repository (\S+) if ! run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_3" clients | grep -x "$MATCH_2" then echo "Client $MATCH_2 is not in repository $MATCH_3" 1>&2 exit 1 fi Checks on results of an attempted operation ------------------------------------------- The `attempt` shell function in `obnam.sh` runs a command, then captures its stdout, stderr, and exit code. The scenarios can then test the results in various ways as separate steps. IMPLEMENTS THEN the attempt succeeded attempt_exit_was 0 IMPLEMENTS THEN the attempt failed with exit code (\d+) attempt_exit_was "$MATCH_1" We want to match the stdout against a regular expression. IMPLEMENTS THEN the output matches "(.+)" echo ----------------------- echo stdout being matched: cat "$DATADIR/attempt.stdout" echo ----------------------- attempt_matches stdout "$MATCH_1" We can also match the stderr against a regular expression. IMPLEMENTS THEN the error message matches "(.+)" echo ----------------------- echo stderr being matched: cat "$DATADIR/attempt.stderr" echo ----------------------- attempt_matches stderr "$MATCH_1" Checks on files --------------- Is a file empty? IMPLEMENTS THEN file (\S+) is empty diff -u /dev/null "$DATADIR/$MATCH_1" Is a file not empty? IMPLEMENTS THEN file (\S+) is not empty ! diff -u /dev/null "$DATADIR/$MATCH_1" Check that a restored file uses at most as much disk space as the original one in live data. IMPLEMENTS THEN file (\S+) from (\S+), restored in (\S+) doesn't use more disk old=$(stat -c %b "$DATADIR/$MATCH_2/$MATCH_1") new=$(stat -c %b "$DATADIR/$MATCH_3/$DATADIR/$MATCH_2/$MATCH_1") test "$old" -lt "$new" Check that a restored directory is empty. IMPLEMENTS THEN (\S+), restored to (\S+), is empty if find "$DATADIR/$MATCH_2/$DATADIR/$MATCH_1" -mindepth 1 | grep . then die "$DATADIR/$MATCH_2/$DATADIR/$MATCH_1 isn't empty" fi Checks on contents of files --------------------------- Regular expressions are very powerful, and sometimes that power is warranted to use. It isn't always clear enough to the lay reader, so be careful. `grep -E` regular expressions are used here. Does any line match? IMPLEMENTS THEN (\S+) matches (.*)$ grep -E -e "$MATCH_2" -- "$DATADIR/$MATCH_1" Does first line match? IMPLEMENTS THEN first line of (\S+) matches (.*)$ head -n1 "$DATADIR/$MATCH_1" | grep -E -e "$MATCH_2" -- Do all lines match? IMPLEMENTS THEN all lines in (\S+) match (\S+) ! grep -E -v -e "$MATCH_2" -- "$DATADIR/$MATCH_1" Does no line match? IMPLEMENTS THEN nothing in (\S+) matches (\S+) if grep -E -e "$MATCH_2" -- "$DATADIR/$MATCH_1" | grep '.*' then echo "At least one line matches, when none may!" 1>&2 exit 1 fi Merely read a file. This checks that the file exists and can be read by the user. IMPLEMENTS WHEN user (\S+) reads file (\S+) cat "$DATADIR/$MATCH_2" Does a restored file match what's in live data? IMPLEMENTS THEN file (.+), restored to (.+), matches live data cmp "$DATADIR/$MATCH_1" "$DATADIR/$MATCH_2/$DATADIR/$MATCH_1" Check on user running test suite -------------------------------- Some tests won't work correctly when `root` is running them. IMPLEMENTS ASSUMING not running as root test "$(id -u)" != 0 For testing FUSE stuff, we need to check that the relevant stuff is available. Previously, we did this by checking that the user running the test suite was in the group `fuse`, but that turns out to have been a Debianism (removed in the Debian `jessie` release). A better check is to check that the `fusermount` command is available. However, if we're on Debian and on a version prior to 8.0, we need to also be in the `fuse` group. (This can be dropped after support for those versions of Debian is dropped from Obnam, probably around first or second quarter of 2015.) IMPLEMENTS ASSUMING user can use FUSE # We _must_ have fusermount in any case. if ! command -v fusermount then echo "No fusermount found. User cannot use FUSE without it." 1>&2 exit 1 fi echo "fusermount found" # We also must be able to read from /dev/fuse. It might not exist, # and if it does, the kernel module providing it might not be # loaded. So we read 0 bytes from it, and if that works, it should # be OK. if ! dd if=/dev/fuse of=/dev/null bs=1 count=0 then echo "Can't read from /dev/null. User can't use FUSE." 1>&2 exit 1 fi echo "Can read from /dev/fuse." # Are we on Debian? If so, /etc/debian_version exists. # If it doesn't, we're done. if [ ! -e /etc/debian_version ] then echo "We are not on Debian. User can use FUSE." exit 0 fi # Read /etc/debian_version, and interpret it as a floating point # number, and compare it to 8.0. Prior to 8.0, we need to be in # the fuse group as well. if awk '($0 + 0.0) < 8.0 { exit 0 } END { exit 1 }' /etc/debian_version then echo "We're on Debian prior to 8.0." if groups | tr ' ' '\n' | grep -Fx fuse then echo "User is in group fuse." else echo "User is NOT in group fuse. User can't use FUSE." exit 1 fi else echo "We're on Debian 8.0 or later." fi # We're good. echo "User can use FUSE." exit 0 Check on whether user extended attributes work ---------------------------------------------- Extended attributes are, at least on some filesystems, a mount-time option which may be disabled. In fact, experience has shown that it often is disabled on build servers. IMPLEMENTS ASSUMING extended attributes are allowed for users touch "$DATADIR/xattr.test" setfattr -n user.foo -v bar "$DATADIR/xattr.test" Nagios ------ Run the Nagios monitoring subcommand. IMPLEMENTS WHEN user (\S+) attempts nagios-last-backup-age against repository (\S+) attempt run_obnam "$MATCH_1" nagios-last-backup-age \ -r "$DATADIR/$MATCH_2" kdirstat -------- Create a kdirstat cache. IMPLEMENTS WHEN user (\S+) creates a kdirstat cache file (\S+) of repository (\S+) run_obnam "$MATCH_1" -r "$DATADIR/$MATCH_3" kdirstat > "$DATADIR/$MATCH_2" Check that the cache mentions each file in the repository. Since grep -E cannot specifically match a tab we check only for one character of whitespace. IMPLEMENTS THEN for each entry in directory (\S+) a line in the kdircache (\S+) matches it find "$DATADIR/$MATCH_1" -type f | while read f ; do \ grep -E -e "^F[[:space:]]$f" "$DATADIR/$MATCH_2" || exit 1; \ done find "$DATADIR/$MATCH_1" -type p | while read p ; do \ grep -E -e "^FIFO[[:space:]]$p" "$DATADIR/$MATCH_2" || exit 1; \ done