summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-07-25 09:54:20 +0300
committerLars Wirzenius <liw@liw.fi>2021-07-25 11:37:57 +0300
commit77a7d5a0fec242b929f62295a1b7d8e7700bfc35 (patch)
treeb716a12f7362b529a86a004390f988bbb27b2b6c
parentad881807180977c9346f3cfd42c9c5f51913e04e (diff)
downloadvmadm-77a7d5a0fec242b929f62295a1b7d8e7700bfc35.tar.gz
test: verify that "vmadm config" works
Sponsored-by: author
-rw-r--r--Cargo.lock26
-rw-r--r--Cargo.toml15
-rw-r--r--src/cmd/config.rs2
-rw-r--r--subplot/vmadm.py24
-rw-r--r--subplot/vmadm.yaml3
-rw-r--r--vmadm.md40
6 files changed, 98 insertions, 12 deletions
diff --git a/Cargo.lock b/Cargo.lock
index afe30bb..8af831c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "aho-corasick"
version = "0.7.15"
@@ -147,6 +149,12 @@ dependencies = [
]
[[package]]
+name = "itoa"
+version = "0.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
+
+[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -336,6 +344,12 @@ dependencies = [
]
[[package]]
+name = "ryu"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
+
+[[package]]
name = "serde"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -356,6 +370,17 @@ dependencies = [
]
[[package]]
+name = "serde_json"
+version = "1.0.64"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
+dependencies = [
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
name = "serde_yaml"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -524,6 +549,7 @@ dependencies = [
"log",
"pretty_env_logger",
"serde",
+ "serde_json",
"serde_yaml",
"shell-words",
"structopt",
diff --git a/Cargo.toml b/Cargo.toml
index e199527..a8ca135 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,14 +12,15 @@ repository = "https://gitlab.com/larswirzenius/vmadm"
[dependencies]
anyhow = "1"
-structopt = "0.3"
-tempfile = "3.2"
-thiserror = "1"
-virt = "0.2"
-serde = { version = "1", features = ["derive"] }
-serde_yaml = "0.8"
bytesize = "1"
+directories-next = "2"
log = "0.4"
pretty_env_logger = "0.4"
+serde = { version = "1", features = ["derive"] }
+serde_json = "1.0.64"
+serde_yaml = "0.8"
shell-words = "1"
-directories-next = "2"
+structopt = "0.3"
+tempfile = "3.2"
+thiserror = "1"
+virt = "0.2"
diff --git a/src/cmd/config.rs b/src/cmd/config.rs
index 996439b..396f089 100644
--- a/src/cmd/config.rs
+++ b/src/cmd/config.rs
@@ -8,7 +8,7 @@ use crate::config::Configuration;
///
/// Write the actual run-time configuration to stdout.
pub fn config(config: &Configuration) -> Result<(), std::io::Error> {
- let config = serde_yaml::to_vec(&config).unwrap();
+ let config = serde_json::to_vec(&config).unwrap();
std::io::stdout().write_all(&config)?;
Ok(())
}
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)
diff --git a/subplot/vmadm.yaml b/subplot/vmadm.yaml
index fb778dd..c6c5ad1 100644
--- a/subplot/vmadm.yaml
+++ b/subplot/vmadm.yaml
@@ -25,3 +25,6 @@
- then: "directories {actual} and {expected} are identical"
function: directories_match
+
+- then: "stdout, as JSON, matches file {filename} with tilde expansion"
+ function: stdout_json_matches
diff --git a/vmadm.md b/vmadm.md
index 2d97876..34ba73f 100644
--- a/vmadm.md
+++ b/vmadm.md
@@ -55,6 +55,22 @@ authorized_keys:
- ~/.ssh/id_rsa.pub
~~~
+~~~{#fullconfig.json .file .json}
+{
+ "image_directory": "~/images",
+ "default_base_image": "~/base.qcow2",
+ "default_image_gib": 5,
+ "default_memory_mib": 2048,
+ "default_cpus": 1,
+ "default_generate_host_certificate": true,
+ "default_autostart": true,
+ "ca_key": "ca_key",
+ "authorized_keys": [
+ "~/.ssh/id_rsa.pub"
+ ]
+}
+~~~
+
~~~{#ssh_key_pub .file}
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChZ6mVuGLBpW7SarFU/Tu6TemquNxatbMUZuTk8RqVtbkvTKeWFZ5h5tntWPHgST8ykYFaIrr8eYuKQkKdBxHW7H8kejTNwRu/rDbRYX5wxTn4jw4RVopGTpxMlGrWeu5CkWPoLAhQtIzzUAnrDGp9sqG6P1G4ohI61wZMFQta9R2uNxXnnes+e2r4Y78GxmlQH/o0ouI8fBnsxRK0IoSfFs2LutO6wjyzR59FdC9TT7wufd5kXMRzxsmPGeXzNcaqvHGxBvRucGFclCkqSRwk3GNEpXZQhlCIoTIoRu0IPAp/430tlx9zJMhhwDlZsOOXRrFYpdWVMSTAAKECLSYx liw@exolobe1
~~~
@@ -202,6 +218,20 @@ when I invoke vmadm delete --config config.yaml smoke.yaml
+# Dump config
+
+This scenario verifies that vmadm can show its actual configuration.
+
+~~~scenario
+given an installed vmadm
+given a Debian 10 OpenStack cloud image
+given file .config/vmadm/config.yaml from config.yaml
+given file fullconfig.json
+when I run vmadm config
+then stdout, as JSON, matches file fullconfig.json with tilde expansion
+~~~
+
+
# Colophon
This is a document meant to be processed with [Subplot][] into an HTML
@@ -213,10 +243,12 @@ author: "Lars Wirzenius"
template: python
bindings:
- subplot/vmadm.yaml
- - subplot/vendored/files.yaml
- - subplot/vendored/runcmd.yaml
+ - lib/files.yaml
+ - lib/runcmd.yaml
functions:
- subplot/vmadm.py
- - subplot/vendored/files.py
- - subplot/vendored/runcmd.py
+ - lib/files.py
+ - lib/runcmd.py
+classes:
+- json
...