'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")
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")
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()
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()
- lldpd()
lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
time.sleep(3)
with namespaces(1):
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'