Skip to content

Commit

Permalink
[1/n] [reconfigurator] add a test wrapper around realize_blueprint_wi…
Browse files Browse the repository at this point in the history
…th_overrides (#6444)

We're going to do more things in this wrapper in #6399.
  • Loading branch information
sunshowers authored Aug 27, 2024
1 parent dd85331 commit c9b3f9e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 69 deletions.
18 changes: 5 additions & 13 deletions nexus/reconfigurator/execution/src/cockroachdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ pub(crate) async fn ensure_settings(
mod test {
use super::*;
use crate::overridables::Overridables;
use crate::RealizeBlueprintOutput;
use crate::test_utils::realize_blueprint_and_expect;
use nexus_db_queries::authn;
use nexus_db_queries::authz;
use nexus_test_utils_macros::nexus_test;
use nexus_types::deployment::CockroachDbPreserveDowngrade;
use std::sync::Arc;
use uuid::Uuid;

type ControlPlaneTestContext =
nexus_test_utils::ControlPlaneTestContext<omicron_nexus::Server>;
Expand Down Expand Up @@ -100,17 +99,10 @@ mod test {
.await;
// Execute the initial blueprint.
let overrides = Overridables::for_test(cptestctx);
let _: RealizeBlueprintOutput =
crate::realize_blueprint_with_overrides(
&opctx,
datastore,
resolver,
&blueprint,
Uuid::new_v4(),
&overrides,
)
.await
.expect("failed to execute initial blueprint");
_ = realize_blueprint_and_expect(
&opctx, datastore, resolver, &blueprint, &overrides,
)
.await;
// The CockroachDB settings should not have changed.
assert_eq!(
settings,
Expand Down
89 changes: 33 additions & 56 deletions nexus/reconfigurator/execution/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ pub fn blueprint_nexus_external_ips(blueprint: &Blueprint) -> Vec<IpAddr> {
mod test {
use super::*;
use crate::overridables::Overridables;
use crate::RealizeBlueprintOutput;
use crate::test_utils::realize_blueprint_and_expect;
use crate::Sled;
use dns_service_client::DnsDiff;
use internal_dns::config::Host;
Expand Down Expand Up @@ -1458,17 +1458,10 @@ mod test {

// Now, execute the initial blueprint.
let overrides = Overridables::for_test(cptestctx);
let _: RealizeBlueprintOutput =
crate::realize_blueprint_with_overrides(
&opctx,
datastore,
resolver,
&blueprint,
Uuid::new_v4(),
&overrides,
)
.await
.expect("failed to execute initial blueprint");
_ = realize_blueprint_and_expect(
&opctx, datastore, resolver, &blueprint, &overrides,
)
.await;

// DNS ought not to have changed.
verify_dns_unchanged(
Expand Down Expand Up @@ -1599,17 +1592,14 @@ mod test {
.await
.expect("failed to set blueprint as target");

let _: RealizeBlueprintOutput =
crate::realize_blueprint_with_overrides(
&opctx,
datastore,
resolver,
&blueprint2,
Uuid::new_v4(),
&overrides,
)
.await
.expect("failed to execute second blueprint");
_ = realize_blueprint_and_expect(
&opctx,
datastore,
resolver,
&blueprint2,
&overrides,
)
.await;

// Now fetch DNS again. Both should have changed this time.
let dns_latest_internal = datastore
Expand Down Expand Up @@ -1674,17 +1664,14 @@ mod test {
}

// If we execute it again, we should see no more changes.
let _: RealizeBlueprintOutput =
crate::realize_blueprint_with_overrides(
&opctx,
datastore,
resolver,
&blueprint2,
Uuid::new_v4(),
&overrides,
)
.await
.expect("failed to execute second blueprint again");
_ = realize_blueprint_and_expect(
&opctx,
datastore,
resolver,
&blueprint2,
&overrides,
)
.await;
verify_dns_unchanged(
&opctx,
datastore,
Expand All @@ -1711,17 +1698,14 @@ mod test {

// One more time, make sure that executing the blueprint does not do
// anything.
let _: RealizeBlueprintOutput =
crate::realize_blueprint_with_overrides(
&opctx,
datastore,
resolver,
&blueprint2,
Uuid::new_v4(),
&overrides,
)
.await
.expect("failed to execute second blueprint again");
_ = realize_blueprint_and_expect(
&opctx,
datastore,
resolver,
&blueprint2,
&overrides,
)
.await;
verify_dns_unchanged(
&opctx,
datastore,
Expand Down Expand Up @@ -1806,17 +1790,10 @@ mod test {
);

// If we execute the blueprint, DNS should not be changed.
let _: RealizeBlueprintOutput =
crate::realize_blueprint_with_overrides(
&opctx,
datastore,
resolver,
&blueprint,
Uuid::new_v4(),
&overrides,
)
.await
.expect("failed to execute blueprint");
_ = realize_blueprint_and_expect(
&opctx, datastore, resolver, &blueprint, &overrides,
)
.await;
let dns_latest_internal = datastore
.dns_config_read(&opctx, DnsGroup::Internal)
.await
Expand Down
2 changes: 2 additions & 0 deletions nexus/reconfigurator/execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ mod omicron_zones;
mod overridables;
mod sagas;
mod sled_state;
#[cfg(test)]
mod test_utils;

pub use dns::blueprint_external_dns_config;
pub use dns::blueprint_internal_dns_config;
Expand Down
37 changes: 37 additions & 0 deletions nexus/reconfigurator/execution/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Test utilities for reconfigurator execution.
use internal_dns::resolver::Resolver;
use nexus_db_queries::{context::OpContext, db::DataStore};
use nexus_types::deployment::Blueprint;
use uuid::Uuid;

use crate::{overridables::Overridables, RealizeBlueprintOutput};

pub(crate) async fn realize_blueprint_and_expect(
opctx: &OpContext,
datastore: &DataStore,
resolver: &Resolver,
blueprint: &Blueprint,
overrides: &Overridables,
) -> RealizeBlueprintOutput {
let output = crate::realize_blueprint_with_overrides(
opctx,
datastore,
resolver,
blueprint,
Uuid::new_v4(),
overrides,
)
.await
// We expect here rather than in the caller because we want to assert that
// the result is a `RealizeBlueprintOutput`. Because the latter is
// `must_use`, the caller may assign it to `_` and miss the `expect` call.
.expect("failed to execute blueprint");

eprintln!("realize_blueprint output: {:#?}", output);
output
}

0 comments on commit c9b3f9e

Please sign in to comment.