From 6e87760b174d68477a4d09f4ef9940b29a477644 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20Mr=C3=A1zek?= Date: Mon, 19 Jun 2023 12:04:47 +0200 Subject: [PATCH] manager: allowed to get 'rundir' from default config --- .../datamodel/config_schema.py | 8 ++------ manager/knot_resolver_manager/server.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/manager/knot_resolver_manager/datamodel/config_schema.py b/manager/knot_resolver_manager/datamodel/config_schema.py index c57a183f2..4fdf5801d 100644 --- a/manager/knot_resolver_manager/datamodel/config_schema.py +++ b/manager/knot_resolver_manager/datamodel/config_schema.py @@ -205,9 +205,5 @@ def get_rundir_without_validation(data: Dict[str, Any]) -> Dir: """ if "rundir" in data: - rundir = data["rundir"] - else: - _ = KresConfig(data) # this should throw a descriptive error - assert False - - return Dir(rundir, object_path="/rundir") + return Dir(data["rundir"], object_path="/rundir") + return KresConfig(data).rundir # this should throw a descriptive error diff --git a/manager/knot_resolver_manager/server.py b/manager/knot_resolver_manager/server.py index 88fb09902..58e22e97c 100644 --- a/manager/knot_resolver_manager/server.py +++ b/manager/knot_resolver_manager/server.py @@ -24,7 +24,11 @@ from knot_resolver_manager.compat import asyncio as asyncio_compat from knot_resolver_manager.config_store import ConfigStore from knot_resolver_manager.constants import DEFAULT_MANAGER_CONFIG_FILE, PID_FILE_NAME, init_user_constants from knot_resolver_manager.datamodel.config_schema import KresConfig, get_rundir_without_validation -from knot_resolver_manager.datamodel.globals import Context, set_global_validation_context +from knot_resolver_manager.datamodel.globals import ( + Context, + reset_global_validation_context, + set_global_validation_context, +) from knot_resolver_manager.datamodel.management_schema import ManagementSchema from knot_resolver_manager.exceptions import CancelStartupExecInsteadException, KresManagerException from knot_resolver_manager.kresd_controller import get_best_controller_implementation @@ -476,10 +480,6 @@ async def start_server(config: Path = DEFAULT_MANAGER_CONFIG_FILE) -> int: # Make sure that the config path does not change meaning when we change working directory config = config.absolute() - # before processing any configuration, set validation context - # - resolve_root = root against which all relative paths will be resolved - set_global_validation_context(Context(config.parent)) - # Preprocess config - load from file or in general take it to the last step before validation. config_raw = await _load_raw_config(config) @@ -487,12 +487,18 @@ async def start_server(config: Path = DEFAULT_MANAGER_CONFIG_FILE) -> int: # working directory. # # If we fail to read rundir from unparsed config, the first config validation error comes from here + set_global_validation_context(Context(config.parent, False)) # Strict validation for Paths is off. _set_working_directory(config_raw) + reset_global_validation_context() # We don't want more than one manager in a single working directory. So we lock it with a PID file. # Warning - this does not prevent multiple managers with the same naming of kresd service. _lock_working_directory() + # before processing any configuration, set validation context + # - resolve_root = root against which all relative paths will be resolved + set_global_validation_context(Context(config.parent)) + # After the working directory is set, we can initialize proper config store with a newly parsed configuration. config_store = await _init_config_store(config_raw) -- 2.47.3