]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Allow to use an arbitrary numeric identifier for NamedInstance
authorNicki Křížek <nicki@isc.org>
Fri, 24 Jan 2025 09:35:06 +0000 (10:35 +0100)
committerMichal Nowak <mnowak@isc.org>
Tue, 4 Feb 2025 12:35:38 +0000 (12:35 +0000)
In some cases, the numeric identifier doesn't correspond to the
directory name (i.e. `resolver` server in `shutdown` test, which is
supposed to be 10.53.0.3). These are typically servers that shouldn't be
auto-started by the runner, thus avoiding the typical `*ns<X>` name.

Support these server by allowing a fallback initialization with custom
numeric identifier in case it can't be parsed from the directory name.

bin/tests/system/isctest/instance.py
bin/tests/system/isctest/run.py
bin/tests/system/shutdown/tests_shutdown.py

index 97f42294e5f3d107bc8d6e61fc34ed848c9a0e77..5725b3e13219051bcf33ee636333343159547b5d 100644 (file)
@@ -50,13 +50,17 @@ class NamedInstance:
     def __init__(
         self,
         identifier: str,
+        num: Optional[int] = None,
         ports: Optional[NamedPorts] = None,
         rndc_logger: Optional[logging.Logger] = None,
         rndc_executor: Optional[RNDCExecutor] = None,
     ) -> None:
         """
-        `identifier` must be an `ns<X>` string, where `<X>` is an integer
-        identifier of the `named` instance this object should represent.
+        `identifier` is the name of the instance's directory
+
+        `num` is optional if the identifier is in a form of `ns<X>`, in which
+        case `<X>` is assumed to be numeric identifier; otherwise it must be
+        provided to assign a numeric identification to the server
 
         `ports` is the `NamedPorts` instance listing the UDP/TCP ports on which
         this `named` instance is listening for various types of traffic (both
@@ -75,7 +79,7 @@ class NamedInstance:
         self.system_test_name = self.directory.parent.name
 
         self.identifier = identifier
-        self.ip = self._identifier_to_ip(identifier)
+        self.num = self._identifier_to_num(identifier, num)
         if ports is None:
             ports = NamedPorts.from_env()
         self.ports = ports
@@ -83,12 +87,21 @@ class NamedInstance:
         self._rndc_executor = rndc_executor or RNDCBinaryExecutor()
         self._rndc_logger = rndc_logger
 
+    @property
+    def ip(self) -> str:
+        """IPv4 address of the instance."""
+        return f"10.53.0.{self.num}"
+
     @staticmethod
-    def _identifier_to_ip(identifier: str) -> str:
+    def _identifier_to_num(identifier: str, num: Optional[int] = None) -> int:
         regex_match = re.match(r"^ns(?P<index>[0-9]{1,2})$", identifier)
         if not regex_match:
-            raise ValueError("Invalid named instance identifier" + identifier)
-        return "10.53.0." + regex_match.group("index")
+            if num is None:
+                raise ValueError(f'Can\'t parse numeric identifier from "{identifier}"')
+            return num
+        parsed_num = int(regex_match.group("index"))
+        assert num is None or num == parsed_num, "mismatched num and identifier"
+        return parsed_num
 
     def rndc(self, command: str, ignore_errors: bool = False, log: bool = True) -> str:
         """
index d714f88a97214fcce07ed9c6eecec11e448d7340..9f8b22ccaefdf0cff14c5b796f73a2b9b1f101de 100644 (file)
@@ -137,18 +137,6 @@ def get_named_cmdline(cfg_dir, cfg_file="named.conf"):
     return named_cmdline
 
 
-def get_custom_named_instance(assumed_ns):
-    # 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.from_env()
-    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")
index 3c168a65560c205e5fce99e0b24ee7471ca34bcc..99929be93a1de54ce56edbb4c4b5f980fc791c2e 100755 (executable)
@@ -170,7 +170,7 @@ def test_named_shutdown(kill_method):
     cfg_dir = "resolver"
 
     named_cmdline = isctest.run.get_named_cmdline(cfg_dir)
-    instance = isctest.run.get_custom_named_instance("ns3")
+    instance = isctest.instance.NamedInstance("resolver", num=3)
 
     with open(os.path.join(cfg_dir, "named.run"), "ab") as named_log:
         with subprocess.Popen(