]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Integrate the Python RNDC client into isctest
authorNicki Křížek <nicki@isc.org>
Tue, 14 Jul 2026 11:42:25 +0000 (11:42 +0000)
committerNicki Křížek <nicki@isc.org>
Thu, 23 Jul 2026 10:03:36 +0000 (12:03 +0200)
Register the rndc module in the isctest package and provide a
NamedInstance.rndc_client() factory next to rndc(), so tests can grab
a client for an instance's control channel without repeating the
address and port details.

Assisted-by: Claude:claude-fable-5
bin/tests/system/isctest/__init__.py
bin/tests/system/isctest/instance.py

index 326b77f0d4e82d4e717f1c1385db3c6c81c109a7..9459d93b8155ee0fd049bb05c645e8303fc0b2f6 100644 (file)
@@ -17,6 +17,7 @@ from . import (  # pylint: disable=redefined-builtin
     kasp,
     log,
     query,
+    rndc,
     run,
     template,
     transfer,
@@ -37,6 +38,7 @@ __all__ = [
     "kasp",
     "log",
     "query",
+    "rndc",
     "run",
     "template",
     "transfer",
index c6e83018143c1cc9fca3f7e7814cafd2cf33e3bf..d6b7fe0501fba3a956fc13d530f8cba1158ef334 100644 (file)
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
+from collections.abc import Iterator
 from pathlib import Path
 from typing import NamedTuple
 
 import abc
+import contextlib
 import os
 import re
 
@@ -24,6 +26,7 @@ import dns.update
 
 from .log import WatchLogFromHere, WatchLogFromStart, debug
 from .query import udp
+from .rndc import RNDCClient
 from .run import CmdResult, EnvCmd, perl
 from .text import TextFile
 
@@ -191,6 +194,21 @@ class NamedInstance(ServerInstance):
         """
         return self._rndc(command, timeout=timeout, **kwargs)
 
+    @contextlib.contextmanager
+    def rndc_client(self, timeout: float = 10) -> Iterator[RNDCClient]:
+        """
+        Connect a Python RNDC client to this instance's control channel;
+        a fast alternative to `rndc()` which does not spawn the rndc
+        binary. Only usable as a context manager:
+
+        ```python
+        with ns1.rndc_client() as client:
+            client.call("status")
+        ```
+        """
+        with RNDCClient(self.ip, self.ports.rndc, timeout=timeout) as client:
+            yield client
+
     def nsupdate(
         self, update_msg: dns.update.UpdateMessage, expected_rcode=dns.rcode.NOERROR
     ):