class ManagementSchema(SchemaNode):
"""
- Configuration of the Manager itself.
+ Management API configuration.
---
listen: Specifies where does the manager listen with its API. Can't be changed in runtime!
- backend: Forces manager to use a specific service manager. Defaults to autodetection.
- rundir: Directory where the manager can create files and which will be manager's cwd
- watchdog: Systemd watchdog configuration. Can only be used with systemd backend.
"""
- # the default listen path here MUST use the default rundir
listen: Listen = Listen({"unix-socket": "./manager.sock"})
- backend: BackendEnum = "auto"
- rundir: UncheckedPath = UncheckedPath(".")
- backend: BackendEnum = "auto"
- watchdog: Union[Literal[False], WatchDogSchema] = False
-
- def _validate(self) -> None:
- if self.watchdog and self.backend not in ["auto", "systemd"]:
- raise ValueError("'watchdog' can only be configured for 'systemd' backend")
class WebmgmtSchema(SchemaNode):
class ServerSchema(SchemaNode):
+ """
+ DNS resolver server control and management configuration.
+
+ ---
+ hostname: Internal Knot Resolver hostname. Default is hostname of machine.
+ groupid: Additional identifier in case more managers are running on single machine.
+ nsid: Name Server Identifier (RFC 5001) which allows DNS clients to request resolver to send back its NSID along with the reply to a DNS request.
+ workers: The number of running 'Knot Resolver daemon' (kresd) workers. Based on number of CPUs if set to 'auto'.
+ use-cache-gc: Use cache garbage collector (kres-cache-gc) automatically.
+ backend: Forces manager to use a specific service manager. Defaults to autodetection.
+ watchdog: Systemd watchdog configuration. Can only be used with 'systemd' backend.
+ rundir: Directory where the manager can create files and which will be manager's cwd
+ management: Management API configuration.
+ webmgmt: Legacy built-in web management API configuration.
+ """
+
class Raw(SchemaNode):
hostname: Optional[str] = None
groupid: Optional[str] = None
nsid: Optional[str] = None
workers: Union[Literal["auto"], int] = 1
use_cache_gc: bool = True
+ backend: BackendEnum = "auto"
+ watchdog: Union[Literal[False], WatchDogSchema] = False
+ rundir: UncheckedPath = UncheckedPath(".")
management: ManagementSchema = ManagementSchema()
webmgmt: Optional[WebmgmtSchema] = None
nsid: Optional[str]
workers: int
use_cache_gc: bool
+ backend: BackendEnum = "auto"
+ watchdog: Union[Literal[False], WatchDogSchema]
+ rundir: UncheckedPath = UncheckedPath(".")
management: ManagementSchema
webmgmt: Optional[WebmgmtSchema]
def _validate(self) -> None:
if self.workers < 0:
raise ValueError("Number of workers must be non-negative")
+ if self.watchdog and self.backend not in ["auto", "systemd"]:
+ raise ValueError("'watchdog' can only be configured for 'systemd' backend")
"""
# if configured, create a subprocess controller manually
controller: Optional[SubprocessController] = None
- if config_store.get().server.management.backend != "auto":
- controller = await get_controller_by_name(config_store.get(), config_store.get().server.management.backend)
+ if config_store.get().server.backend != "auto":
+ controller = await get_controller_by_name(config_store.get(), config_store.get().server.backend)
# Create KresManager. This will perform autodetection of available service managers and
# select the most appropriate to use (or use the one configured directly)
async def _deny_working_directory_changes(config_old: KresConfig, config_new: KresConfig) -> Result[None, str]:
- if config_old.server.management.rundir != config_new.server.management.rundir:
+ if config_old.server.rundir != config_new.server.rundir:
return Result.err("Changing manager's `rundir` during runtime is not allowed.")
return Result.ok(None)
def _set_working_directory(config_raw: ParsedTree):
config = KresConfig(config_raw)
- if not config.server.management.rundir.to_path().exists():
- raise KresdManagerException(f"`rundir` directory ({config.server.management.rundir}) does not exist!")
+ if not config.server.rundir.to_path().exists():
+ raise KresdManagerException(f"`rundir` directory ({config.server.rundir}) does not exist!")
- os.chdir(config.server.management.rundir.to_path())
+ os.chdir(config.server.rundir.to_path())
async def start_server(config: Union[Path, ParsedTree, _DefaultSentinel] = _DEFAULT_SENTINEL):
from pytest import raises
-from knot_resolver_manager.datamodel.server_schema import ManagementSchema
+from knot_resolver_manager.datamodel.server_schema import ServerSchema
from knot_resolver_manager.exceptions import KresdManagerException
-def test_management_watchdog():
- assert ManagementSchema({"watchdog": {"qname": "nic.cz.", "qtype": "A"}})
+def test_watchdog():
+ assert ServerSchema({"watchdog": {"qname": "nic.cz.", "qtype": "A"}})
with raises(KresdManagerException):
- ManagementSchema({"backend": "supervisord", "watchdog": {"qname": "nic.cz.", "qtype": "A"}})
+ ServerSchema({"backend": "supervisord", "watchdog": {"qname": "nic.cz.", "qtype": "A"}})