From 50b79a84dc1bc7ba56aed94a96bfc753f3cdac8b Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Mon, 1 Mar 2021 09:21:10 +0100 Subject: [PATCH] client: don't show age/via for local interfaces --- NEWS | 1 + src/client/display.c | 16 ++++++------- tests/integration/test_basic.py | 2 -- tests/integration/test_lldpcli.py | 39 ++++++++++++++++++++----------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index 14d78934..dc995ab0 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ lldpd (1.0.9) + Do not use interface alias if we set it ourselves. * Changes: + Display port status with "show interfaces". + + Do not display "age" and "via" when using "show interfaces". lldpd (1.0.8) * Fix: diff --git a/src/client/display.c b/src/client/display.c index ab206140..7bbe549c 100644 --- a/src/client/display.c +++ b/src/client/display.c @@ -717,16 +717,16 @@ display_interface(lldpctl_conn_t *conn, struct writer *w, int hidden, tag_start(w, "interface", "Interface"); tag_attr(w, "name", "", lldpctl_atom_get_str(iface, lldpctl_k_interface_name)); - tag_attr(w, "via" , "via", - lldpctl_atom_get_str(port, lldpctl_k_port_protocol)); - if (details > DISPLAY_BRIEF) { - if (!local) + if (!local) { + tag_attr(w, "via" , "via", + lldpctl_atom_get_str(port, lldpctl_k_port_protocol)); + if (details > DISPLAY_BRIEF) { tag_attr(w, "rid" , "RID", lldpctl_atom_get_str(chassis, lldpctl_k_chassis_index)); - tag_attr(w, "age" , "Time", - display_age(lldpctl_atom_get_int(port, lldpctl_k_port_age))); - } - if (local) { + tag_attr(w, "age" , "Time", + display_age(lldpctl_atom_get_int(port, lldpctl_k_port_age))); + } + } else { tag_datatag(w, "status", "Administrative status", lldpctl_atom_get_str(port, lldpctl_k_port_status)); } diff --git a/tests/integration/test_basic.py b/tests/integration/test_basic.py index a470c7f6..4a9459ff 100644 --- a/tests/integration/test_basic.py +++ b/tests/integration/test_basic.py @@ -55,10 +55,8 @@ def test_one_interface(lldpd1, lldpd, lldpcli, namespaces): out = lldpcli("-f", "keyvalue", "show", "interfaces") assert out['lldp.eth0.chassis.descr'].startswith( "Spectacular GNU/Linux 2016 Linux") - assert 'lldp.eth0.age' in out assert 'lldp.eth0.chassis.Router.enabled' in out assert 'lldp.eth0.chassis.Station.enabled' in out - del out['lldp.eth0.age'] del out['lldp.eth0.chassis.descr'] del out['lldp.eth0.chassis.Router.enabled'] del out['lldp.eth0.chassis.Station.enabled'] diff --git a/tests/integration/test_lldpcli.py b/tests/integration/test_lldpcli.py index 1d1da2e8..e6cde3d2 100644 --- a/tests/integration/test_lldpcli.py +++ b/tests/integration/test_lldpcli.py @@ -47,7 +47,8 @@ Interface: eth0, via: LLDP, RID: 1, Time: 0 day, 00:00:{seconds} """------------------------------------------------------------------------------- LLDP interfaces: ------------------------------------------------------------------------------- -Interface: eth0, via: unknown, Time: {time} +Interface: eth0 + Administrative status: RX and TX Chassis: ChassisID: mac 00:00:00:00:00:01 SysName: ns-1.example.com @@ -82,12 +83,16 @@ def test_text_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, dot3 = "" out = result.stdout.decode('ascii') - time = re.search(r'^Interface: .*Time: (.*)$', - out, - re.MULTILINE).group(1) - seconds = re.search(r'^Interface: .*(\d\d)$', - out, - re.MULTILINE).group(1) + if command == "neighbors": + time = re.search(r'^Interface: .*Time: (.*)$', + out, + re.MULTILINE).group(1) + seconds = re.search(r'^Interface: .*(\d\d)$', + out, + re.MULTILINE).group(1) + else: + time = None + seconds = None router = re.search(r'^ Capability: Router, (.*)$', out, re.MULTILINE).group(1) @@ -132,7 +137,7 @@ def test_text_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, {"lldp": { "interface": { "eth0": { - "via": "unknown", + "status": "RX and TX", "chassis": { "ns-1.example.com": { "id": { @@ -164,7 +169,8 @@ def test_json_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, eth0 = j['lldp']['interface']['eth0'] name = next(k for k,v in eth0['chassis'].items() if k.startswith('ns')) - del eth0['age'] + if command == "neighbors": + del eth0['age'] del eth0['chassis'][name]['capability'][3] del eth0['chassis'][name]['capability'][1] @@ -217,7 +223,9 @@ def test_json_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, {"lldp": [{ "interface": [{ "name": "eth0", - "via": "unknown", + "status": [{ + "value": "RX and TX", + }], "chassis": [{ "id": [{ "type": "mac", @@ -254,7 +262,8 @@ def test_json0_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, j = json.loads(out) eth0 = j['lldp'][0]['interface'][0] - del eth0['age'] + if command == "neighbors": + del eth0['age'] del eth0['chassis'][0]['capability'][3] del eth0['chassis'][0]['capability'][1] @@ -300,7 +309,8 @@ def test_json0_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, ("interfaces", """ - + + RX and TX 00:00:00:00:00:01 ns-1.example.com @@ -331,7 +341,10 @@ def test_xml_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, out = result.stdout.decode('ascii') xml = ET.fromstring(out) - age = xml.findall('./interface[1]')[0].attrib['age'] + if command == "neighbors": + age = xml.findall('./interface[1]')[0].attrib['age'] + else: + age = None router = xml.findall("./interface[1]/chassis/" "capability[@type='Router']")[0].attrib['enabled'] station = xml.findall("./interface[1]/chassis/" -- 2.39.5