feat(packages): the rpm epoch in the version, and the installed advisories
driver / standard (pull_request) Failing after 15s
driver / lint (pull_request) Successful in 13s
driver / test (3.12) (pull_request) Failing after 39s
driver / types (pull_request) Failing after 47s
driver / test (3.13) (pull_request) Failing after 39s
driver / lowest (pull_request) Failing after 46s
driver / build (pull_request) Successful in 42s
driver / security (pull_request) Successful in 1m25s
CI / driver (pull_request) Failing after 2m35s
driver / publish (pull_request) Skipped

On an rpm host a package's version now carries its epoch where it has
one (1:6.2.0-13.el9), as on a dpkg host: Oracle's and Red Hat's fixes
name it, and without it an epoch-1 fix read as newer than every
installed build. get_installed_advisory_cves() reads, as root and from
the cache, the CVEs the installed security advisories close, through
napalm-device-types 4.37.0; dnf only (NetOrk/netork#2394).
This commit is contained in:
Christian Manivong committed 2026-11-12 12:10:05 +01:00
1 parent 235c1e9a91
commit 257efdef8e
4 files changed
+108 -2

No files matched your search

+32 -1
View File
@@ -27,6 +27,7 @@ from napalm.base.exceptions import ConnectionClosedException, ConnectionExceptio
from napalm.base.netmiko_helpers import netmiko_args
from napalm_device_types import (
APT_UPGRADABLE_COMMAND,
DNF_INSTALLED_CVES_COMMAND,
DNF_SECURITY_COMMAND,
LLDPCTL_KEYVALUE_COMMAND,
AptProxyMixin,
@@ -51,6 +52,7 @@ from napalm_device_types import (
lldp_neighbors,
open_stream_on_transport,
parse_apt_upgradable,
parse_dnf_installed_cves,
parse_dnf_security,
parse_lldpctl_keyvalue,
run_fix_steps,
@@ -1138,9 +1140,16 @@ class LinuxDriver(
return parse_dpkg_query(self._send(DPKG_QUERY_COMMAND))
def _get_packages_rpm(self) -> list[PackageDict]:
"""``rpm -qa``, the version as ``[epoch:]version-release``, as dpkg writes it.
The epoch is there only where the package has one: Oracle's and Red Hat's
fixes name it (``1:6.2.0-13.el9``), and without it an epoch-1 fix reads as
newer than every installed build (NetOrk/netork#2394).
"""
out = self._send(
"rpm -qa --queryformat "
"'%{NAME}\\t%{VERSION}-%{RELEASE}\\t%{SIZE}\\t%{SUMMARY}\\n' 2>/dev/null"
"'%{NAME}\\t%|EPOCH?{%{EPOCH}:}:{}|%{VERSION}-%{RELEASE}\\t%{SIZE}\\t%{SUMMARY}\\n'"
" 2>/dev/null"
)
packages: list[PackageDict] = []
for line in out.splitlines():
@@ -1477,6 +1486,28 @@ class LinuxDriver(
except ValueError:
return None
def get_installed_advisory_cves(self) -> dict[str, list[str]]:
"""The CVEs the installed security advisories close, per package (dnf 4).
As root, from the cache, as the security read does: root's cache is the one
the host's own updates keep. The output is long (90 000 lines on an Oracle
Linux 9 host), so it gets a longer budget; netOrk reads it only where its
knowledge base holds no records of the release (NetOrk/netork#2394).
:raises NotImplementedError: on any package manager but dnf.
:raises ValueError: when dnf failed or its output was cut short.
"""
if self._pkg_manager != "dnf":
raise NotImplementedError(
f"Installed advisories are not read for {self._pkg_manager!r}"
)
cmd = DNF_INSTALLED_CVES_COMMAND
output, status = _split_status(self._run_privileged(f"{cmd}; echo {_RC_MARKER}$?", 300))
if status != 0:
hint = f"\n{_SUDO_PASSWORD_HINT}" if "password is required" in output else ""
raise RuntimeError(f"dnf updateinfo failed (exit {status}): {output[-200:]}{hint}")
return parse_dnf_installed_cves(output)
def refresh_available_updates(self) -> dict[str, Any]:
"""Refresh the package index (apt-get update, dnf makecache, apk update)."""
cmd = _REFRESH.get(self._pkg_manager or "")