2 import pytest
# type: ignore
4 from cmk
.utils
.exceptions
import MKGeneralException
5 import cmk_base
.config
as config
6 import cmk_base
.core_config
as core_config
9 def test_active_check_arguments(mocker
):
10 with pytest
.raises(MKGeneralException
):
11 core_config
.active_check_arguments("bla", "blub", 1)
13 with pytest
.raises(MKGeneralException
):
14 core_config
.active_check_arguments("bla", "blub", (1, 2))
16 prepare_check_command
= mocker
.patch
.object(config
, "prepare_check_command")
17 core_config
.active_check_arguments("bla", "blub", u
"args 123 -x 1 -y 2")
18 assert prepare_check_command
.called_once()
21 def test_get_host_attributes(monkeypatch
):
22 monkeypatch
.setattr(config
, "all_hosts", ["test-host|abc"])
23 monkeypatch
.setattr(config
, "host_paths", {"test-host": "/"})
24 monkeypatch
.setattr(config
, "host_tags", {
29 monkeypatch
.setattr(config
, "host_labels", {
35 config_cache
= config
.get_config_cache()
36 config_cache
.initialize()
38 attrs
= core_config
.get_host_attributes("test-host", config_cache
)
40 '_ADDRESS_4': '0.0.0.0',
42 '_ADDRESS_FAMILY': '4',
45 '__TAG_tag_group': 'abc',
46 '__LABEL_ding': 'dong',
47 '__LABELSOURCE_ding': 'explicit',
53 @pytest.mark
.parametrize("tag_groups,result", [({
57 u
"__TAG_tg1": u
"val1",
58 u
"__TAG_tg2": u
"val1",
60 u
"täg-113232_eybc": u
"äbcdef"
62 u
"__TAG_täg-113232_eybc": u
"äbcdef",
64 "a.d B/E u-f N_A": "a.d B/E u-f N_A"
66 u
"__TAG_a.d B/E u-f N_A": "a.d B/E u-f N_A",
68 def test_get_tag_attributes(tag_groups
, result
):
69 attributes
= core_config
._get
_tag
_attributes
(tag_groups
, "TAG")
70 assert attributes
== result
71 for k
, v
in attributes
.items():
72 assert isinstance(k
, unicode)
73 assert isinstance(v
, unicode)
76 def test_custom_service_attributes_of(monkeypatch
):
77 config_cache
= config
.get_config_cache()
78 attributes
= core_config
._custom
_service
_attributes
_of
(config_cache
, "luluhost", "laladescr")
79 assert attributes
== {}
81 monkeypatch
.setattr(config
, "all_hosts", ["luluhost"])
82 monkeypatch
.setattr(config
, "host_paths", {"luluhost": "/"})
83 monkeypatch
.setattr(config
, "custom_service_attributes", [
84 ([('deng', '1')], [], config
.ALL_HOSTS
, config
.ALL_SERVICES
, {}),
85 ([('ding', '2'), ('ding', '2a'),
86 ('dong', '3')], [], config
.ALL_HOSTS
, config
.ALL_SERVICES
, {}),
88 config_cache
.initialize()
90 attributes
= core_config
._custom
_service
_attributes
_of
(config_cache
, "luluhost", "laladescr")
91 assert attributes
== {