Skip to content

Commit

Permalink
fix more of my new test
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Mar 9, 2024
1 parent 757018e commit 50394fe
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 41 deletions.
49 changes: 22 additions & 27 deletions nexus/reconfigurator/execution/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<SocketAddrV6>().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);
Expand All @@ -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)
}
};

Expand Down
68 changes: 54 additions & 14 deletions nexus/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 50394fe

Please sign in to comment.