summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-04 09:15:43 +0000
committerLars Wirzenius <liw@liw.fi>2021-02-04 09:15:43 +0000
commit773d8e0458ce32f156606c4cc3d81097539459ff (patch)
tree0820209b255f83bae4132d30df067161e04ec899
parentcda0e5bde3fa0c9c2cb0b4fa9f21fbb758acfbe1 (diff)
parentad48a051596f6b9748340b7ea5b30659e2692684 (diff)
downloadobnam2-773d8e0458ce32f156606c4cc3d81097539459ff.tar.gz
Merge branch 'dump-config' into 'main'
Dump config Closes #60 See merge request larswirzenius/obnam!83
-rw-r--r--obnam.md28
-rw-r--r--src/bin/obnam.rs4
-rw-r--r--src/client.rs4
-rw-r--r--src/cmd/mod.rs3
-rw-r--r--src/cmd/show_config.rs7
-rw-r--r--src/error.rs3
-rw-r--r--subplot/client.yaml3
-rw-r--r--subplot/data.py29
-rw-r--r--subplot/data.yaml7
9 files changed, 83 insertions, 5 deletions
diff --git a/obnam.md b/obnam.md
index e81989b..833fbf4 100644
--- a/obnam.md
+++ b/obnam.md
@@ -820,6 +820,32 @@ and chunk-meta is {"sha256":"abc","generation":null,"ended":null}
and the body matches file data.dat
~~~
+# Acceptance criteria for the Obnam client
+
+The scenarios in chapter verify that the Obnam client works as it
+should, when it is used independently of an Obnam chunk server.
+
+## Client shows its configuration
+
+This scenario verifies that the client can show its current
+configuration, with the `obnam config` command. The configuration is
+stored as YAML, but the command outputs JSON, to make sure it doesn't
+just copy the configuration file to the output.
+
+~~~scenario
+given an installed obnam
+and file config.yaml
+and JSON file config.json converted from YAML file config.yaml
+when I run obnam --config config.yaml config
+then stdout, as JSON, matches file config.json
+~~~
+
+~~~{#config.yaml .file .yaml .numberLines}
+root: live
+server_url: https://backup.example.com
+~~~
+
+
# Acceptance criteria for Obnam as a whole
The scenarios in this chapter apply to Obnam as a whole: the client
@@ -1093,6 +1119,7 @@ bindings:
- subplot/server.yaml
- subplot/client.yaml
- subplot/data.yaml
+ - subplot/vendored/files.yaml
- subplot/vendored/runcmd.yaml
template: python
functions:
@@ -1100,6 +1127,7 @@ functions:
- subplot/client.py
- subplot/data.py
- subplot/vendored/daemon.py
+ - subplot/vendored/files.py
- subplot/vendored/runcmd.py
classes:
- json
diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs
index 4e38e1a..9c5d3f4 100644
--- a/src/bin/obnam.rs
+++ b/src/bin/obnam.rs
@@ -2,7 +2,7 @@ use log::{debug, error, info, LevelFilter};
use log4rs::append::file::FileAppender;
use log4rs::config::{Appender, Config, Logger, Root};
use obnam::client::ClientConfig;
-use obnam::cmd::{backup, get_chunk, list, list_files, restore, show_generation};
+use obnam::cmd::{backup, get_chunk, list, list_files, restore, show_config, show_generation};
use std::path::{Path, PathBuf};
use structopt::StructOpt;
@@ -29,6 +29,7 @@ fn main() -> anyhow::Result<()> {
Command::ListFiles { gen_id } => list_files(&config, &gen_id),
Command::Restore { gen_id, to } => restore(&config, &gen_id, &to),
Command::GetChunk { chunk_id } => get_chunk(&config, &chunk_id),
+ Command::Config => show_config(&config),
};
if let Err(ref e) = result {
@@ -84,6 +85,7 @@ enum Command {
#[structopt()]
chunk_id: String,
},
+ Config,
}
fn setup_logging(filename: &Path) -> anyhow::Result<()> {
diff --git a/src/client.rs b/src/client.rs
index f9c325c..e8e20eb 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -11,13 +11,13 @@ use crate::genlist::GenerationList;
use chrono::{DateTime, Local};
use log::{debug, error, info, trace};
use reqwest::blocking::Client;
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
-#[derive(Debug, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ClientConfig {
pub server_url: String,
pub root: PathBuf,
diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs
index 8f08668..fc517be 100644
--- a/src/cmd/mod.rs
+++ b/src/cmd/mod.rs
@@ -15,3 +15,6 @@ pub use get_chunk::get_chunk;
pub mod show_gen;
pub use show_gen::show_generation;
+
+pub mod show_config;
+pub use show_config::show_config;
diff --git a/src/cmd/show_config.rs b/src/cmd/show_config.rs
new file mode 100644
index 0000000..b4f4cdc
--- /dev/null
+++ b/src/cmd/show_config.rs
@@ -0,0 +1,7 @@
+use crate::client::ClientConfig;
+use crate::error::ObnamError;
+
+pub fn show_config(config: &ClientConfig) -> Result<(), ObnamError> {
+ println!("{}", serde_json::to_string_pretty(config)?);
+ Ok(())
+}
diff --git a/src/error.rs b/src/error.rs
index cf286db..73d4a66 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -40,4 +40,7 @@ pub enum ObnamError {
#[error(transparent)]
SystemTimeError(#[from] SystemTimeError),
+
+ #[error(transparent)]
+ SerdeJsonError(#[from] serde_json::Error),
}
diff --git a/subplot/client.yaml b/subplot/client.yaml
index b1f9b19..eef4714 100644
--- a/subplot/client.yaml
+++ b/subplot/client.yaml
@@ -4,6 +4,9 @@
- given: "a client config based on {filename}"
function: configure_client
+- when: "I invoke obnam --config {filename} config"
+ function: run_obnam_config
+
- when: "I invoke obnam --config {filename} restore <{genid}> {todir}"
function: run_obnam_restore
diff --git a/subplot/data.py b/subplot/data.py
index a24cd0c..2a54037 100644
--- a/subplot/data.py
+++ b/subplot/data.py
@@ -1,6 +1,8 @@
+import json
import logging
import os
import random
+import yaml
def create_file_with_random_data(ctx, filename=None):
@@ -57,3 +59,30 @@ def files_match(ctx, first=None, second=None):
logging.debug(f"files_match: f:\n{f}")
logging.debug(f"files_match: s:\n{s}")
assert_eq(f, s)
+
+
+def convert_yaml_to_json(ctx, yaml_name=None, json_name=None):
+ with open(yaml_name) as f:
+ obj = yaml.safe_load(f)
+ with open(json_name, "w") as f:
+ json.dump(obj, f)
+
+
+def match_stdout_to_json_file(ctx, filename=None):
+ runcmd_get_stdout = globals()["runcmd_get_stdout"]
+ assert_eq = globals()["assert_eq"]
+
+ stdout = runcmd_get_stdout(ctx)
+ stdout = json.loads(stdout.strip())
+ obj = json.load(open(filename))
+ logging.debug(f"match_stdout_to_json_file: stdout={stdout!r}")
+ logging.debug(f"match_stdout_to_json_file: file={obj!r}")
+
+ for key in obj:
+ if key not in stdout:
+ logging.error(f"{key} not in stdout")
+ assert key in stdout
+
+ if stdout[key] != obj[key]:
+ logging.error(f"stdout value for key is not what was exptected")
+ assert_eq(stdout[key], obj[key])
diff --git a/subplot/data.yaml b/subplot/data.yaml
index 7659319..6d384b8 100644
--- a/subplot/data.yaml
+++ b/subplot/data.yaml
@@ -21,5 +21,8 @@
- 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
+- given: "JSON file {json_name} converted from YAML file {yaml_name}"
+ function: convert_yaml_to_json
+
+- then: "stdout, as JSON, matches file {filename}"
+ function: match_stdout_to_json_file