diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-27 07:54:40 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-28 12:24:08 +0200 |
commit | 1c5c97532c91faf8a59bbe7ebcfc645f653db697 (patch) | |
tree | 5d690b3e826472c8515710dce3d9bd256106b249 /subplot | |
parent | 98c482d7903d059a6598a6e7280f0e7b431eac29 (diff) | |
download | vmadm-1c5c97532c91faf8a59bbe7ebcfc645f653db697.tar.gz |
feat: export cloud-init config, set SSH host keys
Diffstat (limited to 'subplot')
-rw-r--r-- | subplot/vmadm.py | 30 | ||||
-rw-r--r-- | subplot/vmadm.yaml | 6 |
2 files changed, 36 insertions, 0 deletions
diff --git a/subplot/vmadm.py b/subplot/vmadm.py index 2374baf..48737a3 100644 --- a/subplot/vmadm.py +++ b/subplot/vmadm.py @@ -1,4 +1,6 @@ +import logging import os +import yaml def install_vmadm(ctx): @@ -16,6 +18,34 @@ def install_vmadm(ctx): # This can be removed once the Subplot lib/files library creates # directories. os.mkdir(".ssh") + os.mkdir("expected") + + +def invoke_cloud_init(ctx, filename=None, dirname=None): + runcmd_run = globals()["runcmd_run"] + runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"] + + runcmd_run(ctx, ["vmadm", "cloud-init", filename, dirname]) + runcmd_exit_code_is_zero(ctx) + + +def directories_match(ctx, actual=None, expected=None): + assert_eq = globals()["assert_eq"] + + efiles = list(sorted(os.listdir(expected))) + afiles = list(sorted(os.listdir(expected))) + assert_eq(efiles, afiles) + for filename in efiles: + with open(os.path.join("expected", filename)) as f: + edata = yaml.safe_load(f) + with open(os.path.join("actual", filename)) as f: + adata = yaml.safe_load(f) + if "runcmd" in adata: + del adata["runcmd"] + logging.debug(f"directories_match: filename={filename}") + logging.debug(f"directories_match: edata={edata!r}") + logging.debug(f"directories_match: adata={adata!r}") + assert_eq(edata, adata) def create_vm(ctx, filename=None): diff --git a/subplot/vmadm.yaml b/subplot/vmadm.yaml index 40fce49..374391b 100644 --- a/subplot/vmadm.yaml +++ b/subplot/vmadm.yaml @@ -1,9 +1,15 @@ - given: "an installed vmadm" function: install_vmadm +- when: "I invoke vmadm cloud-init {filename} {dirname}" + function: invoke_cloud_init + - when: "I invoke vmadm new {filename}" function: create_vm cleanup: delete_vm - when: "I invoke ssh -F {config} {target} {args:text}" function: run_hostname_over_ssh + +- then: "directories {actual} and {expected} are identical" + function: directories_match |