コード例 #1
0
def test__get_status(mocker):
    """
    Test "_get_status" method must return main check status.

    :param mocker: mock
    :type mocker: MockerFixture
    """

    mocker.patch("sys.argv",
                 ["check_supervisord.py", "-s", "127.0.0.1", "-p", "9001"])
    checker = CheckSupervisord()
    result = checker._get_status(
        data=[{
            "description": "pid 666, uptime 0 days, 0:00:00",
            "pid": 666,
            "stderr_logfile": "",
            "stop": 0,
            "logfile": "/var/log/example.log",
            "exitstatus": 0,
            "spawnerr": "",
            "now": 0,
            "group": "example",
            "name": "example",
            "statename": "RUNNING",
            "start": 0,
            "state": 20,
            "stdout_logfile": "/var/log/example.log",
        }])

    assert result == "ok"  # nosec: B101
コード例 #2
0
def test__get_output(mocker):
    """
    Test "_get_status" method must return human readable statuses.

    :param mocker: mock
    :type mocker: MockerFixture
    """

    expected = "OK: 'example': OK"
    data = [{
        "description": "pid 666, uptime 0 days, 0:00:00",
        "pid": 666,
        "stderr_logfile": "",
        "stop": 0,
        "logfile": "/var/log/example.log",
        "exitstatus": 0,
        "spawnerr": "",
        "now": 0,
        "group": "example",
        "name": "example",
        "statename": "RUNNING",
        "start": 0,
        "state": 20,
        "stdout_logfile": "/var/log/example.log",
    }]
    mocker.patch("sys.argv",
                 ["check_supervisord.py", "-s", "127.0.0.1", "-p", "9001"])
    checker = CheckSupervisord()
    status = checker._get_status(data=data)
    result = checker._get_output(
        data=data,
        status=status,
    )

    assert result.strip() == expected  # nosec: B101
コード例 #3
0
def test__get_output__warning__backoff(mocker):
    """
    Test "_get_status" method must return human readable statuses (warning case)
    (backoff state).

    :param mocker: mock
    :type mocker: MockerFixture
    """

    expected = (
        "WARNING: something curiously with 'example-warning': (BACKOFF), 'example': OK"
    )
    data = [
        {
            "description": "pid 666, uptime 0 days, 0:00:00",
            "pid": 666,
            "stderr_logfile": "",
            "stop": 0,
            "logfile": "/var/log/example.log",
            "exitstatus": 0,
            "spawnerr": "",
            "now": 0,
            "group": "example",
            "name": "example",
            "statename": "RUNNING",
            "start": 0,
            "state": 20,
            "stdout_logfile": "/var/log/example.log",
        },
        {
            "description": "pid 666, uptime 0 days, 0:00:00",
            "pid": 666,
            "stderr_logfile": "",
            "stop": 0,
            "logfile": "/var/log/example.log",
            "exitstatus": 0,
            "spawnerr": "",
            "now": 0,
            "group": "example-warning",
            "name": "example-warning",
            "statename": "BACKOFF",
            "start": 0,
            "state": 30,
            "stdout_logfile": "/var/log/example.log",
        },
    ]
    mocker.patch("sys.argv",
                 ["check_supervisord.py", "-s", "127.0.0.1", "-p", "9001"])
    checker = CheckSupervisord()
    status = checker._get_status(data=data)
    result = checker._get_output(
        data=data,
        status=status,
    )

    assert result.strip() == expected  # nosec: B101
コード例 #4
0
def test__get_output__unknown__no_data(mocker):
    """
    Test "_get_status" method must return human readable statuses (unknown case)
    (no data).

    :param mocker: mock
    :type mocker: MockerFixture
    """

    expected = "UNKNOWN: No program configured/found"
    data = []
    mocker.patch("sys.argv",
                 ["check_supervisord.py", "-s", "127.0.0.1", "-p", "9001"])
    checker = CheckSupervisord()
    status = checker._get_status(data=data)
    result = checker._get_output(
        data=data,
        status=status,
    )

    assert result.strip() == expected  # nosec: B101