Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Remove the unused instance-DNS view and its hostname-derivation function.
--
-- `dns_records_instance` derived forward A/AAAA names directly from instance IP
-- addresses via nico_inet_to_dns_hostname(). It was dropped from the served
-- `dns_records` view in 20250113220120 and has not been served since. IP-derived
-- hostnames are produced by the host-naming strategy (the Rust
-- `address_to_hostname` helper) and stored in machine_interfaces.hostname, which
-- the shortname/adm views serve -- so this view and function are a stale SQL
-- duplicate of that logic, with no remaining consumers.
DROP VIEW IF EXISTS dns_records_instance;
DROP FUNCTION IF EXISTS nico_inet_to_dns_hostname(inet);
160 changes: 0 additions & 160 deletions crates/api-db/src/dns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ pub fn arpa_qname_to_ip(qname: &str) -> Option<IpAddr> {

#[cfg(test)]
mod tests {
use carbide_test_support::Outcome::*;
use carbide_test_support::{Case, check_cases_async};
use sqlx::Row;

#[test]
fn test_normalize_domain_name() {
Expand Down Expand Up @@ -115,163 +112,6 @@ mod tests {
);
}

#[crate::sqlx_test]
async fn test_dns_hostname_from_ipv6_expands_to_rust_format(pool: sqlx::PgPool) {
check_cases_async(
[
Case {
scenario: "ipv4 dotted-quad becomes dashed octets",
input: "192.168.1.2",
expect: Yields("192-168-1-2".to_string()),
},
Case {
scenario: "unspecified address expands every hextet",
input: "::",
expect: Yields("0000-0000-0000-0000-0000-0000-0000-0000".to_string()),
},
Case {
scenario: "loopback keeps the low hextet",
input: "::1",
expect: Yields("0000-0000-0000-0000-0000-0000-0000-0001".to_string()),
},
Case {
scenario: "documentation prefix expands in full",
input: "2001:db8::2",
expect: Yields("2001-0db8-0000-0000-0000-0000-0000-0002".to_string()),
},
Case {
scenario: "ipv4-mapped folds into the trailing hextets",
input: "::ffff:192.0.2.128",
expect: Yields("0000-0000-0000-0000-0000-ffff-c000-0280".to_string()),
},
],
|address| {
// Clone the (Arc-backed) pool per case so the future owns it and
// the closure stays `Fn` — see check_cases_async's signature.
let pool = pool.clone();
async move {
sqlx::query_scalar::<_, String>("SELECT nico_inet_to_dns_hostname($1::inet)")
.bind(address)
.fetch_one(&pool)
.await
.map_err(drop)
}
},
)
.await;
}

#[crate::sqlx_test]
async fn test_dns_records_instance_ipv6_qname_expands_hostname(pool: sqlx::PgPool) {
sqlx::query(
"INSERT INTO domains (id, name)
VALUES ('10000000-0000-0000-0000-000000000001', 'dwrt1.com')",
)
.execute(&pool)
.await
.unwrap();

sqlx::query(
"INSERT INTO network_segments (id, name, version)
VALUES ('20000000-0000-0000-0000-000000000001', 'tenant-segment', 'test')",
)
.execute(&pool)
.await
.unwrap();

sqlx::query(
"INSERT INTO machines (id, dpf)
VALUES ('host-1', '{\"enabled\": true, \"used_for_ingestion\": false}'::jsonb)",
)
.execute(&pool)
.await
.unwrap();

sqlx::query(
"INSERT INTO machine_interfaces (
id,
machine_id,
segment_id,
mac_address,
domain_id,
primary_interface,
hostname,
association_type
)
VALUES (
'30000000-0000-0000-0000-000000000001',
'host-1',
'20000000-0000-0000-0000-000000000001',
'02:00:00:00:00:01',
'10000000-0000-0000-0000-000000000001',
true,
'host-1',
'Machine'
)",
)
.execute(&pool)
.await
.unwrap();

let network_config = serde_json::json!({
"interfaces": [
{
"function_id": { "type": "physical" },
"ip_addrs": {
"unspecified": "::",
"loopback": "::1",
"tenant": "2001:db8::2"
}
}
]
});

sqlx::query("INSERT INTO instances (machine_id, network_config) VALUES ($1, $2::jsonb)")
.bind("host-1")
.bind(network_config)
.execute(&pool)
.await
.unwrap();

let rows = sqlx::query(
"SELECT DISTINCT q_name, host(resource_record) AS resource_record
FROM dns_records_instance",
)
.fetch_all(&pool)
.await
.unwrap();

let records = rows
.iter()
.map(|row| {
(
row.try_get::<String, _>("resource_record").unwrap(),
row.try_get::<String, _>("q_name").unwrap(),
)
})
.collect::<Vec<_>>();

let expected_records = vec![
(
"::".to_string(),
"0000-0000-0000-0000-0000-0000-0000-0000.dwrt1.com.".to_string(),
),
(
"::1".to_string(),
"0000-0000-0000-0000-0000-0000-0000-0001.dwrt1.com.".to_string(),
),
(
"2001:db8::2".to_string(),
"2001-0db8-0000-0000-0000-0000-0000-0002.dwrt1.com.".to_string(),
),
];

assert_eq!(records.len(), expected_records.len());
for expected_record in expected_records {
assert!(records.contains(&expected_record));
}
}

#[crate::sqlx_test]
async fn find_ptr_record_resolves_address_to_hostname(pool: sqlx::PgPool) {
sqlx::query(
Expand Down
Loading