fix(updates): read dnf and yum updates from the cached metadata
driver / standard (pull_request) Failing after 15s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 1m0s
driver / test (3.12) (pull_request) Failing after 1m1s
driver / test (3.13) (pull_request) Failing after 53s
driver / lowest (pull_request) Failing after 28s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m9s
CI / driver (pull_request) Failing after 2m30s
driver / publish (pull_request) Skipped

`dnf check-update` and `yum check-update`, and yum's security query, download
the repositories' metadata first whenever the cached copy has expired. On an
Oracle Linux host on OCI that outlasted netOrk's 120 s poll on every run, and
the device went offline. They now run with --cacheonly, as apt's read uses its
local index; refresh_available_updates (`dnf makecache`) still refreshes it.
Without a cache the read fails at once and says to refresh the index. The
README row claimed check-update ran unprivileged; it runs as root.

dnf's security query is NAPALM/napalm-device-types#76.

Closes #59
This commit is contained in:
Christian Manivong committed 2026-11-02 08:07:48 +01:00
1 parent 60ff9d9700
commit d226ebf764
4 files changed
+48 -10

No files matched your search

+13 -8
View File
@@ -117,9 +117,9 @@ _REFRESH = {
}
#: yum's counterpart of DNF_SECURITY_COMMAND, in the same shape: parse_dnf_security
#: (napalm-device-types 4.7) needs the ``__DNF_RC=`` line, and behind ``| cat`` it is
#: the only place yum's own exit status survives.
#: the only place yum's own exit status survives. Cached metadata only, as there.
_YUM_SECURITY_COMMAND = (
"{ LC_ALL=C yum updateinfo list security -q 2>/dev/null; echo __DNF_RC=$?; } | cat"
"{ LC_ALL=C yum --cacheonly updateinfo list security -q 2>/dev/null; echo __DNF_RC=$?; } | cat"
)
#: The exit status ``DNF_SECURITY_COMMAND`` and ``_YUM_SECURITY_COMMAND`` report.
_DNF_RC_RE = re.compile(r"^__DNF_RC=(\d+)\s*$", re.MULTILINE)
@@ -1466,17 +1466,22 @@ class LinuxDriver(
return parse_apt_upgradable(self._send(APT_UPGRADABLE_COMMAND, read_timeout=60))
def _get_updates_rpm(self) -> list[UpdateDict]:
"""dnf/yum check-update: exit 100 means updates, 0 none, anything else failed."""
"""dnf/yum check-update: exit 100 means updates, 0 none, anything else failed.
It reads the cached metadata only, as apt reads its local index: with an
expired cache dnf downloaded the repositories' metadata first, which
outlasted the whole poll (#59). Refreshing is ``refresh_available_updates``.
"""
cmd = (
"dnf check-update --quiet 2>/dev/null"
"dnf --cacheonly check-update --quiet 2>/dev/null"
if self._pkg_manager == "dnf"
else "yum check-update -q 2>/dev/null"
else "yum --cacheonly check-update -q 2>/dev/null"
)
output, status = _split_status(self._run_privileged(f"{cmd}; echo {_RC_MARKER}$?", 120))
if status not in (0, 100):
raise RuntimeError(
f"{self._pkg_manager} check-update failed (exit {status}): {output[-200:]}"
)
# Without cached metadata --cacheonly fails at once, and stderr is gone.
reason = output[-200:] or "no cached metadata? refresh the package index"
raise RuntimeError(f"{self._pkg_manager} check-update failed (exit {status}): {reason}")
security = self._rpm_security_names()
updates: list[UpdateDict] = []
for line in output.splitlines():