Skip to content

Commit 87c347f

Browse files
author
Bohdan Biloshytskyi
committed
Added Tests for multipath check plugin
SUP-26871 Change-Id: I82b7dfb8848b300652a38e0b8aec614fa7268416
1 parent a2e14bf commit 87c347f

File tree

1 file changed

+131
-6
lines changed

1 file changed

+131
-6
lines changed

tests/unit/cmk/plugins/collection/agent_based/test_multipath.py

Lines changed: 131 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
discover_multipath,
1414
parse_multipath,
1515
)
16-
from cmk.plugins.lib.multipath import Section
16+
from cmk.plugins.lib.multipath import Group, Section
1717

1818
STRING_TABLE: Final = [
19+
# First paths
1920
["ORA_ZAPPL2T_DATA_3", "(3600601604d40310047cf93ce66f7e111)", "dm-67", "DGC,RAID", "5"],
2021
["size=17G", "features='1", "queue_if_no_path'", "hwhandler='1", "alua'", "wp=rw"],
2122
["|-+-", "policy='round-robin", "0'", "prio=0", "status=active"],
@@ -24,6 +25,7 @@
2425
["`-+-", "policy='round-robin", "0'", "prio=0", "status=enabled"],
2526
["|-", "5:0:0:54", "sdbd", "67:112", "active", "undef", "running"],
2627
["`-", "3:0:0:54", "sdhf", "133:80", "active", "undef", "running"],
28+
# Second paths
2729
["ORA_UC41T_OLOG_1", "(prefix.3600601604d403100912ab0b365f7e111)", "dm-112", "DGC,RAID", "5"],
2830
["size=17G features='1 queue_if_no_path' hwhandler='1 alua' wp=rw"],
2931
["|-+-", "policy='round-robin", "0'", "prio=0", "status=active"],
@@ -48,6 +50,77 @@ def _get_section() -> Section:
4850
return parse_multipath(STRING_TABLE)
4951

5052

53+
def test_parse_multipath_section_keys(section: Section) -> None:
54+
assert set(section.keys()) == {
55+
"3600601604d40310047cf93ce66f7e111",
56+
"prefix.3600601604d403100912ab0b365f7e111",
57+
"broken_paths",
58+
}
59+
60+
61+
@pytest.mark.parametrize(
62+
"item,expected",
63+
[
64+
(
65+
"3600601604d40310047cf93ce66f7e111",
66+
Group(
67+
paths=["sddz", "sdkb", "sdbd", "sdhf"],
68+
broken_paths=[],
69+
luns=[
70+
"3:0:1:54(sddz)",
71+
"5:0:1:54(sdkb)",
72+
"5:0:0:54(sdbd)",
73+
"3:0:0:54(sdhf)",
74+
],
75+
uuid="3600601604d40310047cf93ce66f7e111",
76+
state="prio=0status=enabled",
77+
numpaths=4,
78+
device="dm-67",
79+
alias="ORA_ZAPPL2T_DATA_3",
80+
),
81+
),
82+
(
83+
"prefix.3600601604d403100912ab0b365f7e111",
84+
Group(
85+
paths=["sdew"],
86+
broken_paths=[],
87+
luns=["5:0:0:77(sdew)"],
88+
uuid="prefix.3600601604d403100912ab0b365f7e111",
89+
state="prio=0status=active",
90+
numpaths=1,
91+
device="dm-112",
92+
alias="ORA_UC41T_OLOG_1",
93+
),
94+
),
95+
(
96+
"broken_paths",
97+
Group(
98+
paths=["sdbd", "sdhf"],
99+
broken_paths=[
100+
"5:0:0:54(sdbd)",
101+
"3:0:0:54(sdhf)",
102+
],
103+
luns=[
104+
"5:0:0:54(sdbd)",
105+
"3:0:0:54(sdhf)",
106+
],
107+
uuid="broken_paths",
108+
state="prio=0status=active",
109+
numpaths=2,
110+
device="dm-67",
111+
alias="BROKEN_PATH",
112+
),
113+
),
114+
],
115+
)
116+
def test_parse_multipath_groups(
117+
item: str,
118+
expected: Group,
119+
section: Section,
120+
) -> None:
121+
assert section[item] == expected
122+
123+
51124
def test_discovery(section: Section) -> None:
52125
assert sorted(discover_multipath({"use_alias": False}, section)) == [
53126
Service(item="3600601604d40310047cf93ce66f7e111", parameters={"levels": 4}),
@@ -76,11 +149,19 @@ def test_check_percent_levels(section: Section) -> None:
76149
]
77150

78151

79-
def test_check_count_levels(section: Section) -> None:
152+
@pytest.mark.parametrize(
153+
"levels,state",
154+
[
155+
(3, State.WARN), # Actual level is higher then expected so the state is WARN
156+
(4, State.OK), # Actual level
157+
(5, State.CRIT), # Actual level is lower then expected so the state is CRIT
158+
],
159+
)
160+
def test_check_count_levels(levels: int, state: State, section: Section) -> None:
80161
assert list(
81162
check_multipath(
82163
"3600601604d40310047cf93ce66f7e111",
83-
{"levels": 3},
164+
{"levels": levels},
84165
section,
85166
)
86167
) == [
@@ -89,13 +170,13 @@ def test_check_count_levels(section: Section) -> None:
89170
summary="(ORA_ZAPPL2T_DATA_3): Paths active: 100.00%",
90171
),
91172
Result(
92-
state=State.WARN,
93-
summary="4 of 4 (expected: 3)",
173+
state=state,
174+
summary=f"4 of 4 (expected: {levels})",
94175
),
95176
]
96177

97178

98-
def test_check_broken_paths(section: Section) -> None:
179+
def test_check_broken_paths_no_level_configuration(section: Section) -> None:
99180
assert list(
100181
check_multipath(
101182
"broken_paths",
@@ -106,3 +187,47 @@ def test_check_broken_paths(section: Section) -> None:
106187
state=State.CRIT,
107188
summary="Broken paths: 5:0:0:54(sdbd),3:0:0:54(sdhf)",
108189
)
190+
191+
192+
def test_check_branch_broken_paths_result_added_with_levels_int(section: Section) -> None:
193+
assert list(
194+
check_multipath(
195+
"broken_paths",
196+
{"levels": 2},
197+
section,
198+
)
199+
) == [
200+
Result(state=State.OK, summary="(BROKEN_PATH): Paths active: 0%"),
201+
Result(state=State.CRIT, summary="0 of 2 (expected: 2)"),
202+
Result(
203+
state=State.CRIT,
204+
summary="Broken paths: 5:0:0:54(sdbd),3:0:0:54(sdhf)",
205+
),
206+
]
207+
208+
209+
def test_check_returns_nothing_for_unknown_item(section: Section) -> None:
210+
assert list(check_multipath("does_not_exist", {"levels": 1}, section)) == []
211+
212+
213+
def test_check_branch_broken_paths_result_added_with_levels_tuple(section: Section) -> None:
214+
assert list(
215+
check_multipath(
216+
"broken_paths",
217+
{"levels": (110.0, 40.0)},
218+
section,
219+
)
220+
) == [
221+
Result(
222+
state=State.CRIT,
223+
summary="(BROKEN_PATH): Paths active: 0% (warn/crit below 110.00%/40.00%)",
224+
),
225+
Result(
226+
state=State.OK,
227+
summary="0 of 2",
228+
),
229+
Result(
230+
state=State.CRIT,
231+
summary="Broken paths: 5:0:0:54(sdbd),3:0:0:54(sdhf)",
232+
),
233+
]

0 commit comments

Comments
 (0)