fix: a failed listening-socket fallback raises (#11) #25

Merged
christianmanivong merged 1 commits from fix/bugs-2026-11 into main 2026-11-01 22:07:57 +00:00
3 changed files with 21 additions and 1 deletions

No files matched your search

+3
View File
@@ -26,6 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3.12 venv no longer has.
### Fixed
- `get_listening_sockets()` raises when the reading without root fails as well
(`sockstat` on FreeBSD, `netstat` on OpenBSD). It returned an empty list, which
read as a host where every port had closed.
- `get_arp_table()` reports an unknown age as `-1.0` (napalm-device-types'
`ARP_AGE_UNKNOWN`). It reported the time until the entry *expires* (FreeBSD's
`expires in N seconds`, OpenBSD's `Expire` column), which is no age: an entry
+4 -1
View File
@@ -399,6 +399,9 @@ class BsdDriver(SnmpAgentMixin, EnsurePackageMixin, HostStatusMixin, OSDriver):
first, and without root when that brings nothing back, which the
reading then says (``attributed: False``). BSD has no systemd units or
container IDs to name.
:raises RuntimeError: when the reading without root fails too: a list
that was never read must not read as every port closed.
"""
privileged = self.run_command(self.LISTENING_COMMAND, privileged=True)
if privileged.exit_code == 0 and privileged.stdout.strip():
@@ -407,7 +410,7 @@ class BsdDriver(SnmpAgentMixin, EnsurePackageMixin, HostStatusMixin, OSDriver):
"sockets": self._parse_listening(privileged.stdout, attributed=True),
}
command = self.LISTENING_FALLBACK_COMMAND or self.LISTENING_COMMAND
plain = self.run_command(command, privileged=False)
plain = self._read(command)
return {
"attributed": False,
"sockets": self._parse_listening(plain.stdout, attributed=False),
+14
View File
@@ -232,6 +232,20 @@ class TestListeningSockets:
}
assert calls == [("fstat -n", True), (OpenBSDDriver.LISTENING_FALLBACK_COMMAND, False)]
@pytest.mark.parametrize("cls", [FreeBSDDriver, OpenBSDDriver])
def test_a_failed_fallback_raises_instead_of_reading_as_no_sockets(self, cls):
"""Both readings failing is no empty host: every port would read as closed."""
driver = _driver(cls, {})
def run(command, privileged=False, timeout=60, stdin=None):
if privileged:
return type("R", (), {"stdout": "", "stderr": "", "exit_code": 1})()
return type("R", (), {"stdout": "", "stderr": "not found", "exit_code": 127})()
driver.run_command = run # type: ignore[method-assign]
with pytest.raises(RuntimeError, match="not found"):
driver.get_listening_sockets()
class _Result:
def __init__(self, stdout: str = "", exit_code: int = 0, stderr: str = "") -> None: