Skip to content

[reconfigurator] database support for PendingMgsUpdate for RoT #8588

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

Merged
merged 10 commits into from
Jul 20, 2025
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 70 additions & 8 deletions nexus/db-model/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Types for representing the deployed software and configuration in the
//! database

use crate::inventory::{SpMgsSlot, SpType, ZoneType};
use crate::inventory::{HwRotSlot, SpMgsSlot, SpType, ZoneType};
use crate::omicron_zone_config::{self, OmicronZoneNic};
use crate::typed_uuid::DbTypedUuid;
use crate::{
Expand All @@ -22,8 +22,8 @@ use nexus_db_schema::schema::{
bp_clickhouse_keeper_zone_id_to_node_id,
bp_clickhouse_server_zone_id_to_node_id, bp_omicron_dataset,
bp_omicron_physical_disk, bp_omicron_zone, bp_omicron_zone_nic,
bp_oximeter_read_policy, bp_pending_mgs_update_sp, bp_sled_metadata,
bp_target,
bp_oximeter_read_policy, bp_pending_mgs_update_rot,
bp_pending_mgs_update_sp, bp_sled_metadata, bp_target,
};
use nexus_sled_agent_shared::inventory::OmicronZoneDataset;
use nexus_types::deployment::BlueprintHostPhase2DesiredContents;
Expand All @@ -36,6 +36,7 @@ use nexus_types::deployment::BlueprintZoneDisposition;
use nexus_types::deployment::BlueprintZoneType;
use nexus_types::deployment::ClickhouseClusterConfig;
use nexus_types::deployment::CockroachDbPreserveDowngrade;
use nexus_types::deployment::ExpectedActiveRotSlot;
use nexus_types::deployment::PendingMgsUpdate;
use nexus_types::deployment::PendingMgsUpdateDetails;
use nexus_types::deployment::{
Expand Down Expand Up @@ -1302,6 +1303,14 @@ impl BpOximeterReadPolicy {
}
}

pub trait BpPendingMgsUpdateComponent {
/// Converts a BpMgsUpdate into a PendingMgsUpdate
fn into_generic(self, baseboard_id: Arc<BaseboardId>) -> PendingMgsUpdate;

/// Retrieves the baseboard ID
fn hw_baseboard_id(&self) -> &Uuid;
}

#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = bp_pending_mgs_update_sp)]
pub struct BpPendingMgsUpdateSp {
Expand All @@ -1315,11 +1324,12 @@ pub struct BpPendingMgsUpdateSp {
pub expected_inactive_version: Option<DbArtifactVersion>,
}

impl BpPendingMgsUpdateSp {
pub fn into_generic(
self,
baseboard_id: Arc<BaseboardId>,
) -> PendingMgsUpdate {
impl BpPendingMgsUpdateComponent for BpPendingMgsUpdateSp {
fn hw_baseboard_id(&self) -> &Uuid {
&self.hw_baseboard_id
}

fn into_generic(self, baseboard_id: Arc<BaseboardId>) -> PendingMgsUpdate {
PendingMgsUpdate {
baseboard_id,
sp_type: self.sp_type.into(),
Expand All @@ -1338,3 +1348,55 @@ impl BpPendingMgsUpdateSp {
}
}
}

#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = bp_pending_mgs_update_rot)]
pub struct BpPendingMgsUpdateRot {
pub blueprint_id: DbTypedUuid<BlueprintKind>,
pub hw_baseboard_id: Uuid,
pub sp_type: SpType,
pub sp_slot: SpMgsSlot,
pub artifact_sha256: ArtifactHash,
pub artifact_version: DbArtifactVersion,
pub expected_active_slot: HwRotSlot,
pub expected_active_version: DbArtifactVersion,
pub expected_inactive_version: Option<DbArtifactVersion>,
pub expected_persistent_boot_preference: HwRotSlot,
pub expected_pending_persistent_boot_preference: Option<HwRotSlot>,
pub expected_transient_boot_preference: Option<HwRotSlot>,
}

impl BpPendingMgsUpdateComponent for BpPendingMgsUpdateRot {
fn hw_baseboard_id(&self) -> &Uuid {
&self.hw_baseboard_id
}

fn into_generic(self, baseboard_id: Arc<BaseboardId>) -> PendingMgsUpdate {
PendingMgsUpdate {
baseboard_id,
sp_type: self.sp_type.into(),
slot_id: **self.sp_slot,
artifact_hash: self.artifact_sha256.into(),
artifact_version: (*self.artifact_version).clone(),
details: PendingMgsUpdateDetails::Rot {
expected_active_slot: ExpectedActiveRotSlot {
slot: self.expected_active_slot.into(),
version: (*self.expected_active_version).clone(),
},
expected_inactive_version: self
.expected_inactive_version
.map(|v| ExpectedVersion::Version(v.into()))
.unwrap_or(ExpectedVersion::NoValidVersion),
expected_persistent_boot_preference: self
.expected_persistent_boot_preference
.into(),
expected_pending_persistent_boot_preference: self
.expected_pending_persistent_boot_preference
.map(|s| s.into()),
expected_transient_boot_preference: self
.expected_transient_boot_preference
.map(|s| s.into()),
},
}
}
}
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: Version = Version::new(166, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(167, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(167, "add-pending-mgs-updates-rot"),
KnownVersion::new(166, "bundle-user-comment"),
KnownVersion::new(165, "route-config-rib-priority"),
KnownVersion::new(164, "fix-leaked-bp-oximeter-read-policy-rows"),
Expand Down
1 change: 1 addition & 0 deletions nexus/db-queries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ criterion.workspace = true
expectorate.workspace = true
hyper-rustls.workspace = true
gateway-client.workspace = true
gateway-types.workspace = true
illumos-utils.workspace = true
internal-dns-resolver.workspace = true
itertools.workspace = true
Expand Down
Loading
Loading