Skip to content

Commit

Permalink
Switch Gimlet revision from i64 to u32
Browse files Browse the repository at this point in the history
Fixes #6095
  • Loading branch information
bnaecker committed Jul 16, 2024
1 parent 8316247 commit f5dba74
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ async fn cmd_nexus_sleds_list_uninitialized(
cubby: u16,
serial: String,
part: String,
revision: i64,
revision: u32,
}
let rows = sleds.into_iter().map(|sled| UninitializedSledRow {
rack_id: sled.rack_id,
Expand Down
12 changes: 6 additions & 6 deletions nexus/db-model/src/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use uuid::Uuid;
pub struct SledBaseboard {
pub serial_number: String,
pub part_number: String,
pub revision: i64,
pub revision: u32,
}

/// Hardware information about the sled.
Expand All @@ -53,7 +53,7 @@ pub struct Sled {
is_scrimlet: bool,
serial_number: String,
part_number: String,
revision: i64,
revision: SqlU32,

pub usable_hardware_threads: SqlU32,
pub usable_physical_ram: ByteCount,
Expand Down Expand Up @@ -128,7 +128,7 @@ impl From<Sled> for views::Sled {
baseboard: shared::Baseboard {
serial: sled.serial_number,
part: sled.part_number,
revision: sled.revision,
revision: *sled.revision,
},
policy: sled.policy.into(),
state: sled.state.into(),
Expand All @@ -155,7 +155,7 @@ impl From<Sled> for params::SledAgentInfo {
baseboard: Baseboard {
serial: sled.serial_number.clone(),
part: sled.part_number.clone(),
revision: sled.revision,
revision: *sled.revision,
},
usable_hardware_threads: sled.usable_hardware_threads.into(),
usable_physical_ram: sled.usable_physical_ram.into(),
Expand Down Expand Up @@ -192,7 +192,7 @@ pub struct SledUpdate {
is_scrimlet: bool,
serial_number: String,
part_number: String,
revision: i64,
revision: SqlU32,

pub usable_hardware_threads: SqlU32,
pub usable_physical_ram: ByteCount,
Expand Down Expand Up @@ -221,7 +221,7 @@ impl SledUpdate {
is_scrimlet: hardware.is_scrimlet,
serial_number: baseboard.serial_number,
part_number: baseboard.part_number,
revision: baseboard.revision,
revision: SqlU32(baseboard.revision),
usable_hardware_threads: SqlU32::new(
hardware.usable_hardware_threads,
),
Expand Down
16 changes: 10 additions & 6 deletions nexus/db-model/src/switch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use super::Generation;
use crate::schema::switch;
use crate::{schema::switch, SqlU32};
use chrono::{DateTime, Utc};
use db_macros::Asset;
use nexus_types::{external_api::shared, external_api::views, identity::Asset};
Expand All @@ -12,7 +16,7 @@ use uuid::Uuid;
pub struct SwitchBaseboard {
pub serial_number: String,
pub part_number: String,
pub revision: i64,
pub revision: u32,
}

/// Database representation of a Switch.
Expand All @@ -28,7 +32,7 @@ pub struct Switch {

serial_number: String,
part_number: String,
revision: i64,
revision: SqlU32,
}

impl Switch {
Expand All @@ -37,7 +41,7 @@ impl Switch {
id: Uuid,
serial_number: String,
part_number: String,
revision: i64,
revision: u32,
rack_id: Uuid,
) -> Self {
Self {
Expand All @@ -47,7 +51,7 @@ impl Switch {
rack_id,
serial_number,
part_number,
revision,
revision: SqlU32(revision),
}
}
}
Expand All @@ -60,7 +64,7 @@ impl From<Switch> for views::Switch {
baseboard: shared::Baseboard {
serial: switch.serial_number,
part: switch.part_number,
revision: switch.revision,
revision: *switch.revision,
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions nexus/reconfigurator/planning/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl Sled {
sled_agent_client::types::Baseboard::Gimlet {
identifier: serial.clone(),
model: model.clone(),
revision: i64::from(revision),
revision,
}
}
SledHardware::Pc => sled_agent_client::types::Baseboard::Pc {
Expand Down Expand Up @@ -591,7 +591,7 @@ impl Sled {
.map(|sledhw| sled_agent_client::types::Baseboard::Gimlet {
identifier: sledhw.baseboard_id.serial_number.clone(),
model: sledhw.baseboard_id.part_number.clone(),
revision: i64::from(sledhw.sp.baseboard_revision),
revision: sledhw.sp.baseboard_revision,
})
.unwrap_or(sled_agent_client::types::Baseboard::Unknown);

Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ impl super::Nexus {
baseboard: Baseboard {
serial: k.serial_number.clone(),
part: k.part_number.clone(),
revision: v.baseboard_revision.into(),
revision: v.baseboard_revision,
},
rack_id: self.rack_id,
cubby: v.sp_slot,
Expand Down
2 changes: 1 addition & 1 deletion nexus/test-utils/src/resource_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub async fn create_switch(
client: &ClientTestContext,
serial: &str,
part: &str,
revision: i64,
revision: u32,
rack_id: Uuid,
) -> views::Switch {
object_put(
Expand Down
2 changes: 1 addition & 1 deletion nexus/types/src/external_api/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub enum UpdateableComponentType {
pub struct Baseboard {
pub serial: String,
pub part: String,
pub revision: i64,
pub revision: u32,
}

/// A sled that has not been added to an initialized rack yet
Expand Down
3 changes: 2 additions & 1 deletion openapi/bootstrap-agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@
},
"revision": {
"type": "integer",
"format": "int64"
"format": "uint32",
"minimum": 0
},
"type": {
"type": "string",
Expand Down
3 changes: 2 additions & 1 deletion openapi/nexus-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,8 @@
},
"revision": {
"type": "integer",
"format": "int64"
"format": "uint32",
"minimum": 0
},
"serial": {
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -10013,7 +10013,8 @@
},
"revision": {
"type": "integer",
"format": "int64"
"format": "uint32",
"minimum": 0
},
"serial": {
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion openapi/sled-agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,8 @@
},
"revision": {
"type": "integer",
"format": "int64"
"format": "uint32",
"minimum": 0
},
"type": {
"type": "string",
Expand Down
3 changes: 2 additions & 1 deletion openapi/wicketd.json
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,8 @@
},
"revision": {
"type": "integer",
"format": "int64"
"format": "uint32",
"minimum": 0
},
"type": {
"type": "string",
Expand Down
3 changes: 2 additions & 1 deletion schema/rss-sled-plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
},
"revision": {
"type": "integer",
"format": "int64"
"format": "uint32",
"minimum": 0.0
},
"type": {
"type": "string",
Expand Down
7 changes: 1 addition & 6 deletions sled-agent/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,12 +1021,7 @@ async fn inventory(
async fn sled_identifiers(
request_context: RequestContext<SledAgent>,
) -> Result<HttpResponseOk<SledIdentifiers>, HttpError> {
request_context
.context()
.sled_identifiers()
.await
.map(HttpResponseOk)
.map_err(HttpError::from)
Ok(HttpResponseOk(request_context.context().sled_identifiers().await))
}

/// Get the internal state of the local bootstore node
Expand Down
13 changes: 4 additions & 9 deletions sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,20 +1197,15 @@ impl SledAgent {
/// interested in the switch identifiers, MGS is the current best way to do
/// that, by asking for the local switch's slot, and then that switch's SP
/// state.
pub(crate) async fn sled_identifiers(
&self,
) -> Result<SledIdentifiers, Error> {
pub(crate) async fn sled_identifiers(&self) -> SledIdentifiers {
let baseboard = self.inner.hardware.baseboard();
Ok(SledIdentifiers {
SledIdentifiers {
rack_id: self.inner.start_request.body.rack_id,
sled_id: self.inner.id,
model: baseboard.model().to_string(),
revision: baseboard
.revision()
.try_into()
.map_err(|_| Error::UnexpectedRevision(baseboard.revision()))?,
revision: baseboard.revision(),
serial: baseboard.identifier().to_string(),
})
}
}

/// Return basic information about ourselves: identity and status
Expand Down
17 changes: 16 additions & 1 deletion sled-hardware/src/illumos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl HardwareSnapshot {
let baseboard = Baseboard::new_gimlet(
string_from_property(&properties[0])?,
string_from_property(&properties[1])?,
i64_from_property(&properties[2])?,
u32_from_property(&properties[2])?,
);
let boot_storage_unit =
BootStorageUnit::try_from(i64_from_property(&properties[3])?)?;
Expand Down Expand Up @@ -412,6 +412,21 @@ fn get_parent_node<'a>(
Ok(parent)
}

/// Convert a property to a `u32` if possible, passing through an `i64`.
///
/// Returns an error if either:
///
/// - The actual devinfo property isn't an integer type.
/// - The value does not fit in a `u32`.
fn u32_from_property(prop: &Property<'_>) -> Result<u32, Error> {
i64_from_property(prop).and_then(|val| {
u32::try_from(val).map_err(|_| Error::UnexpectedPropertyType {
name: prop.name(),
ty: "u32".to_string(),
})
})
}

fn i64_from_property(prop: &Property<'_>) -> Result<i64, Error> {
prop.as_i64().ok_or_else(|| Error::UnexpectedPropertyType {
name: prop.name(),
Expand Down
6 changes: 3 additions & 3 deletions sled-hardware/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod underlay;
)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Baseboard {
Gimlet { identifier: String, model: String, revision: i64 },
Gimlet { identifier: String, model: String, revision: u32 },

Unknown,

Expand All @@ -34,7 +34,7 @@ impl Baseboard {
pub fn new_gimlet(
identifier: String,
model: String,
revision: i64,
revision: u32,
) -> Self {
Self::Gimlet { identifier, model, revision }
}
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Baseboard {
}
}

pub fn revision(&self) -> i64 {
pub fn revision(&self) -> u32 {
match self {
Self::Gimlet { revision, .. } => *revision,
Self::Pc { .. } => 0,
Expand Down
1 change: 1 addition & 0 deletions sled-storage/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ pub(crate) async fn ensure_zpool_has_datasets(
if let Ok(epoch) = epoch_str.parse::<u64>() {
epoch
} else {
println!(">>>> {epoch_str}");
return Err(DatasetError::CannotParseEpochProperty(
dataset.to_string(),
));
Expand Down
6 changes: 3 additions & 3 deletions wicketd/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,15 +879,15 @@ async fn get_location(
Baseboard::new_gimlet(
state.serial_number.clone(),
state.model.clone(),
i64::from(state.revision),
state.revision,
)
});
} else if let (Some(sled_baseboard), Some(state)) =
(sled_baseboard.as_ref(), sp.state.as_ref())
{
if sled_baseboard.identifier() == state.serial_number
&& sled_baseboard.model() == state.model
&& sled_baseboard.revision() == i64::from(state.revision)
&& sled_baseboard.revision() == state.revision
{
sled_id = Some(sp.id);
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ async fn post_start_update(
Some(baseboard) => {
if baseboard.identifier() == sp_state.serial_number
&& baseboard.model() == sp_state.model
&& baseboard.revision() == i64::from(sp_state.revision)
&& baseboard.revision() == sp_state.revision
{
self_update = Some(*target);
continue;
Expand Down
2 changes: 1 addition & 1 deletion wicketd/src/rss_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl CurrentRssConfig {
let baseboard = Baseboard::new_gimlet(
state.serial_number.clone(),
state.model.clone(),
state.revision.into(),
state.revision,
);
let bootstrap_ip = bootstrap_sleds.get(&baseboard).copied();
Some(BootstrapSledDescription {
Expand Down

0 comments on commit f5dba74

Please sign in to comment.