feat(host-status): tell an interrupted dnf, yum, apk or opkg #98

Merged
christianmanivong merged 3 commits from feat/interrupted-pm-851 into main 2026-11-07 19:18:08 +00:00
Owner

What

get_host_status() now tells an interrupted package manager on hosts without dpkg too, and names the one it read in the new package_manager field (dpkg, dnf, yum, apk, opkg, or None). The reading lives in a new module, napalm_device_types/package_managers.py, whose command part is appended to HOST_STATUS_COMMAND; host_status.py picks the reading that says most (interrupted, then clean, then busy).

  • dnf / yum (rpm): a package installed in two versions (rpm -qa --qf '%{NAME} %{ARCH}', duplicates), leaving out dnf's default installonlypkgs plus any the host adds in dnf.conf (asked of rpm by what they provide) and gpg-pubkey: state duplicate. A transaction that never ended: dnf 4's newest row in the libdnf trans table still at state 0 (UNKNOWN; finish() writes 1 DONE or 2 ERROR), read read-only through Python's sqlite3, or yum's transaction-all.* journal in /var/lib/yum (one renamed .disabled is ignored, as yum-complete-transaction does). dnf 5's history is not read, only its duplicates.
  • apk: a package whose f: line in /lib/apk/db/installed carries f (broken files) or s (broken script): broken-files, broken-script. These are the packages apk fix with no arguments picks. x and S are not faults.
  • opkg: a package in /usr/lib/opkg/status whose Status: is unpacked, half-configured or half-installed, or that has the reinstreq flag (reinstall-required).
  • Busy: while rpm, dnf, dnf5, yum, dnf-automatic, packagekitd, apk or opkg runs (from /proc/<pid>/comm, which BusyBox hosts have too), that manager's answer is None.

Everything is read without root and changes nothing. MINOR: a new field.

Why

NetOrk/netork#851, a follow-up to #738, which covered dpkg only. netOrk decides what to do with it: it repairs opkg (opkg configure) and only warns for dnf, yum and apk.

Sources for the formats

  • libdnf transaction/Types.hpp (TransactionState), transaction/sql/create_tables.sql (trans), transaction/private/Transaction.cpp (begin/finish); dnf cli/output.py and db/history.py (how history shows an unfinished transaction).
  • yum-utils yum-complete-transaction (the transaction-all* journal in /var/lib/yum).
  • apk-tools src/database.c (the f: field and its flags), src/app_fix.c (what apk fix picks with no arguments), src/commit.c.
  • opkg-lede libopkg/pkg.c (state words, the Status: line), libopkg/opkg_cmd.c (opkg configure configures every SS_UNPACKED package).

Tests

Fixtures only. The outputs are shaped after the formats above. They have not been recorded on a host yet and should be checked against an Oracle Linux 9 host (dnf) and an OpenWrt 25.12 router (apk). Per manager: clean means not interrupted, interrupted means it is reported with its packages, and busy means unknown. The command part also runs on a real sh and on busybox sh, with stand-in rpm, dnf, apk and opkg, a stand-in sqlite history and status files. The whole command runs under busybox sh. The full suite passes (1463 passed, 2 skipped; coverage 97 %). ruff and mypy --strict are clean.

Refs NetOrk/netork#851

