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

[reconfigurator] Introduce IdMap and use it in BlueprintZonesConfig #7327

Merged
merged 11 commits into from
Jan 14, 2025
10 changes: 5 additions & 5 deletions nexus/db-queries/src/db/datastore/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use nexus_db_model::BpSledOmicronPhysicalDisks;
use nexus_db_model::BpSledOmicronZones;
use nexus_db_model::BpSledState;
use nexus_db_model::BpTarget;
use nexus_types::deployment::id_map::IdMap;
use nexus_types::deployment::Blueprint;
use nexus_types::deployment::BlueprintDatasetsConfig;
use nexus_types::deployment::BlueprintMetadata;
Expand Down Expand Up @@ -266,7 +267,7 @@ impl DataStore {
.blueprint_zones
.iter()
.flat_map(|(sled_id, zones_config)| {
zones_config.zones.values().map(move |zone| {
zones_config.zones.iter().map(move |zone| {
BpOmicronZone::new(blueprint_id, *sled_id, zone)
.map_err(|e| Error::internal_error(&format!("{:#}", e)))
})
Expand All @@ -276,7 +277,7 @@ impl DataStore {
.blueprint_zones
.values()
.flat_map(|zones_config| {
zones_config.zones.values().filter_map(|zone| {
zones_config.zones.iter().filter_map(|zone| {
BpOmicronZoneNic::new(blueprint_id, zone)
.with_context(|| format!("zone {}", zone.id))
.map_err(|e| Error::internal_error(&format!("{:#}", e)))
Expand Down Expand Up @@ -587,7 +588,7 @@ impl DataStore {
s.sled_id.into(),
BlueprintZonesConfig {
generation: *s.generation,
zones: BTreeMap::new(),
zones: IdMap::new(),
},
);
bail_unless!(
Expand Down Expand Up @@ -794,7 +795,7 @@ impl DataStore {
e.to_string()
))
})?;
sled_zones.zones.insert(zone.id, zone);
sled_zones.zones.insert(zone);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

}
}
}
Expand Down Expand Up @@ -2840,7 +2841,6 @@ mod tests {
),
}]
.into_iter()
.map(|z| (z.id, z))
.collect(),
},
);
Expand Down
6 changes: 0 additions & 6 deletions nexus/db-queries/src/db/datastore/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,6 @@ mod test {
},
]
.into_iter()
.map(|z| (z.id, z))
.collect(),
},
);
Expand Down Expand Up @@ -1516,7 +1515,6 @@ mod test {
},
]
.into_iter()
.map(|z| (z.id, z))
.collect(),
},
);
Expand All @@ -1535,7 +1533,6 @@ mod test {
),
}]
.into_iter()
.map(|z| (z.id, z))
.collect(),
},
);
Expand Down Expand Up @@ -1771,7 +1768,6 @@ mod test {
},
]
.into_iter()
.map(|z| (z.id, z))
.collect(),
},
);
Expand Down Expand Up @@ -2008,7 +2004,6 @@ mod test {
),
}]
.into_iter()
.map(|z| (z.id, z))
.collect(),
},
);
Expand Down Expand Up @@ -2150,7 +2145,6 @@ mod test {
},
]
.into_iter()
.map(|z| (z.id, z))
.collect(),
},
);
Expand Down
4 changes: 2 additions & 2 deletions nexus/db-queries/src/db/datastore/support_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ mod test {
.values()
.flat_map(|zones_config| {
let mut nexus_zones = vec![];
for (_, zone) in &zones_config.zones {
for zone in &zones_config.zones {
if matches!(zone.zone_type, BlueprintZoneType::Nexus(_))
&& zone.disposition.matches(filter)
{
Expand Down Expand Up @@ -957,7 +957,7 @@ mod test {

fn expunge_nexus_for_bundle(bp: &mut Blueprint, bundle: &SupportBundle) {
for zones in bp.blueprint_zones.values_mut() {
for (_, zone) in &mut zones.zones {
for mut zone in &mut zones.zones {
if zone.id == bundle.assigned_nexus.unwrap().into() {
zone.disposition = BlueprintZoneDisposition::Expunged;
}
Expand Down
19 changes: 5 additions & 14 deletions nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3146,11 +3146,7 @@ mod tests {
.service_create_network_interface_raw(
&opctx,
db_nic_from_zone(
bp1.blueprint_zones[&sled_ids[2]]
.zones
.first_key_value()
.unwrap()
.1,
bp1.blueprint_zones[&sled_ids[2]].zones.first().unwrap(),
),
)
.await
Expand Down Expand Up @@ -3184,9 +3180,8 @@ mod tests {
&opctx,
bp1.blueprint_zones[&sled_ids[2]]
.zones
.first_key_value()
.first()
.unwrap()
.1
.id
.into_untyped_uuid(),
bp1_nic.id(),
Expand Down Expand Up @@ -3218,11 +3213,7 @@ mod tests {
.service_create_network_interface_raw(
&opctx,
db_nic_from_zone(
bp3.blueprint_zones[&sled_id]
.zones
.first_key_value()
.unwrap()
.1,
bp3.blueprint_zones[&sled_id].zones.first().unwrap(),
),
)
.await
Expand Down Expand Up @@ -3277,7 +3268,7 @@ mod tests {
.blueprint_zones
.get_mut(&sled_ids[2])
.expect("zones for sled");
sled2.zones.values_mut().next().unwrap().disposition =
sled2.zones.iter_mut().next().unwrap().disposition =
BlueprintZoneDisposition::Quiesced;
sled2.generation = sled2.generation.next();

Expand All @@ -3286,7 +3277,7 @@ mod tests {
.blueprint_zones
.get_mut(&sled_ids[3])
.expect("zones for sled");
sled3.zones.values_mut().next().unwrap().disposition =
sled3.zones.iter_mut().next().unwrap().disposition =
BlueprintZoneDisposition::Expunged;
sled3.generation = sled3.generation.next();

Expand Down
Loading
Loading