From a418dedd2f9a19d3ec436cad7c400f2d8692bad1 Mon Sep 17 00:00:00 2001 From: Rain Date: Mon, 26 Aug 2024 17:46:46 -0700 Subject: [PATCH 1/3] [spr] initial version Created using spr 1.3.6-beta.1 --- Cargo.lock | 2 +- .../execution/src/cockroachdb.rs | 18 ++-- nexus/reconfigurator/execution/src/dns.rs | 85 +++++++------------ nexus/reconfigurator/execution/src/lib.rs | 2 + .../execution/src/test_utils.rs | 37 ++++++++ 5 files changed, 74 insertions(+), 70 deletions(-) create mode 100644 nexus/reconfigurator/execution/src/test_utils.rs diff --git a/Cargo.lock b/Cargo.lock index 7074e409932..5903f4a3743 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3616,7 +3616,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2 0.5.7", "tokio", "tower-service", "tracing", diff --git a/nexus/reconfigurator/execution/src/cockroachdb.rs b/nexus/reconfigurator/execution/src/cockroachdb.rs index 12ff896d9df..33b8176df68 100644 --- a/nexus/reconfigurator/execution/src/cockroachdb.rs +++ b/nexus/reconfigurator/execution/src/cockroachdb.rs @@ -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; @@ -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, diff --git a/nexus/reconfigurator/execution/src/dns.rs b/nexus/reconfigurator/execution/src/dns.rs index 1c878a9adab..9531843259d 100644 --- a/nexus/reconfigurator/execution/src/dns.rs +++ b/nexus/reconfigurator/execution/src/dns.rs @@ -458,7 +458,7 @@ pub fn blueprint_nexus_external_ips(blueprint: &Blueprint) -> Vec { 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; @@ -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( @@ -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 @@ -1674,17 +1664,10 @@ 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, &blueprint, &overrides, + ) + .await; verify_dns_unchanged( &opctx, datastore, @@ -1711,17 +1694,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, @@ -1806,17 +1786,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 diff --git a/nexus/reconfigurator/execution/src/lib.rs b/nexus/reconfigurator/execution/src/lib.rs index 2c70c7acbb4..7987c020661 100644 --- a/nexus/reconfigurator/execution/src/lib.rs +++ b/nexus/reconfigurator/execution/src/lib.rs @@ -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; diff --git a/nexus/reconfigurator/execution/src/test_utils.rs b/nexus/reconfigurator/execution/src/test_utils.rs new file mode 100644 index 00000000000..6d8c40ce2e0 --- /dev/null +++ b/nexus/reconfigurator/execution/src/test_utils.rs @@ -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` (which is `must_use` + // so it must be assigned to `_`). + .expect("failed to execute blueprint"); + + eprintln!("realize_blueprint output: {:#?}", output); + output +} From 6afb07cfa810bb577b5c6d1183bb261cbb481bb6 Mon Sep 17 00:00:00 2001 From: Rain Date: Mon, 26 Aug 2024 17:56:41 -0700 Subject: [PATCH 2/3] hakari Created using spr 1.3.6-beta.1 --- Cargo.lock | 1 - workspace-hack/Cargo.toml | 2 -- 2 files changed, 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5903f4a3743..18a7bc5e750 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6536,7 +6536,6 @@ dependencies = [ "similar", "slog", "smallvec 1.13.2", - "socket2 0.5.7", "spin 0.9.8", "string_cache", "subtle", diff --git a/workspace-hack/Cargo.toml b/workspace-hack/Cargo.toml index a39daa57353..c2e4408f213 100644 --- a/workspace-hack/Cargo.toml +++ b/workspace-hack/Cargo.toml @@ -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" } @@ -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" } From 47565149fd21e09967819f3e4ba4fc9c20d3ae4c Mon Sep 17 00:00:00 2001 From: Rain Date: Mon, 26 Aug 2024 18:47:26 -0700 Subject: [PATCH 3/3] fix test Created using spr 1.3.6-beta.1 --- nexus/reconfigurator/execution/src/dns.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nexus/reconfigurator/execution/src/dns.rs b/nexus/reconfigurator/execution/src/dns.rs index 9531843259d..9ab84e15ffd 100644 --- a/nexus/reconfigurator/execution/src/dns.rs +++ b/nexus/reconfigurator/execution/src/dns.rs @@ -1665,7 +1665,11 @@ mod test { // If we execute it again, we should see no more changes. _ = realize_blueprint_and_expect( - &opctx, datastore, resolver, &blueprint, &overrides, + &opctx, + datastore, + resolver, + &blueprint2, + &overrides, ) .await; verify_dns_unchanged(