Skip to content
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions live-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ omicron-workspace-hack.workspace = true
[dev-dependencies]
anyhow.workspace = true
assert_matches.workspace = true
diffus.workspace = true
dropshot.workspace = true
futures.workspace = true
internal-dns-resolver.workspace = true
Expand Down
50 changes: 39 additions & 11 deletions live-tests/tests/test_nexus_add_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod common;
use anyhow::Context;
use common::reconfigurator::blueprint_edit_current_target;
use common::LiveTestContext;
use diffus::Diffable;
use futures::TryStreamExt;
use live_tests_macros::live_test;
use nexus_client::types::Saga;
Expand All @@ -15,14 +16,42 @@ use nexus_inventory::CollectionBuilder;
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
use nexus_reconfigurator_preparation::PlanningInputFromDb;
use nexus_sled_agent_shared::inventory::ZoneKind;
use nexus_types::deployment::SledFilter;
use nexus_types::deployment::diff_visitors::visit_blueprint::VisitBlueprint;
use nexus_types::deployment::diff_visitors::visit_blueprint_zones_config::VisitBlueprintZonesConfig;
use nexus_types::deployment::BpVisitorContext;
use nexus_types::deployment::{BlueprintZoneConfig, SledFilter};
use omicron_common::address::NEXUS_INTERNAL_PORT;
use omicron_test_utils::dev::poll::wait_for_condition;
use omicron_test_utils::dev::poll::CondCheckError;
use omicron_uuid_kinds::SledUuid;
use slog::{debug, info};
use std::net::SocketAddrV6;
use std::time::Duration;

// A visitor that is used to capture changes to a blueprint used by this test
#[derive(Default)]
pub struct TestVisitor {
pub added_zones: Vec<(SledUuid, BlueprintZoneConfig)>,
}

impl<'e> VisitBlueprint<'e> for TestVisitor {
fn zones_visitor(
&mut self,
) -> Option<&mut impl VisitBlueprintZonesConfig<'e>> {
Some(&mut *self)
}
}

impl<'e> VisitBlueprintZonesConfig<'e> for TestVisitor {
fn visit_zones_insert(
&mut self,
ctx: &mut nexus_types::deployment::BpVisitorContext,
node: &BlueprintZoneConfig,
) {
self.added_zones.push((ctx.sled_id.unwrap(), node.clone()));
}
}

// TODO-coverage This test could check other stuff:
//
// - that after adding:
Expand Down Expand Up @@ -71,16 +100,15 @@ async fn test_nexus_add_remove(lc: &LiveTestContext) {
.expect("editing blueprint to add zone");

// Figure out which zone is new and make a new client for it.
let diff = blueprint2.diff_since_blueprint(&blueprint1);
let new_zone = diff
.zones
.added
.values()
.next()
.expect("at least one sled with added zones")
.zones
.first()
.expect("at least one added zone on that sled");
// Utilize diffus directly rather than our wrapper to capture the changes
// in `TestVisitor`.
let diff = blueprint1.diff(&blueprint2);
let mut ctx = BpVisitorContext::default();
let mut visitor = TestVisitor::default();
visitor.visit_blueprint(&mut ctx, diff);
let (modified_sled_id, new_zone) =
visitor.added_zones.iter().next().expect("at least one added zone");
assert_eq!(*modified_sled_id, sled_id);
assert_eq!(new_zone.kind(), ZoneKind::Nexus);
let new_zone_addr = new_zone.underlay_ip();
let new_zone_sockaddr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2010,11 +2010,12 @@ pub mod test {

// One sled was added.
assert_eq!(diff.sleds_added.len(), 1);
let sled_id = diff.sleds_added.first().unwrap();
let new_sled_zones = diff.zones.added.get(sled_id).unwrap();
let (sled_id, sled_insert) =
diff.sleds_added.first_key_value().unwrap();
let new_sled_zones = sled_insert.zones.unwrap();
assert_eq!(*sled_id, new_sled_id);
// The generation number should be newer than the initial default.
assert!(new_sled_zones.generation_after.unwrap() > Generation::new());
assert!(new_sled_zones.generation > Generation::new());

// All zones' underlay addresses ought to be on the sled's subnet.
for z in &new_sled_zones.zones {
Expand Down
Loading
Loading