diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-11-13 07:36:34 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-11-13 07:36:34 +0000 |
commit | 179993f3bdd5e5d4dd728fc2a8f5d63274f95966 (patch) | |
tree | 5595fe6c724a15d445dd64f46fefaa94db846174 | |
parent | 39e23fb3b16cb6777d8e63e9e2dc59ab6f908d67 (diff) | |
parent | a2d15ccf200ae449a64cd895615a89ec42b4ab6a (diff) | |
download | obnam2-179993f3bdd5e5d4dd728fc2a8f5d63274f95966.tar.gz |
Merge branch 'subplot' into 'main'
Subplot
See merge request larswirzenius/obnam!9
-rwxr-xr-x | check | 7 | ||||
-rwxr-xr-x | format.sh | 8 | ||||
-rw-r--r-- | obnam.md | 14 | ||||
-rw-r--r-- | subplot/obnam.py | 61 | ||||
-rw-r--r-- | subplot/obnam.yaml | 18 |
5 files changed, 97 insertions, 11 deletions
@@ -21,6 +21,11 @@ cargo clippy $quiet cargo fmt -- --check $hideok cargo test $quiet -./format.sh +sp-docgen obnam.md -o obnam.html +sp-docgen obnam.md -o obnam.pdf + +sp-codegen obnam.md -o test.py +rm -f test.log +$hideok python3 test.py --log test.log "$@" echo "Everything seems to be in order." diff --git a/format.sh b/format.sh deleted file mode 100755 index e7f3c70..0000000 --- a/format.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# Build docs. - -set -eu - -sp-docgen obnam.md -o obnam.html -sp-docgen obnam.md -o obnam.pdf @@ -306,10 +306,20 @@ and their metadata are identical to the original. This is the simplest possible, but still useful requirement for a backup system. ~~~scenario -given a chunk server +given an installed obnam +and a chunk server +and a client config based on smoke.yaml and a file live/data.dat containing some random data -when I back up live with obnam-backup +when I invoke obnam-backup smoke.yaml then backup command is successful +and backup generation is GEN +when I invoke obnam-restore smoke.yaml <GEN> restore.db rest +then data in live and rest match +~~~ + +~~~{#smoke.yaml .file .yaml .numberLines} +root: live +dbname: tmp.db ~~~ ## Backups and restores diff --git a/subplot/obnam.py b/subplot/obnam.py index 79a4649..ee48985 100644 --- a/subplot/obnam.py +++ b/subplot/obnam.py @@ -6,6 +6,7 @@ import re import requests import shutil import socket +import subprocess import tarfile import time import urllib3 @@ -34,6 +35,8 @@ def start_chunk_server(ctx): logging.debug(f"Picked randomly port for obnam-server: {config['port']}") ctx["config"] = config + ctx["server_name"] = "localhost" + ctx["server_port"] = port ctx["url"] = f"http://localhost:{port}" start_daemon(ctx, "obnam-server", [_binary("obnam-server"), filename]) @@ -213,3 +216,61 @@ def _expand_vars(ctx, s): result.append(value) s = s[m.end() :] return "".join(result) + + +def install_obnam(ctx): + runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"] + srcdir = globals()["srcdir"] + + # Add the directory with built Rust binaries to the path. + runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug")) + + +def configure_client(ctx, filename=None): + get_file = globals()["get_file"] + + config = get_file(filename) + ctx["client-config"] = yaml.safe_load(config) + + +def run_obnam_backup(ctx, filename=None): + runcmd_run = globals()["runcmd_run"] + + _write_obnam_client_config(ctx, filename) + runcmd_run(ctx, ["env", "RUST_LOG=obnam", "obnam-backup", filename]) + + +def _write_obnam_client_config(ctx, filename): + config = ctx["client-config"] + config["server_name"] = ctx["server_name"] + config["server_port"] = ctx["server_port"] + with open(filename, "w") as f: + yaml.safe_dump(config, stream=f) + + +def run_obnam_restore(ctx, filename=None, genid=None, dbname=None, todir=None): + runcmd_run = globals()["runcmd_run"] + + genid = ctx["vars"][genid] + _write_obnam_client_config(ctx, filename) + runcmd_run( + ctx, ["env", "RUST_LOG=obnam", "obnam-restore", filename, genid, dbname, todir] + ) + + +def capture_generation_id(ctx, varname=None): + runcmd_get_stdout = globals()["runcmd_get_stdout"] + + stdout = runcmd_get_stdout(ctx) + gen_id = "unknown" + for line in stdout.splitlines(): + if line.startswith("gen id:"): + gen_id = line.split()[-1] + + v = ctx.get("vars", {}) + v[varname] = gen_id + ctx["vars"] = v + + +def live_and_restored_data_match(ctx, live=None, restore=None): + subprocess.check_call(["diff", "-rq", f"{live}/.", f"{restore}/{live}/."]) diff --git a/subplot/obnam.yaml b/subplot/obnam.yaml index c2a3608..7d2d85b 100644 --- a/subplot/obnam.yaml +++ b/subplot/obnam.yaml @@ -1,3 +1,9 @@ +- given: "an installed obnam" + function: install_obnam + +- given: "a client config based on {filename}" + function: configure_client + - given: "a chunk server" function: start_chunk_server cleanup: stop_chunk_server @@ -33,6 +39,12 @@ - when: "I back up {dirname} with obnam-backup" function: back_up_directory +- when: "I invoke obnam-backup {filename}" + function: run_obnam_backup + +- when: "I invoke obnam-restore {filename} <{genid}> {dbname} {todir}" + function: run_obnam_restore + - then: "HTTP status code is {status}" function: status_code_is @@ -51,3 +63,9 @@ - then: "backup command is successful" function: command_is_successful + +- then: "backup generation is {varname}" + function: capture_generation_id + +- then: "data in {live} and {restore} match" + function: live_and_restored_data_match |