Skip to content
Merged
17 changes: 17 additions & 0 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,19 @@ impl From<omicron_common::api::internal::shared::NetworkInterfaceKind>
}
}

// TODO-cleanup This is icky; can we move these methods to a separate client so
// we don't need to add this header by hand?
// https://github.com/oxidecomputer/omicron/issues/8900
trait ApiVersionHeader {
fn api_version_header(self, api_version: &'static str) -> Self;
}

impl ApiVersionHeader for reqwest::RequestBuilder {
fn api_version_header(self, api_version: &'static str) -> Self {
self.header("api-version", api_version)
}
}

/// Exposes additional [`Client`] interfaces for use by the test suite. These
/// are bonus endpoints, not generated in the real client.
#[async_trait]
Expand All @@ -353,6 +366,7 @@ impl TestInterfaces for Client {
let url = format!("{}/vmms/{}/poke-single-step", baseurl, id);
client
.post(url)
.api_version_header(self.api_version())
.send()
.await
.expect("instance_single_step() failed unexpectedly");
Expand All @@ -364,6 +378,7 @@ impl TestInterfaces for Client {
let url = format!("{}/vmms/{}/poke", baseurl, id);
client
.post(url)
.api_version_header(self.api_version())
.send()
.await
.expect("instance_finish_transition() failed unexpectedly");
Expand All @@ -375,6 +390,7 @@ impl TestInterfaces for Client {
let url = format!("{}/disks/{}/poke", baseurl, id);
client
.post(url)
.api_version_header(self.api_version())
.send()
.await
.expect("disk_finish_transition() failed unexpectedly");
Expand All @@ -390,6 +406,7 @@ impl TestInterfaces for Client {
let url = format!("{baseurl}/vmms/{id}/sim-migration-source");
client
.post(url)
.api_version_header(self.api_version())
.json(&params)
.send()
.await
Expand Down
68 changes: 1 addition & 67 deletions dev-tools/omdb/src/bin/omdb/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
//! omdb commands that query or update specific Sleds

use crate::Omdb;
use crate::check_allow_destructive::DestructiveOperationToken;
use crate::helpers::CONNECTION_OPTIONS_HEADING;
use anyhow::Context;
use anyhow::bail;
use clap::Args;
use clap::Subcommand;
use sled_agent_client::types::ChickenSwitchDestroyOrphanedDatasets;

/// Arguments to the "omdb sled-agent" subcommand
#[derive(Debug, Args)]
Expand Down Expand Up @@ -39,11 +37,6 @@ enum SledAgentCommands {
/// print information about the local bootstore node
#[clap(subcommand)]
Bootstore(BootstoreCommands),

/// control "chicken switches" (potentially-destructive sled-agent behavior
/// that can be toggled on or off via `omdb`)
#[clap(subcommand)]
ChickenSwitch(ChickenSwitchCommands),
}

#[derive(Debug, Subcommand)]
Expand All @@ -58,12 +51,6 @@ enum BootstoreCommands {
Status,
}

#[derive(Debug, Subcommand)]
enum ChickenSwitchCommands {
/// interact with the "destroy orphaned datasets" chicken switch
DestroyOrphans(DestroyOrphansArgs),
}

#[derive(Debug, Args)]
struct DestroyOrphansArgs {
#[command(subcommand)]
Expand All @@ -84,7 +71,7 @@ impl SledAgentArgs {
/// Run a `omdb sled-agent` subcommand.
pub(crate) async fn run_cmd(
&self,
omdb: &Omdb,
_omdb: &Omdb,
log: &slog::Logger,
) -> Result<(), anyhow::Error> {
// This is a little goofy. The sled URL is required, but can come
Expand All @@ -105,29 +92,6 @@ impl SledAgentArgs {
SledAgentCommands::Bootstore(BootstoreCommands::Status) => {
cmd_bootstore_status(&client).await
}
SledAgentCommands::ChickenSwitch(
ChickenSwitchCommands::DestroyOrphans(DestroyOrphansArgs {
command: DestroyOrphansCommands::Get,
}),
) => cmd_chicken_switch_destroy_orphans_get(&client).await,
SledAgentCommands::ChickenSwitch(
ChickenSwitchCommands::DestroyOrphans(DestroyOrphansArgs {
command: DestroyOrphansCommands::Enable,
}),
) => {
let token = omdb.check_allow_destructive()?;
cmd_chicken_switch_destroy_orphans_set(&client, true, token)
.await
}
SledAgentCommands::ChickenSwitch(
ChickenSwitchCommands::DestroyOrphans(DestroyOrphansArgs {
command: DestroyOrphansCommands::Disable,
}),
) => {
let token = omdb.check_allow_destructive()?;
cmd_chicken_switch_destroy_orphans_set(&client, false, token)
.await
}
}
}
}
Expand Down Expand Up @@ -193,33 +157,3 @@ async fn cmd_bootstore_status(

Ok(())
}

/// Runs `omdb sled-agent chicken-switch destroy-orphans get`
async fn cmd_chicken_switch_destroy_orphans_get(
client: &sled_agent_client::Client,
) -> Result<(), anyhow::Error> {
let ChickenSwitchDestroyOrphanedDatasets { destroy_orphans } = client
.chicken_switch_destroy_orphaned_datasets_get()
.await
.context("get chicken switch value")?
.into_inner();
let status = if destroy_orphans { "enabled" } else { "disabled" };
println!("destroy orphaned datasets {status}");
Ok(())
}

/// Runs `omdb sled-agent chicken-switch destroy-orphans {enable,disable}`
async fn cmd_chicken_switch_destroy_orphans_set(
client: &sled_agent_client::Client,
destroy_orphans: bool,
_token: DestructiveOperationToken,
) -> Result<(), anyhow::Error> {
let options = ChickenSwitchDestroyOrphanedDatasets { destroy_orphans };
client
.chicken_switch_destroy_orphaned_datasets_put(&options)
.await
.context("put chicken switch value")?;
let status = if destroy_orphans { "enabled" } else { "disabled" };
println!("destroy orphaned datasets {status}");
Ok(())
}
8 changes: 3 additions & 5 deletions dev-tools/omdb/tests/usage_errors.out
Original file line number Diff line number Diff line change
Expand Up @@ -1063,11 +1063,9 @@ Debug a specific Sled
Usage: omdb sled-agent [OPTIONS] <COMMAND>

Commands:
zones print information about zones
bootstore print information about the local bootstore node
chicken-switch control "chicken switches" (potentially-destructive sled-agent behavior that can
be toggled on or off via `omdb`)
help Print this message or the help of the given subcommand(s)
zones print information about zones
bootstore print information about the local bootstore node
help Print this message or the help of the given subcommand(s)

Options:
--log-level <LOG_LEVEL> log level filter [env: LOG_LEVEL=] [default: warn]
Expand Down
6 changes: 6 additions & 0 deletions nexus/mgs-updates/src/test_util/host_phase_2_test_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ impl HostPhase2TestContext {
bind_address: "[::1]:0".parse().unwrap(),
..Default::default()
})
.version_policy(dropshot::VersionPolicy::Dynamic(Box::new(
dropshot::ClientSpecifiesVersionInHeader::new(
omicron_common::api::VERSION_HEADER,
sled_agent_api::VERSION_REMOVE_DESTROY_ORPHANED_DATASETS_CHICKEN_SWITCH,
),
)))
.start()
.context("failed to create dropshot server")?
};
Expand Down
Loading
Loading