diff --git a/bin/tests/system/isctest/instance.py b/bin/tests/system/isctest/instance.py index 97f42294e5..5725b3e132 100644 --- a/bin/tests/system/isctest/instance.py +++ b/bin/tests/system/isctest/instance.py @@ -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` string, where `` 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`, in which + case `` 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[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: """ diff --git a/bin/tests/system/isctest/run.py b/bin/tests/system/isctest/run.py index d714f88a97..9f8b22ccae 100644 --- a/bin/tests/system/isctest/run.py +++ b/bin/tests/system/isctest/run.py @@ -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") diff --git a/bin/tests/system/shutdown/tests_shutdown.py b/bin/tests/system/shutdown/tests_shutdown.py index 3c168a6556..99929be93a 100755 --- a/bin/tests/system/shutdown/tests_shutdown.py +++ b/bin/tests/system/shutdown/tests_shutdown.py @@ -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(