]> git.ipfire.org Git - thirdparty/lldpd.git/blobdiff - tests/integration/test_basic.py
Merge pull request #285 from vincentbernat/feature/linux-caps
[thirdparty/lldpd.git] / tests / integration / test_basic.py
index 51f77c5e4a1cd4bc63a056ed173c1c6feb2aa150..28c1896f73d6ae892ba750d478391b5760950c7b 100644 (file)
@@ -25,7 +25,8 @@ def test_one_neighbor(lldpd1, lldpd, lldpcli, namespaces):
                        "lldp.eth0.chassis.Bridge.enabled": "off",
                        "lldp.eth0.chassis.Wlan.enabled": "off",
                        "lldp.eth0.port.mac": "00:00:00:00:00:02",
-                       "lldp.eth0.port.descr": "eth1"}
+                       "lldp.eth0.port.descr": "eth1",
+                       "lldp.eth0.port.ttl": "120"}
 
 
 @pytest.mark.parametrize("neighbors", (5, 10, 20))
@@ -36,7 +37,7 @@ def test_several_neighbors(lldpd, lldpcli, links, namespaces, neighbors):
         with namespaces(i):
             lldpd(sleep=(i == 1 and 2 or 0),
                   silent=True)
-    time.sleep(2)
+    time.sleep(10)
     with namespaces(1):
         out = lldpcli("-f", "keyvalue", "show", "neighbors")
         for i in range(2, neighbors + 1):
@@ -44,6 +45,46 @@ def test_several_neighbors(lldpd, lldpcli, links, namespaces, neighbors):
                 'ns-{}.example.com'.format(i)
 
 
+def test_one_interface(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+    with namespaces(1):
+        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']
+        assert out == {"lldp.eth0.via": "unknown",
+                       "lldp.eth0.chassis.mac": "00:00:00:00:00:01",
+                       "lldp.eth0.chassis.name": "ns-1.example.com",
+                       "lldp.eth0.chassis.mgmt-ip": "fe80::200:ff:fe00:1",
+                       "lldp.eth0.chassis.Bridge.enabled": "off",
+                       "lldp.eth0.chassis.Wlan.enabled": "off",
+                       "lldp.eth0.port.mac": "00:00:00:00:00:01",
+                       "lldp.eth0.port.descr": "eth0",
+                       "lldp.eth0.ttl.ttl": "120"}
+
+@pytest.mark.parametrize("interfaces", (5, 10, 20))
+def test_several_interfaces(lldpd, lldpcli, links, namespaces, interfaces):
+    for i in range(2, interfaces + 1):
+        links(namespaces(1), namespaces(i))
+    for i in range(1, interfaces + 1):
+        with namespaces(i):
+            lldpd()
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "interfaces")
+        for i in range(2, interfaces + 1):
+            assert out['lldp.eth{}.chassis.mac'.format((i - 2)*2)] == \
+                '00:00:00:00:00:01'
+            assert out['lldp.eth{}.port.mac'.format((i - 2)*2)] == \
+                '00:00:00:00:00:{num:02x}'.format(num=(i - 2)*2 + 1)
+
+
 def test_overrided_description(lldpd1, lldpd, lldpcli, namespaces):
     with namespaces(2):
         lldpd("-S", "Modified description")
@@ -52,6 +93,40 @@ def test_overrided_description(lldpd1, lldpd, lldpcli, namespaces):
         assert out['lldp.eth0.chassis.descr'] == "Modified description"
 
 
