From 50394febbb946c978dacaa9561becdfaf4bcdfba Mon Sep 17 00:00:00 2001 From: David Pacheco Date: Fri, 8 Mar 2024 22:06:46 -0800 Subject: [PATCH] fix more of my new test --- nexus/reconfigurator/execution/src/dns.rs | 49 ++++++++-------- nexus/test-utils/src/lib.rs | 68 ++++++++++++++++++----- 2 files changed, 76 insertions(+), 41 deletions(-) diff --git a/nexus/reconfigurator/execution/src/dns.rs b/nexus/reconfigurator/execution/src/dns.rs index 8d0f46e006..ab0b9b17ef 100644 --- a/nexus/reconfigurator/execution/src/dns.rs +++ b/nexus/reconfigurator/execution/src/dns.rs @@ -22,11 +22,6 @@ use nexus_types::identity::Resource; use nexus_types::internal_api::params::DnsConfigParams; use nexus_types::internal_api::params::DnsConfigZone; use nexus_types::internal_api::params::DnsRecord; -use omicron_common::address::CLICKHOUSE_KEEPER_PORT; -use omicron_common::address::CRUCIBLE_PORT; -use omicron_common::address::DNS_HTTP_PORT; -use omicron_common::address::NTP_PORT; -use omicron_common::address::OXIMETER_PORT; use omicron_common::api::external::Error; use omicron_common::api::external::Generation; use omicron_common::api::external::InternalContext; @@ -237,36 +232,32 @@ pub fn blueprint_internal_dns_config( let mut dns_builder = DnsConfigBuilder::new(); // XXX-dap don't panic + // See oxidecomputer/omicron#4988. fn parse_port(address: &str) -> u16 { address.parse::().unwrap().port() } - // The code below assumes that all zones are using the default port numbers. - // That should be true, as those are the only ports ever used today. - // In an ideal world, the correct port would be pulled out of the - // `OmicronZoneType` variant instead. Although that information is present, - // it's irritatingly non-trivial to do right now because SocketAddrs are - // represented as strings, so we'd need to parse all of them and handle all - // the errors, even though they should never happen. - // See oxidecomputer/omicron#4988. for (_, omicron_zone) in blueprint.all_omicron_zones() { if !blueprint.zones_in_service.contains(&omicron_zone.id) { continue; } let (service_name, port) = match &omicron_zone.zone_type { - OmicronZoneType::BoundaryNtp { .. } => { - (ServiceName::BoundaryNtp, NTP_PORT) + OmicronZoneType::BoundaryNtp { address, .. } => { + let port = parse_port(&address); + (ServiceName::BoundaryNtp, port) } - OmicronZoneType::InternalNtp { .. } => { - (ServiceName::InternalNtp, NTP_PORT) + OmicronZoneType::InternalNtp { address, .. } => { + let port = parse_port(&address); + (ServiceName::InternalNtp, port) } OmicronZoneType::Clickhouse { address, .. } => { let port = parse_port(&address); (ServiceName::Clickhouse, port) } - OmicronZoneType::ClickhouseKeeper { .. } => { - (ServiceName::ClickhouseKeeper, CLICKHOUSE_KEEPER_PORT) + OmicronZoneType::ClickhouseKeeper { address, .. } => { + let port = parse_port(&address); + (ServiceName::ClickhouseKeeper, port) } OmicronZoneType::CockroachDb { address, .. } => { let port = parse_port(&address); @@ -276,21 +267,25 @@ pub fn blueprint_internal_dns_config( let port = parse_port(internal_address); (ServiceName::Nexus, port) } - OmicronZoneType::Crucible { .. } => { - (ServiceName::Crucible(omicron_zone.id), CRUCIBLE_PORT) + OmicronZoneType::Crucible { address, .. } => { + let port = parse_port(address); + (ServiceName::Crucible(omicron_zone.id), port) } OmicronZoneType::CruciblePantry { address } => { let port = parse_port(address); (ServiceName::CruciblePantry, port) } - OmicronZoneType::Oximeter { .. } => { - (ServiceName::Oximeter, OXIMETER_PORT) + OmicronZoneType::Oximeter { address } => { + let port = parse_port(address); + (ServiceName::Oximeter, port) } - OmicronZoneType::ExternalDns { .. } => { - (ServiceName::ExternalDns, DNS_HTTP_PORT) + OmicronZoneType::ExternalDns { http_address, .. } => { + let port = parse_port(http_address); + (ServiceName::ExternalDns, port) } - OmicronZoneType::InternalDns { .. } => { - (ServiceName::InternalDns, DNS_HTTP_PORT) + OmicronZoneType::InternalDns { http_address, .. } => { + let port = parse_port(http_address); + (ServiceName::InternalDns, port) } }; diff --git a/nexus/test-utils/src/lib.rs b/nexus/test-utils/src/lib.rs index 1967e66f05..3bb2508739 100644 --- a/nexus/test-utils/src/lib.rs +++ b/nexus/test-utils/src/lib.rs @@ -61,6 +61,7 @@ use trust_dns_resolver::config::ResolverOpts; use trust_dns_resolver::TokioAsyncResolver; use uuid::Uuid; +use chrono::SecondsFormat; use omicron_common::api::external::Generation; use omicron_common::api::external::Vni; pub use sim::TEST_HARDWARE_THREADS; @@ -193,18 +194,6 @@ impl RackInitRequestBuilder { // Keeps track of: // - The "ServicePutRequest" (for handoff to Nexus) // - The internal DNS configuration for this service - // XXX-dap remove me - fn add_service( - &mut self, - address: SocketAddrV6, - kind: ServiceKind, - service_name: internal_dns::ServiceName, - sled_id: Uuid, - ) { - let zone_id = Uuid::new_v4(); - self.add_service_with_id(zone_id, address, kind, service_name, sled_id); - } - fn add_service_with_id( &mut self, zone_id: Uuid, @@ -957,7 +946,9 @@ impl<'a, N: NexusServer> ControlPlaneTestContextBuilder<'a, N> { .mac_addrs .next() .expect("ran out of MAC addresses"); - self.rack_init_builder.add_service( + let zone_id = Uuid::new_v4(); + self.rack_init_builder.add_service_with_id( + zone_id, dropshot_address, ServiceKind::ExternalDns { external_address: (*dns_address.ip()).into(), @@ -975,6 +966,36 @@ impl<'a, N: NexusServer> ControlPlaneTestContextBuilder<'a, N> { internal_dns::ServiceName::ExternalDns, sled_id, ); + + let zpool_id = Uuid::new_v4(); + let pool_name = illumos_utils::zpool::ZpoolName::new_external(zpool_id) + .to_string() + .parse() + .unwrap(); + self.omicron_zones.push(OmicronZoneConfig { + id: zone_id, + underlay_address: *dropshot_address.ip(), + zone_type: OmicronZoneType::ExternalDns { + dataset: OmicronZoneDataset { pool_name }, + dns_address: dns_address.to_string(), + http_address: dropshot_address.to_string(), + nic: NetworkInterface { + id: Uuid::new_v4(), + ip: (*dns_address.ip()).into(), + kind: NetworkInterfaceKind::Service(zone_id), + mac, + name: format!("external-dns-{}", zone_id).parse().unwrap(), + primary: true, + slot: 0, + subnet: sled_agent_client::types::Ipv4Net::from( + *DNS_OPTE_IPV4_SUBNET, + ) + .into(), + vni: Vni::SERVICES_VNI, + }, + }, + }); + self.external_dns = Some(dns); } @@ -987,13 +1008,32 @@ impl<'a, N: NexusServer> ControlPlaneTestContextBuilder<'a, N> { let SocketAddr::V6(address) = dns.dropshot_server.local_addr() else { panic!("Unsupported IPv4 DNS address"); }; - self.rack_init_builder.add_service( + let zone_id = Uuid::new_v4(); + self.rack_init_builder.add_service_with_id( + zone_id, address, ServiceKind::InternalDns, internal_dns::ServiceName::InternalDns, sled_id, ); + let zpool_id = Uuid::new_v4(); + let pool_name = illumos_utils::zpool::ZpoolName::new_external(zpool_id) + .to_string() + .parse() + .unwrap(); + self.omicron_zones.push(OmicronZoneConfig { + id: zone_id, + underlay_address: *address.ip(), + zone_type: OmicronZoneType::InternalDns { + dataset: OmicronZoneDataset { pool_name }, + dns_address: dns.dns_server.local_address().to_string(), + http_address: address.to_string(), + gz_address: Ipv6Addr::LOCALHOST, + gz_address_index: 0, + }, + }); + self.internal_dns = Some(dns); }