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
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
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:
"""
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")