From f3321a7a2a79d8a0515219471e195d9c18392e42 Mon Sep 17 00:00:00 2001 From: "@fabrc" Date: Tue, 8 Jul 2025 14:38:35 -0300 Subject: [PATCH] fixes issue #938 by including the directories in frr_sbin_search to the search path for the executables of service FRRzebra --- daemon/core/services/defaults/frrservices/services.py | 11 ++++++++++- daemon/core/services/manager.py | 2 +- daemon/core/utils.py | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/daemon/core/services/defaults/frrservices/services.py b/daemon/core/services/defaults/frrservices/services.py index df1c12892..3305f1695 100644 --- a/daemon/core/services/defaults/frrservices/services.py +++ b/daemon/core/services/defaults/frrservices/services.py @@ -8,6 +8,7 @@ from core.nodes.physical import Rj45Node from core.nodes.wireless import WirelessNode from core.services.base import CoreService +from core.nodes.base import CoreNode GROUP: str = "FRR" FRR_STATE_DIR: str = "/var/run/frr" @@ -92,6 +93,14 @@ class FRRZebra(CoreService): startup: list[str] = ["bash frrboot.sh zebra"] validate: list[str] = ["pidof zebra"] shutdown: list[str] = ["pkill -f zebra"] + path: str = "/usr/local/sbin /usr/sbin /usr/lib/frr /usr/libexec/frr" + + def __init__(self, node: CoreNode = None) -> None: + CoreService.__init__(self, node) + self.path = self.node.session.options.get( + "frr_sbin_search", + default=self.path, + ).strip('"') def data(self) -> dict[str, Any]: frr_conf = self.files[0] @@ -100,7 +109,7 @@ def data(self) -> dict[str, Any]: ).strip('"') frr_sbin_search = self.node.session.options.get( "frr_sbin_search", - default="/usr/local/sbin /usr/sbin /usr/lib/frr /usr/libexec/frr", + default=self.path, ).strip('"') services = [] diff --git a/daemon/core/services/manager.py b/daemon/core/services/manager.py index 06d619fab..7f2b4f809 100644 --- a/daemon/core/services/manager.py +++ b/daemon/core/services/manager.py @@ -68,7 +68,7 @@ def add(self, service: type[CoreService]) -> None: # validate dependent executables are present for executable in service.executables: try: - utils.which(executable, required=True) + utils.which(executable, required=True, path=hasattr(service, "path") and service.path or None) except CoreError as e: raise CoreError(f"service({service.name}): {e}") diff --git a/daemon/core/utils.py b/daemon/core/utils.py index 6eef22630..9e11ee44b 100644 --- a/daemon/core/utils.py +++ b/daemon/core/utils.py @@ -146,7 +146,7 @@ def close_onexec(fd: int) -> None: fcntl.fcntl(fd, fcntl.F_SETFD, fdflags | fcntl.FD_CLOEXEC) -def which(command: str, required: bool) -> str | None: +def which(command: str, required: bool, path: str | None = None) -> str | None: """ Find location of desired executable within current PATH. @@ -155,7 +155,7 @@ def which(command: str, required: bool) -> str | None: :return: command location or None :raises ValueError: when not found and required """ - found_path = shutil.which(command) + found_path = shutil.which(command, path=path and path.replace(" ", ":")) if found_path is None and required: raise CoreError(f"failed to find required executable({command}) in path") return found_path