diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-07-25 09:54:20 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-07-25 11:37:57 +0300 |
commit | 77a7d5a0fec242b929f62295a1b7d8e7700bfc35 (patch) | |
tree | b716a12f7362b529a86a004390f988bbb27b2b6c /subplot/vmadm.py | |
parent | ad881807180977c9346f3cfd42c9c5f51913e04e (diff) | |
download | vmadm-77a7d5a0fec242b929f62295a1b7d8e7700bfc35.tar.gz |
test: verify that "vmadm config" works
Sponsored-by: author
Diffstat (limited to 'subplot/vmadm.py')
-rw-r--r-- | subplot/vmadm.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/subplot/vmadm.py b/subplot/vmadm.py index dcdcbb6..42f857a 100644 --- a/subplot/vmadm.py +++ b/subplot/vmadm.py @@ -1,3 +1,5 @@ +import io +import json import logging import os import shutil @@ -105,3 +107,25 @@ def run_hostname_over_ssh(ctx, config=None, target=None, args=None): runcmd_run(ctx, ["chmod", "-R", "u=rwX,go=", ".ssh"]) runcmd_run(ctx, ["ssh", "-F", config, target] + args.split()) runcmd_exit_code_is_zero(ctx) + + +def stdout_json_matches(ctx, filename=None): + runcmd_get_stdout = globals()["runcmd_get_stdout"] + assert_dict_eq = globals()["assert_dict_eq"] + + stdout = io.StringIO(runcmd_get_stdout(ctx)) + actual = yaml.safe_load(stdout) + + with open(filename) as f: + expected = json.load(f) + + for key in expected: + value = expected[key] + if isinstance(value, str): + expected[key] = os.path.expanduser(value) + elif isinstance(value, list) and value and isinstance(value[0], str): + expected[key] = [os.path.expanduser(item) for item in value] + + logging.debug(f"actual: {actual}") + logging.debug(f"expect: {expected}") + assert_dict_eq(actual, expected) |