From ce4a6777560d367614aae4f171b78e7acab3cbb3 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sun, 1 Nov 2026 22:12:07 +0100 Subject: [PATCH 1/3] fix: report FreeBSD and OpenBSD hosts in the role bsd BsdDriver set no ROLE, so both drivers inherited OSDriver's "linux" and an application that shows or branches on the role treated a BSD host as a Linux one. One key for both systems. Closes #10 --- CHANGELOG.md | 4 ++++ README.md | 4 ++-- napalm_bsd/base.py | 3 +++ tests/test_drivers.py | 8 +++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea29083..a599bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 3.12 venv no longer has. ### Fixed +- FreeBSD and OpenBSD hosts are in the role `bsd`, one key for both (#10). They + inherited `OSDriver`'s `linux`, so an application that shows or branches on the + role treated them as Linux hosts. An application that keys on `linux` for every + general-purpose host has to accept `bsd` as well. - `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 diff --git a/README.md b/README.md index f5e304b..1e2afbb 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ NAPALM drivers for **FreeBSD** (`freebsd`) and **OpenBSD** (`openbsd`) hosts, over SSH, built on [napalm-device-types](https://git.netork.io/NAPALM/napalm-device-types)' -`OSDriver`. Written for netOrk, which provisions and manages BSD VMs -(NetOrk/netork#792). +`OSDriver`, in the role `bsd` (one for both systems). Written for netOrk, which +provisions and manages BSD VMs (NetOrk/netork#792). ## Design diff --git a/napalm_bsd/base.py b/napalm_bsd/base.py index 89f9967..4300e4f 100644 --- a/napalm_bsd/base.py +++ b/napalm_bsd/base.py @@ -90,6 +90,9 @@ def render_snmpd_conf(settings: SnmpAgentSettingsDict) -> str: class BsdDriver(SnmpAgentMixin, EnsurePackageMixin, HostStatusMixin, OSDriver): """Base for the BSD drivers; a concrete one names the commands that differ.""" + #: One role for FreeBSD and OpenBSD. It replaces OSDriver's "linux", which + #: would have the application treat a BSD host as a Linux one (#10). + ROLE = "bsd" VENDOR = "" #: A full init sequence, as on any general-purpose host. REBOOT_SETTLE_SECONDS = 90 diff --git a/tests/test_drivers.py b/tests/test_drivers.py index cb9c003..1988f8c 100644 --- a/tests/test_drivers.py +++ b/tests/test_drivers.py @@ -6,7 +6,7 @@ from pathlib import Path import pytest from napalm.base import NetworkDriver -from napalm_device_types import OSDriver +from napalm_device_types import OSDriver, primary_role_of, role_keys_of from napalm_bsd import FreeBSDDriver, OpenBSDDriver, base from napalm_bsd.base import BsdDriver @@ -106,6 +106,12 @@ class TestIdentity: assert getattr(cls, getter) is not getattr(NetworkDriver, getter, None) assert getattr(cls, getter) is not getattr(OSDriver, getter, None) + @pytest.mark.parametrize("cls", [FreeBSDDriver, OpenBSDDriver]) + def test_the_role_is_bsd_not_linux(self, cls): + """One key for both BSDs (#10); OSDriver's inherited "linux" would call them Linux.""" + assert role_keys_of(cls) == ["bsd"] + assert primary_role_of(cls) == "bsd" + @pytest.mark.parametrize("cls", [FreeBSDDriver, OpenBSDDriver]) def test_leaves_napalms_get_users_alone(self, cls): """NAPALM's get_users is a different getter; the host's accounts are get_os_users.""" -- 2.54.0 From 86cdde03bf000241021b48aa51977965ebc55063 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sun, 1 Nov 2026 22:13:09 +0100 Subject: [PATCH 2/3] fix(openbsd): declare the CPU unknown in the SNMP health profile net-snmp on OpenBSD answers ssCpuIdle with 0 on an idle host (and hrProcessorLoad with 100), so a reading of the standard OID shows every OpenBSD host at 100 % CPU. The profile now marks the CPU unknown, and the application reports no figure instead of a wrong one. Memory, swap and load stay on the standard reading. Closes #7 --- CHANGELOG.md | 5 +++++ README.md | 3 ++- napalm_bsd/openbsd.py | 7 ++++++- tests/test_drivers.py | 12 ++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a599bc7..ba2cc9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 3.12 venv no longer has. ### Fixed +- An OpenBSD host no longer reads as 100 % busy (#7). net-snmp on OpenBSD answers + `ssCpuIdle` with 0 on an idle machine, so `OpenBSDDriver` declares the CPU unknown + in its `SNMP_HEALTH_PROFILE` (`{"cpu": {"unknown": True}}`), and the application + reports no CPU figure. Memory, swap and load are read as before. Requires the + napalm-device-types release with `SnmpValueSpec.unknown`. - FreeBSD and OpenBSD hosts are in the role `bsd`, one key for both (#10). They inherited `OSDriver`'s `linux`, so an application that shows or branches on the role treated them as Linux hosts. An application that keys on `linux` for every diff --git a/README.md b/README.md index 1e2afbb..c78bd28 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,8 @@ on Linux (v2c, community `public`, every address), so the agent answers UCD-SNMP-MIB for netOrk's health metrics. Memory, swap and load are right on both systems. CPU: FreeBSD reports `ssCpuIdle` about a minute after the agent starts; on OpenBSD net-snmp's CPU figures are wrong (0 % idle on an idle -machine, also in `hrProcessorLoad`). +machine, also in `hrProcessorLoad`), so `OpenBSDDriver`'s `SNMP_HEALTH_PROFILE` +marks the CPU unknown and the application reports none. ## Connection arguments diff --git a/napalm_bsd/openbsd.py b/napalm_bsd/openbsd.py index c7ec403..e9351a2 100644 --- a/napalm_bsd/openbsd.py +++ b/napalm_bsd/openbsd.py @@ -2,7 +2,9 @@ from __future__ import annotations -from napalm_device_types import FingerprintRule +from typing import ClassVar + +from napalm_device_types import FingerprintRule, SnmpHealthProfile from napalm_bsd import parse from napalm_bsd.base import BASE_SYSTEM, BsdDriver @@ -16,6 +18,9 @@ class OpenBSDDriver(BsdDriver): DRIVER_NAME = "openbsd" # OpenBSD's SSH banner names no OS; its sysDescr does ("OpenBSD host 7.9 GENERIC.MP#449"). SNMP_FINGERPRINT = [FingerprintRule("openbsd", weight=5.0)] + # net-snmp maps OpenBSD's CPU states wrongly: ssCpuIdle is 0 on an idle host, and + # hrProcessorLoad 100. No figure beats one that says the host is always busy (#7). + SNMP_HEALTH_PROFILE: ClassVar[SnmpHealthProfile] = {"cpu": {"unknown": True}} OS_VERSION_COMMAND = "uname -sr" # The kernel's build, e.g. GENERIC.MP#449; the release is in uname -r. diff --git a/tests/test_drivers.py b/tests/test_drivers.py index 1988f8c..1358553 100644 --- a/tests/test_drivers.py +++ b/tests/test_drivers.py @@ -465,6 +465,18 @@ class TestServices: assert driver.calls == [] +class TestSnmpHealthProfile: + """Where netOrk's SNMP poll reads each health value (#7).""" + + def test_openbsd_cpu_is_unknown(self): + """net-snmp on OpenBSD answers 0 % idle on an idle host: no value beats 100 %.""" + assert OpenBSDDriver.SNMP_HEALTH_PROFILE == {"cpu": {"unknown": True}} + + def test_freebsd_is_read_the_standard_way(self): + """FreeBSD's ssCpuIdle is right, as are memory, swap and load on both.""" + assert not getattr(FreeBSDDriver, "SNMP_HEALTH_PROFILE", None) + + class TestSnmp: """net-snmp from packages, as decided in NetOrk/netork#800: UCD-SNMP-MIB, the same health metrics as on Linux. Set up through napalm-device-types' -- 2.54.0 From ccce4a8406063235507807b9b0ba3c5fccaae766 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Mon, 2 Nov 2026 00:31:34 +0100 Subject: [PATCH 3/3] chore(deps): floor napalm-device-types at 4.23.0 4.23.0 is on PyPI with everything this branch uses; the git pre-install in CI is no longer needed. --- .gitea/workflows/ci.yml | 2 -- CHANGELOG.md | 1 + pyproject.toml | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index c1a016c..7530c79 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -11,7 +11,5 @@ jobs: uses: NAPALM/driver-standard/.gitea/workflows/driver.yml@main with: standard-ref: main - # Until the napalm-device-types release with LocalAccountsMixin is on PyPI. - pre-install: "git+https://git.netork.io/NAPALM/napalm-device-types.git" secrets: PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 374c5e3..3e7823d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `LocalAccountsMixin`. ### Changed +- The floor on napalm-device-types is 4.23.0, the first release with what this driver uses. - Python 3.12 is the floor (`requires-python = ">=3.12"`): netOrk runs every driver on 3.12, so 3.10 and 3.11 are no longer tested (NAPALM/driver-standard#6). - The floor on napalm is 5.1: older releases import `pkg_resources`, which a Python diff --git a/pyproject.toml b/pyproject.toml index ff75372..f19ef8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ classifiers = [ ] dependencies = [ "napalm>=5.1", # older releases import pkg_resources, which a 3.12 venv lacks - "napalm-device-types>=4.21.1", + "napalm-device-types>=4.23.0", "paramiko>=5.0.0", # CVE-2026-44405 ] -- 2.54.0