Skip to content

Commit

Permalink
Add inventory Collection to BlueprintBuilder (#6624)
Browse files Browse the repository at this point in the history
A follow up PR will use this for clickhouse keeper allocation.
  • Loading branch information
andrewjstone authored Sep 20, 2024
1 parent ade19ee commit 453311a
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dev-tools/reconfigurator-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dns-service-client.workspace = true
dropshot.workspace = true
humantime.workspace = true
indexmap.workspace = true
nexus-inventory.workspace = true
nexus-reconfigurator-planning.workspace = true
nexus-reconfigurator-execution.workspace = true
nexus-sled-agent-shared.workspace = true
Expand Down
8 changes: 8 additions & 0 deletions dev-tools/reconfigurator-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use clap::ValueEnum;
use clap::{Args, Parser, Subcommand};
use dns_service_client::DnsDiff;
use indexmap::IndexMap;
use nexus_inventory::CollectionBuilder;
use nexus_reconfigurator_execution::blueprint_external_dns_config;
use nexus_reconfigurator_execution::blueprint_internal_dns_config;
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
Expand Down Expand Up @@ -736,10 +737,17 @@ fn cmd_blueprint_edit(
let blueprint = sim.blueprint_lookup(blueprint_id)?;
let creator = args.creator.as_deref().unwrap_or("reconfigurator-cli");
let planning_input = sim.planning_input(blueprint)?;
let latest_collection = sim
.collections
.iter()
.max_by_key(|(_, c)| c.time_started)
.map(|(_, c)| c.clone())
.unwrap_or_else(|| CollectionBuilder::new("sim").build());
let mut builder = BlueprintBuilder::new_based_on(
&sim.log,
blueprint,
&planning_input,
&latest_collection,
creator,
)
.context("creating blueprint builder")?;
Expand Down
1 change: 1 addition & 0 deletions live-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ nexus-client.workspace = true
nexus-config.workspace = true
nexus-db-model.workspace = true
nexus-db-queries.workspace = true
nexus-inventory.workspace = true
nexus-reconfigurator-planning.workspace = true
nexus-reconfigurator-preparation.workspace = true
nexus-sled-agent-shared.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions live-tests/tests/common/reconfigurator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use anyhow::{ensure, Context};
use nexus_client::types::BlueprintTargetSet;
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
use nexus_types::deployment::{Blueprint, PlanningInput};
use nexus_types::inventory::Collection;
use slog::{debug, info};

/// Modify the system by editing the current target blueprint
Expand Down Expand Up @@ -35,6 +36,7 @@ use slog::{debug, info};
pub async fn blueprint_edit_current_target(
log: &slog::Logger,
planning_input: &PlanningInput,
collection: &Collection,
nexus: &nexus_client::Client,
edit_fn: &dyn Fn(&mut BlueprintBuilder) -> Result<(), anyhow::Error>,
) -> Result<(Blueprint, Blueprint), anyhow::Error> {
Expand Down Expand Up @@ -68,6 +70,7 @@ pub async fn blueprint_edit_current_target(
log,
&blueprint1,
&planning_input,
&collection,
"test-suite",
)
.context("creating BlueprintBuilder")?;
Expand Down
8 changes: 8 additions & 0 deletions live-tests/tests/test_nexus_add_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use futures::TryStreamExt;
use live_tests_macros::live_test;
use nexus_client::types::Saga;
use nexus_client::types::SagaState;
use nexus_inventory::CollectionBuilder;
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
use nexus_reconfigurator_planning::blueprint_builder::EnsureMultiple;
use nexus_reconfigurator_preparation::PlanningInputFromDb;
Expand Down Expand Up @@ -43,6 +44,11 @@ async fn test_nexus_add_remove(lc: &LiveTestContext) {
let planning_input = PlanningInputFromDb::assemble(&opctx, &datastore)
.await
.expect("planning input");
let collection = datastore
.inventory_get_latest_collection(opctx)
.await
.expect("latest inventory collection")
.unwrap_or_else(|| CollectionBuilder::new("test").build());
let initial_nexus_clients = lc.all_internal_nexus_clients().await.unwrap();
let nexus = initial_nexus_clients.first().expect("internal Nexus client");

Expand All @@ -54,6 +60,7 @@ async fn test_nexus_add_remove(lc: &LiveTestContext) {
let (blueprint1, blueprint2) = blueprint_edit_current_target(
log,
&planning_input,
&collection,
&nexus,
&|builder: &mut BlueprintBuilder| {
let nnexus = builder
Expand Down Expand Up @@ -123,6 +130,7 @@ async fn test_nexus_add_remove(lc: &LiveTestContext) {
let _ = blueprint_edit_current_target(
log,
&planning_input,
&collection,
&nexus,
&|builder: &mut BlueprintBuilder| {
builder
Expand Down
16 changes: 16 additions & 0 deletions nexus/db-queries/src/db/datastore/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,7 @@ mod tests {
use super::*;
use crate::db::datastore::test_utils::datastore_test;
use nexus_inventory::now_db_precision;
use nexus_inventory::CollectionBuilder;
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
use nexus_reconfigurator_planning::blueprint_builder::Ensure;
use nexus_reconfigurator_planning::blueprint_builder::EnsureMultiple;
Expand Down Expand Up @@ -1815,6 +1816,7 @@ mod tests {
&logctx.log,
&blueprint1,
&planning_input,
&collection,
"test",
)
.expect("failed to create builder");
Expand Down Expand Up @@ -1987,6 +1989,9 @@ mod tests {
.unwrap_err();
assert!(err.to_string().contains("no target blueprint set"));

// Create an initial empty collection
let collection = CollectionBuilder::new("test").build();

// Create three blueprints:
// * `blueprint1` has no parent
// * `blueprint2` and `blueprint3` both have `blueprint1` as parent
Expand All @@ -1998,6 +2003,7 @@ mod tests {
&logctx.log,
&blueprint1,
&EMPTY_PLANNING_INPUT,
&collection,
"test2",
)
.expect("failed to create builder")
Expand All @@ -2006,6 +2012,7 @@ mod tests {
&logctx.log,
&blueprint1,
&EMPTY_PLANNING_INPUT,
&collection,
"test3",
)
.expect("failed to create builder")
Expand Down Expand Up @@ -2105,6 +2112,7 @@ mod tests {
&logctx.log,
&blueprint3,
&EMPTY_PLANNING_INPUT,
&collection,
"test3",
)
.expect("failed to create builder")
Expand Down Expand Up @@ -2137,6 +2145,9 @@ mod tests {
let mut db = test_setup_database(&logctx.log).await;
let (opctx, datastore) = datastore_test(&logctx, &db).await;

// Create an initial empty collection
let collection = CollectionBuilder::new("test").build();

// Create an initial blueprint and a child.
let blueprint1 = BlueprintBuilder::build_empty_with_sleds(
std::iter::empty(),
Expand All @@ -2146,6 +2157,7 @@ mod tests {
&logctx.log,
&blueprint1,
&EMPTY_PLANNING_INPUT,
&collection,
"test2",
)
.expect("failed to create builder")
Expand Down Expand Up @@ -2248,6 +2260,9 @@ mod tests {
let mut db = test_setup_database(&logctx.log).await;
let (opctx, datastore) = datastore_test(&logctx, &db).await;

// Create an initial empty collection
let collection = CollectionBuilder::new("test").build();

// Create an initial blueprint and a child.
let blueprint1 = BlueprintBuilder::build_empty_with_sleds(
std::iter::empty(),
Expand All @@ -2257,6 +2272,7 @@ mod tests {
&logctx.log,
&blueprint1,
&EMPTY_PLANNING_INPUT,
&collection,
"test2",
)
.expect("failed to create builder")
Expand Down
6 changes: 6 additions & 0 deletions nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2240,12 +2240,17 @@ mod tests {
// sled IDs running services.
assert_service_sled_ids(&datastore, &[]).await;

// Build an initial empty collection
let collection =
system.to_collection_builder().expect("collection builder").build();

// Create a blueprint that has a Nexus on our third sled.
let bp1 = {
let mut builder = BlueprintBuilder::new_based_on(
&logctx.log,
&bp0,
&planning_input,
&collection,
"test",
)
.expect("created blueprint builder");
Expand Down Expand Up @@ -2315,6 +2320,7 @@ mod tests {
&logctx.log,
&bp2,
&planning_input,
&collection,
"test",
)
.expect("created blueprint builder");
Expand Down
3 changes: 3 additions & 0 deletions nexus/reconfigurator/execution/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ mod test {
use nexus_db_queries::context::OpContext;
use nexus_db_queries::db::DataStore;
use nexus_inventory::now_db_precision;
use nexus_inventory::CollectionBuilder;
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
use nexus_reconfigurator_planning::blueprint_builder::EnsureMultiple;
use nexus_reconfigurator_planning::example::example;
Expand Down Expand Up @@ -1544,10 +1545,12 @@ mod test {

builder.build()
};
let collection = CollectionBuilder::new("test").build();
let mut builder = BlueprintBuilder::new_based_on(
&log,
&blueprint,
&planning_input,
&collection,
"test suite",
)
.unwrap();
Expand Down
Loading

0 comments on commit 453311a

Please sign in to comment.