implement terminate for Hickory

both in the NameServer and Resolver roles
This commit is contained in:
Jorge Aparicio 2024-03-11 16:41:59 +01:00
parent 6189787d9f
commit 4f277c1dbb
3 changed files with 73 additions and 6 deletions

View File

@ -132,7 +132,12 @@ impl Implementation {
match self {
Implementation::Bind => &["named", "-g", "-d5"],
Implementation::Hickory(_) => &["hickory-dns", "-d"],
Implementation::Hickory(_) => &[
"sh",
"-c",
"echo $$ > /tmp/hickory.pid
exec hickory-dns -d",
],
Implementation::Unbound => match role {
Role::NameServer => &["nsd", "-d"],
@ -146,7 +151,7 @@ impl Implementation {
match self {
Implementation::Bind => "/tmp/named.pid",
Implementation::Hickory(_) => unimplemented!(),
Implementation::Hickory(_) => "/tmp/hickory.pid",
Implementation::Unbound => match role {
Role::NameServer => "/tmp/nsd.pid",

View File

@ -371,7 +371,10 @@ kill -TERM $(cat {pidfile})"
self.container.status_ok(&["sh", "-c", &kill])?;
let output = self.state.child.wait()?;
if !output.status.success() {
// the hickory-dns binary does not do signal handling so it won't shut down gracefully; we
// will still get some logs so we'll ignore the fact that it fails to shut down ...
let is_hickory = matches!(self.implementation, Implementation::Hickory(_));
if !is_hickory && !output.status.success() {
return Err(
format!("could not terminate the `{}` process", self.implementation).into(),
);
@ -431,8 +434,12 @@ fn admin_ns(ns_count: usize) -> FQDN {
#[cfg(test)]
mod tests {
use std::thread;
use std::time::Duration;
use crate::client::{Client, DigSettings};
use crate::record::RecordType;
use crate::Repository;
use super::*;
@ -532,4 +539,32 @@ mod tests {
Ok(())
}
#[test]
fn terminate_hickory_works() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(
&Implementation::Hickory(Repository("https://github.com/hickory-dns/hickory-dns")),
FQDN::ROOT,
&network,
)?
.start()?;
// hickory-dns does not do signal handling so we need to wait until it prints something to
// the console
thread::sleep(Duration::from_millis(500));
let logs = ns.terminate()?;
eprintln!("{logs}");
let mut found = false;
for line in logs.lines() {
if line.contains("Hickory DNS") && line.contains("starting") {
found = true;
}
}
assert!(found);
Ok(())
}
}

View File

@ -48,8 +48,13 @@ kill -TERM $(cat {pidfile})"
self.container.status_ok(&["sh", "-c", &kill])?;
let output = self.child.wait()?;
if !output.status.success() {
return Err("could not terminate the `unbound` process".into());
// the hickory-dns binary does not do signal handling so it won't shut down gracefully; we
// will still get some logs so we'll ignore the fact that it fails to shut down ...
let is_hickory = matches!(self.implementation, Implementation::Hickory(_));
if !is_hickory && !output.status.success() {
return Err(
format!("could not terminate the `{}` process", self.implementation).into(),
);
}
assert!(
@ -148,7 +153,7 @@ impl ResolverSettings {
#[cfg(test)]
mod tests {
use crate::{name_server::NameServer, FQDN};
use crate::{name_server::NameServer, Repository, FQDN};
use super::*;
@ -179,4 +184,26 @@ mod tests {
Ok(())
}
#[test]
fn terminate_hickory_works() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(&Implementation::Unbound, FQDN::ROOT, &network)?.start()?;
let resolver = Resolver::new(&network, Root::new(ns.fqdn().clone(), ns.ipv4_addr()))
.start(&Implementation::Hickory(Repository(
"https://github.com/hickory-dns/hickory-dns",
)))?;
let logs = resolver.terminate()?;
eprintln!("{logs}");
let mut found = false;
for line in logs.lines() {
if line.contains("Hickory DNS") && line.contains("starting") {
found = true;
}
}
assert!(found);
Ok(())
}
}