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

[1/n] [reconfigurator] add a test wrapper around realize_blueprint_with_overrides #6444

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
3 changes: 1 addition & 2 deletions Cargo.lock

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

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
}
2 changes: 0 additions & 2 deletions workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ sha2 = { version = "0.10.8", features = ["oid"] }
similar = { version = "2.6.0", features = ["bytes", "inline", "unicode"] }
slog = { version = "2.7.0", features = ["dynamic-keys", "max_level_trace", "release_max_level_debug", "release_max_level_trace"] }
smallvec = { version = "1.13.2", default-features = false, features = ["const_new"] }
socket2 = { version = "0.5.7", default-features = false, features = ["all"] }
spin = { version = "0.9.8" }
string_cache = { version = "0.8.7" }
subtle = { version = "2.5.0" }
Expand Down Expand Up @@ -211,7 +210,6 @@ sha2 = { version = "0.10.8", features = ["oid"] }
similar = { version = "2.6.0", features = ["bytes", "inline", "unicode"] }
slog = { version = "2.7.0", features = ["dynamic-keys", "max_level_trace", "release_max_level_debug", "release_max_level_trace"] }
smallvec = { version = "1.13.2", default-features = false, features = ["const_new"] }
socket2 = { version = "0.5.7", default-features = false, features = ["all"] }
spin = { version = "0.9.8" }
string_cache = { version = "0.8.7" }
subtle = { version = "2.5.0" }
Expand Down
Loading