Skip to content

Commit

Permalink
[nexus/sled-agent] use SledUuid in more places (#6695)
Browse files Browse the repository at this point in the history
Noticed this while working on nearby code.
  • Loading branch information
sunshowers authored Sep 27, 2024
1 parent 888f6a1 commit 48125c8
Show file tree
Hide file tree
Showing 32 changed files with 125 additions and 99 deletions.
1 change: 1 addition & 0 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ progenitor::generate_api!(
TypedUuidForInstanceKind = omicron_uuid_kinds::InstanceUuid,
TypedUuidForOmicronZoneKind = omicron_uuid_kinds::OmicronZoneUuid,
TypedUuidForPropolisKind = omicron_uuid_kinds::PropolisUuid,
TypedUuidForSledKind = omicron_uuid_kinds::SledUuid,
TypedUuidForZpoolKind = omicron_uuid_kinds::ZpoolUuid,
Vni = omicron_common::api::external::Vni,
ZpoolKind = omicron_common::zpool_name::ZpoolKind,
Expand Down
5 changes: 2 additions & 3 deletions nexus-sled-agent-shared/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ use omicron_common::{
disk::DiskVariant,
zpool_name::ZpoolName,
};
use omicron_uuid_kinds::ZpoolUuid;
use omicron_uuid_kinds::{DatasetUuid, OmicronZoneUuid};
use omicron_uuid_kinds::{SledUuid, ZpoolUuid};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
// Export this type for convenience -- this way, dependents don't have to
// depend on sled-hardware-types.
pub use sled_hardware_types::Baseboard;
use strum::EnumIter;
use uuid::Uuid;

/// Identifies information about disks which may be attached to Sleds.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
Expand Down Expand Up @@ -93,7 +92,7 @@ impl From<illumos_utils::zfs::DatasetProperties> for InventoryDataset {
/// Identity and basic status information about this sled agent
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
pub struct Inventory {
pub sled_id: Uuid,
pub sled_id: SledUuid,
pub sled_agent_address: SocketAddrV6,
pub sled_role: SledRole,
pub baseboard: Baseboard,
Expand Down
1 change: 1 addition & 0 deletions nexus/db-model/src/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct SledSystemHardware {
/// Database representation of a Sled.
#[derive(Queryable, Insertable, Debug, Clone, Selectable, Asset)]
#[diesel(table_name = sled)]
// TODO-cleanup: use #[asset(uuid_kind = SledKind)]
pub struct Sled {
#[diesel(embed)]
pub identity: SledIdentity,
Expand Down
3 changes: 2 additions & 1 deletion nexus/db-queries/src/db/datastore/physical_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ mod test {
use omicron_common::api::external::ByteCount;
use omicron_common::disk::{DiskIdentity, DiskVariant};
use omicron_test_utils::dev;
use omicron_uuid_kinds::SledUuid;
use std::net::{Ipv6Addr, SocketAddrV6};
use std::num::NonZeroU32;

Expand Down Expand Up @@ -692,7 +693,7 @@ mod test {
reservoir_size: ByteCount::from(1024),
sled_role: SledRole::Gimlet,
sled_agent_address: "[::1]:56792".parse().unwrap(),
sled_id: sled.id(),
sled_id: SledUuid::from_untyped_uuid(sled.id()),
usable_hardware_threads: 10,
usable_physical_ram: ByteCount::from(1024 * 1024),
disks,
Expand Down
2 changes: 1 addition & 1 deletion nexus/internal-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ pub trait NexusInternalApi {
/// Path parameters for Sled Agent requests (internal API)
#[derive(Deserialize, JsonSchema)]
pub struct SledAgentPathParam {
pub sled_id: Uuid,
pub sled_id: SledUuid,
}

/// Path parameters for Disk requests (internal API)
Expand Down
3 changes: 1 addition & 2 deletions nexus/inventory/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use nexus_types::inventory::ServiceProcessor;
use nexus_types::inventory::SledAgent;
use nexus_types::inventory::Zpool;
use omicron_uuid_kinds::CollectionKind;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::SledUuid;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
Expand Down Expand Up @@ -477,7 +476,7 @@ impl CollectionBuilder {
source: &str,
inventory: Inventory,
) -> Result<(), anyhow::Error> {
let sled_id = SledUuid::from_untyped_uuid(inventory.sled_id);
let sled_id = inventory.sled_id;

let baseboard_id = match inventory.baseboard {
Baseboard::Pc { .. } => None,
Expand Down
8 changes: 3 additions & 5 deletions nexus/inventory/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use nexus_types::inventory::CabooseWhich;
use nexus_types::inventory::Collection;
use nexus_types::inventory::RotPage;
use nexus_types::inventory::RotPageWhich;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::SledUuid;
use slog::o;
use slog::{debug, error};
use std::sync::Arc;
Expand Down Expand Up @@ -351,7 +349,7 @@ impl<'a> Collector<'a> {
}
};

let sled_id = SledUuid::from_untyped_uuid(inventory.sled_id);
let sled_id = inventory.sled_id;
self.in_progress.found_sled_inventory(&sled_agent_url, inventory)?;

let maybe_config =
Expand Down Expand Up @@ -385,12 +383,12 @@ mod test {
use omicron_common::zpool_name::ZpoolName;
use omicron_sled_agent::sim;
use omicron_uuid_kinds::OmicronZoneUuid;
use omicron_uuid_kinds::SledUuid;
use omicron_uuid_kinds::ZpoolUuid;
use std::fmt::Write;
use std::net::Ipv6Addr;
use std::net::SocketAddrV6;
use std::sync::Arc;
use uuid::Uuid;

fn dump_collection(collection: &Collection) -> String {
// Construct a stable, human-readable summary of the Collection
Expand Down Expand Up @@ -532,7 +530,7 @@ mod test {

async fn sim_sled_agent(
log: slog::Logger,
sled_id: Uuid,
sled_id: SledUuid,
zone_id: OmicronZoneUuid,
) -> sim::Server {
// Start a simulated sled agent.
Expand Down
3 changes: 1 addition & 2 deletions nexus/inventory/src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use nexus_types::inventory::RotPage;
use nexus_types::inventory::RotPageWhich;
use omicron_common::api::external::ByteCount;
use omicron_common::disk::DiskVariant;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::SledUuid;
use std::sync::Arc;
use strum::IntoEnumIterator;
Expand Down Expand Up @@ -558,7 +557,7 @@ pub fn sled_agent(
reservoir_size: ByteCount::from(1024),
sled_role,
sled_agent_address: "[::1]:56792".parse().unwrap(),
sled_id: sled_id.into_untyped_uuid(),
sled_id,
usable_hardware_threads: 10,
usable_physical_ram: ByteCount::from(1024 * 1024),
disks,
Expand Down
5 changes: 2 additions & 3 deletions nexus/reconfigurator/planning/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use omicron_common::disk::DiskIdentity;
use omicron_common::disk::DiskVariant;
use omicron_common::policy::INTERNAL_DNS_REDUNDANCY;
use omicron_common::policy::NEXUS_REDUNDANCY;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::PhysicalDiskUuid;
use omicron_uuid_kinds::SledUuid;
use omicron_uuid_kinds::ZpoolUuid;
Expand Down Expand Up @@ -551,7 +550,7 @@ impl Sled {
reservoir_size: ByteCount::from(1024),
sled_role,
sled_agent_address,
sled_id: sled_id.into_untyped_uuid(),
sled_id,
usable_hardware_threads: 10,
usable_physical_ram: ByteCount::from(1024 * 1024),
// Populate disks, appearing like a real device.
Expand Down Expand Up @@ -705,7 +704,7 @@ impl Sled {
reservoir_size: inv_sled_agent.reservoir_size,
sled_role: inv_sled_agent.sled_role,
sled_agent_address: inv_sled_agent.sled_agent_address,
sled_id: sled_id.into_untyped_uuid(),
sled_id,
usable_hardware_threads: inv_sled_agent.usable_hardware_threads,
usable_physical_ram: inv_sled_agent.usable_physical_ram,
disks: vec![],
Expand Down
3 changes: 1 addition & 2 deletions nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ use omicron_common::api::external::NameOrId;
use omicron_common::api::external::ResourceType;
use omicron_common::api::internal::shared::ExternalPortDiscovery;
use omicron_common::api::internal::shared::LldpAdminStatus;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::SledUuid;
use oxnet::IpNet;
use sled_agent_client::types::AddSledRequest;
Expand Down Expand Up @@ -886,7 +885,7 @@ impl super::Nexus {
generation: 0,
schema_version: 1,
body: StartSledAgentRequestBody {
id: allocation.sled_id.into_untyped_uuid(),
id: allocation.sled_id.into(),
rack_id: allocation.rack_id,
use_trust_quorum: true,
is_lrtq_learner: true,
Expand Down
17 changes: 13 additions & 4 deletions nexus/src/internal_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ impl NexusInternalApi for NexusInternalApiImpl {
let path = path_params.into_inner();
let sled_id = &path.sled_id;
let handler = async {
let (.., sled) =
nexus.sled_lookup(&opctx, sled_id)?.fetch().await?;
let (.., sled) = nexus
.sled_lookup(&opctx, &sled_id.into_untyped_uuid())?
.fetch()
.await?;
Ok(HttpResponseOk(sled.into()))
};
apictx
Expand All @@ -103,7 +105,9 @@ impl NexusInternalApi for NexusInternalApiImpl {
let info = sled_info.into_inner();
let sled_id = &path.sled_id;
let handler = async {
nexus.upsert_sled(&opctx, *sled_id, info).await?;
nexus
.upsert_sled(&opctx, sled_id.into_untyped_uuid(), info)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
Expand All @@ -122,7 +126,12 @@ impl NexusInternalApi for NexusInternalApiImpl {
let path = path_params.into_inner();
let sled_id = &path.sled_id;
let handler = async {
nexus.sled_request_firewall_rules(&opctx, *sled_id).await?;
nexus
.sled_request_firewall_rules(
&opctx,
sled_id.into_untyped_uuid(),
)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx
Expand Down
6 changes: 3 additions & 3 deletions nexus/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub struct ControlPlaneTestContext<N> {

impl<N: NexusServer> ControlPlaneTestContext<N> {
pub fn first_sled(&self) -> SledUuid {
SledUuid::from_untyped_uuid(self.sled_agent.sled_agent.id)
self.sled_agent.sled_agent.id
}

pub fn all_sled_agents(&self) -> impl Iterator<Item = &sim::Server> {
Expand Down Expand Up @@ -805,7 +805,7 @@ impl<'a, N: NexusServer> ControlPlaneTestContextBuilder<'a, N> {
(self.sled_agent2.as_ref(), &self.blueprint_zones2),
] {
if let Some(sa) = maybe_sled_agent {
let sled_id = SledUuid::from_untyped_uuid(sa.sled_agent.id);
let sled_id = sa.sled_agent.id;
blueprint_zones.insert(
sled_id,
BlueprintZonesConfig {
Expand Down Expand Up @@ -1432,7 +1432,7 @@ pub async fn start_sled_agent(
sim_mode: sim::SimMode,
) -> Result<sim::Server, String> {
let config = sim::Config::for_testing(
id.into_untyped_uuid(),
id,
sim_mode,
Some(nexus_address),
Some(update_directory),
Expand Down
8 changes: 4 additions & 4 deletions nexus/test-utils/src/resource_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ impl<'a, N: NexusServer> DiskTestBuilder<'a, N> {
Self {
cptestctx,
sled_agents: WhichSledAgents::Specific(
SledUuid::from_untyped_uuid(cptestctx.sled_agent.sled_agent.id),
cptestctx.sled_agent.sled_agent.id,
),
zpool_count: DiskTest::<'a, N>::DEFAULT_ZPOOL_COUNT,
}
Expand Down Expand Up @@ -985,7 +985,7 @@ impl<'a, N: NexusServer> DiskTest<'a, N> {
}
WhichSledAgents::All => cptestctx
.all_sled_agents()
.map(|agent| SledUuid::from_untyped_uuid(agent.sled_agent.id))
.map(|agent| agent.sled_agent.id)
.collect(),
};

Expand Down Expand Up @@ -1023,7 +1023,7 @@ impl<'a, N: NexusServer> DiskTest<'a, N> {
sleds
.into_iter()
.find_map(|server| {
if server.sled_agent.id == sled_id.into_untyped_uuid() {
if server.sled_agent.id == sled_id {
Some(server.sled_agent.clone())
} else {
None
Expand Down Expand Up @@ -1087,7 +1087,7 @@ impl<'a, N: NexusServer> DiskTest<'a, N> {
let sled_agent = sleds
.into_iter()
.find_map(|server| {
if server.sled_agent.id == sled_id.into_untyped_uuid() {
if server.sled_agent.id == sled_id {
Some(server.sled_agent.clone())
} else {
None
Expand Down
8 changes: 3 additions & 5 deletions nexus/tests/integration_tests/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,7 @@ async fn test_instance_start_creates_networking_state(

let mut checked = false;
for agent in &sled_agents {
if Some(agent.id) == with_vmm.sled_id().map(SledUuid::into_untyped_uuid)
{
if Some(agent.id) == with_vmm.sled_id() {
assert_sled_vpc_routes(
agent,
&opctx,
Expand Down Expand Up @@ -1010,8 +1009,7 @@ async fn test_instance_migrate_v2p_and_routes(
assert_sled_v2p_mappings(sled_agent, &nics[0], guest_nics[0].vni).await;
}

let testctx_sled_id =
SledUuid::from_untyped_uuid(cptestctx.sled_agent.sled_agent.id);
let testctx_sled_id = cptestctx.sled_agent.sled_agent.id;
let dst_sled_id = if original_sled_id == testctx_sled_id {
other_sleds[0].0
} else {
Expand Down Expand Up @@ -1095,7 +1093,7 @@ async fn test_instance_migrate_v2p_and_routes(
// updated here because Nexus presumes that the instance's new sled
// agent will have updated any mappings there. Remove this bifurcation
// when Nexus programs all mappings explicitly.
if sled_agent.id != dst_sled_id.into_untyped_uuid() {
if sled_agent.id != dst_sled_id {
assert_sled_v2p_mappings(sled_agent, &nics[0], guest_nics[0].vni)
.await;
} else {
Expand Down
9 changes: 3 additions & 6 deletions openapi/nexus-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,7 @@
"name": "sled_id",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
"$ref": "#/components/schemas/TypedUuidForSledKind"
}
}
],
Expand Down Expand Up @@ -1238,8 +1237,7 @@
"name": "sled_id",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
"$ref": "#/components/schemas/TypedUuidForSledKind"
}
}
],
Expand Down Expand Up @@ -1277,8 +1275,7 @@
"name": "sled_id",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
"$ref": "#/components/schemas/TypedUuidForSledKind"
}
}
],
Expand Down
14 changes: 10 additions & 4 deletions openapi/sled-agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -3362,8 +3362,7 @@
"type": "string"
},
"sled_id": {
"type": "string",
"format": "uuid"
"$ref": "#/components/schemas/TypedUuidForSledKind"
},
"sled_role": {
"$ref": "#/components/schemas/SledRole"
Expand Down Expand Up @@ -4987,8 +4986,11 @@
"properties": {
"id": {
"description": "Uuid of the Sled Agent to be created.",
"type": "string",
"format": "uuid"
"allOf": [
{
"$ref": "#/components/schemas/TypedUuidForSledKind"
}
]
},
"is_lrtq_learner": {
"description": "Is this node an LRTQ learner node?\n\nWe only put the node into learner mode if `use_trust_quorum` is also true.",
Expand Down Expand Up @@ -5116,6 +5118,10 @@
"type": "string",
"format": "uuid"
},
"TypedUuidForSledKind": {
"type": "string",
"format": "uuid"
},
"TypedUuidForZpoolKind": {
"type": "string",
"format": "uuid"
Expand Down
Loading

0 comments on commit 48125c8

Please sign in to comment.