コード例 #1
0
def test__get_output__performance_data(mocker):
    """
    Test "_get_output" method must return human readable HDD's statuses
    with performance data.
    """

    expected = "OK: device /dev/sda is functional and stable 27C | /dev/sda=27\n"
    data = {
        "/dev/sda": {
            "template": "ok",
            "priority": 4,
            "data": {
                "device": "/dev/sda",
                "temperature": 27,
                "scale": "C",
                "warning": 40,
                "critical": 65,
            },
        },
    }
    mocker.patch("sys.argv",
                 ["check_hddtemp.py", "-s", "127.0.0.1", "-p", "7634", "-P"])
    checker = CheckHDDTemp()
    status = checker._get_status(data=data)
    result = checker._get_output(data=data, status=status)

    assert result == expected  # nosec: B101
コード例 #2
0
def test__get_output__sleeping(mocker):
    """
    Test "_get_output" method must return human readable HDD's statuses
    (sleeping case).
    """

    expected = "OK: device /dev/sda is functional and stable 27C, device /dev/sdb is sleeping\n"  # noqa: E501
    data = {
        "/dev/sda": {
            "template": "ok",
            "priority": 4,
            "data": {
                "device": "/dev/sda",
                "temperature": 27,
                "scale": "C",
                "warning": 40,
                "critical": 65,
            },
        },
        "/dev/sdb": {
            "template": "sleeping",
            "priority": 5,
            "data": {
                "device": "/dev/sdb",
                "temperature": "SLP",
                "scale": "C",
                "warning": 40,
                "critical": 65,
            },
        },
    }
    mocker.patch("sys.argv",
                 ["check_hddtemp.py", "-s", "127.0.0.1", "-p", "7634"])
    checker = CheckHDDTemp()
    status = checker._get_status(data=data)
    result = checker._get_output(data=data, status=status)

    assert result == expected  # nosec: B101
コード例 #3
0
def test__get_output__unknown_device_temperature(mocker):
    """
    Test "_get_output" method must return human readable HDD's statuses
    (unknown device temperature case).
    """

    expected = "UNKNOWN: device /dev/sdb temperature info not found in server response or can't be recognized by hddtemp, device /dev/sda is functional and stable 27C\n"  # noqa: E501
    data = {
        "/dev/sda": {
            "template": "ok",
            "priority": 4,
            "data": {
                "device": "/dev/sda",
                "temperature": 27,
                "scale": "C",
                "warning": 40,
                "critical": 65,
            },
        },
        "/dev/sdb": {
            "template": "unknown",
            "priority": 3,
            "data": {
                "device": "/dev/sdb",
                "temperature": "UNK",
                "scale": "*",
                "warning": 40,
                "critical": 65,
            },
        },
    }
    mocker.patch("sys.argv",
                 ["check_hddtemp.py", "-s", "127.0.0.1", "-p", "7634"])
    checker = CheckHDDTemp()
    status = checker._get_status(data=data)
    result = checker._get_output(data=data, status=status)

    assert result == expected  # nosec: B101