Skip to content

Commit e11a985

Browse files
committed
Avoid hardwired paths to Python modules
Change-Id: I31fc4b7b7f12b380d9fcecf61af00cb245118124
1 parent daba41a commit e11a985

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

tests/performance/nagios_core_plugin_import.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
44
# conditions defined in the file COPYING, which is part of this source code package.
55
import importlib
6+
import importlib.resources
67
import re
78
import sys
89
from collections.abc import Generator
@@ -12,6 +13,7 @@
1213
from types import ModuleType
1314
from typing import Final, get_args
1415

16+
import cmk.base.core.nagios # astrein: disable=cmk-module-layer-violation
1517
from cmk.base.core.nagios import HostCheckConfig # astrein: disable=cmk-module-layer-violation
1618
from cmk.ccc.hostaddress import HostAddress, HostName # astrein: disable=cmk-module-layer-violation
1719
from cmk.discover_plugins import PluginLocation # astrein: disable=cmk-module-layer-violation
@@ -96,11 +98,6 @@ def list_agent_based_plugins(self) -> dict[str, list[str]]:
9698

9799
def dump_host_check_file(self) -> None:
98100
"""Creates a host check file which loads all agent based plugins"""
99-
100-
template_file: Path = (
101-
self.omd_root / "lib/python3/cmk/base/core/nagios/_host_check_template.py"
102-
)
103-
104101
plugin_locations = [
105102
PluginLocation(module=module_name, name=plugin_name)
106103
for module_name, plugin_names in self.agent_based_plugins.items()
@@ -120,7 +117,9 @@ def dump_host_check_file(self) -> None:
120117
ipv6addresses={},
121118
hostname=self.host_name,
122119
)
123-
template_text = template_file.read_text(encoding="utf-8")
120+
template_text = importlib.resources.read_text(
121+
cmk.base.core.nagios, "_host_check_template.py", encoding="utf-8"
122+
)
124123
startpos = template_text.find("CONFIG = HostCheckConfig(")
125124
endpos = template_text.find(")\n", startpos) + 1
126125
replacement = f"CONFIG = {pformat(host_check_config)}"

0 commit comments

Comments
 (0)