+def test_overrided_description2(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        lldpcli("configure", "system", "description", "Modified description")
+        lldpcli("update")
+        time.sleep(1)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out['lldp.eth0.chassis.descr'] == "Modified description"
+
+
+def test_overrided_chassisid(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        lldpcli("configure", "system", "chassisid", "Modified chassis ID")
+        lldpcli("update")
+        time.sleep(1)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out['lldp.eth0.chassis.local'] == "Modified chassis ID"
+
+
+def test_overrided_chassisid_reverse(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        lldpcli("configure", "system", "chassisid", "Modified chassis ID")
+        lldpcli("unconfigure", "system", "chassisid")
+        lldpcli("update")
+        time.sleep(1)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out['lldp.eth0.chassis.mac'] == "00:00:00:00:00:02"
+
+
 def test_hide_kernel(lldpd1, lldpd, lldpcli, namespaces):
     with namespaces(2):
         lldpd("-k")
@@ -87,3 +162,182 @@ def test_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
     with namespaces(1):
         out = lldpcli("-f", "keyvalue", "show", "neighbors")
         assert out["lldp.eth0.chassis.mgmt-ip"] == "172.25.21.47"
+
+
+def test_change_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
+    with namespaces(2):
+        ipr = pyroute2.IPRoute()
+        idx = ipr.link_lookup(ifname="eth1")[0]
+        ipr.addr('add', index=idx, address="192.168.14.2", mask=24)
+        lldpd("-m", "192.168.*")
+        # We need a short TX interval as updating the IP address
+        # doesn't trigger a resend.
+        lldpcli("configure", "lldp", "tx-interval", "2")
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.2"
+    with namespaces(2):
+        ipr.addr('del', index=idx, address="192.168.14.2", mask=24)
+        ipr.addr('add', index=idx, address="192.168.14.5", mask=24)
+        time.sleep(5)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.5"
+
+
+def test_portid_subtype_ifname(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        lldpcli("configure", "lldp", "portidsubtype", "ifname")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.ifname"] == "eth1"
+        assert out["lldp.eth0.port.descr"] == "eth1"
+
+
+def test_portid_subtype_with_alias(lldpd1, lldpd, lldpcli, links, namespaces):
+    with namespaces(2):
+        ipr = pyroute2.IPRoute()
+        idx = ipr.link_lookup(ifname="eth1")[0]
+        ipr.link('set', index=idx, ifalias="alias of eth1")
+        lldpd()
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.ifname"] == "eth1"
+        assert out["lldp.eth0.port.descr"] == "alias of eth1"
+
+
+def test_portid_subtype_macaddress(lldpd1, lldpd, lldpcli, links, namespaces):
+    with namespaces(2):
+        ipr = pyroute2.IPRoute()
+        idx = ipr.link_lookup(ifname="eth1")[0]
+        ipr.link('set', index=idx, ifalias="alias of eth1")
+        lldpd()
+        lldpcli("configure", "lldp", "portidsubtype", "macaddress")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.mac"] == "00:00:00:00:00:02"
+        assert out["lldp.eth0.port.descr"] == "eth1"
+
+
+def test_portid_subtype_local(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.local"] == "localname"
+        assert out["lldp.eth0.port.descr"] == "eth1"
+
+
+def test_portid_subtype_local_with_description(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        lldpcli("configure", "lldp", "portidsubtype", "local", "localname", "description", "localdescription")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.local"] == "localname"
+        assert out["lldp.eth0.port.descr"] == "localdescription"
+
+
+def test_portdescription(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        lldpcli("configure", "lldp", "portdescription", "localdescription")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.descr"] == "localdescription"
+
+
+def test_portid_subtype_local_with_alias(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        ipr = pyroute2.IPRoute()
+        idx = ipr.link_lookup(ifname="eth1")[0]
+        ipr.link('set', index=idx, ifalias="alias of eth1")
+        lldpd()
+        lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.local"] == "localname"
+        assert out["lldp.eth0.port.descr"] == "alias of eth1"
+
+
+def test_port_status_txonly(lldpd, lldpcli, namespaces, links):
+    links(namespaces(1), namespaces(2))
+    with namespaces(1):
+        lldpd()
+        lldpcli("configure", "lldp", "status", "tx-only")
+    with namespaces(2):
+        lldpd()
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out == {}
+        lldpcli("update")
+    with namespaces(2):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
+
+
+def test_port_status_rxonly(lldpd, lldpcli, namespaces, links):
+    links(namespaces(1), namespaces(2))
+    with namespaces(1):
+        lldpd()
+        lldpcli("configure", "lldp", "status", "rx-only")
+    with namespaces(2):
+        lldpd()
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
+        lldpcli("update")
+    with namespaces(2):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out == {}
+
+
+def test_port_status_rxandtx(lldpd, lldpcli, namespaces, links):
+    links(namespaces(1), namespaces(2))
+    with namespaces(1):
+        lldpd()
+        lldpcli("configure", "lldp", "status", "rx-and-tx")  # noop
+    with namespaces(2):
+        lldpd()
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
+        lldpcli("update")
+    with namespaces(2):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
+
+
+def test_port_status_disabled(lldpd, lldpcli, namespaces, links):
+    links(namespaces(1), namespaces(2))
+    with namespaces(1):
+        lldpd()
+        lldpcli("configure", "lldp", "status", "disabled")
+    with namespaces(2):
+        lldpd()
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out == {}
+        lldpcli("update")
+    with namespaces(2):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out == {}
+
+
+def test_set_interface_alias(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(1):
+        lldpcli("configure", "system", "interface", "description")
+    with namespaces(2):
+        lldpd()
+    with namespaces(1):
+        ipr = pyroute2.IPRoute()
+        link = ipr.link('get', ifname='eth0')[0]
+        assert link.get_attr('IFLA_IFALIAS') == 'lldpd: connected to ns-2.example.com'