From f75eb2433ac790891eaeb07248cf98d525cd5a13 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 8 Dec 2020 08:51:14 +0200 Subject: refactor: move functions around so that data stuff is in data.yaml --- client.yaml | 2 +- subplot/client.py | 34 ---------------------------------- subplot/client.yaml | 9 --------- subplot/data.py | 32 +++++++++++++++++++++++++++++--- subplot/data.yaml | 10 ++++++++-- 5 files changed, 38 insertions(+), 49 deletions(-) diff --git a/client.yaml b/client.yaml index 53582aa..1d1cd27 100644 --- a/client.yaml +++ b/client.yaml @@ -1,3 +1,3 @@ server_url: https://localhost:8888/chunks -root: /home/liw/pers/debian-ansible +root: /home/liw/pers/obnam/git/live dbname: foo.db diff --git a/subplot/client.py b/subplot/client.py index 75baa8f..d89b7d4 100644 --- a/subplot/client.py +++ b/subplot/client.py @@ -1,5 +1,4 @@ import os -import subprocess import yaml @@ -47,39 +46,6 @@ def capture_generation_id(ctx, varname=None): ctx["vars"] = v -def create_manifest_of_live(ctx, dirname=None, manifest=None): - _create_manifest_of_directory(ctx, dirname=dirname, manifest=manifest) - - -def create_manifest_of_restored(ctx, dirname=None, restored=None, manifest=None): - _create_manifest_of_directory( - ctx, dirname=os.path.join(restored, "./" + dirname), manifest=manifest - ) - - -def _create_manifest_of_directory(ctx, dirname=None, manifest=None): - runcmd_run = globals()["runcmd_run"] - runcmd_get_exit_code = globals()["runcmd_get_exit_code"] - runcmd_get_stdout = globals()["runcmd_get_stdout"] - - runcmd_run(ctx, ["summain", dirname]) - assert runcmd_get_exit_code(ctx) == 0 - stdout = runcmd_get_stdout(ctx) - open(manifest, "w").write(stdout) - - -def files_match(ctx, first=None, second=None): - assert_eq = globals()["assert_eq"] - - f = open(first).read() - s = open(first).read() - assert_eq(f, s) - - -def live_and_restored_data_match(ctx, live=None, restore=None): - subprocess.check_call(["diff", "-rq", f"{live}/.", f"{restore}/{live}/."]) - - def generation_list_contains(ctx, gen_id=None): runcmd_stdout_contains = globals()["runcmd_stdout_contains"] gen_id = ctx["vars"][gen_id] diff --git a/subplot/client.yaml b/subplot/client.yaml index 6894025..63033c3 100644 --- a/subplot/client.yaml +++ b/subplot/client.yaml @@ -4,12 +4,6 @@ - given: "a client config based on {filename}" function: configure_client -- given: a manifest of the directory {dirname} in {manifest} - function: create_manifest_of_live - -- given: a manifest of the directory {dirname} restored in {restored} in {manifest} - function: create_manifest_of_restored - - when: "I invoke obnam restore {filename} <{genid}> {todir}" function: run_obnam_restore @@ -18,6 +12,3 @@ - then: "generation list contains <{gen_id}>" function: generation_list_contains - -- then: files {first} and {second} match - function: files_match diff --git a/subplot/data.py b/subplot/data.py index a1b9032..c4cb0a7 100644 --- a/subplot/data.py +++ b/subplot/data.py @@ -1,7 +1,6 @@ import logging import os import random -import subprocess def create_file_with_random_data(ctx, filename=None): @@ -14,5 +13,32 @@ def create_file_with_random_data(ctx, filename=None): f.write(data) -def live_and_restored_data_match(ctx, live=None, restore=None): - subprocess.check_call(["diff", "-rq", f"{live}/.", f"{restore}/{live}/."]) +def create_manifest_of_live(ctx, dirname=None, manifest=None): + _create_manifest_of_directory(ctx, dirname=dirname, manifest=manifest) + + +def create_manifest_of_restored(ctx, dirname=None, restored=None, manifest=None): + _create_manifest_of_directory( + ctx, dirname=os.path.join(restored, "./" + dirname), manifest=manifest + ) + + +def _create_manifest_of_directory(ctx, dirname=None, manifest=None): + runcmd_run = globals()["runcmd_run"] + runcmd_get_exit_code = globals()["runcmd_get_exit_code"] + runcmd_get_stdout = globals()["runcmd_get_stdout"] + + runcmd_run(ctx, ["summain", dirname]) + assert runcmd_get_exit_code(ctx) == 0 + stdout = runcmd_get_stdout(ctx) + open(manifest, "w").write(stdout) + + +def files_match(ctx, first=None, second=None): + assert_eq = globals()["assert_eq"] + + f = open(first).read() + s = open(first).read() + logging.debug(f"files_match: f={f!r}") + logging.debug(f"files_match: s={s!r}") + assert_eq(f, s) diff --git a/subplot/data.yaml b/subplot/data.yaml index 8006240..4f9871a 100644 --- a/subplot/data.yaml +++ b/subplot/data.yaml @@ -6,5 +6,11 @@ - given: "a file {filename} containing some random data" function: create_file_with_random_data -- then: "data in {live} and {restore} match" - function: live_and_restored_data_match +- given: a manifest of the directory {dirname} in {manifest} + function: create_manifest_of_live + +- given: a manifest of the directory {dirname} restored in {restored} in {manifest} + function: create_manifest_of_restored + +- then: files {first} and {second} match + function: files_match -- cgit v1.2.1