fix(host-agent): a large update records its package count (#6794)
The root helper counted updated packages from the last 2,000 characters of the package manager's output. Every manager prints its count (apt's "N upgraded, N newly installed", dnf's "Upgrade N Packages", zypper's "N packages to upgrade", pacman's "Packages (N)") before the long log of what it then does, so a large update pushed the line out of the tail and the job recorded no count. Docker03's 2026-11-01 job applied 17 updates and reported none; Docker02's single package was counted. The update steps now read their whole output (run(keep=None)), and only the failure text and the job's detail are cut short. Agent 1.26.1, so hosts show the helper as an update to take. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -270,7 +270,7 @@ def test_a_zypper_update_that_asks_for_a_reboot_still_worked(maint, monkeypatch)
|
||||
monkeypatch.setattr(maint, "_os_release_id", lambda path="/etc/os-release": "sles")
|
||||
ran = []
|
||||
|
||||
def fake_run(cmd, deadline=0, env=None, ok_codes=(0,)):
|
||||
def fake_run(cmd, deadline=0, env=None, ok_codes=(0,), keep=0):
|
||||
ran.append(cmd[2])
|
||||
code = 102 if cmd[2] == "update" else 0
|
||||
return code in ok_codes, "3 packages to upgrade.\n"
|
||||
@@ -282,6 +282,20 @@ def test_a_zypper_update_that_asks_for_a_reboot_still_worked(maint, monkeypatch)
|
||||
assert ran == ["refresh", "update"]
|
||||
|
||||
|
||||
def test_a_large_update_still_counts_its_packages(maint, monkeypatch):
|
||||
"""apt prints its count before the log of unpacking and setting up each
|
||||
package, which runs far past what a detail keeps."""
|
||||
_manager(monkeypatch, maint, ("apt-get",))
|
||||
log = "17 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n" + \
|
||||
"Setting up libfoo (1.2-3) ...\n" * 200
|
||||
monkeypatch.setattr(maint, "run", lambda cmd, **kw: (True, log if kw.get("keep", 0) is None
|
||||
else log[-maint.OUTPUT_KEPT_CHARS:]))
|
||||
monkeypatch.setattr(maint, "reboot_required", lambda: False)
|
||||
got = maint.do_update()
|
||||
assert got["ok"] and got["packages"] == 17
|
||||
assert len(got["detail"]) <= 500
|
||||
|
||||
|
||||
def test_a_failed_step_says_which(maint, monkeypatch):
|
||||
_manager(monkeypatch, maint, ("pacman",))
|
||||
monkeypatch.setattr(maint, "run", lambda cmd, **kw: (False, "error: failed to synchronize all databases"))
|
||||
|
||||
Reference in New Issue
Block a user