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

[reconfigurator] Move resource allocation out of BlueprintBuilder #7235

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
71 changes: 58 additions & 13 deletions nexus/db-queries/src/db/datastore/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,7 @@ mod tests {
use nexus_reconfigurator_planning::blueprint_builder::Ensure;
use nexus_reconfigurator_planning::blueprint_builder::EnsureMultiple;
use nexus_reconfigurator_planning::example::example;
use nexus_reconfigurator_planning::example::ExampleSystemBuilder;
use nexus_types::deployment::blueprint_zone_type;
use nexus_types::deployment::BlueprintZoneConfig;
use nexus_types::deployment::BlueprintZoneDisposition;
Expand Down Expand Up @@ -2889,32 +2890,71 @@ mod tests {

#[tokio::test]
async fn test_ensure_external_networking_bails_on_bad_target() {
let test_name = "test_ensure_external_networking_bails_on_bad_target";

// Setup
let logctx = dev::test_setup_log(
"test_ensure_external_networking_bails_on_bad_target",
);
let logctx = dev::test_setup_log(test_name);
let db = TestDatabase::new_with_datastore(&logctx.log).await;
let (opctx, datastore) = (db.opctx(), db.datastore());

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

let blueprint1 =
create_blueprint_with_external_ip(&datastore, &opctx).await;
// Create two blueprints, both of which have external networking (via 1
// Nexus zone).
let (example_system, blueprint1) =
ExampleSystemBuilder::new(&opctx.log, test_name)
.nsleds(1)
.nexus_count(1)
.internal_dns_count(0)
.expect("internal DNS count can be 0")
.external_dns_count(0)
.expect("external DNS count can be 0")
.crucible_pantry_count(0)
.build();
let blueprint2 = BlueprintBuilder::new_based_on(
&logctx.log,
&blueprint1,
&EMPTY_PLANNING_INPUT,
&collection,
"test2",
&example_system.input,
&example_system.collection,
&format!("{test_name}-2"),
)
.expect("failed to create builder")
.build();

// Insert both into the blueprint table.
// Insert an IP pool range covering the one Nexus IP.
let nexus_ip = blueprint1
.all_omicron_zones(BlueprintZoneFilter::ShouldBeRunning)
.find_map(|(_, zone_config)| {
zone_config
.zone_type
.external_networking()
.map(|(ip, _nic)| ip.ip())
})
.expect("found external IP");
let (service_ip_pool, _) = datastore
.ip_pools_service_lookup(&opctx)
.await
.expect("lookup service ip pool");
datastore
.ip_pool_add_range(
&opctx,
&service_ip_pool,
&IpRange::try_from((nexus_ip, nexus_ip))
.expect("valid IP range"),
)
.await
.expect("add range to service IP pool");

// Insert both (plus the original parent of blueprint1, internal to
// `ExampleSystemBuilder`) into the blueprint table.
let blueprint0 = example_system.initial_blueprint;
datastore.blueprint_insert(&opctx, &blueprint0).await.unwrap();
datastore.blueprint_insert(&opctx, &blueprint1).await.unwrap();
datastore.blueprint_insert(&opctx, &blueprint2).await.unwrap();

let bp0_target = BlueprintTarget {
target_id: blueprint0.id,
enabled: true,
time_made_target: now_db_precision(),
};
let bp1_target = BlueprintTarget {
target_id: blueprint1.id,
enabled: true,
Expand All @@ -2926,7 +2966,12 @@ mod tests {
time_made_target: now_db_precision(),
};

// Set bp1_target as the current target.
// Set bp1_target as the current target (which requires making bp0 the
// target first).
datastore
.blueprint_target_set_current(&opctx, bp0_target)
.await
.unwrap();
datastore
.blueprint_target_set_current(&opctx, bp1_target)
.await
Expand Down
Loading
Loading