fix: a build Ubuntu is phasing in is not pending where apt holds it back, 4.58.1 (NetOrk/netork#3110)
driver / lint (pull_request) Successful in 14s
driver / standard (pull_request) Successful in 18s
driver / lowest (pull_request) Successful in 41s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m17s
driver / test (3.13) (pull_request) Successful in 1m17s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Successful in 1m56s
driver / publish (pull_request) Skipped
driver / lint (pull_request) Successful in 14s
driver / standard (pull_request) Successful in 18s
driver / lowest (pull_request) Successful in 41s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m17s
driver / test (3.13) (pull_request) Successful in 1m17s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Successful in 1m56s
driver / publish (pull_request) Skipped
apt list --upgradable lists a phased build on every host; apt upgrade installs it only where the rollout has reached. APT_UPGRADABLE_COMMAND now also simulates apt-get upgrade (no root, no lock) and marks what it defers for phasing; parse_apt_upgradable leaves those packages out. A failed simulation marks nothing, so the listing stands.
This commit is contained in:
1 parent
98041be694
commit
65fcebc499
4 files changed
+130
-4
No files matched your search
@@ -10,6 +10,12 @@ apt: the suites a candidate comes from are its ``origin``; any suite ending in
|
||||
``-security`` makes it a security update. A security fix that a later
|
||||
``-updates`` build superseded shows only ``-updates`` and counts as not
|
||||
security -- netOrk's CVE matching is what catches those.
|
||||
|
||||
apt also lists a build Ubuntu is still phasing in -- handing it to a share of
|
||||
its hosts first -- on every host, while ``apt upgrade`` holds it back where the
|
||||
host is not yet in the share. Such a package is not pending there, and an
|
||||
update would not install it, so the read leaves out what apt defers for
|
||||
phasing (netOrk #3110).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -28,9 +34,16 @@ from napalm_device_types.updates import PackageSourcesUnreadable
|
||||
#: ``__APT_E:``, so a failed read says why (netOrk #3087); the rest of what it
|
||||
#: writes to stderr, its warnings, stays out. Plain ``sh``: stdout goes round
|
||||
#: the pipe on descriptor 3.
|
||||
#:
|
||||
#: After it, a simulated ``apt-get upgrade`` -- no root, no lock -- names what apt
|
||||
#: defers for phasing, each line of its list marked ``__APT_PHASED:``. Where the
|
||||
#: simulation fails it names nothing, and the listing stands as it is.
|
||||
APT_UPGRADABLE_COMMAND = (
|
||||
"{ { LC_ALL=C apt list --upgradable 2>&1 1>&3 3>&-; echo __APT_RC=$? 1>&3; }"
|
||||
" | sed -n 's/^E: /__APT_E: /p'; } 3>&1 | cat"
|
||||
" | sed -n 's/^E: /__APT_E: /p';"
|
||||
" LC_ALL=C apt-get -s -o Debug::NoLocking=1 upgrade 2>/dev/null"
|
||||
" | sed -n '/deferred due to phasing:$/,/^[^ ]/{/^ /s/^ */__APT_PHASED: /p;}'; }"
|
||||
" 3>&1 | cat"
|
||||
)
|
||||
|
||||
#: apt's last word when it cannot read its sources, in ``LC_ALL=C``.
|
||||
@@ -63,6 +76,7 @@ _APT_LINE = re.compile(r"^(\S+)/(\S+)\s+(\S+)\s+\S+\s+\[upgradable from:\s+(\S+)
|
||||
_SECURITY_SUITE = "-security"
|
||||
_APT_STATUS = re.compile(r"^__APT_RC=(\d+)\s*$", re.MULTILINE)
|
||||
_APT_ERROR = re.compile(r"^__APT_E: (.*?)\s*$", re.MULTILINE)
|
||||
_APT_PHASED = re.compile(r"^__APT_PHASED: (.*?)\s*$", re.MULTILINE)
|
||||
_DNF_STATUS = re.compile(r"^__DNF_RC=(\d+)\s*$", re.MULTILINE)
|
||||
_CVE_ID = re.compile(r"^CVE-\d{4}-\d{4,}$")
|
||||
|
||||
@@ -103,13 +117,20 @@ def parse_apt_upgradable(output: str) -> list[UpdateDict]:
|
||||
A package listed for several architectures (``libc6`` for amd64 and i386)
|
||||
is one entry; it counts as a security update if any of its lines does.
|
||||
|
||||
A package apt defers for phasing (``__APT_PHASED:``) is left out: apt would
|
||||
not upgrade it on this host.
|
||||
|
||||
:raises PackageSourcesUnreadable: when apt could not read its list of sources.
|
||||
:raises ValueError: when apt failed otherwise or its exit status never arrived.
|
||||
"""
|
||||
listing = _listing(output, _APT_STATUS, "apt list --upgradable")
|
||||
deferred = {
|
||||
name.split(":")[0] for names in _APT_PHASED.findall(listing) for name in names.split()
|
||||
}
|
||||
by_name: dict[str, UpdateDict] = {}
|
||||
for line in _joined_lines(_listing(output, _APT_STATUS, "apt list --upgradable")):
|
||||
for line in _joined_lines(listing):
|
||||
match = _APT_LINE.match(line)
|
||||
if not match:
|
||||
if not match or match.group(1) in deferred:
|
||||
continue
|
||||
name, listed, new_version, current_version = match.groups()
|
||||
suites = list(dict.fromkeys(listed.split(","))) # apt may list a suite twice
|
||||
|
||||
Reference in new issue
Block a user