From: Vincent Bernat Date: Fri, 20 May 2016 18:13:07 +0000 (+0200) Subject: tests: add test of `lldpcli watch` X-Git-Tag: 0.9.3~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d12b1391a295c46a9cc518dce6a4b1870fde4f70;p=thirdparty%2Flldpd.git tests: add test of `lldpcli watch` --- diff --git a/NEWS b/NEWS index ee2fa0d7..c6f83fae 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ lldpd (0.9.3) * Change: + Do not rely on support of constructors for liblldpctl. + Always log to stderr (even in addition to syslog). + + `lldpcli watch` accepts a limit on the number of received events. * Fix: + `lldpcli -f {xml,json} watch` should work now. + Consider `veth` interfaces as physical interfaces. diff --git a/tests/integration/test_lldpcli.py b/tests/integration/test_lldpcli.py index 32aa6230..521cc6fd 100644 --- a/tests/integration/test_lldpcli.py +++ b/tests/integration/test_lldpcli.py @@ -205,3 +205,78 @@ def test_port_keep_configuration(lldpd1, lldpd, lldpcli, namespaces, links): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") assert out['lldp.eth2.port.descr'] == 'eth3' assert out['lldp.eth2.port.power.device-type'] == 'PSE' + + +def test_watch(lldpd1, lldpd, lldpcli, namespaces, links): + with namespaces(2): + lldpd() + with namespaces(1): + result = lldpcli("show", "neighbors") + assert result.returncode == 0 + out = result.stdout.decode('ascii') + assert "ns-2.example.com" in out + + # Put a link down and immediately watch for a change + links.down('eth0') + result = lldpcli("watch", "limit", "1") + assert result.returncode == 0 + expected = out.replace('LLDP neighbors:', 'LLDP neighbor deleted:') + expected = re.sub(r', Time: 0 day, 00:.*$', '', expected, + flags=re.MULTILINE) + got = result.stdout.decode('ascii') + got = re.sub(r', Time: 0 day, 00:.*$', '', got, + flags=re.MULTILINE) + assert got == expected + + +@pytest.mark.skipif('XML' not in pytest.config.lldpcli.outputs, + reason="XML not supported") +def test_watch_xml(lldpd1, lldpd, lldpcli, namespaces, links): + with namespaces(2): + lldpd() + with namespaces(1): + result = lldpcli("-f", "xml", "show", "neighbors") + assert result.returncode == 0 + expected = result.stdexpected.decode('ascii') + expected = ET.fromstring(expected) + assert [x.text + for x in expected.findall("./interface/chassis/name")] == \ + ["ns-2.example.com"] + + # Put a link down and immediately watch for a change + links.down('eth0') + result = lldpcli("-f", "xml", "watch", "limit", "1") + assert result.returncode == 0 + expected.tag = 'lldp-deleted' + expected.set('label', 'LLDP neighbor deleted') + expected.find('./interface').set('age', '') + got = result.stdout.decode('ascii') + got = ET.fromstring(got) + got.find('./interface').set('age', '') + assert ET.tostring(got) == ET.tostring(expected) + + +@pytest.mark.skipif('JSON' not in pytest.config.lldpcli.outputs, + reason="JSON not supported") +def test_watch_json(lldpd1, lldpd, lldpcli, namespaces, links): + with namespaces(2): + lldpd() + with namespaces(1): + result = lldpcli("-f", "json", "show", "neighbors") + assert result.returncode == 0 + expected = result.stdout.decode('ascii') + expected = json.loads(expected) + assert 'ns-2.example.com' in \ + expected['lldp']['interface']['eth0']['chassis'] + + # Put a link down and immediately watch for a change + links.down('eth0') + result = lldpcli("-f", "json", "watch", "limit", "1") + assert result.returncode == 0 + got = result.stdout.decode('ascii') + got = json.loads(got) + expected['lldp-deleted'] = expected['lldp'] + del expected['lldp'] + del expected['lldp-deleted']['interface']['eth0']['age'] + del got['lldp-deleted']['interface']['eth0']['age'] + assert got == expected