Skip to content

Commit cbae98c

Browse files
authored
database support for PendingMgsUpdate for SP updates (#8291)
1 parent a1d38ab commit cbae98c

File tree

7 files changed

+469
-11
lines changed

7 files changed

+469
-11
lines changed

nexus/db-model/src/deployment.rs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
//! Types for representing the deployed software and configuration in the
66
//! database
77
8-
use crate::inventory::ZoneType;
8+
use crate::inventory::{SpMgsSlot, SpType, ZoneType};
99
use crate::omicron_zone_config::{self, OmicronZoneNic};
1010
use crate::typed_uuid::DbTypedUuid;
1111
use crate::{
12-
ArtifactHash, ByteCount, DbOximeterReadMode, Generation, MacAddr, Name,
13-
SledState, SqlU8, SqlU16, SqlU32, TufArtifact, impl_enum_type, ipv6,
12+
ArtifactHash, ByteCount, DbArtifactVersion, DbOximeterReadMode, Generation,
13+
MacAddr, Name, SledState, SqlU8, SqlU16, SqlU32, TufArtifact,
14+
impl_enum_type, ipv6,
1415
};
1516
use anyhow::{Context, Result, anyhow, bail};
1617
use chrono::{DateTime, Utc};
@@ -21,10 +22,10 @@ use nexus_db_schema::schema::{
2122
bp_clickhouse_keeper_zone_id_to_node_id,
2223
bp_clickhouse_server_zone_id_to_node_id, bp_omicron_dataset,
2324
bp_omicron_physical_disk, bp_omicron_zone, bp_omicron_zone_nic,
24-
bp_oximeter_read_policy, bp_sled_metadata, bp_target,
25+
bp_oximeter_read_policy, bp_pending_mgs_update_sp, bp_sled_metadata,
26+
bp_target,
2527
};
2628
use nexus_sled_agent_shared::inventory::OmicronZoneDataset;
27-
use nexus_types::deployment::BlueprintDatasetDisposition;
2829
use nexus_types::deployment::BlueprintPhysicalDiskConfig;
2930
use nexus_types::deployment::BlueprintPhysicalDiskDisposition;
3031
use nexus_types::deployment::BlueprintTarget;
@@ -33,14 +34,18 @@ use nexus_types::deployment::BlueprintZoneDisposition;
3334
use nexus_types::deployment::BlueprintZoneType;
3435
use nexus_types::deployment::ClickhouseClusterConfig;
3536
use nexus_types::deployment::CockroachDbPreserveDowngrade;
37+
use nexus_types::deployment::PendingMgsUpdate;
38+
use nexus_types::deployment::PendingMgsUpdateDetails;
3639
use nexus_types::deployment::{
3740
BlueprintDatasetConfig, BlueprintZoneImageVersion, OximeterReadMode,
3841
};
42+
use nexus_types::deployment::{BlueprintDatasetDisposition, ExpectedVersion};
3943
use nexus_types::deployment::{BlueprintZoneImageSource, blueprint_zone_type};
4044
use nexus_types::deployment::{
4145
OmicronZoneExternalFloatingAddr, OmicronZoneExternalFloatingIp,
4246
OmicronZoneExternalSnatIp,
4347
};
48+
use nexus_types::inventory::BaseboardId;
4449
use omicron_common::api::internal::shared::NetworkInterface;
4550
use omicron_common::disk::DiskIdentity;
4651
use omicron_common::zpool_name::ZpoolName;
@@ -50,6 +55,7 @@ use omicron_uuid_kinds::{
5055
PhysicalDiskKind, SledKind, SledUuid, ZpoolKind, ZpoolUuid,
5156
};
5257
use std::net::{IpAddr, SocketAddrV6};
58+
use std::sync::Arc;
5359
use uuid::Uuid;
5460

5561
/// See [`nexus_types::deployment::Blueprint`].
@@ -1245,3 +1251,40 @@ impl BpOximeterReadPolicy {
12451251
}
12461252
}
12471253
}
1254+
1255+
#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
1256+
#[diesel(table_name = bp_pending_mgs_update_sp)]
1257+
pub struct BpPendingMgsUpdateSp {
1258+
pub blueprint_id: DbTypedUuid<BlueprintKind>,
1259+
pub hw_baseboard_id: Uuid,
1260+
pub sp_type: SpType,
1261+
pub sp_slot: SpMgsSlot,
1262+
pub artifact_sha256: ArtifactHash,
1263+
pub artifact_version: DbArtifactVersion,
1264+
pub expected_active_version: DbArtifactVersion,
1265+
pub expected_inactive_version: Option<DbArtifactVersion>,
1266+
}
1267+
1268+
impl BpPendingMgsUpdateSp {
1269+
pub fn into_generic(
1270+
self,
1271+
baseboard_id: Arc<BaseboardId>,
1272+
) -> PendingMgsUpdate {
1273+
PendingMgsUpdate {
1274+
baseboard_id,
1275+
sp_type: self.sp_type.into(),
1276+
slot_id: u32::from(**self.sp_slot),
1277+
artifact_hash: self.artifact_sha256.into(),
1278+
artifact_version: (*self.artifact_version).clone(),
1279+
details: PendingMgsUpdateDetails::Sp {
1280+
expected_active_version: (*self.expected_active_version)
1281+
.clone(),
1282+
expected_inactive_version: match self.expected_inactive_version
1283+
{
1284+
Some(v) => ExpectedVersion::Version((*v).clone()),
1285+
None => ExpectedVersion::NoValidVersion,
1286+
},
1287+
},
1288+
}
1289+
}
1290+
}

nexus/db-model/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ pub use switch_interface::*;
237237
pub use switch_port::*;
238238
pub use target_release::*;
239239
pub use tuf_repo::*;
240+
pub use typed_uuid::DbTypedUuid;
240241
pub use typed_uuid::to_db_typed_uuid;
241242
pub use upstairs_repair::*;
242243
pub use user_builtin::*;

nexus/db-model/src/schema_versions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
1616
///
1717
/// This must be updated when you change the database schema. Refer to
1818
/// schema/crdb/README.adoc in the root of this repository for details.
19-
pub const SCHEMA_VERSION: Version = Version::new(153, 0, 0);
19+
pub const SCHEMA_VERSION: Version = Version::new(154, 0, 0);
2020

2121
/// List of all past database schema versions, in *reverse* order
2222
///
@@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
2828
// | leaving the first copy as an example for the next person.
2929
// v
3030
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
31+
KnownVersion::new(154, "add-pending-mgs-updates"),
3132
KnownVersion::new(153, "chicken-switches"),
3233
KnownVersion::new(152, "ereports"),
3334
KnownVersion::new(151, "zone-image-resolver-inventory"),

0 commit comments

Comments
 (0)