|
| 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