Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Jan 11, 2025
1 parent 31a2508 commit c74b122
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 9 deletions.
3 changes: 2 additions & 1 deletion nexus/types/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ use proptest::{arbitrary::any, strategy::Strategy};
mod blueprint_diff;
mod blueprint_display;
mod clickhouse;
mod diff_visitors;
pub mod diff_visitors;
pub mod execution;
mod network_resources;
mod planning_input;
mod tri_map;
mod zone_type;

pub use clickhouse::ClickhouseClusterConfig;
pub use diff_visitors::BpVisitorContext;
pub use network_resources::AddNetworkResourceError;
pub use network_resources::OmicronZoneExternalFloatingAddr;
pub use network_resources::OmicronZoneExternalFloatingIp;
Expand Down
3 changes: 1 addition & 2 deletions nexus/types/src/deployment/diff_visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
//!
//! Modelled after [`syn::visit`](https://docs.rs/syn/1/syn/visit).
mod visit_blueprint_zones_config;
pub mod visit_blueprint_zones_config;

use diffus::edit::enm;
use omicron_uuid_kinds::{OmicronZoneUuid, SledUuid};

use super::{
BlueprintZoneConfig, BlueprintZoneDisposition, BlueprintZoneType,
BlueprintZonesConfig, EditedBlueprintZoneConfig,
EditedBlueprintZonesConfig,
};

/// A context for blueprint related visitors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub trait VisitBlueprintZonesConfig<'e> {
// A change in a value in `BlueprintZonesConfig::zones`
fn visit_zone_change(
&mut self,
ctx: &mut BpVisitorContext,
change: Change<'e, BlueprintZoneConfig>,
_ctx: &mut BpVisitorContext,
_change: Change<'e, BlueprintZoneConfig>,
) {
// Leaf node
}
Expand Down Expand Up @@ -102,7 +102,7 @@ pub trait VisitBlueprintZonesConfig<'e> {
fn visit_zone_zone_type_change(
&mut self,
_ctx: &mut BpVisitorContext,
_node: Change<'e, BlueprintZoneType>,
_change: Change<'e, BlueprintZoneType>,
) {
// Leaf node - for now
}
Expand Down Expand Up @@ -142,6 +142,8 @@ pub fn visit_root<'e, V>(
}
}
}
// Reset the context
ctx.zone_id = None;
}
}
}
Expand Down Expand Up @@ -190,17 +192,20 @@ mod tests {
impl<'e> VisitBlueprintZonesConfig<'e> for TestVisitor<'e> {
fn visit_generation_change(
&mut self,
_ctx: &mut BpVisitorContext,
ctx: &mut BpVisitorContext,
change: Change<'e, Generation>,
) {
assert_eq!(change.before, &self.before.generation);
assert_eq!(change.after, &self.after.generation);
assert_ne!(self.before.generation, self.after.generation);

// We aren't operating on a particular zone
assert!(ctx.zone_id.is_none());
}

fn visit_zones_insert(
&mut self,
_ctx: &mut BpVisitorContext,
ctx: &mut BpVisitorContext,
node: &BlueprintZoneConfig,
) {
let before: BTreeSet<_> = self.before.zones.keys().collect();
Expand All @@ -211,12 +216,15 @@ mod tests {
// The inserted node is the same as what's in `after`
assert_eq!(node, self.after.zones.get(&node.id).unwrap());

// The key for the current zone id was filled in
assert_eq!(ctx.zone_id, Some(node.id));

self.total_inserts += 1;
}

fn visit_zones_remove(
&mut self,
_ctx: &mut BpVisitorContext,
ctx: &mut BpVisitorContext,
node: &BlueprintZoneConfig,
) {
let before: BTreeSet<_> = self.before.zones.keys().collect();
Expand All @@ -227,8 +235,96 @@ mod tests {
// The removed node is the same as what's in `before`
assert_eq!(node, self.before.zones.get(&node.id).unwrap());

// The key for the current zone id was filled in
assert_eq!(ctx.zone_id, Some(node.id));

self.total_removes += 1;
}

fn visit_zone_change(
&mut self,
ctx: &mut BpVisitorContext,
change: Change<'e, BlueprintZoneConfig>,
) {
// The key for the current zone id was filled in and
// the zone with the same id was changed
assert_eq!(ctx.zone_id, Some(change.before.id));
assert_eq!(ctx.zone_id, Some(change.after.id));

// The change is actually correct
assert_eq!(
self.before.zones.get(&ctx.zone_id.unwrap()),
Some(change.before)
);
assert_eq!(
self.after.zones.get(&ctx.zone_id.unwrap()),
Some(change.after)
);
}

fn visit_zone_disposition_change(
&mut self,
ctx: &mut BpVisitorContext,
change: Change<'e, BlueprintZoneDisposition>,
) {
assert_ne!(change.before, change.after);
assert_eq!(
self.before
.zones
.get(&ctx.zone_id.unwrap())
.unwrap()
.disposition,
*change.before
);
assert_eq!(
self.after
.zones
.get(&ctx.zone_id.unwrap())
.unwrap()
.disposition,
*change.after
);
}

fn visit_zone_filesystem_pool_change(
&mut self,
ctx: &mut BpVisitorContext,
change: Change<'e, Option<ZpoolName>>,
) {
assert_ne!(change.before, change.after);
assert_eq!(
self.before
.zones
.get(&ctx.zone_id.unwrap())
.unwrap()
.filesystem_pool,
*change.before
);
assert_eq!(
self.after
.zones
.get(&ctx.zone_id.unwrap())
.unwrap()
.filesystem_pool,
*change.after
);
}

fn visit_zone_zone_type_change(
&mut self,
ctx: &mut BpVisitorContext,
change: Change<'e, BlueprintZoneType>,
) {
assert_ne!(change.before, change.after);
assert_eq!(
self.before.zones.get(&ctx.zone_id.unwrap()).unwrap().zone_type,
*change.before
);
assert_eq!(
self.after.zones.get(&ctx.zone_id.unwrap()).unwrap().zone_type,
*change.after
);
}
}

#[proptest]
Expand Down

0 comments on commit c74b122

Please sign in to comment.