feat(fixes): configure_lldp_agent(interfaces) template
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 57s
driver / test (3.12) (pull_request) Successful in 1m7s
driver / test (3.13) (pull_request) Successful in 56s
driver / lowest (pull_request) Successful in 30s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 58s
CI / driver (pull_request) Successful in 2m32s
driver / publish (pull_request) Skipped

LLDP getters used to install, start and reconfigure lldpd on their own,
on every poll. Getters only read now, so starting the agent needs an
action the application calls. The template installs the agent through
ensure_package, has the driver write the interfaces it runs on, then
enables and restarts it through manage_service. The caller names the
interfaces: an agent on every interface also advertises on a WAN port.

Refs NAPALM/napalm-openwrt#8
This commit is contained in:
christianmanivong committed 2026-11-01 22:11:21 +01:00
1 parent a809e6c02f
commit bc17862a44
5 files changed
+155 -3

No files matched your search

+81
View File
@@ -14,6 +14,7 @@ from napalm_device_types import (
EnsurePackageMixin,
FirewallDriver,
HypervisorDriver,
LldpAgentMixin,
ManagementControllerDriver,
MediaDriver,
OSDriver,
@@ -169,11 +170,91 @@ class TestEnsurePackage:
assert "no candidate" in result["output"]
class _Lldp(LldpAgentMixin):
"""The generic steps over ensure_package and manage_service; the driver's configure."""
def __init__(self, refuse: str = ""):
self.calls: list = []
self.refuse = refuse
def ensure_package(self, name):
self.calls.append(("ensure_package", name))
ok = self.refuse != "install"
return {"success": ok, "steps": [], "output": "installed" if ok else "E: no candidate"}
def _write_lldp_agent_config(self, interfaces):
self.calls.append(("configure", interfaces))
return {"ok": self.refuse != "configure", "output": "interfaces set"}
def manage_service(self, name, action):
self.calls.append((action, name))
ok = self.refuse != action
return {"success": ok, "output": "" if ok else f"cannot {action}"}
class TestLldpAgent:
def test_install_configure_enable_and_restart_on_the_caller_s_interfaces(self):
agent = _Lldp()
result = agent.configure_lldp_agent(["br-lan"])
assert result["success"] is True
assert agent.calls == [
("ensure_package", "lldpd"),
("configure", ["br-lan"]),
("enable", "lldpd"),
("restart", "lldpd"),
]
assert [s["step"] for s in result["steps"]] == ["install", "configure", "start"]
def test_a_failed_install_configures_nothing(self):
agent = _Lldp(refuse="install")
result = agent.configure_lldp_agent(["br-lan"])
assert result["success"] is False
assert agent.calls == [("ensure_package", "lldpd")]
assert "no candidate" in result["output"]
def test_an_agent_that_will_not_start_at_boot_is_not_restarted(self):
agent = _Lldp(refuse="enable")
result = agent.configure_lldp_agent(["br-lan"])
assert result["success"] is False
assert ("restart", "lldpd") not in agent.calls
assert "cannot enable" in result["output"]
def test_a_failed_restart_fails_the_fix(self):
result = _Lldp(refuse="restart").configure_lldp_agent(["br-lan"])
assert result["success"] is False
assert result["steps"][-1]["step"] == "start"
def test_the_package_and_service_names_are_the_driver_s(self):
agent = _Lldp()
agent.LLDP_AGENT_PACKAGE = "lldpd-full"
agent.LLDP_AGENT_SERVICE = "lldpd.service"
agent.configure_lldp_agent(["eth0"])
assert ("ensure_package", "lldpd-full") in agent.calls
assert ("restart", "lldpd.service") in agent.calls
def test_no_interface_is_refused_before_anything_changes(self):
agent = _Lldp()
with pytest.raises(ValueError):
agent.configure_lldp_agent([])
assert agent.calls == []
@pytest.mark.parametrize("base", ROLE_BASES, ids=lambda b: b.__name__)
@pytest.mark.parametrize(
"method",
[
"configure_snmp_agent",
"configure_lldp_agent",
"ensure_package",
"configure_package_proxy",
"grant_container_engine_access",