Ejemplo n.º 1
0
def test_cluster_check_lnx_if(monkeypatch, value_store):
    section: Dict[str, lnx_if.Section] = {}
    ifaces = []
    for i in range(3):
        iface = copy.copy(INTERFACE)
        iface.node = 'node%s' % i
        ifaces_node = [iface] * (i + 1)
        section[iface.node] = ifaces_node, {}
        ifaces += ifaces_node
    monkeypatch.setattr('time.time', lambda: 0)
    with pytest.raises(IgnoreResultsError):
        list(lnx_if.cluster_check_lnx_if(
            INTERFACE.index,
            PARAMS,
            section,
        ))
    monkeypatch.setattr('time.time', lambda: 1)
    result_lnx_if = list(
        lnx_if.cluster_check_lnx_if(
            INTERFACE.index,
            PARAMS,
            section,
        ))
    monkeypatch.setattr('time.time', lambda: 2)
    result_interfaces = list(
        interfaces.check_multiple_interfaces(
            INTERFACE.index,
            PARAMS,
            ifaces,
        ))
    assert result_lnx_if == result_interfaces
Ejemplo n.º 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:]
        )
Ejemplo n.º 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:]