Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration - with defaults - to enable virtualized sled storage #633

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions nexus/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use dropshot::ConfigLogging;
use dropshot::ConfigLoggingLevel;
use omicron_common::api::external::IdentityMetadata;
use omicron_common::api::internal::nexus::ProducerEndpoint;
use omicron_sled_agent::sim;
use omicron_test_utils::dev;
use oximeter_collector::Oximeter;
use oximeter_producer::Server as ProducerServer;
Expand All @@ -37,7 +38,7 @@ pub struct ControlPlaneTestContext {
pub database: dev::db::CockroachInstance,
pub clickhouse: dev::clickhouse::ClickHouseInstance,
pub logctx: LogContext,
pub sled_agent: omicron_sled_agent::sim::Server,
pub sled_agent: sim::Server,
pub oximeter: Oximeter,
pub producer: ProducerServer,
}
Expand Down Expand Up @@ -171,20 +172,21 @@ pub async fn start_sled_agent(
log: Logger,
nexus_address: SocketAddr,
id: Uuid,
) -> Result<omicron_sled_agent::sim::Server, String> {
let config = omicron_sled_agent::sim::Config {
) -> Result<sim::Server, String> {
let config = sim::Config {
id,
sim_mode: omicron_sled_agent::sim::SimMode::Explicit,
sim_mode: sim::SimMode::Explicit,
nexus_address,
dropshot: ConfigDropshot {
bind_address: SocketAddr::new("127.0.0.1".parse().unwrap(), 0),
..Default::default()
},
/* TODO-cleanup this is unused */
log: ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Debug },
storage: sim::ConfigStorage::default(),
};

omicron_sled_agent::sim::Server::start(&config, &log).await
sim::Server::start(&config, &log).await
}

pub async fn start_oximeter(
Expand Down
8 changes: 7 additions & 1 deletion sled-agent/src/bin/sled-agent-sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use dropshot::ConfigLogging;
use dropshot::ConfigLoggingLevel;
use omicron_common::cmd::fatal;
use omicron_common::cmd::CmdError;
use omicron_sled_agent::sim::{run_server, Config, SimMode};
use omicron_sled_agent::sim::{
run_server, Config, ConfigStorage, ConfigZpool, SimMode,
};
use std::net::SocketAddr;
use structopt::StructOpt;
use uuid::Uuid;
Expand Down Expand Up @@ -73,6 +75,10 @@ async fn do_run() -> Result<(), CmdError> {
..Default::default()
},
log: ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info },
storage: ConfigStorage {
// Create 10 "virtual" U.2s, with 1 TB of storage.
zpools: vec![ConfigZpool { size: 1 << 40 }; 10],
},
};

run_server(&config).await.map_err(CmdError::Failure)
Expand Down
17 changes: 17 additions & 0 deletions sled-agent/src/sim/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ pub enum SimMode {
Explicit,
}

/// Configuration for a simulated zpool.
///
/// Currently, each zpool will receive a single Crucible Dataset.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct ConfigZpool {
/// The size of the Zpool in bytes.
pub size: u64,
}

/// Configuration describing simulated storage.
#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize)]
pub struct ConfigStorage {
pub zpools: Vec<ConfigZpool>,
}

/**
* Configuration for a sled agent
*/
Expand All @@ -48,4 +63,6 @@ pub struct Config {
pub dropshot: ConfigDropshot,
/** configuration for the sled agent debug log */
pub log: ConfigLogging,
/** configuration for the sled agent's storage */
pub storage: ConfigStorage,
}
2 changes: 1 addition & 1 deletion sled-agent/src/sim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ mod simulatable;
mod sled_agent;
mod storage;

pub use config::{Config, SimMode};
pub use config::{Config, ConfigStorage, ConfigZpool, SimMode};
pub use server::{run_server, Server};
pub use sled_agent::SledAgent;
10 changes: 10 additions & 0 deletions sled-agent/src/sim/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ impl Server {
.map_err(|error| format!("initializing server: {}", error))?
.start();

// Create all the Zpools requested by the config, and allocate a single
// Crucible dataset for each. This emulates the setup we expect to have
// on the physical rack.
for zpool in &config.storage.zpools {
let zpool_id = uuid::Uuid::new_v4();
sled_agent.create_zpool(zpool_id, zpool.size).await;
let dataset_id = uuid::Uuid::new_v4();
sled_agent.create_crucible_dataset(zpool_id, dataset_id).await;
}

/*
* Notify the control plane that we're up, and continue trying this
* until it succeeds. We retry with an randomized, capped exponential
Expand Down