Skip to content
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

initial inventory for automated update #4291

Merged
merged 21 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
add new database test, restore and fix previous builder test
davepacheco committed Oct 26, 2023
commit 298400060aa641f864dab6860eb92ffdb3a6b8e7
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.

2 changes: 1 addition & 1 deletion dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
//! would be the only consumer -- and in that case it's okay to query the
//! database directly.

// NOTE: eminates from Tabled macros
// NOTE: emanates from Tabled macros
#![allow(clippy::useless_vec)]

use crate::Omdb;
113 changes: 101 additions & 12 deletions nexus/db-model/src/inventory.rs
Original file line number Diff line number Diff line change
@@ -48,6 +48,16 @@ impl From<PowerState> for HwPowerState {
}
}

impl From<HwPowerState> for PowerState {
fn from(value: HwPowerState) -> Self {
match value {
HwPowerState::A0 => PowerState::A0,
HwPowerState::A1 => PowerState::A1,
HwPowerState::A2 => PowerState::A2,
}
}
}

// See [`nexus_types::inventory::RotSlot`].
impl_enum_type!(
#[derive(SqlType, Debug, QueryId)]
@@ -72,6 +82,15 @@ impl From<RotSlot> for HwRotSlot {
}
}

impl From<HwRotSlot> for RotSlot {
fn from(value: HwRotSlot) -> RotSlot {
match value {
HwRotSlot::A => RotSlot::A,
HwRotSlot::B => RotSlot::B,
}
}
}

// See [`nexus_types::inventory::CabooseWhich`].
impl_enum_type!(
#[derive(SqlType, Debug, QueryId)]
@@ -91,19 +110,24 @@ impl_enum_type!(

impl From<nexus_types::inventory::CabooseWhich> for CabooseWhich {
fn from(c: nexus_types::inventory::CabooseWhich) -> Self {
use nexus_types::inventory as nexus_inventory;
match c {
nexus_types::inventory::CabooseWhich::SpSlot0 => {
CabooseWhich::SpSlot0
}
nexus_types::inventory::CabooseWhich::SpSlot1 => {
CabooseWhich::SpSlot1
}
nexus_types::inventory::CabooseWhich::RotSlotA => {
CabooseWhich::RotSlotA
}
nexus_types::inventory::CabooseWhich::RotSlotB => {
CabooseWhich::RotSlotB
}
nexus_inventory::CabooseWhich::SpSlot0 => CabooseWhich::SpSlot0,
nexus_inventory::CabooseWhich::SpSlot1 => CabooseWhich::SpSlot1,
nexus_inventory::CabooseWhich::RotSlotA => CabooseWhich::RotSlotA,
nexus_inventory::CabooseWhich::RotSlotB => CabooseWhich::RotSlotB,
}
}
}

impl From<CabooseWhich> for nexus_types::inventory::CabooseWhich {
fn from(row: CabooseWhich) -> Self {
use nexus_types::inventory as nexus_inventory;
match row {
CabooseWhich::SpSlot0 => nexus_inventory::CabooseWhich::SpSlot0,
CabooseWhich::SpSlot1 => nexus_inventory::CabooseWhich::SpSlot1,
CabooseWhich::RotSlotA => nexus_inventory::CabooseWhich::RotSlotA,
CabooseWhich::RotSlotB => nexus_inventory::CabooseWhich::RotSlotB,
}
}
}
@@ -144,6 +168,16 @@ impl From<nexus_types::inventory::SpType> for SpType {
}
}

impl From<SpType> for nexus_types::inventory::SpType {
fn from(value: SpType) -> Self {
match value {
SpType::Sled => nexus_types::inventory::SpType::Sled,
SpType::Switch => nexus_types::inventory::SpType::Switch,
SpType::Power => nexus_types::inventory::SpType::Power,
}
}
}

/// See [`nexus_types::inventory::Collection`].
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = inv_collection)]
@@ -184,6 +218,15 @@ impl<'a> From<&'a BaseboardId> for HwBaseboardId {
}
}

impl From<HwBaseboardId> for BaseboardId {
fn from(row: HwBaseboardId) -> Self {
BaseboardId {
part_number: row.part_number,
serial_number: row.serial_number,
}
}
}

/// See [`nexus_types::inventory::Caboose`].
#[derive(
Queryable,
@@ -217,6 +260,17 @@ impl<'a> From<&'a Caboose> for SwCaboose {
}
}

impl From<SwCaboose> for Caboose {
fn from(row: SwCaboose) -> Self {
Self {
board: row.board,
git_commit: row.git_commit,
name: row.name,
version: row.version,
}
}
}

/// See [`nexus_types::inventory::Collection`].
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = inv_collection_error)]
@@ -253,6 +307,20 @@ pub struct InvServiceProcessor {
pub power_state: HwPowerState,
}

impl From<InvServiceProcessor> for nexus_types::inventory::ServiceProcessor {
fn from(row: InvServiceProcessor) -> Self {
Self {
time_collected: row.time_collected,
source: row.source,
sp_type: nexus_types::inventory::SpType::from(row.sp_type),
sp_slot: **row.sp_slot,
baseboard_revision: **row.baseboard_revision,
hubris_archive: row.hubris_archive_id,
power_state: PowerState::from(row.power_state),
}
}
}

/// Newtype wrapping the MGS-reported slot number for an SP
///
/// Current racks only have 32 slots for any given SP type. MGS represents the
@@ -340,6 +408,27 @@ pub struct InvRootOfTrust {
pub slot_b_sha3_256: Option<String>,
}

impl From<InvRootOfTrust> for nexus_types::inventory::RotState {
fn from(row: InvRootOfTrust) -> Self {
Self {
time_collected: row.time_collected,
source: row.source,
active_slot: RotSlot::from(row.slot_active),
persistent_boot_preference: RotSlot::from(
row.slot_boot_pref_persistent,
),
pending_persistent_boot_preference: row
.slot_boot_pref_persistent_pending
.map(RotSlot::from),
transient_boot_preference: row
.slot_boot_pref_transient
.map(RotSlot::from),
slot_a_sha3_256_digest: row.slot_a_sha3_256,
slot_b_sha3_256_digest: row.slot_b_sha3_256,
}
}
}

/// See [`nexus_types::inventory::CabooseFound`].
#[derive(Queryable, Clone, Debug, Selectable)]
#[diesel(table_name = inv_caboose)]
1 change: 1 addition & 0 deletions nexus/db-queries/Cargo.toml
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ expectorate.workspace = true
hyper-rustls.workspace = true
internal-dns.workspace = true
itertools.workspace = true
nexus-inventory.workspace = true
nexus-test-utils.workspace = true
omicron-sled-agent.workspace = true
omicron-test-utils.workspace = true
Loading