From: Vincent Bernat Date: Mon, 12 Mar 2018 20:47:48 +0000 (+0100) Subject: tests: update tests for configuration keeping on port down/removed X-Git-Tag: 1.0.0~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=246d153846ab978064346f403b780112e67e7fb3;p=thirdparty%2Flldpd.git tests: update tests for configuration keeping on port down/removed --- diff --git a/tests/integration/fixtures/network.py b/tests/integration/fixtures/network.py index aa2a85c3..64785e88 100644 --- a/tests/integration/fixtures/network.py +++ b/tests/integration/fixtures/network.py @@ -108,6 +108,14 @@ class LinksFactory(object): """Create a bond.""" return self._bond_or_team("bond", name, *ifaces) + def dummy(self, name): + """Create a dummy interface.""" + ipr = pyroute2.IPRoute() + ipr.link('add', ifname=name, kind='dummy') + idx = ipr.link_lookup(ifname=name)[0] + ipr.link('set', index=idx, state='up') + return idx + def vlan(self, name, id, iface): """Create a VLAN.""" ipr = pyroute2.IPRoute() diff --git a/tests/integration/test_lldpcli.py b/tests/integration/test_lldpcli.py index aafafd63..add740b6 100644 --- a/tests/integration/test_lldpcli.py +++ b/tests/integration/test_lldpcli.py @@ -389,9 +389,9 @@ def test_new_port_take_default(lldpd1, lldpd, lldpcli, namespaces, links): @pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features, reason="Dot3 not supported") -def test_port_keep_configuration(lldpd1, lldpd, lldpcli, namespaces, links): - links(namespaces(1), namespaces(2)) - with namespaces(2): +def test_port_keep_configuration_when_down(lldpd, lldpcli, namespaces, links): + with namespaces(1): + links.dummy('eth3') lldpd() result = lldpcli(*("configure ports eth3 dot3 power " "pse supported enabled paircontrol powerpairs " @@ -400,14 +400,34 @@ def test_port_keep_configuration(lldpd1, lldpd, lldpcli, namespaces, links): time.sleep(3) links.down('eth3') time.sleep(4) + # eth3 configuration is kept because the port still exists. + out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") + assert out['lldp.eth3.port.power.device-type'] == 'PSE' + links.up('eth3') time.sleep(4) + # eth3 configuration is unchanged out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") assert out['lldp.eth3.port.power.device-type'] == 'PSE' + + +@pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features, + reason="Dot3 not supported") +def test_port_forget_configuration(lldpd, lldpcli, + namespaces, links): with namespaces(1): - out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth2.port.descr'] == 'eth3' - assert out['lldp.eth2.port.power.device-type'] == 'PSE' + links.dummy('eth3') + lldpd() + result = lldpcli(*("configure dot3 power " + "pse supported enabled paircontrol powerpairs " + "spare class class-3").split()) + assert result.returncode == 0 + time.sleep(3) + links.remove('eth3') + time.sleep(4) + # eth3 configuration was forgotten because it disappeared. + out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") + assert 'lldp.eth3.port.power.device-type' not in out def test_watch(lldpd1, lldpd, lldpcli, namespaces, links):