Beispiel #1
0
def test_check_lnx_if(monkeypatch, value_store):
    section_if = [INTERFACE]
    section: lnx_if.Section = (section_if, {})
    monkeypatch.setattr('time.time', lambda: 0)
    with pytest.raises(IgnoreResultsError):
        list(lnx_if.check_lnx_if(
            INTERFACE.index,
            PARAMS,
            section,
        ))
    monkeypatch.setattr('time.time', lambda: 1)
    result_lnx_if = list(
        lnx_if.check_lnx_if(
            INTERFACE.index,
            PARAMS,
            section,
        ))
    monkeypatch.setattr('time.time', lambda: 2)
    result_interfaces = list(
        interfaces.check_multiple_interfaces(
            INTERFACE.index,
            PARAMS,
            section_if,
        ))
    assert result_lnx_if == result_interfaces
Beispiel #2
0
def test_lnx_if_regression(
    monkeypatch,
    string_table,
    discovery_results,
    items_params_results,
):
    section = lnx_if.parse_lnx_if(string_table)

    assert (
        list(
            lnx_if.discover_lnx_if(
                [interfaces.DISCOVERY_DEFAULT_PARAMETERS],
                section,
            )
        )
        == discovery_results
    )

    monkeypatch.setattr(interfaces, "get_value_store", lambda: {})
    for item, par, res in items_params_results:
        assert (
            list(
                lnx_if.check_lnx_if(
                    item,
                    par,
                    section,
                )
            )
            == res
        )

    node_name = "node"
    for item, par, res in items_params_results:
        assert (
            list(
                lnx_if.cluster_check_lnx_if(
                    item,
                    par,
                    {node_name: section},
                )
            )
            == [
                Result(  # type: ignore[call-overload]
                    state=res[0].state,
                    summary=res[0].summary + " on %s" % node_name if res[0].summary else None,
                    notice=res[0].summary + " on %s" % node_name if not res[0].summary else None,
                    details=res[0].details + " on %s" % node_name if res[0].details else None,
                ),
            ]
            + res[1:]
        )
Beispiel #3
0
def test_lnx_if_regression(
    monkeypatch,
    string_table,
    discovery_results,
    items_params_results,
):
    section = lnx_if.parse_lnx_if(string_table)

    assert list(
        lnx_if.discover_lnx_if(
            [type_defs.Parameters(interfaces.DISCOVERY_DEFAULT_PARAMETERS)],
            section,
        )) == discovery_results

    monkeypatch.setattr(interfaces, 'get_value_store', lambda: {})
    for item, par, res in items_params_results:
        assert list(
            lnx_if.check_lnx_if(
                item,
                type_defs.Parameters(par),
                section,
            )) == res

    node_name = 'node'
    for item, par, res in items_params_results:
        assert list(
            lnx_if.cluster_check_lnx_if(
                item,
                type_defs.Parameters(par),
                {node_name: section},
            )) == [
                Result(
                    state=res[0].state,
                    summary=res[0].summary.replace(' ', ' on %s: ' % node_name,
                                                   1),
                )
            ] + res[1:]
Beispiel #4
0
def test_lnx_if_with_bonding(monkeypatch) -> None:

    section = lnx_if.parse_lnx_if([
        ["[start_iplink]"],
        [
            "1:",
            "lo:",
            "<LOOPBACK,UP,LOWER_UP>",
            "mtu",
            "65536",
            "qdisc",
            "noqueue",
            "state",
            "UNKNOWN",
            "mode",
            "DEFAULT",
            "group",
            "default",
            "qlen",
            "1000",
        ],
        ["link/loopback", "00:00:00:00:00:00", "brd", "00:00:00:00:00:00"],
        [
            "2:",
            "wlp3s0:",
            "<BROADCAST,MULTICAST,UP,LOWER_UP>",
            "mtu",
            "1500",
            "qdisc",
            "fq_codel",
            "state",
            "UP",
            "mode",
            "DORMANT",
            "group",
            "default",
            "qlen",
            "1000",
        ],
        ["link/ether", "AA:AA:AA:AA:AA:BB", "brd", "BB:BB:BB:BB:BB:BB"],
        [
            "3:",
            "docker0:",
            "<BROADCAST,MULTICAST,UP,LOWER_UP>",
            "mtu",
            "1500",
            "qdisc",
            "noqueue",
            "state",
            "UP",
            "mode",
            "DEFAULT",
            "group",
            "default",
        ],
        ["link/ether", "AA:AA:AA:AA:AA:AA", "brd", "BB:BB:BB:BB:BB:BB"],
        [
            "5:",
            "veth6a06585@if4:",
            "<BROADCAST,MULTICAST,UP,LOWER_UP>",
            "mtu",
            "1500",
            "qdisc",
            "noqueue",
            "master",
            "docker0",
            "state",
            "UP",
            "mode",
            "DEFAULT",
            "group",
            "default",
        ],
        [
            "link/ether",
            "AA:AA:AA:AA:AA:AA",
            "brd",
            "BB:BB:BB:BB:BB:BB",
            "link-netnsid",
            "0",
        ],
        ["[end_iplink]"],
        [
            "lo",
            " 164379850  259656    0    0    0     0          0         0 164379850  259656    0    0    0     0       0          0",
        ],
        [
            "wlp3s0",
            " 130923553  201184    0    0    0     0          0     16078 23586281  142684    0    0    0     0       0          0",
        ],
        [
            "docker0",
            "       0       0    0    0    0     0          0         0    16250     184    0    0    0     0       0          0",
        ],
        [
            "veth6a06585",
            "       0       0    0    0    0     0          0         0    25963     287    0    0    0     0       0          0",
        ],
    ])

    section_bonding: Mapping[str, bonding.Bond] = {
        "bond0": {
            "interfaces": {
                "wlp3s0": {
                    "hwaddr": "BB:BB:BB:BB:BB:BB",
                },
            },
        },
    }

    monkeypatch.setattr(interfaces, "get_value_store", lambda: {})
    assert list(
        lnx_if.check_lnx_if(
            "4",
            {
                "errors": {
                    "both": ("abs", (10, 20))
                },
                "speed": 0,
                "state": ["1"]
            },
            section,
            section_bonding,
        )) == [
            Result(state=state.OK, summary="[wlp3s0]"),
            Result(state=state.OK,
                   summary="(up)",
                   details="Operational state: up"),
            Result(state=state.OK, summary="MAC: BB:BB:BB:BB:BB:BB"),
            Result(state=state.OK, summary="Speed: unknown"),
        ]