Skip to content

database support for PendingMgsUpdate for SP updates #8291

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

Draft
wants to merge 11 commits into
base: dap/rustfmt-bailout
Choose a base branch
from
Draft
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
53 changes: 48 additions & 5 deletions nexus/db-model/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
//! Types for representing the deployed software and configuration in the
//! database

use crate::inventory::ZoneType;
use crate::inventory::{SpMgsSlot, SpType, ZoneType};
use crate::omicron_zone_config::{self, OmicronZoneNic};
use crate::typed_uuid::DbTypedUuid;
use crate::{
ArtifactHash, ByteCount, DbOximeterReadMode, Generation, MacAddr, Name,
SledState, SqlU8, SqlU16, SqlU32, TufArtifact, impl_enum_type, ipv6,
ArtifactHash, ByteCount, DbArtifactVersion, DbOximeterReadMode, Generation,
MacAddr, Name, SledState, SqlU8, SqlU16, SqlU32, TufArtifact,
impl_enum_type, ipv6,
};
use anyhow::{Context, Result, anyhow, bail};
use chrono::{DateTime, Utc};
Expand All @@ -21,10 +22,10 @@ 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_sled_metadata, bp_target,
bp_oximeter_read_policy, bp_pending_mgs_update_sp, bp_sled_metadata,
bp_target,
};
use nexus_sled_agent_shared::inventory::OmicronZoneDataset;
use nexus_types::deployment::BlueprintDatasetDisposition;
use nexus_types::deployment::BlueprintPhysicalDiskConfig;
use nexus_types::deployment::BlueprintPhysicalDiskDisposition;
use nexus_types::deployment::BlueprintTarget;
Expand All @@ -33,14 +34,18 @@ use nexus_types::deployment::BlueprintZoneDisposition;
use nexus_types::deployment::BlueprintZoneType;
use nexus_types::deployment::ClickhouseClusterConfig;
use nexus_types::deployment::CockroachDbPreserveDowngrade;
use nexus_types::deployment::PendingMgsUpdate;
use nexus_types::deployment::PendingMgsUpdateDetails;
use nexus_types::deployment::{
BlueprintDatasetConfig, BlueprintZoneImageVersion, OximeterReadMode,
};
use nexus_types::deployment::{BlueprintDatasetDisposition, ExpectedVersion};
use nexus_types::deployment::{BlueprintZoneImageSource, blueprint_zone_type};
use nexus_types::deployment::{
OmicronZoneExternalFloatingAddr, OmicronZoneExternalFloatingIp,
OmicronZoneExternalSnatIp,
};
use nexus_types::inventory::BaseboardId;
use omicron_common::api::internal::shared::NetworkInterface;
use omicron_common::disk::DiskIdentity;
use omicron_common::zpool_name::ZpoolName;
Expand All @@ -50,6 +55,7 @@ use omicron_uuid_kinds::{
PhysicalDiskKind, SledKind, SledUuid, ZpoolKind, ZpoolUuid,
};
use std::net::{IpAddr, SocketAddrV6};
use std::sync::Arc;
use uuid::Uuid;

/// See [`nexus_types::deployment::Blueprint`].
Expand Down Expand Up @@ -1245,3 +1251,40 @@ impl BpOximeterReadPolicy {
}
}
}

#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = bp_pending_mgs_update_sp)]
pub struct BpPendingMgsUpdateSp {
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_version: DbArtifactVersion,
pub expected_inactive_version: Option<DbArtifactVersion>,
}

impl BpPendingMgsUpdateSp {
pub fn into_generic(
self,
baseboard_id: Arc<BaseboardId>,
) -> PendingMgsUpdate {
PendingMgsUpdate {
baseboard_id,
sp_type: self.sp_type.into(),
slot_id: u32::from(**self.sp_slot),
artifact_hash: self.artifact_sha256.into(),
artifact_version: (*self.artifact_version).clone(),
details: PendingMgsUpdateDetails::Sp {
expected_active_version: (*self.expected_active_version)
.clone(),
expected_inactive_version: match self.expected_inactive_version
{
Some(v) => ExpectedVersion::Version((*v).clone()),
None => ExpectedVersion::NoValidVersion,
},
},
}
}
}
1 change: 1 addition & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ pub use switch_interface::*;
pub use switch_port::*;
pub use target_release::*;
pub use tuf_repo::*;
pub use typed_uuid::DbTypedUuid;
pub use typed_uuid::to_db_typed_uuid;
pub use upstairs_repair::*;
pub use user_builtin::*;
Expand Down
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(150, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(151, 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(151, "add-pending-mgs-updates"),
KnownVersion::new(150, "add-last-reconciliation-orphaned-datasets"),
KnownVersion::new(149, "bp-add-target-release-min-gen"),
KnownVersion::new(148, "clean-misplaced-m2s"),
Expand Down
Loading
Loading