def test_inventory_lnx_if_empty() -> None: assert list(lnx_if.inventory_lnx_if(lnx_if.parse_lnx_if([]), None)) == [ Attributes( path=["networking"], inventory_attributes={ "available_ethernet_ports": 0, "total_ethernet_ports": 0, "total_interfaces": 0, }, status_attributes={}, ), ]
def test_inventory_lnx_if_no_bonding() -> None: assert [ e for e in lnx_if.inventory_lnx_if( lnx_if.parse_lnx_if([ ["[start_iplink]"], [ "1:", "wlp3s0:", "<BROADCAST,MULTICAST>", "mtu", "1500", "qdisc", "fq_codel", "state", "UP", "mode", "DORMANT", "group", "default", "qlen", "1000", ], [ "link/ether", "AA:AA:AA:AA:AA:AA", "brd", "BB:BB:BB:BB:BB:BB" ], ["[end_iplink]"], [ "wlp3s0", "130923553 201184 0 0 0 0 0 16078 23586281 142684 0 0 0 0 0 0" ], ]), None, ) if isinstance(e, TableRow) ] == [ TableRow( path=["networking", "interfaces"], key_columns={ "index": 1, "description": "wlp3s0", "alias": "wlp3s0", }, inventory_columns={ "speed": 0, "phys_address": "AA:AA:AA:AA:AA:AA", "oper_status": 2, "port_type": 6, "available": True, }, status_columns={}, ), ]
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:] )
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:]
def test_parse_lnx_if(string_table, result): assert lnx_if.parse_lnx_if(string_table)[0][0] == interfaces.Interface( *result)
def test_lnx_if_status_flags(string_table, result): assert parse_lnx_if(string_table)[0] == result
parsed = parse_lnx_if([ [u'[start_iplink]'], [u'1:', u'lo:', u'<LOOPBACK,UP,LOWER_UP>', u'mtu', u'65536', u'qdisc', u'noqueue', u'state', u'UNKNOWN', u'mode', u'DEFAULT', u'group', u'default', u'qlen', u'1000'], [u'link/loopback', u'00:00:00:00:00:00', u'brd', u'00:00:00:00:00:00'], [u'2:', u'wlp3s0:', u'<BROADCAST,MULTICAST,UP,LOWER_UP>', u'mtu', u'1500', u'qdisc', u'fq_codel', u'state', u'UP', u'mode', u'DORMANT', u'group', u'default', u'qlen', u'1000'], [u'link/ether', u'AA:AA:AA:AA:AA:AA', u'brd', u'BB:BB:BB:BB:BB:BB'], [u'3:', u'docker0:', u'<BROADCAST,MULTICAST,UP,LOWER_UP>', u'mtu', u'1500', u'qdisc', u'noqueue', u'state', u'UP', u'mode', u'DEFAULT', u'group', u'default'], [u'link/ether', u'AA:AA:AA:AA:AA:AA', u'brd', u'BB:BB:BB:BB:BB:BB'], [u'5:', u'veth6a06585@if4:', u'<BROADCAST,MULTICAST,UP,LOWER_UP>', u'mtu', u'1500', u'qdisc', u'noqueue', u'master', u'docker0', u'state', u'UP', u'mode', u'DEFAULT', u'group', u'default'], [u'link/ether', u'AA:AA:AA:AA:AA:AA', u'brd', u'BB:BB:BB:BB:BB:BB', u'link-netnsid', u'0'], [u'[end_iplink]'], [u'lo', u' 164379850 259656 0 0 0 0 0 0 164379850 259656 0 0 0 0 0 0'], [u'wlp3s0', u' 130923553 201184 0 0 0 0 0 16078 23586281 142684 0 0 0 0 0 0'], [u'docker0', u' 0 0 0 0 0 0 0 0 16250 184 0 0 0 0 0 0'], [u'veth6a06585', u' 0 0 0 0 0 0 0 0 25963 287 0 0 0 0 0 0'], [u'[lo]'], [u'Link detected', u' yes'], [u'Address', u' 00', u'00', u'00', u'00', u'00', u'00'], [u'[docker0]'], [u'Link detected', u' yes'], [u'Address', u' AA', u'AA', u'AA', u'AA', u'AA', u'AA'], [u'[veth6a06585]'], [u'Speed', u' 10000Mb/s'], [u'Duplex', u' Full'], [u'Auto-negotiation', u' off'], [u'Link detected', u' yes'], [u'Address', u' AA', u'AA', u'AA', u'AA', u'AA', u'AA'], [u'[wlp3s0]'], [u'Address', u' AA', u'AA', u'AA', u'AA', u'AA', u'AA'], ])
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"), ]
# yapf: disable # type: ignore from cmk.base.plugins.agent_based.lnx_if import parse_lnx_if checkname = 'lnx_if' parsed = parse_lnx_if([ [u'em0', u'376716785370 417455222 0 0 0 0 0 0 383578105955 414581956 0 0 0 0 0 0'], [u'tun0', u'342545566242 0 259949262 0 0 0 0 0 0 19196 0 0 0 0'], [u'tun1', u'2422824602 0 2357563 0 0 0 0 0 0 0 0 0 0 0'], [u'[em0]'], [u'Speed', u' 1000Mb/s'], [u'Duplex', u' Full'], [u'Auto-negotiation', u' on'], [u'Link detected', u' yes'], [u'Address', u' 00', u'AA', u'11', u'BB', u'22', u'CC'], [u'[tun0]'], [u'Link detected', u' yes'], [u'Address', u' 123'], [u'[tun1]'], [u'Link detected', u' yes'], [u'Address', u' 456'], ]) discovery = {'': [('1', "{'state': ['1'], 'speed': 1000000000}"), ('2', "{'state': ['1'], 'speed': 0}"), ('3', "{'state': ['1'], 'speed': 0}")]} checks = {'': [('1', {'errors': (0.01, 0.1), 'speed': 1000000000, 'state': ['1']},
def test_inventory_lnx_if(string_table: List[List[str]], expected_result: InventoryResult): assert list(lnx_if.inventory_lnx_if( lnx_if.parse_lnx_if(string_table))) == expected_result
def test_parse_lnx_if(string_table, result): assert lnx_if.parse_lnx_if( string_table)[0][0] == interfaces.finalize_interface( interfaces.PreInterface(*result))