Skip to content

Commit e372a39

Browse files
committed
nimble_volumes: Add unit tests
Jira: CMK-37374 Change-Id: Id6bff98e3182a66d7b5b3448688b51ea64ecfec3
1 parent 330f3ee commit e372a39

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

cmk/base/legacy_checks/nimble_volumes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
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

6+
# mypy: disable-error-code="no-untyped-call"
67
# mypy: disable-error-code="no-untyped-def"
78

9+
import time
810

911
from cmk.agent_based.legacy.v0_unstable import LegacyCheckDefinition
1012
from cmk.agent_based.v2 import SNMPTree, startswith, StringTable
@@ -22,14 +24,18 @@ def inventory_nimble_volumes(info):
2224

2325

2426
def check_nimble_volumes(item, params, info):
27+
yield from _check_nimble_volumes(item, params, info, time.time())
28+
29+
30+
def _check_nimble_volumes(item, params, info, now):
2531
for line in info:
2632
if line[1] == item:
2733
if line[4] == "0":
2834
yield 3, "Volume is offline!"
2935
continue
3036
total = int(line[2])
3137
free = total - int(line[3])
32-
yield df_check_filesystem_list(item, params, [(item, total, free, 0)])
38+
yield df_check_filesystem_list(item, params, [(item, total, free, 0)], this_time=now)
3339

3440

3541
def parse_nimble_volumes(string_table: StringTable) -> StringTable:
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2026 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
6+
# mypy: disable-error-code="no-untyped-call"
7+
8+
import pytest
9+
10+
from cmk.base.legacy_checks.nimble_volumes import (
11+
_check_nimble_volumes,
12+
inventory_nimble_volumes,
13+
parse_nimble_volumes,
14+
)
15+
from cmk.plugins.lib.df import FILESYSTEM_DEFAULT_PARAMS
16+
17+
from .checktestlib import mock_item_state
18+
19+
STRING_TABLE = [
20+
["1", "vol-ok", "1073741824", "536870912", "1"],
21+
["", "vol-empty-size", "", "", ""],
22+
]
23+
24+
25+
def test_discovery_skips_volumes_without_size_data() -> None:
26+
section = parse_nimble_volumes(STRING_TABLE)
27+
assert list(inventory_nimble_volumes(section)) == [("vol-ok", {})]
28+
29+
30+
def test_check_ok_volume() -> None:
31+
section = parse_nimble_volumes(STRING_TABLE)
32+
with mock_item_state({"df.vol-ok.delta": (0, 0)}):
33+
results = list(_check_nimble_volumes("vol-ok", FILESYSTEM_DEFAULT_PARAMS, section, 60.0))
34+
assert len(results) == 1
35+
state, summary, perfdata = results[0]
36+
assert state == 0
37+
assert summary.startswith("Used: 50.00% - 512 TiB of 1.00 PiB")
38+
assert ("fs_size", 1073741824, None, None, 0, None) in perfdata
39+
40+
41+
@pytest.mark.xfail(strict=True, reason="CMK-37374")
42+
def test_check_does_not_crash_on_empty_size_values() -> None:
43+
section = parse_nimble_volumes(STRING_TABLE)
44+
assert not list(
45+
_check_nimble_volumes("vol-empty-size", FILESYSTEM_DEFAULT_PARAMS, section, 60.0)
46+
)

0 commit comments

Comments
 (0)