Skip to content

Commit 682caa3

Browse files
authored
PendingMgsUpdate slot id should be a u16 (#8398)
1 parent 4a67564 commit 682caa3

File tree

13 files changed

+56
-48
lines changed

13 files changed

+56
-48
lines changed

dev-tools/reconfigurator-cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ fn cmd_blueprint_edit(
13171317
let update = PendingMgsUpdate {
13181318
baseboard_id: baseboard_id.clone(),
13191319
sp_type: sp.sp_type,
1320-
slot_id: u32::from(sp.sp_slot),
1320+
slot_id: sp.sp_slot,
13211321
details,
13221322
artifact_hash,
13231323
artifact_version,

dev-tools/reconfigurator-sp-updater/src/main.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Inventory {
188188
struct SpInfo {
189189
baseboard_id: Arc<BaseboardId>,
190190
sp_type: SpType,
191-
sp_slot_id: u32,
191+
sp_slot_id: u16,
192192
}
193193

194194
impl Inventory {
@@ -213,16 +213,21 @@ impl Inventory {
213213
}),
214214
)
215215
.then(async move |sp_id| {
216+
let sp_slot = u16::try_from(sp_id.slot).with_context(|| {
217+
format!("sp slot number is out of range: {sp_id:?}")
218+
})?;
216219
c.sp_get(sp_id.type_, sp_id.slot)
217220
.await
218221
.with_context(|| format!("fetching info about SP {:?}", sp_id))
219-
.map(|s| (sp_id, s))
222+
.map(|s| (sp_id.type_, sp_slot, s))
220223
})
221224
.collect::<Vec<Result<_, _>>>()
222225
.await
223226
.into_iter()
224227
.filter_map(|r| match r {
225-
Ok((sp_id, v)) => Some((sp_id, v.into_inner())),
228+
Ok((sp_type, sp_slot, v)) => {
229+
Some((sp_type, sp_slot, v.into_inner()))
230+
}
226231
Err(error) => {
227232
warn!(
228233
log,
@@ -236,17 +241,14 @@ impl Inventory {
236241

237242
let sps_by_serial = sp_infos
238243
.into_iter()
239-
.map(|(sp_id, sp_state)| {
244+
.map(|(sp_type, sp_slot, sp_state)| {
240245
let baseboard_id = Arc::new(BaseboardId {
241246
serial_number: sp_state.serial_number,
242247
part_number: sp_state.model,
243248
});
244249
let serial_number = baseboard_id.serial_number.clone();
245-
let sp_info = SpInfo {
246-
baseboard_id,
247-
sp_type: sp_id.type_,
248-
sp_slot_id: sp_id.slot,
249-
};
250+
let sp_info =
251+
SpInfo { baseboard_id, sp_type, sp_slot_id: sp_slot };
250252
(serial_number, sp_info)
251253
})
252254
.collect();

nexus/db-model/src/deployment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ impl BpPendingMgsUpdateSp {
12731273
PendingMgsUpdate {
12741274
baseboard_id,
12751275
sp_type: self.sp_type.into(),
1276-
slot_id: u32::from(**self.sp_slot),
1276+
slot_id: **self.sp_slot,
12771277
artifact_hash: self.artifact_sha256.into(),
12781278
artifact_version: (*self.artifact_version).clone(),
12791279
details: PendingMgsUpdateDetails::Sp {

nexus/db-queries/src/db/datastore/deployment.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,19 +517,13 @@ impl DataStore {
517517
} => continue,
518518
};
519519

520-
// slot_ids fit into a u16 in practice. This will be
521-
// enforced at compile time shortly. See
522-
// oxidecomputer/omicron#8378.
523-
let update_slot_id = u16::try_from(update.slot_id)
524-
.expect("slot id to fit into u16");
525-
526520
let db_blueprint_id = DbTypedUuid::from(blueprint_id)
527521
.into_sql::<diesel::sql_types::Uuid>(
528522
);
529523
let db_sp_type =
530524
SpType::from(update.sp_type).into_sql::<SpTypeEnum>();
531525
let db_slot_id =
532-
SpMgsSlot::from(SqlU16::from(update_slot_id))
526+
SpMgsSlot::from(SqlU16::from(update.slot_id))
533527
.into_sql::<diesel::sql_types::Int4>();
534528
let db_artifact_hash =
535529
ArtifactHash::from(update.artifact_hash)
@@ -2813,7 +2807,7 @@ mod tests {
28132807
builder.pending_mgs_update_insert(PendingMgsUpdate {
28142808
baseboard_id: baseboard_id.clone(),
28152809
sp_type: sp.sp_type,
2816-
slot_id: u32::from(sp.sp_slot),
2810+
slot_id: sp.sp_slot,
28172811
details: PendingMgsUpdateDetails::Sp {
28182812
expected_active_version: "1.0.0".parse().unwrap(),
28192813
expected_inactive_version: ExpectedVersion::NoValidVersion,

nexus/mgs-updates/src/common_sp_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ pub enum PrecheckError {
297297
)]
298298
WrongDevice {
299299
sp_type: SpType,
300-
slot_id: u32,
300+
slot_id: u16,
301301
expected_part: String,
302302
expected_serial: String,
303303
found_part: String,

nexus/mgs-updates/src/driver_update.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) struct SpComponentUpdate {
5656
pub log: slog::Logger,
5757
pub component: SpComponent,
5858
pub target_sp_type: SpType,
59-
pub target_sp_slot: u32,
59+
pub target_sp_slot: u16,
6060
pub firmware_slot: u16,
6161
pub update_id: SpUpdateUuid,
6262
}
@@ -242,7 +242,7 @@ pub(crate) async fn apply_update(
242242
client
243243
.sp_component_update(
244244
sp_type,
245-
sp_slot,
245+
u32::from(sp_slot),
246246
component,
247247
sp_update.firmware_slot,
248248
&sp_update.update_id.as_untyped_uuid(),
@@ -450,7 +450,11 @@ async fn wait_for_delivery(
450450
let status = mgs_clients
451451
.try_all_serially(log, |client| async move {
452452
let update_status = client
453-
.sp_component_update_status(sp_type, sp_slot, component)
453+
.sp_component_update_status(
454+
sp_type,
455+
u32::from(sp_slot),
456+
component,
457+
)
454458
.await?;
455459

456460
debug!(
@@ -549,7 +553,12 @@ async fn abort_update(
549553
.try_all_serially(log, |mgs_client| async move {
550554
let arg = UpdateAbortBody { id: update_id };
551555
mgs_client
552-
.sp_component_update_abort(sp_type, sp_slot, component, &arg)
556+
.sp_component_update_abort(
557+
sp_type,
558+
u32::from(sp_slot),
559+
component,
560+
&arg,
561+
)
553562
.await
554563
})
555564
.await
@@ -712,7 +721,7 @@ mod test {
712721
gwtestctx: &GatewayTestContext,
713722
artifacts: &TestArtifacts,
714723
sp_type: SpType,
715-
slot_id: u32,
724+
slot_id: u16,
716725
artifact_hash: &ArtifactHash,
717726
expected_result: UpdateCompletedHow,
718727
) {
@@ -796,7 +805,7 @@ mod test {
796805
gwtestctx: &GatewayTestContext,
797806
artifacts: &TestArtifacts,
798807
sp_type: SpType,
799-
slot_id: u32,
808+
slot_id: u16,
800809
artifact_hash: &ArtifactHash,
801810
expected_result: UpdateCompletedHow,
802811
) {

nexus/mgs-updates/src/rot_updater.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
217217
// Verify that the device is the one we think it is.
218218
let state = mgs_clients
219219
.try_all_serially(log, move |mgs_client| async move {
220-
mgs_client.sp_get(update.sp_type, update.slot_id).await
220+
mgs_client.sp_get(update.sp_type, u32::from(update.slot_id)).await
221221
})
222222
.await?
223223
.into_inner();
@@ -276,7 +276,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
276276
mgs_client
277277
.sp_component_caboose_get(
278278
update.sp_type,
279-
update.slot_id,
279+
u32::from(update.slot_id),
280280
&SpComponent::ROT.to_string(),
281281
active.to_u16(),
282282
)
@@ -326,7 +326,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
326326
mgs_client
327327
.sp_component_caboose_get(
328328
update.sp_type,
329-
update.slot_id,
329+
u32::from(update.slot_id),
330330
&SpComponent::ROT.to_string(),
331331
expected_active_slot.slot().toggled().to_u16(),
332332
)
@@ -415,7 +415,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
415415
mgs_client
416416
.sp_component_active_slot_set(
417417
update.sp_type,
418-
update.slot_id,
418+
u32::from(update.slot_id),
419419
&SpComponent::ROT.to_string(),
420420
persist,
421421
&SpComponentFirmwareSlot { slot: inactive_slot }
@@ -426,7 +426,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
426426
mgs_client
427427
.sp_component_reset(
428428
update.sp_type,
429-
update.slot_id,
429+
u32::from(update.slot_id),
430430
&SpComponent::ROT.to_string(),
431431
)
432432
.await?;

nexus/mgs-updates/src/sp_updater.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ impl SpComponentUpdateHelper for ReconfiguratorSpUpdater {
164164
// Verify that the device is the one we think it is.
165165
let state = mgs_clients
166166
.try_all_serially(log, move |mgs_client| async move {
167-
mgs_client.sp_get(update.sp_type, update.slot_id).await
167+
mgs_client
168+
.sp_get(update.sp_type, u32::from(update.slot_id))
169+
.await
168170
})
169171
.await?
170172
.into_inner();
@@ -188,7 +190,7 @@ impl SpComponentUpdateHelper for ReconfiguratorSpUpdater {
188190
mgs_client
189191
.sp_component_caboose_get(
190192
update.sp_type,
191-
update.slot_id,
193+
u32::from(update.slot_id),
192194
&SpComponent::SP_ITSELF.to_string(),
193195
0,
194196
)
@@ -240,7 +242,7 @@ impl SpComponentUpdateHelper for ReconfiguratorSpUpdater {
240242
mgs_client
241243
.sp_component_caboose_get(
242244
update.sp_type,
243-
update.slot_id,
245+
u32::from(update.slot_id),
244246
&SpComponent::SP_ITSELF.to_string(),
245247
1,
246248
)
@@ -300,7 +302,7 @@ impl SpComponentUpdateHelper for ReconfiguratorSpUpdater {
300302
mgs_client
301303
.sp_component_reset(
302304
update.sp_type,
303-
update.slot_id,
305+
u32::from(update.slot_id),
304306
&SpComponent::SP_ITSELF.to_string(),
305307
)
306308
.await?;

nexus/mgs-updates/src/test_util/sp_test_state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ impl SpTestState {
5656
pub async fn load(
5757
mgs_client: &gateway_client::Client,
5858
sp_type: SpType,
59-
sp_slot: u32,
59+
sp_slot: u16,
6060
) -> Result<SpTestState, GatewayClientError> {
61+
let sp_slot = u32::from(sp_slot);
6162
let caboose_sp_active = mgs_client
6263
.sp_component_caboose_get(
6364
sp_type,

nexus/mgs-updates/src/test_util/updates.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct UpdateDescription<'a> {
6767

6868
// Update parameters
6969
pub sp_type: SpType,
70-
pub slot_id: u32,
70+
pub slot_id: u16,
7171
pub artifact_hash: &'a ArtifactHash,
7272

7373
// Overrides
@@ -266,7 +266,7 @@ pub struct InProgressAttempt {
266266

267267
// Parameters of the update itself
268268
sp_type: SpType,
269-
slot_id: u32,
269+
slot_id: u16,
270270
deployed_caboose: hubtools::Caboose,
271271

272272
// Status of the driver
@@ -385,7 +385,7 @@ pub struct FinishedUpdateAttempt {
385385
impl FinishedUpdateAttempt {
386386
async fn new(
387387
sp_type: SpType,
388-
slot_id: u32,
388+
slot_id: u16,
389389
sp1: SpTestState,
390390
deployed_caboose: hubtools::Caboose,
391391
result: Result<UpdateCompletedHow, ApplyUpdateError>,

0 commit comments

Comments
 (0)