Skip to content

Commit

Permalink
mark the demo saga commands destructive; fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Aug 10, 2024
1 parent 3366598 commit c2ef417
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
11 changes: 8 additions & 3 deletions dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,13 @@ impl NexusArgs {
match command {
SagasCommands::List => cmd_nexus_sagas_list(&client).await,
SagasCommands::DemoCreate => {
cmd_nexus_sagas_demo_create(&client).await
let token = omdb.check_allow_destructive()?;
cmd_nexus_sagas_demo_create(&client, token).await
}
SagasCommands::DemoComplete(args) => {
cmd_nexus_sagas_demo_complete(&client, args).await
let token = omdb.check_allow_destructive()?;
cmd_nexus_sagas_demo_complete(&client, args, token)
.await
}
}
}
Expand Down Expand Up @@ -1657,13 +1660,14 @@ async fn cmd_nexus_sagas_list(
/// Runs `omdb nexus sagas demo-create`
async fn cmd_nexus_sagas_demo_create(
client: &nexus_client::Client,
_destruction_token: DestructiveOperationToken,
) -> Result<(), anyhow::Error> {
let demo_saga =
client.saga_demo_create().await.context("creating demo saga")?;
println!("saga id: {}", demo_saga.saga_id);
println!(
"demo saga id: {} (use this with `demo-complete`)",
demo_saga.demo_saga_id.to_string(),
demo_saga.demo_saga_id,
);
Ok(())
}
Expand All @@ -1672,6 +1676,7 @@ async fn cmd_nexus_sagas_demo_create(
async fn cmd_nexus_sagas_demo_complete(
client: &nexus_client::Client,
args: &DemoSagaIdArgs,
_destruction_token: DestructiveOperationToken,
) -> Result<(), anyhow::Error> {
if let Err(error) = client
.saga_demo_complete(&args.demo_saga_id)
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/omdb/tests/successes.out
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ NOTE: This command only reads in-memory state from the targeted Nexus instance.
Sagas may be missing if they were run by a different Nexus instance or if they
finished before this Nexus instance last started up.
=============================================
EXECUTING COMMAND: omdb ["nexus", "sagas", "demo-create"]
EXECUTING COMMAND: omdb ["--destructive", "nexus", "sagas", "demo-create"]
termination: Exited(0)
---------------------------------------------
stdout:
Expand Down
11 changes: 10 additions & 1 deletion dev-tools/omdb/tests/test_all_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ async fn test_omdb_usage_errors() {
&["nexus", "background-tasks"],
&["nexus", "blueprints"],
&["nexus", "sagas"],
// Missing "--destructive" flag. The URL is bogus but just ensures that
// we get far enough to hit the error we care about.
&[
"nexus",
"--nexus-internal-url",
"http://[::1]:111",
"sagas",
"demo-create",
],
&["nexus", "sleds"],
&["sled-agent"],
&["sled-agent", "zones"],
Expand Down Expand Up @@ -136,7 +145,7 @@ async fn test_omdb_success_cases(cptestctx: &ControlPlaneTestContext) {
&["nexus", "background-tasks", "doc"],
&["nexus", "background-tasks", "show"],
&["nexus", "sagas", "list"],
&["nexus", "sagas", "demo-create"],
&["--destructive", "nexus", "sagas", "demo-create"],
&["nexus", "sagas", "list"],
&[
"--destructive",
Expand Down
9 changes: 9 additions & 0 deletions dev-tools/omdb/tests/usage_errors.out
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,15 @@ Connection Options:
Safety Options:
-w, --destructive Allow potentially-destructive subcommands
=============================================
EXECUTING COMMAND: omdb ["nexus", "--nexus-internal-url", "http://[::1]:111", "sagas", "demo-create"]
termination: Exited(1)
---------------------------------------------
stdout:
---------------------------------------------
stderr:
note: using Nexus URL http://[::1]:111
Error: This command is potentially destructive. Pass the `-w` / `--destructive` flag to allow it.
=============================================
EXECUTING COMMAND: omdb ["nexus", "sleds"]
termination: Exited(2)
---------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/demo_saga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async fn test_demo_saga(cptestctx: &ControlPlaneTestContext) {
eprintln!("found sagas (before): {:?}", sagas_before);
let demo_saga = nexus_client.saga_demo_create().await.unwrap();
let saga_id = demo_saga.saga_id;
assert!(sagas_before.into_iter().find(|s| s.id == saga_id).is_none());
assert!(!sagas_before.into_iter().any(|s| s.id == saga_id));

let sagas_after = list_sagas(&nexus_client).await;
eprintln!("found sagas (after): {:?}", sagas_after);
Expand Down

0 comments on commit c2ef417

Please sign in to comment.