fix: the apt read ends on its own status echo, 4.59.1 (NetOrk/netork#3139)
driver / lint (pull_request) Successful in 12s
driver / standard (pull_request) Successful in 14s
driver / lowest (pull_request) Successful in 41s
driver / types (pull_request) Successful in 59s
driver / test (3.13) (pull_request) Successful in 1m11s
driver / test (3.12) (pull_request) Successful in 1m21s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m4s
CI / driver (pull_request) Successful in 1m59s
driver / publish (pull_request) Skipped
driver / lint (pull_request) Successful in 12s
driver / standard (pull_request) Successful in 14s
driver / lowest (pull_request) Successful in 41s
driver / types (pull_request) Successful in 59s
driver / test (3.13) (pull_request) Successful in 1m11s
driver / test (3.12) (pull_request) Successful in 1m21s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m4s
CI / driver (pull_request) Successful in 1m59s
driver / publish (pull_request) Skipped
APT_UPGRADABLE_COMMAND printed __APT_PHASED (4.58.1) and __APT_E (4.57.0) after __APT_RC. A screen-scraping transport reads until the command's last status echo and the prompt after it, so on a host where apt defers a package for phasing, or reports an error, the read never ended and ran into its timeout. __APT_END is now echoed once everything else is written.
This commit is contained in:
1 parent
85119a770e
commit
9106871bfa
4 files changed
+53
-3
No files matched your search
@@ -7,6 +7,16 @@ recorded here; their history is the git log.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [4.59.1] - 2026-12-05
|
||||
|
||||
### Fixed
|
||||
- `APT_UPGRADABLE_COMMAND` ends on its own status echo, `__APT_END=`, written once
|
||||
everything else is. A screen-scraping transport reads until the command's last status
|
||||
echo and the prompt after it. The `__APT_PHASED:` lines (4.58.1) and the `__APT_E:` lines
|
||||
(4.57.0) came after `__APT_RC`, so on a host where apt defers a package for phasing, or
|
||||
reports an error, the read never ended and ran into its timeout (NetOrk/netork#3139).
|
||||
The parse does not read the new line.
|
||||
|
||||
## [4.59.0] - 2026-12-05
|
||||
|
||||
### Added
|
||||
|
||||
@@ -38,12 +38,17 @@ from napalm_device_types.updates import PackageSourcesUnreadable
|
||||
#: 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.
|
||||
#:
|
||||
#: Its last line is ``__APT_END=``, echoed once everything else is written. A
|
||||
#: screen-scraping transport reads until the command's last status echo and the
|
||||
#: prompt after it; ``__APT_PHASED`` and ``__APT_E`` came after ``__APT_RC``, and
|
||||
#: the read never ended (netOrk #3139). The parse does not read it.
|
||||
APT_UPGRADABLE_COMMAND = (
|
||||
"{ { LC_ALL=C apt list --upgradable 2>&1 1>&3 3>&-; echo __APT_RC=$? 1>&3; }"
|
||||
"{ { { LC_ALL=C apt list --upgradable 2>&1 1>&3 3>&-; echo __APT_RC=$? 1>&3; }"
|
||||
" | 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"
|
||||
" 3>&1; echo __APT_END=$?; } | cat"
|
||||
)
|
||||
|
||||
#: apt's last word when it cannot read its sources, in ``LC_ALL=C``.
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "napalm-device-types"
|
||||
version = "4.59.0"
|
||||
version = "4.59.1"
|
||||
description = "Abstract device-type base classes for NAPALM drivers"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
|
||||
@@ -12,6 +12,7 @@ Fixture lines are from real hosts (Ubuntu 24.04, Debian 13 / OMV, Proxmox VE 9).
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
@@ -230,6 +231,11 @@ Conf openssl (3.0.13-0ubuntu3.6 Ubuntu:24.04/noble-updates [amd64])
|
||||
"""
|
||||
|
||||
|
||||
#: The marker of the command's last ``echo __NAME=$?``: a screen-scraping
|
||||
#: transport reads until it, with a number, and the prompt line after it.
|
||||
_LAST_STATUS_ECHO = re.escape(re.findall(r"echo\s+(__[A-Z_]+=)\$\?", APT_UPGRADABLE_COMMAND)[-1])
|
||||
|
||||
|
||||
def _fake_apt(tmp_path, apt_get: str, apt_get_rc: int = 0) -> dict[str, str]:
|
||||
"""A PATH whose ``apt`` lists :data:`PHASING` and whose ``apt-get`` says *apt_get*."""
|
||||
bin_dir = tmp_path / "bin"
|
||||
@@ -290,6 +296,35 @@ class TestPhasedUpdates:
|
||||
|
||||
assert len(parse_apt_upgradable(out)) == 3
|
||||
|
||||
def test_the_command_ends_on_its_last_status_echo(self, tmp_path):
|
||||
"""A screen-scraping transport reads until the command's last status echo
|
||||
and the prompt after it (napalm-linux's ``expect_for``). What apt-get
|
||||
defers came after ``__APT_RC``, so the read never ended on a host with a
|
||||
phased package and ran into its timeout (netOrk #3139)."""
|
||||
env = _fake_apt(tmp_path, APT_GET_UPGRADE)
|
||||
|
||||
out = subprocess.run(
|
||||
["sh", "-c", APT_UPGRADABLE_COMMAND], capture_output=True, text=True, env=env
|
||||
).stdout
|
||||
|
||||
assert re.fullmatch(_LAST_STATUS_ECHO + r"\d+", out.splitlines()[-1])
|
||||
assert [u["name"] for u in parse_apt_upgradable(out)] == ["openssl"]
|
||||
|
||||
def test_apts_errors_come_before_the_last_status_echo(self, tmp_path):
|
||||
"""``sed`` writes apt's marked errors when apt is done, after ``__APT_RC``."""
|
||||
env = _fake_apt(tmp_path, "")
|
||||
(tmp_path / "bin" / "apt").write_text(
|
||||
"#!/bin/sh\necho 'E: The list of sources could not be read.' >&2\nexit 100\n"
|
||||
)
|
||||
|
||||
out = subprocess.run(
|
||||
["sh", "-c", APT_UPGRADABLE_COMMAND], capture_output=True, text=True, env=env
|
||||
).stdout
|
||||
|
||||
assert re.fullmatch(_LAST_STATUS_ECHO + r"\d+", out.splitlines()[-1])
|
||||
with pytest.raises(PackageSourcesUnreadable):
|
||||
parse_apt_upgradable(out)
|
||||
|
||||
def test_the_simulation_needs_no_root_and_no_lock(self):
|
||||
assert "apt-get -s" in APT_UPGRADABLE_COMMAND
|
||||
assert "Debug::NoLocking=1" in APT_UPGRADABLE_COMMAND
|
||||
|
||||
Reference in new issue
Block a user