Skip to content

Commit 007c97f

Browse files
authored
[12/n] [wicket-common] use IdOrdMap within MgsV1Inventory (#10861)
Make the SP-uniqueness invariant explicit. This can be landed without breaking rkdeploy because the wire protocol is the same (`IdOrdMap` serializes as a sequence). Depends on: * #10859
1 parent 374ac00 commit 007c97f

5 files changed

Lines changed: 35 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openapi/wicketd.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2620,10 +2620,22 @@
26202620
"type": "object",
26212621
"properties": {
26222622
"sps": {
2623+
"title": "IdOrdMap",
2624+
"x-rust-type": {
2625+
"crate": "iddqd",
2626+
"parameters": [
2627+
{
2628+
"$ref": "#/components/schemas/SpInventory"
2629+
}
2630+
],
2631+
"path": "iddqd::IdOrdMap",
2632+
"version": "*"
2633+
},
26232634
"type": "array",
26242635
"items": {
26252636
"$ref": "#/components/schemas/SpInventory"
2626-
}
2637+
},
2638+
"uniqueItems": true
26272639
}
26282640
},
26292641
"required": [

wicket-common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dpd-client.workspace = true
1313
dropshot.workspace = true
1414
gateway-client.workspace = true
1515
gateway-types.workspace = true
16+
iddqd.workspace = true
1617
maplit.workspace = true
1718
omicron-common.workspace = true
1819
omicron-workspace-hack.workspace = true

wicket-common/src/example.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::{collections::BTreeMap, net::Ipv6Addr};
88

99
use gateway_types::component::{SpState, SpType};
1010
use gateway_types::rot::{RotSlot, RotState};
11+
use iddqd::id_ord_map;
1112
use maplit::{btreemap, btreeset};
1213
use sled_agent_types::early_networking::{
1314
BgpConfig, BgpPeerConfig, LinkFec, LinkSpeed, LldpAdminStatus,
@@ -68,14 +69,9 @@ impl ExampleRackSetupData {
6869
identifier: "serial 1 2 3".into(),
6970
};
7071

71-
let mut inventory = MgsV1Inventory {
72-
sps: vec![
73-
SpInventory::new(SpIdentifier { slot: 1, typ: SpType::Sled }),
74-
SpInventory::new(SpIdentifier { slot: 5, typ: SpType::Sled }),
75-
],
76-
};
77-
78-
inventory.sps[0].state = Some(SpState {
72+
let mut sp0 =
73+
SpInventory::new(SpIdentifier { slot: 1, typ: SpType::Sled });
74+
sp0.state = Some(SpState {
7975
serial_number: "serial 1 2 3".into(),
8076
model: "model1".into(),
8177
revision: 3,
@@ -91,7 +87,9 @@ impl ExampleRackSetupData {
9187
slot_b_sha3_256_digest: None,
9288
},
9389
});
94-
inventory.sps[1].state = Some(SpState {
90+
let mut sp1 =
91+
SpInventory::new(SpIdentifier { slot: 5, typ: SpType::Sled });
92+
sp1.state = Some(SpState {
9593
serial_number: "serial 4 5 6".into(),
9694
model: "model2".into(),
9795
revision: 5,
@@ -107,6 +105,7 @@ impl ExampleRackSetupData {
107105
slot_b_sha3_256_digest: None,
108106
},
109107
});
108+
let inventory = MgsV1Inventory { sps: id_ord_map! { sp0, sp1 } };
110109

111110
let ddm_discovered_sleds: BTreeMap<_, _> = [
112111
(our_baseboard.clone(), Ipv6Addr::LOCALHOST),

wicket-common/src/inventory.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub use gateway_client::types::{
1010
pub use gateway_types::component::{SpIdentifier, SpState, SpType};
1111
pub use gateway_types::ignition::{SpIgnition, SpIgnitionSystemType};
1212
pub use gateway_types::rot::{RotSlot, RotState};
13+
use iddqd::{IdOrdItem, IdOrdMap, id_upcast};
1314
use omicron_common::snake_case_result;
1415
use omicron_common::snake_case_result::SnakeCaseResult;
1516
use schemars::JsonSchema;
@@ -46,7 +47,7 @@ pub struct MgsV1InventorySnapshot {
4647
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
4748
#[serde(tag = "mgs_inventory", rename_all = "snake_case")]
4849
pub struct MgsV1Inventory {
49-
pub sps: Vec<SpInventory>,
50+
pub sps: IdOrdMap<SpInventory>,
5051
}
5152

5253
impl From<BTreeSet<BootstrapSledDescription>> for SledInventory {
@@ -191,6 +192,16 @@ impl SpInventory {
191192
}
192193
}
193194

195+
impl IdOrdItem for SpInventory {
196+
type Key<'a> = SpIdentifier;
197+
198+
fn key(&self) -> Self::Key<'_> {
199+
self.id
200+
}
201+
202+
id_upcast!();
203+
}
204+
194205
/// RoT-related data that isn't already supplied in [`SpState`].
195206
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
196207
#[serde(tag = "sp_inventory", rename_all = "snake_case")]

0 commit comments

Comments
 (0)