From f337ae7fb895552655a67d8f0d93a865605882e5 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Mon, 2 Nov 2026 08:07:48 +0100 Subject: [PATCH] fix(updates): read dnf's security advisories from the cached metadata DNF_SECURITY_COMMAND ran `dnf updateinfo list --security`, which downloads the repositories' metadata first whenever the cached copy has expired. On an Oracle Linux host on OCI that took longer than netOrk's whole 120 s poll. It now runs with --cacheonly, as APT_UPGRADABLE_COMMAND reads apt's local index; refreshing stays `dnf makecache`. Without a cache dnf fails at once, and the __DNF_RC marker already turns that into "security unknown". Closes #76 --- CHANGELOG.md | 8 ++++++++ napalm_device_types/package_updates.py | 7 +++++-- tests/test_package_updates.py | 12 ++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf010e5..aa6e349 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ recorded here; their history is the git log. ## [Unreleased] +### Fixed +- `DNF_SECURITY_COMMAND` reads the cached metadata only (`dnf --cacheonly`), as + `APT_UPGRADABLE_COMMAND` reads apt's local index (#76). With an expired cache dnf + downloaded the repositories' metadata first, and on an Oracle Linux host on OCI that + outlasted netOrk's whole poll budget. Refreshing the index stays a step of its own + (`dnf makecache`). Without a cache dnf fails at once, which already reads as + "security unknown". + ## [4.23.0] - 2026-11-02 ### Changed diff --git a/napalm_device_types/package_updates.py b/napalm_device_types/package_updates.py index 7ff7f9f..2d1b69f 100644 --- a/napalm_device_types/package_updates.py +++ b/napalm_device_types/package_updates.py @@ -28,9 +28,12 @@ APT_UPGRADABLE_COMMAND = "{ LC_ALL=C apt list --upgradable 2>/dev/null; echo __A #: Read-only. Lists the packages that a pending security advisory covers. A #: failed dnf prints nothing, the same as no advisories, so its exit status is -#: printed inside the group, as apt's is. +#: printed inside the group, as apt's is. It reads the cached metadata only, as +#: apt reads its local index: an expired cache otherwise makes dnf download the +#: repositories' metadata first, which can take minutes (#76). DNF_SECURITY_COMMAND = ( - "{ LC_ALL=C dnf updateinfo list --security --quiet 2>/dev/null; echo __DNF_RC=$?; } | cat" + "{ LC_ALL=C dnf --cacheonly updateinfo list --security --quiet 2>/dev/null;" + " echo __DNF_RC=$?; } | cat" ) # openssl/noble-updates,noble-security 3.0.13-0ubuntu3.6 amd64 [upgradable from: 3.0.13-0ubuntu3.5] diff --git a/tests/test_package_updates.py b/tests/test_package_updates.py index 63d1342..b12a796 100644 --- a/tests/test_package_updates.py +++ b/tests/test_package_updates.py @@ -176,6 +176,18 @@ __DNF_RC=0 with pytest.raises(ValueError, match="exit status 1"): parse_dnf_security(out) + def test_the_command_reads_only_the_cached_metadata(self, tmp_path): + """An expired cache made dnf download the repositories' metadata inside the + poll, which outlasted its whole budget (#76).""" + args = tmp_path / "args" + dnf = tmp_path / "dnf" + dnf.write_text(f"#!/bin/sh\nprintf '%s\\n' \"$@\" > {args}\n") + dnf.chmod(0o755) + env = {"PATH": f"{tmp_path}:{os.environ.get('PATH', '/usr/bin:/bin')}"} + subprocess.run(["sh", "-c", DNF_SECURITY_COMMAND], capture_output=True, env=env) + + assert "--cacheonly" in args.read_text().split() + @pytest.mark.parametrize( ("nevra", "name"), [ -- 2.54.0