Skip to content

Commit

Permalink
omdb nexus blueprints target set --diff`
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Aug 26, 2024
1 parent 876ae85 commit 50b2348
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
47 changes: 41 additions & 6 deletions dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ struct BlueprintTargetSetArgs {
blueprint_id: Uuid,
/// whether this blueprint should be enabled
enabled: BlueprintTargetSetEnabled,
/// if specified, diff against the current target and wait for confirmation
/// before proceeding
#[clap(long)]
diff: bool,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
Expand Down Expand Up @@ -1734,12 +1738,43 @@ async fn cmd_nexus_blueprints_target_set(
// operator. (In the case of the current target blueprint being changed
// entirely, that will result in a failure to set the current target
// below, because its parent will no longer be the current target.)
BlueprintTargetSetEnabled::Inherit => client
.blueprint_target_view()
.await
.map(|current| current.into_inner().enabled)
.context("failed to fetch current target blueprint")?,
BlueprintTargetSetEnabled::Inherit => {
client
.blueprint_target_view()
.await
.context("failed to fetch current target blueprint")?
.into_inner()
.enabled
}
};

if args.diff {
let blueprint1 = client
.blueprint_view(
&client
.blueprint_target_view()
.await
.context("failed to fetch current target blueprint")?
.into_inner()
.target_id,
)
.await
.context("failed to fetch target blueprint")?
.into_inner();
let blueprint2 =
client.blueprint_view(&args.blueprint_id).await.with_context(
|| format!("fetching blueprint {}", args.blueprint_id),
)?;
let diff = blueprint2.diff_since_blueprint(&blueprint1);
println!("{}", diff.display());
println!(
"\nDo you want to make {} the target blueprint?",
args.blueprint_id
);
let mut prompt = ConfirmationPrompt::new();
prompt.read_and_validate("y/N", "y")?;
}

client
.blueprint_target_set(&nexus_client::types::BlueprintTargetSet {
target_id: args.blueprint_id,
Expand Down Expand Up @@ -1966,7 +2001,7 @@ impl ConfirmationPrompt {
{
Ok(input)
} else {
bail!("expungement aborted")
bail!("operation aborted")
}
}

Expand Down
8 changes: 8 additions & 0 deletions nexus/src/app/sagas/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ mod test {
subscribe.await.unwrap();
println!("demo saga: {demo_saga_id} done");

// Completing again at this point should produce a 404.
let error = hub.complete(demo_saga_id).unwrap_err();
assert_matches!(error, Error::NotFound { .. });

// It's also possible that the completion request arrives before the
// saga started waiting. In that case, the sequence is:
//
Expand All @@ -187,6 +191,8 @@ mod test {
println!("demo saga: {demo_saga_id} subscribed");
subscribe.await.unwrap();
println!("demo saga: {demo_saga_id} done");
let error = hub.complete(demo_saga_id).unwrap_err();
assert_matches!(error, Error::NotFound { .. });

// It's also possible to have no preregistration at all. This happens
// if the demo saga was recovered. That's fine, too, but then it will
Expand All @@ -199,6 +205,8 @@ mod test {
println!("demo saga: {demo_saga_id} marked completed");
subscribe.await.unwrap();
println!("demo saga: {demo_saga_id} done");
let error = hub.complete(demo_saga_id).unwrap_err();
assert_matches!(error, Error::NotFound { .. });

// If there's no preregistration and we get a completion request, then
// that request should fail.
Expand Down

0 comments on commit 50b2348

Please sign in to comment.