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
@@ -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