From: Nicki Křížek Date: Thu, 23 Jan 2025 15:00:36 +0000 (+0100) Subject: Add start/stop wrappers to control NamedInstance X-Git-Tag: v9.21.5~4^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37699ad84b40aef38d6596d49f9625454a13cdac;p=thirdparty%2Fbind9.git Add start/stop wrappers to control NamedInstance The start()/stop() functions can be used in the pytests in the same way as start_server and stop_server functions were used in shell tests. Note that the servers obtained through the servers fixture are still started and stopped by the test runner at the start and end of the test. This makes these functions mostly useful for restarting the server(s) mid-test. --- diff --git a/bin/tests/system/isctest/instance.py b/bin/tests/system/isctest/instance.py index d3b3083262a..97f42294e5f 100644 --- a/bin/tests/system/isctest/instance.py +++ b/bin/tests/system/isctest/instance.py @@ -11,13 +11,15 @@ # See the COPYRIGHT file distributed with this work for additional # information regarding copyright ownership. -from typing import NamedTuple, Optional +from typing import List, NamedTuple, Optional import logging import os +from pathlib import Path import re from .rndc import RNDCBinaryExecutor, RNDCException, RNDCExecutor +from .run import perl from .log import info, LogFile, WatchLogFromStart, WatchLogFromHere @@ -67,6 +69,12 @@ class NamedInstance: `rndc_executor` is an object implementing the `RNDCExecutor` interface that is used for executing RNDC commands on this `named` instance. """ + self.directory = Path(identifier).absolute() + if not self.directory.is_dir(): + raise ValueError(f"{self.directory} isn't a directory") + self.system_test_name = self.directory.parent.name + + self.identifier = identifier self.ip = self._identifier_to_ip(identifier) if ports is None: ports = NamedPorts.from_env() @@ -175,3 +183,19 @@ class NamedInstance: info(fmt, args) else: self._rndc_logger.info(fmt, args) + + def stop(self, args: Optional[List[str]] = None) -> None: + """Stop the instance.""" + args = args or [] + perl( + f"{os.environ['srcdir']}/stop.pl", + [self.system_test_name, self.identifier] + args, + ) + + def start(self, args: Optional[List[str]] = None) -> None: + """Start the instance.""" + args = args or [] + perl( + f"{os.environ['srcdir']}/start.pl", + [self.system_test_name, self.identifier] + args, + )