Skip to content

PendingMgsUpdate slot id should be a u16 #8398

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

Open
wants to merge 1 commit into
base: dap/mgs-update-db
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion dev-tools/reconfigurator-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ fn cmd_blueprint_edit(
let update = PendingMgsUpdate {
baseboard_id: baseboard_id.clone(),
sp_type: sp.sp_type,
slot_id: u32::from(sp.sp_slot),
slot_id: sp.sp_slot,
details,
artifact_hash,
artifact_version,
Expand Down
20 changes: 11 additions & 9 deletions dev-tools/reconfigurator-sp-updater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl Inventory {
struct SpInfo {
baseboard_id: Arc<BaseboardId>,
sp_type: SpType,
sp_slot_id: u32,
sp_slot_id: u16,
}

impl Inventory {
Expand All @@ -214,16 +214,21 @@ impl Inventory {
}),
)
.then(async move |sp_id| {
let sp_slot = u16::try_from(sp_id.slot).with_context(|| {
format!("sp slot number is out of range: {sp_id:?}")
})?;
c.sp_get(sp_id.type_, sp_id.slot)
.await
.with_context(|| format!("fetching info about SP {:?}", sp_id))
.map(|s| (sp_id, s))
.map(|s| (sp_id.type_, sp_slot, s))
})
.collect::<Vec<Result<_, _>>>()
.await
.into_iter()
.filter_map(|r| match r {
Ok((sp_id, v)) => Some((sp_id, v.into_inner())),
Ok((sp_type, sp_slot, v)) => {
Some((sp_type, sp_slot, v.into_inner()))
}
Err(error) => {
warn!(
log,
Expand All @@ -237,17 +242,14 @@ impl Inventory {

let sps_by_serial = sp_infos
.into_iter()
.map(|(sp_id, sp_state)| {
.map(|(sp_type, sp_slot, sp_state)| {
let baseboard_id = Arc::new(BaseboardId {
serial_number: sp_state.serial_number,
part_number: sp_state.model,
});
let serial_number = baseboard_id.serial_number.clone();
let sp_info = SpInfo {
baseboard_id,
sp_type: sp_id.type_,
sp_slot_id: sp_id.slot,
};
let sp_info =
SpInfo { baseboard_id, sp_type, sp_slot_id: sp_slot };
(serial_number, sp_info)
})
.collect();
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-model/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ impl BpPendingMgsUpdateSp {
PendingMgsUpdate {
baseboard_id,
sp_type: self.sp_type.into(),
slot_id: u32::from(**self.sp_slot),
slot_id: **self.sp_slot,
artifact_hash: self.artifact_sha256.into(),
artifact_version: (*self.artifact_version).clone(),
details: PendingMgsUpdateDetails::Sp {
Expand Down
10 changes: 2 additions & 8 deletions nexus/db-queries/src/db/datastore/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,19 +517,13 @@ impl DataStore {
} => continue,
};

// slot_ids fit into a u16 in practice. This will be
// enforced at compile time shortly. See
// oxidecomputer/omicron#8378.
let update_slot_id = u16::try_from(update.slot_id)
.expect("slot id to fit into u16");

let db_blueprint_id = DbTypedUuid::from(blueprint_id)
.into_sql::<diesel::sql_types::Uuid>(
);
let db_sp_type =
SpType::from(update.sp_type).into_sql::<SpTypeEnum>();
let db_slot_id =
SpMgsSlot::from(SqlU16::from(update_slot_id))
SpMgsSlot::from(SqlU16::from(update.slot_id))
.into_sql::<diesel::sql_types::Int4>();
let db_artifact_hash =
ArtifactHash::from(update.artifact_hash)
Expand Down Expand Up @@ -2663,7 +2657,7 @@ mod tests {
builder.pending_mgs_update_insert(PendingMgsUpdate {
baseboard_id: baseboard_id.clone(),
sp_type: sp.sp_type,
slot_id: u32::from(sp.sp_slot),
slot_id: sp.sp_slot,
details: PendingMgsUpdateDetails::Sp {
expected_active_version: "1.0.0".parse().unwrap(),
expected_inactive_version: ExpectedVersion::NoValidVersion,
Expand Down
2 changes: 1 addition & 1 deletion nexus/mgs-updates/src/common_sp_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub enum PrecheckError {
)]
WrongDevice {
sp_type: SpType,
slot_id: u32,
slot_id: u16,
expected_part: String,
expected_serial: String,
found_part: String,
Expand Down
21 changes: 15 additions & 6 deletions nexus/mgs-updates/src/driver_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) struct SpComponentUpdate {
pub log: slog::Logger,
pub component: SpComponent,
pub target_sp_type: SpType,
pub target_sp_slot: u32,
pub target_sp_slot: u16,
pub firmware_slot: u16,
pub update_id: SpUpdateUuid,
}
Expand Down Expand Up @@ -240,7 +240,7 @@ pub(crate) async fn apply_update(
client
.sp_component_update(
sp_type,
sp_slot,
u32::from(sp_slot),
component,
sp_update.firmware_slot,
&sp_update.update_id.as_untyped_uuid(),
Expand Down Expand Up @@ -445,7 +445,11 @@ async fn wait_for_delivery(
let status = mgs_clients
.try_all_serially(log, |client| async move {
let update_status = client
.sp_component_update_status(sp_type, sp_slot, component)
.sp_component_update_status(
sp_type,
u32::from(sp_slot),
component,
)
.await?;

debug!(
Expand Down Expand Up @@ -544,7 +548,12 @@ async fn abort_update(
.try_all_serially(log, |mgs_client| async move {
let arg = UpdateAbortBody { id: update_id };
mgs_client
.sp_component_update_abort(sp_type, sp_slot, component, &arg)
.sp_component_update_abort(
sp_type,
u32::from(sp_slot),
component,
&arg,
)
.await
})
.await
Expand Down Expand Up @@ -707,7 +716,7 @@ mod test {
gwtestctx: &GatewayTestContext,
artifacts: &TestArtifacts,
sp_type: SpType,
slot_id: u32,
slot_id: u16,
artifact_hash: &ArtifactHash,
expected_result: UpdateCompletedHow,
) {
Expand Down Expand Up @@ -791,7 +800,7 @@ mod test {
gwtestctx: &GatewayTestContext,
artifacts: &TestArtifacts,
sp_type: SpType,
slot_id: u32,
slot_id: u16,
artifact_hash: &ArtifactHash,
expected_result: UpdateCompletedHow,
) {
Expand Down
10 changes: 5 additions & 5 deletions nexus/mgs-updates/src/rot_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
// Verify that the device is the one we think it is.
let state = mgs_clients
.try_all_serially(log, move |mgs_client| async move {
mgs_client.sp_get(update.sp_type, update.slot_id).await
mgs_client.sp_get(update.sp_type, u32::from(update.slot_id)).await
})
.await?
.into_inner();
Expand Down Expand Up @@ -276,7 +276,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
mgs_client
.sp_component_caboose_get(
update.sp_type,
update.slot_id,
u32::from(update.slot_id),
&SpComponent::ROT.to_string(),
active.to_u16(),
)
Expand Down Expand Up @@ -326,7 +326,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
mgs_client
.sp_component_caboose_get(
update.sp_type,
update.slot_id,
u32::from(update.slot_id),
&SpComponent::ROT.to_string(),
expected_active_slot.slot().toggled().to_u16(),
)
Expand Down Expand Up @@ -415,7 +415,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
mgs_client
.sp_component_active_slot_set(
update.sp_type,
update.slot_id,
u32::from(update.slot_id),
&SpComponent::ROT.to_string(),
persist,
&SpComponentFirmwareSlot { slot: inactive_slot }
Expand All @@ -426,7 +426,7 @@ impl SpComponentUpdateHelper for ReconfiguratorRotUpdater {
mgs_client
.sp_component_reset(
update.sp_type,
update.slot_id,
u32::from(update.slot_id),
&SpComponent::ROT.to_string(),
)
.await?;
Expand Down
10 changes: 6 additions & 4 deletions nexus/mgs-updates/src/sp_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ impl SpComponentUpdateHelper for ReconfiguratorSpUpdater {
// Verify that the device is the one we think it is.
let state = mgs_clients
.try_all_serially(log, move |mgs_client| async move {
mgs_client.sp_get(update.sp_type, update.slot_id).await
mgs_client
.sp_get(update.sp_type, u32::from(update.slot_id))
.await
})
.await?
.into_inner();
Expand All @@ -188,7 +190,7 @@ impl SpComponentUpdateHelper for ReconfiguratorSpUpdater {
mgs_client
.sp_component_caboose_get(
update.sp_type,
update.slot_id,
u32::from(update.slot_id),
&SpComponent::SP_ITSELF.to_string(),
0,
)
Expand Down Expand Up @@ -240,7 +242,7 @@ impl SpComponentUpdateHelper for ReconfiguratorSpUpdater {
mgs_client
.sp_component_caboose_get(
update.sp_type,
update.slot_id,
u32::from(update.slot_id),
&SpComponent::SP_ITSELF.to_string(),
1,
)
Expand Down Expand Up @@ -300,7 +302,7 @@ impl SpComponentUpdateHelper for ReconfiguratorSpUpdater {
mgs_client
.sp_component_reset(
update.sp_type,
update.slot_id,
u32::from(update.slot_id),
&SpComponent::SP_ITSELF.to_string(),
)
.await?;
Expand Down
3 changes: 2 additions & 1 deletion nexus/mgs-updates/src/test_util/sp_test_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ impl SpTestState {
pub async fn load(
mgs_client: &gateway_client::Client,
sp_type: SpType,
sp_slot: u32,
sp_slot: u16,
) -> Result<SpTestState, GatewayClientError> {
let sp_slot = u32::from(sp_slot);
let caboose_sp_active = mgs_client
.sp_component_caboose_get(
sp_type,
Expand Down
6 changes: 3 additions & 3 deletions nexus/mgs-updates/src/test_util/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct UpdateDescription<'a> {

// Update parameters
pub sp_type: SpType,
pub slot_id: u32,
pub slot_id: u16,
pub artifact_hash: &'a ArtifactHash,

// Overrides
Expand Down Expand Up @@ -265,7 +265,7 @@ pub struct InProgressAttempt {

// Parameters of the update itself
sp_type: SpType,
slot_id: u32,
slot_id: u16,
deployed_caboose: hubtools::Caboose,

// Status of the driver
Expand Down Expand Up @@ -385,7 +385,7 @@ pub struct FinishedUpdateAttempt {
impl FinishedUpdateAttempt {
async fn new(
sp_type: SpType,
slot_id: u32,
slot_id: u16,
sp1: SpTestState,
deployed_caboose: hubtools::Caboose,
result: Result<UpdateCompletedHow, ApplyUpdateError>,
Expand Down
12 changes: 6 additions & 6 deletions nexus/reconfigurator/planning/src/mgs_updates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn mgs_update_status(
update,
);
Ok(MgsUpdateStatus::Impossible)
} else if u32::from(sp_info.sp_slot) != update.slot_id {
} else if sp_info.sp_slot != update.slot_id {
warn!(
log,
"baseboard with in-progress SP update has moved";
Expand Down Expand Up @@ -466,7 +466,7 @@ fn try_make_update_sp(
Some(PendingMgsUpdate {
baseboard_id: baseboard_id.clone(),
sp_type: sp_info.sp_type,
slot_id: u32::from(sp_info.sp_slot),
slot_id: sp_info.sp_slot,
details: PendingMgsUpdateDetails::Sp {
expected_active_version,
expected_inactive_version,
Expand Down Expand Up @@ -562,7 +562,7 @@ mod test {
/// - switch 1: sidecar-c
/// - psc 0: psc-b
/// - psc 1: psc-c
fn test_config() -> BTreeMap<(SpType, u32), (&'static str, &'static str)> {
fn test_config() -> BTreeMap<(SpType, u16), (&'static str, &'static str)> {
BTreeMap::from([
((SpType::Sled, 0), ("sled_0", "gimlet-d")),
((SpType::Sled, 1), ("sled_1", "gimlet-e")),
Expand Down Expand Up @@ -667,7 +667,7 @@ mod test {
// `inactive_version` in the inactive slot.
fn make_collection(
active_version: ArtifactVersion,
active_version_exceptions: &BTreeMap<(SpType, u32), ArtifactVersion>,
active_version_exceptions: &BTreeMap<(SpType, u16), ArtifactVersion>,
inactive_version: ExpectedVersion,
) -> Collection {
let mut builder = nexus_inventory::CollectionBuilder::new(
Expand Down Expand Up @@ -706,7 +706,7 @@ mod test {
};

let baseboard_id = builder
.found_sp_state("test", sp_type, sp_slot, sp_state)
.found_sp_state("test", sp_type, u32::from(sp_slot), sp_state)
.unwrap();
let active_version = active_version_exceptions
.get(&(sp_type, sp_slot))
Expand Down Expand Up @@ -1142,7 +1142,7 @@ mod test {
}

fn verify_one_sp_update(
expected_updates: &mut BTreeMap<(SpType, u32), (&str, ArtifactHash)>,
expected_updates: &mut BTreeMap<(SpType, u16), (&str, ArtifactHash)>,
update: &PendingMgsUpdate,
) {
let sp_type = update.sp_type;
Expand Down
4 changes: 2 additions & 2 deletions nexus/types/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ pub struct PendingMgsUpdate {
/// what type of baseboard this is
pub sp_type: SpType,
/// last known MGS slot (cubby number) of the baseboard
pub slot_id: u32,
pub slot_id: u16,

/// component-specific details of the pending update
pub details: PendingMgsUpdateDetails,
Expand All @@ -1237,7 +1237,7 @@ impl slog::KV for PendingMgsUpdate {
slog::KV::serialize(&self.baseboard_id, record, serializer)?;
serializer
.emit_str(Key::from("sp_type"), &format!("{:?}", self.sp_type))?;
serializer.emit_u32(Key::from("sp_slot"), self.slot_id)?;
serializer.emit_u16(Key::from("sp_slot"), self.slot_id)?;
slog::KV::serialize(&self.details, record, serializer)?;
serializer.emit_str(
Key::from("artifact_hash"),
Expand Down
Loading