From e48cd90c6eaca31a7e377256d46aad7aa5167958 Mon Sep 17 00:00:00 2001 From: Rain Date: Tue, 13 Aug 2024 12:24:30 -0700 Subject: [PATCH] [omicron-zones] ensure name_prefix for clickhouse-server is valid (#6312) Followup from #6297 -- `name_prefix` requires dashes. --- Cargo.lock | 1 + nexus-sled-agent-shared/Cargo.toml | 1 + nexus-sled-agent-shared/src/inventory.rs | 28 ++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b38a4905e..3f7b669e37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5140,6 +5140,7 @@ dependencies = [ "schemars", "serde", "sled-hardware-types", + "strum", "uuid", ] diff --git a/nexus-sled-agent-shared/Cargo.toml b/nexus-sled-agent-shared/Cargo.toml index 8e2358e902..544cebfbe4 100644 --- a/nexus-sled-agent-shared/Cargo.toml +++ b/nexus-sled-agent-shared/Cargo.toml @@ -14,4 +14,5 @@ omicron-workspace-hack.workspace = true schemars.workspace = true serde.workspace = true sled-hardware-types.workspace = true +strum.workspace = true uuid.workspace = true diff --git a/nexus-sled-agent-shared/src/inventory.rs b/nexus-sled-agent-shared/src/inventory.rs index 2f1361a6f2..2a94fc50db 100644 --- a/nexus-sled-agent-shared/src/inventory.rs +++ b/nexus-sled-agent-shared/src/inventory.rs @@ -20,6 +20,7 @@ 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. @@ -381,7 +382,9 @@ impl OmicronZoneType { /// the four representations if at all possible. If you must add a new one, /// please add it here rather than doing something ad-hoc in the calling code /// so it's more legible. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, EnumIter, +)] pub enum ZoneKind { BoundaryNtp, Clickhouse, @@ -453,7 +456,7 @@ impl ZoneKind { ZoneKind::BoundaryNtp | ZoneKind::InternalNtp => Self::NTP_PREFIX, ZoneKind::Clickhouse => "clickhouse", ZoneKind::ClickhouseKeeper => "clickhouse-keeper", - ZoneKind::ClickhouseServer => "clickhouse_server", + ZoneKind::ClickhouseServer => "clickhouse-server", // Note "cockroach" for historical reasons. ZoneKind::CockroachDb => "cockroach", ZoneKind::Crucible => "crucible", @@ -486,3 +489,24 @@ impl ZoneKind { } } } + +#[cfg(test)] +mod tests { + use omicron_common::api::external::Name; + use strum::IntoEnumIterator; + + use super::*; + + #[test] + fn test_name_prefixes() { + for zone_kind in ZoneKind::iter() { + let name_prefix = zone_kind.name_prefix(); + name_prefix.parse::().unwrap_or_else(|e| { + panic!( + "failed to parse name prefix {:?} for zone kind {:?}: {}", + name_prefix, zone_kind, e + ); + }); + } + } +}