Skip to content

Commit 1cf6458

Browse files
authored
BlueprintBuilder::new_based_on(): remove PlanningInput argument (#9417)
Finishes implementing the second bullet of #9238: as of this PR, constructing a `BlueprintBuilder` no longer requires an inventory collection or a `PlanningInput`. I'm hopeful this helps guide future decisions about whether a given bit of logic should live in the planner or the builder.
1 parent 1f6c50e commit 1cf6458

File tree

15 files changed

+114
-173
lines changed

15 files changed

+114
-173
lines changed

dev-tools/reconfigurator-cli/src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,14 +2245,13 @@ fn cmd_blueprint_edit(
22452245
.map(|c| c.clone())
22462246
.unwrap_or_else(|| CollectionBuilder::new("sim").build());
22472247

2248-
let mut builder = BlueprintBuilder::new_based_on(
2249-
&sim.log,
2250-
blueprint,
2251-
&planning_input,
2252-
creator,
2253-
rng,
2254-
)
2255-
.context("creating blueprint builder")?;
2248+
let mut builder =
2249+
BlueprintBuilder::new_based_on(&sim.log, blueprint, creator, rng)
2250+
.context("creating blueprint builder")?;
2251+
2252+
// We're acting as the planner here, so we need to update the builder for
2253+
// any static changes in the input (e.g., new sleds, new DNS versions, ...).
2254+
Planner::update_builder_from_planning_input(&mut builder, &planning_input);
22562255

22572256
if let Some(comment) = args.comment {
22582257
builder.comment(comment);

live-tests/tests/common/reconfigurator.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use nexus_lockstep_client::types::{
1212
};
1313
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
1414
use nexus_reconfigurator_planning::planner::PlannerRng;
15-
use nexus_types::deployment::{Blueprint, BlueprintSource, PlanningInput};
15+
use nexus_types::deployment::{Blueprint, BlueprintSource};
1616
use nexus_types::external_api::views::SledState;
1717
use nexus_types::inventory::Collection;
1818
use omicron_test_utils::dev::poll::{CondCheckError, wait_for_condition};
@@ -80,7 +80,6 @@ pub async fn blueprint_load_target_enabled(
8080
/// their test environment.
8181
pub async fn blueprint_edit_current_target(
8282
log: &slog::Logger,
83-
planning_input: &PlanningInput,
8483
nexus: &nexus_lockstep_client::Client,
8584
edit_fn: &dyn Fn(&mut BlueprintBuilder) -> Result<(), anyhow::Error>,
8685
) -> Result<(Blueprint, Blueprint), anyhow::Error> {
@@ -92,7 +91,6 @@ pub async fn blueprint_edit_current_target(
9291
let mut builder = BlueprintBuilder::new_based_on(
9392
log,
9493
&blueprint1,
95-
&planning_input,
9694
"test-suite",
9795
PlannerRng::from_entropy(),
9896
)

live-tests/tests/test_nexus_add_remove.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ async fn test_nexus_add_remove(lc: &LiveTestContext) {
6868
let sled_id = *commissioned_sled_ids.first().expect("any sled id");
6969
let (blueprint1, blueprint2) = blueprint_edit_current_target(
7070
log,
71-
&planning_input,
7271
&nexus,
7372
&|builder: &mut BlueprintBuilder| {
7473
// We have to tell the builder what image source to use for the new
@@ -188,7 +187,6 @@ async fn test_nexus_add_remove(lc: &LiveTestContext) {
188187
// Now expunge the zone we just created.
189188
let (_blueprint2, blueprint3) = blueprint_edit_current_target(
190189
log,
191-
&planning_input,
192190
&nexus,
193191
&|builder: &mut BlueprintBuilder| {
194192
builder

live-tests/tests/test_nexus_handoff.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ async fn test_nexus_handoff(lc: &LiveTestContext) {
170170
let (_blueprint_initial, blueprint_new_nexus) =
171171
blueprint_edit_current_target(
172172
log,
173-
&planning_input,
174173
&nexus,
175174
&|builder: &mut BlueprintBuilder| {
176175
let mut external_networking_alloc =
@@ -264,14 +263,9 @@ async fn test_nexus_handoff(lc: &LiveTestContext) {
264263
info!(log, "created demo saga"; "demo_saga" => ?demo_saga);
265264

266265
// Now update the target blueprint to trigger a handoff.
267-
let planning_input =
268-
PlanningInputFromDb::assemble(opctx, datastore, planner_config)
269-
.await
270-
.expect("planning input");
271266
let (_blueprint_new_nexus, blueprint_handoff) =
272267
blueprint_edit_current_target(
273268
log,
274-
&planning_input,
275269
&nexus,
276270
&|builder: &mut BlueprintBuilder| {
277271
builder.set_nexus_generation(next_generation);
@@ -427,16 +421,11 @@ async fn test_nexus_handoff(lc: &LiveTestContext) {
427421
info!(log, "all new Nexus instances report running!");
428422

429423
// Clean up: expunge the old Nexus instances.
430-
let planning_input =
431-
PlanningInputFromDb::assemble(opctx, datastore, planner_config)
432-
.await
433-
.expect("planning input");
434424
let new_nexus =
435425
new_nexus_clients.values().next().expect("one new Nexus client");
436426
let (_blueprint_handoff, blueprint_cleanup) =
437427
blueprint_edit_current_target(
438428
log,
439-
&planning_input,
440429
new_nexus,
441430
&|builder: &mut BlueprintBuilder| {
442431
for (id, current_zone) in &current_nexus_zones {

nexus/db-queries/src/db/datastore/deployment.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,7 @@ mod tests {
31493149
use nexus_reconfigurator_planning::blueprint_builder::EnsureMultiple;
31503150
use nexus_reconfigurator_planning::example::ExampleSystemBuilder;
31513151
use nexus_reconfigurator_planning::example::example;
3152+
use nexus_reconfigurator_planning::planner::Planner;
31523153
use nexus_reconfigurator_planning::planner::PlannerRng;
31533154
use nexus_types::deployment::BlueprintArtifactVersion;
31543155
use nexus_types::deployment::BlueprintHostPhase2DesiredContents;
@@ -3159,7 +3160,6 @@ mod tests {
31593160
use nexus_types::deployment::ExpectedActiveRotSlot;
31603161
use nexus_types::deployment::PendingMgsUpdate;
31613162
use nexus_types::deployment::PlanningInput;
3162-
use nexus_types::deployment::PlanningInputBuilder;
31633163
use nexus_types::deployment::SledDetails;
31643164
use nexus_types::deployment::SledDisk;
31653165
use nexus_types::deployment::SledFilter;
@@ -3191,16 +3191,12 @@ mod tests {
31913191
use std::mem;
31923192
use std::net::Ipv6Addr;
31933193
use std::sync::Arc;
3194-
use std::sync::LazyLock;
31953194
use std::sync::atomic::AtomicBool;
31963195
use std::sync::atomic::Ordering;
31973196
use std::time::Duration;
31983197
use tufaceous_artifact::ArtifactHash;
31993198
use tufaceous_artifact::ArtifactVersion;
32003199

3201-
static EMPTY_PLANNING_INPUT: LazyLock<PlanningInput> =
3202-
LazyLock::new(|| PlanningInputBuilder::empty_input());
3203-
32043200
#[derive(Default)]
32053201
pub struct NetworkResourceControlFlow {
32063202
pub target_check_done: Option<Arc<AtomicBool>>,
@@ -3448,12 +3444,19 @@ mod tests {
34483444
let mut builder = BlueprintBuilder::new_based_on(
34493445
&logctx.log,
34503446
&blueprint1,
3451-
&planning_input,
34523447
"test",
34533448
PlannerRng::from_entropy(),
34543449
)
34553450
.expect("failed to create builder");
34563451

3452+
// We made changes to the planning input we want to be reflected in the
3453+
// new blueprint; reuse the `Planner`'s method for replicating those
3454+
// changes.
3455+
Planner::update_builder_from_planning_input(
3456+
&mut builder,
3457+
&planning_input,
3458+
);
3459+
34573460
// Ensure disks on our sled
34583461
assert_eq!(
34593462
EnsureMultiple::from(
@@ -3795,7 +3798,6 @@ mod tests {
37953798
let mut builder = BlueprintBuilder::new_based_on(
37963799
&logctx.log,
37973800
&blueprint2,
3798-
&planning_input,
37993801
"dummy",
38003802
PlannerRng::from_entropy(),
38013803
)
@@ -3851,7 +3853,6 @@ mod tests {
38513853
let mut builder = BlueprintBuilder::new_based_on(
38523854
&logctx.log,
38533855
&blueprint3,
3854-
&planning_input,
38553856
"dummy",
38563857
PlannerRng::from_entropy(),
38573858
)
@@ -3904,7 +3905,6 @@ mod tests {
39043905
let mut builder = BlueprintBuilder::new_based_on(
39053906
&logctx.log,
39063907
&blueprint4,
3907-
&planning_input,
39083908
"dummy",
39093909
PlannerRng::from_entropy(),
39103910
)
@@ -3961,7 +3961,6 @@ mod tests {
39613961
let blueprint6 = BlueprintBuilder::new_based_on(
39623962
&logctx.log,
39633963
&blueprint5,
3964-
&planning_input,
39653964
"dummy",
39663965
PlannerRng::from_entropy(),
39673966
)
@@ -4032,7 +4031,6 @@ mod tests {
40324031
let blueprint2 = BlueprintBuilder::new_based_on(
40334032
&logctx.log,
40344033
&blueprint1,
4035-
&EMPTY_PLANNING_INPUT,
40364034
"test2",
40374035
PlannerRng::from_entropy(),
40384036
)
@@ -4041,7 +4039,6 @@ mod tests {
40414039
let blueprint3 = BlueprintBuilder::new_based_on(
40424040
&logctx.log,
40434041
&blueprint1,
4044-
&EMPTY_PLANNING_INPUT,
40454042
"test3",
40464043
PlannerRng::from_entropy(),
40474044
)
@@ -4141,7 +4138,6 @@ mod tests {
41414138
let blueprint4 = BlueprintBuilder::new_based_on(
41424139
&logctx.log,
41434140
&blueprint3,
4144-
&EMPTY_PLANNING_INPUT,
41454141
"test3",
41464142
PlannerRng::from_entropy(),
41474143
)
@@ -4180,7 +4176,6 @@ mod tests {
41804176
let blueprint2 = BlueprintBuilder::new_based_on(
41814177
&logctx.log,
41824178
&blueprint1,
4183-
&EMPTY_PLANNING_INPUT,
41844179
"test2",
41854180
PlannerRng::from_entropy(),
41864181
)
@@ -4365,7 +4360,6 @@ mod tests {
43654360
let blueprint2 = BlueprintBuilder::new_based_on(
43664361
&logctx.log,
43674362
&blueprint1,
4368-
&example_system.input,
43694363
&format!("{test_name}-2"),
43704364
PlannerRng::from_entropy(),
43714365
)

nexus/db-queries/src/db/datastore/deployment/external_networking.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,6 @@ mod tests {
14511451
let mut builder = BlueprintBuilder::new_based_on(
14521452
&opctx.log,
14531453
&bp1,
1454-
&input,
14551454
TEST_NAME,
14561455
PlannerRng::from_entropy(),
14571456
)
@@ -1496,7 +1495,6 @@ mod tests {
14961495
let mut builder = BlueprintBuilder::new_based_on(
14971496
&opctx.log,
14981497
&bp2,
1499-
&input,
15001498
TEST_NAME,
15011499
PlannerRng::from_entropy(),
15021500
)

nexus/db-queries/src/db/datastore/rack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,6 @@ mod test {
12151215
let mut builder = BlueprintBuilder::new_based_on(
12161216
log,
12171217
&EMPTY_BLUEPRINT,
1218-
&planning_input,
12191218
test_name,
12201219
PlannerRng::from_entropy(),
12211220
)
@@ -1224,6 +1223,7 @@ mod test {
12241223
for (sled_id, sled_resources) in
12251224
planning_input.all_sled_resources(SledFilter::InService)
12261225
{
1226+
builder.ensure_sled_exists(sled_id, sled_resources.subnet);
12271227
builder
12281228
.sled_add_disks(sled_id, &sled_resources)
12291229
.expect("added disks");

nexus/db-queries/src/db/datastore/vpc.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,6 +2980,7 @@ mod tests {
29802980
use nexus_db_model::IpConfig;
29812981
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
29822982
use nexus_reconfigurator_planning::blueprint_editor::ExternalNetworkingAllocator;
2983+
use nexus_reconfigurator_planning::planner::Planner;
29832984
use nexus_reconfigurator_planning::planner::PlannerRng;
29842985
use nexus_reconfigurator_planning::system::SledBuilder;
29852986
use nexus_reconfigurator_planning::system::SystemDescription;
@@ -3325,11 +3326,19 @@ mod tests {
33253326
let mut builder = BlueprintBuilder::new_based_on(
33263327
&logctx.log,
33273328
&bp0,
3328-
&planning_input,
33293329
"test",
33303330
PlannerRng::from_entropy(),
33313331
)
33323332
.expect("created blueprint builder");
3333+
3334+
// We made changes to the planning input we want to be reflected in
3335+
// the new blueprint; reuse the `Planner`'s method for replicating
3336+
// those changes.
3337+
Planner::update_builder_from_planning_input(
3338+
&mut builder,
3339+
&planning_input,
3340+
);
3341+
33333342
for &sled_id in &sled_ids {
33343343
builder
33353344
.sled_add_disks(
@@ -3418,7 +3427,6 @@ mod tests {
34183427
let mut builder = BlueprintBuilder::new_based_on(
34193428
&logctx.log,
34203429
&bp2,
3421-
&planning_input,
34223430
"test",
34233431
PlannerRng::from_entropy(),
34243432
)

0 commit comments

Comments
 (0)