Extract "custom" named instances support to isctest.run module

(cherry picked from commit 2cec1de43b)
This commit is contained in:
Michal Nowak 2024-07-22 16:20:02 +02:00
parent 1220435e27
commit 4e3cc58eba
No known key found for this signature in database
2 changed files with 57 additions and 26 deletions

View file

@ -9,12 +9,26 @@
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
import os
import subprocess
import time
from typing import Optional
from typing import Any, Optional
import isctest.log
import dns.message
# compatiblity with dnspython<2.0.0
try:
# In dnspython>=2.0.0, dns.rcode.Rcode class is available
# pylint: disable=invalid-name
dns_rcode = dns.rcode.Rcode # type: Any
except AttributeError:
# In dnspython<2.0.0, selected rcodes are available as integers directly
# from dns.rcode
dns_rcode = dns.rcode
def cmd( # pylint: disable=too-many-arguments
args,
@ -70,3 +84,38 @@ def retry_with_timeout(func, timeout, delay=1, msg=None):
if msg is None:
msg = f"{func.__module__}.{func.__qualname__} timed out after {timeout} s"
assert False, msg
def get_named_cmdline(cfg_dir, cfg_file="named.conf"):
cfg_dir = os.path.join(os.getcwd(), cfg_dir)
assert os.path.isdir(cfg_dir)
cfg_file = os.path.join(cfg_dir, cfg_file)
assert os.path.isfile(cfg_file)
named = os.getenv("NAMED")
assert named is not None
named_cmdline = [named, "-c", cfg_file, "-d", "99", "-g"]
return named_cmdline
def get_custom_named_instance(assumed_ns, ports):
# This test launches and monitors a named instance itself rather than using
# bin/tests/system/start.pl, so manually defining a NamedInstance here is
# necessary for sending RNDC commands to that instance. If this "custom"
# instance listens on 10.53.0.3, use "ns3" as the identifier passed to
# the NamedInstance constructor.
named_ports = isctest.instance.NamedPorts(
dns=ports["PORT"], rndc=ports["CONTROLPORT"]
)
instance = isctest.instance.NamedInstance(assumed_ns, named_ports)
return instance
def assert_custom_named_is_alive(named_proc, resolver_ip):
assert named_proc.poll() is None, "named isn't running"
msg = dns.message.make_query("version.bind", "TXT", "CH")
isctest.query.tcp(msg, resolver_ip, expected_rcode=dns_rcode.NOERROR)

View file

@ -156,37 +156,19 @@ def wait_for_proc_termination(proc, max_timeout=10):
["rndc", "sigterm"],
)
def test_named_shutdown(ports, kill_method):
# pylint: disable-msg=too-many-locals
cfg_dir = os.path.join(os.getcwd(), "resolver")
assert os.path.isdir(cfg_dir)
cfg_file = os.path.join(cfg_dir, "named.conf")
assert os.path.isfile(cfg_file)
named = os.getenv("NAMED")
assert named is not None
# This test launches and monitors a named instance itself rather than using
# bin/tests/system/start.pl, so manually defining a NamedInstance here is
# necessary for sending RNDC commands to that instance. This "custom"
# instance listens on 10.53.0.3, so use "ns3" as the identifier passed to
# the NamedInstance constructor.
named_ports = isctest.instance.NamedPorts(
dns=ports["PORT"], rndc=ports["CONTROLPORT"]
)
instance = isctest.instance.NamedInstance("ns3", named_ports)
resolver_ip = "10.53.0.3"
named_cmdline = [named, "-c", cfg_file, "-d", "99", "-g"]
cfg_dir = "resolver"
named_cmdline = isctest.run.get_named_cmdline(cfg_dir)
instance = isctest.run.get_custom_named_instance("ns3", ports)
with open(os.path.join(cfg_dir, "named.run"), "ab") as named_log:
with subprocess.Popen(
named_cmdline, cwd=cfg_dir, stderr=named_log
) as named_proc:
try:
assert named_proc.poll() is None, "named isn't running"
msg = dns.message.make_query("version.bind", "TXT", "CH")
res = isctest.query.tcp(msg, resolver_ip)
isctest.check.noerror(res)
isctest.run.assert_custom_named_is_alive(named_proc, resolver_ip)
do_work(
named_proc,
resolver_ip,