feat(updates): apply_updates on FreeBSD and OpenBSD, each line as it comes, 0.6.0 (#13) #35

Merged
christianmanivong merged 5 commits from feature/apply-updates-13 into main 2026-11-29 22:48:29 +00:00
Owner

Closes #13. Part of NetOrk/netork#1105; the application side is NetOrk/netork#1112 (branch refactor/bsd-updates-driver-1112).

apply_updates(packages, *, log=None) on FreeBSD and OpenBSD, in a new strict module napalm_bsd/updates.py (BsdUpdatesMixin, mixed into BsdDriver). The commands come over from the application unchanged:

  • FreeBSD: env ASSUME_ALWAYS_YES=yes pkg upgrade -y [packages], then for a classic base freebsd-update --not-running-from-cron install of what updatesready says is fetched (exit 2 = nothing, no failure). pkgbase (FreeBSD-base repository) has no extra step.
  • OpenBSD: pkg_add -u -I [packages], then syspatch, run again when it exits 2 after updating itself; a second 2 is "nothing left" and no failure.
  • The base system runs after the packages when base-system is chosen or nothing is; chosen packages alone leave it alone.

The whole upgrade runs as root as one sh script on an exec channel, with stdout and stderr merged. The sudo password goes on stdin only, and the script starts with exec </dev/null (#8). A root login also runs the script in sh, never in a csh login shell. log receives each line as the host prints it, and output holds all of it. The exit status decides success. A host that prints nothing for 300 s, or a connection that drops, is a failure that keeps what was printed until then. A name that is not a package name raises ValueError before anything is sent.

get_host_status already has its FreeBSD branch (napalm-device-types 4.1, freebsd-version -k vs -r); nothing to add.

Tests: tests/test_apply_updates.py (commands per OS and choice, sudo/root handling, streaming split across chunks, exit status, timeout, dropped connection, the log keyword). The output samples are illustrative lines; no recorded upgrade output from a real host was taken for this PR.

Before merge (coordinator):

  • log is declared by napalm-device-types on feature/ap-dhcp-contracts-695 (commit 059d97f6de229d05bc705bc57bb26520967544b5, to be released as 4.54.0). CI pre-installs that commit for now (pre-install in .gitea/workflows/ci.yml). Before merging, drop the pre-install and raise the floor in pyproject.toml to napalm-device-types>=4.54.0. The driver needs nothing from 4.54.0 at runtime, so the floor is about the contract, not imports.
  • Version 0.6.0 (release commit included). It also releases what was already under [Unreleased] since 0.5.0. If feature/host-shutdown-2841 merges first, I merge main into this branch and move its entries under 0.6.0.
Closes #13. Part of NetOrk/netork#1105; the application side is NetOrk/netork#1112 (branch `refactor/bsd-updates-driver-1112`). `apply_updates(packages, *, log=None)` on FreeBSD and OpenBSD, in a new strict module `napalm_bsd/updates.py` (`BsdUpdatesMixin`, mixed into `BsdDriver`). The commands come over from the application unchanged: - FreeBSD: `env ASSUME_ALWAYS_YES=yes pkg upgrade -y [packages]`, then for a classic base `freebsd-update --not-running-from-cron install` of what `updatesready` says is fetched (exit 2 = nothing, no failure). pkgbase (`FreeBSD-base` repository) has no extra step. - OpenBSD: `pkg_add -u -I [packages]`, then `syspatch`, run again when it exits 2 after updating itself; a second 2 is "nothing left" and no failure. - The base system runs after the packages when `base-system` is chosen or nothing is; chosen packages alone leave it alone. The whole upgrade runs as root as one `sh` script on an exec channel, with stdout and stderr merged. The sudo password goes on stdin only, and the script starts with `exec </dev/null` (#8). A root login also runs the script in `sh`, never in a csh login shell. `log` receives each line as the host prints it, and `output` holds all of it. The exit status decides `success`. A host that prints nothing for 300 s, or a connection that drops, is a failure that keeps what was printed until then. A name that is not a package name raises `ValueError` before anything is sent. `get_host_status` already has its FreeBSD branch (napalm-device-types 4.1, `freebsd-version -k` vs `-r`); nothing to add. Tests: `tests/test_apply_updates.py` (commands per OS and choice, sudo/root handling, streaming split across chunks, exit status, timeout, dropped connection, the `log` keyword). The output samples are illustrative lines; no recorded upgrade output from a real host was taken for this PR. **Before merge (coordinator):** - `log` is declared by napalm-device-types on `feature/ap-dhcp-contracts-695` (commit 059d97f6de229d05bc705bc57bb26520967544b5, to be released as 4.54.0). CI pre-installs that commit for now (`pre-install` in `.gitea/workflows/ci.yml`). Before merging, drop the `pre-install` and raise the floor in `pyproject.toml` to `napalm-device-types>=4.54.0`. The driver needs nothing from 4.54.0 at runtime, so the floor is about the contract, not imports. - Version 0.6.0 (release commit included). It also releases what was already under [Unreleased] since 0.5.0. If `feature/host-shutdown-2841` merges first, I merge main into this branch and move its entries under 0.6.0.
christianmanivong added 2 commits 2026-11-29 19:44:01 +00:00
The upgrade commands move here from the application (NetOrk/netork#1112):
pkg upgrade or pkg_add -u for the chosen packages or every one, then the
base system's patches when base-system is chosen or nothing is. A classic
FreeBSD base installs what freebsd-update fetched (nothing fetched is no
failure; pkgbase needs no extra step); OpenBSD runs syspatch again when it
updated itself, and a second exit 2 is "nothing left".

The whole upgrade runs as root as one sh script on an exec channel, stderr
merged, the sudo password on stdin only and the script's stdin closed. The
log keyword napalm-device-types declares on apply_updates receives each line
as the host prints it. A host silent for 300 s, or a dropped connection, is
a failure with what was printed until then.

CI pre-installs napalm-device-types' branch commit with that declaration
until 4.54.0 is on PyPI.
chore(release): 0.6.0
driver / lint (pull_request) Successful in 14s
driver / standard (pull_request) Successful in 19s
driver / lowest (pull_request) Successful in 37s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m6s
driver / test (3.13) (pull_request) Successful in 53s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Failing after 1m1s
CI / driver (pull_request) Failing after 1m57s
driver / publish (pull_request) Skipped
7da46774ab
christianmanivong added 1 commit 2026-11-29 21:59:35 +00:00
Merge NAPALM/napalm-bsd main (#36) into feature/apply-updates-13
driver / lint (pull_request) Successful in 12s
driver / standard (pull_request) Successful in 17s
driver / lowest (pull_request) Successful in 31s
driver / types (pull_request) Successful in 1m3s
driver / test (3.12) (pull_request) Successful in 59s
driver / test (3.13) (pull_request) Successful in 1m1s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Failing after 54s
CI / driver (pull_request) Failing after 1m57s
driver / publish (pull_request) Skipped
a706b7a942
#36's [Unreleased] entry moves under 0.6.0 with this branch's.
christianmanivong added 1 commit 2026-11-29 22:12:17 +00:00
build: require napalm-device-types 4.54.0 for apply_updates' log
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m20s
driver / test (3.13) (pull_request) Successful in 1m14s
driver / lowest (pull_request) Successful in 30s
driver / test (3.12) (pull_request) Successful in 1m22s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Failing after 59s
CI / driver (pull_request) Failing after 2m35s
driver / publish (pull_request) Skipped
635845723d
christianmanivong added 1 commit 2026-11-29 22:44:45 +00:00
security: name why the upgrade's exec_command line is safe (bandit B601)
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 13s
driver / test (3.13) (pull_request) Successful in 50s
driver / types (pull_request) Successful in 56s
driver / lowest (pull_request) Successful in 27s
driver / test (3.12) (pull_request) Successful in 1m5s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 55s
CI / driver (pull_request) Successful in 2m6s
driver / publish (pull_request) Skipped
7c573ecdda
christianmanivong merged commit 9242c1da2e into main 2026-11-29 22:48:29 +00:00
christianmanivong deleted branch feature/apply-updates-13 2026-11-29 22:48:30 +00:00
Sign in to join this conversation.