## What `get_host_status()` now tells an interrupted package manager on hosts without dpkg too, and names the one it read in the new `package_manager` field (`dpkg`, `dnf`, `yum`, `apk`, `opkg`, or None). The reading lives in a new module, `napalm_device_types/package_managers.py`, whose command part is appended to `HOST_STATUS_COMMAND`; `host_status.py` picks the reading that says most (interrupted, then clean, then busy). - **dnf / yum (rpm):** a package installed in two versions (`rpm -qa --qf '%{NAME} %{ARCH}'`, duplicates), leaving out dnf's default `installonlypkgs` plus any the host adds in `dnf.conf` (asked of rpm by what they provide) and `gpg-pubkey`: state `duplicate`. A transaction that never ended: dnf 4's newest row in the libdnf `trans` table still at `state` 0 (UNKNOWN; `finish()` writes 1 DONE or 2 ERROR), read read-only through Python's `sqlite3`, or yum's `transaction-all.*` journal in `/var/lib/yum` (one renamed `.disabled` is ignored, as `yum-complete-transaction` does). dnf 5's history is not read, only its duplicates. - **apk:** a package whose `f:` line in `/lib/apk/db/installed` carries `f` (broken files) or `s` (broken script): `broken-files`, `broken-script`. These are the packages `apk fix` with no arguments picks. `x` and `S` are not faults. - **opkg:** a package in `/usr/lib/opkg/status` whose `Status:` is `unpacked`, `half-configured` or `half-installed`, or that has the `reinstreq` flag (`reinstall-required`). - **Busy:** while `rpm`, `dnf`, `dnf5`, `yum`, `dnf-automatic`, `packagekitd`, `apk` or `opkg` runs (from `/proc/<pid>/comm`, which BusyBox hosts have too), that manager's answer is None. Everything is read without root and changes nothing. MINOR: a new field. ## Why NetOrk/netork#851, a follow-up to #738, which covered dpkg only. netOrk decides what to do with it: it repairs opkg (`opkg configure`) and only warns for dnf, yum and apk. ## Sources for the formats - libdnf `transaction/Types.hpp` (`TransactionState`), `transaction/sql/create_tables.sql` (`trans`), `transaction/private/Transaction.cpp` (`begin`/`finish`); dnf `cli/output.py` and `db/history.py` (how history shows an unfinished transaction). - yum-utils `yum-complete-transaction` (the `transaction-all*` journal in `/var/lib/yum`). - apk-tools `src/database.c` (the `f:` field and its flags), `src/app_fix.c` (what `apk fix` picks with no arguments), `src/commit.c`. - opkg-lede `libopkg/pkg.c` (state words, the `Status:` line), `libopkg/opkg_cmd.c` (`opkg configure` configures every `SS_UNPACKED` package). ## Tests Fixtures only. The outputs are shaped after the formats above. They have not been recorded on a host yet and should be checked against an Oracle Linux 9 host (dnf) and an OpenWrt 25.12 router (apk). Per manager: clean means not interrupted, interrupted means it is reported with its packages, and busy means unknown. The command part also runs on a real `sh` and on `busybox sh`, with stand-in `rpm`, `dnf`, `apk` and `opkg`, a stand-in sqlite history and status files. The whole command runs under `busybox sh`. The full suite passes (1463 passed, 2 skipped; coverage 97 %). ruff and mypy --strict are clean. Refs NetOrk/netork#851
christianmanivong added 1 commit 2026-11-07 14:01:13 +00:00
feat(host-status): tell an interrupted dnf, yum, apk or opkg
driver / standard (pull_request) Failing after 18s
driver / lint (pull_request) Successful in 17s
driver / types (pull_request) Successful in 1m9s
driver / test (3.12) (pull_request) Successful in 1m22s
driver / lowest (pull_request) Successful in 39s
driver / build (pull_request) Successful in 36s
driver / test (3.13) (pull_request) Successful in 2m14s
driver / security (pull_request) Failing after 1m1s
CI / driver (pull_request) Failing after 2m42s
driver / publish (pull_request) Skipped
58ed0f0a94
get_host_status() read only dpkg's state. It now also reads the rpm
database and dnf's history (or yum's journal), apk's installed database
and opkg's status file, without root, and names the manager it read in
the new package_manager field. While one of them runs, the answer is
unknown, as for dpkg.

Refs NetOrk/netork#851
christianmanivong added 2 commits 2026-11-07 19:14:18 +00:00
# Conflicts:
#	CHANGELOG.md
fix(host-status): keep models.py at its recorded size, one literal for the dnf query
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 58s
driver / test (3.12) (pull_request) Successful in 1m11s
driver / test (3.13) (pull_request) Successful in 1m5s
driver / lowest (pull_request) Successful in 40s
driver / build (pull_request) Successful in 36s
driver / security (pull_request) Successful in 1m6s
CI / driver (pull_request) Successful in 2m38s
driver / publish (pull_request) Skipped
92891473be
The quality ratchet records models.py at 1454 lines and the new comments
had made it 1460. bandit read the dnf history query, built with an
f-string for its path, as SQL put together from strings (B608); it is a
fixed query, now one literal with the path spelt out, and a test holds
it to DNF_HISTORY.

Refs NetOrk/netork#851
christianmanivong merged commit afffd0915c into main 2026-11-07 19:18:08 +00:00
christianmanivong deleted branch feat/interrupted-pm-851 2026-11-07 19:18:08 +00:00
Sign in to join this conversation.