fix: read a command to its exit status, not to the first line that looks like a prompt #12

Merged
christianmanivong merged 1 commits from fix/read-to-the-marker into master 2026-10-06 05:29:25 +00:00
Owner

_send waited for any output ending in #, $ or >. netmiko searches that pattern in everything read so far. A chunk that happened to end in such a line therefore ended the read while the command was still running.

apt's bad-signature line, ... <ftpmaster@ubuntu.com>, did exactly that:

  • refresh_available_updates returned half its output;
  • the rest arrived as the next command's output: the remaining lines, the exit status and the prompt;
  • the update read after it then failed with "no exit status".

This hit nine hosts on 2026-10-06 (netOrk #615).

Change

A command that ends in echo __NAME=$? is now read until that marker, with a number, and the prompt line after it. That covers __NETORK_RC= and device-types' __APT_RC= and __SVC_RC=.

  • The echoed command line carries a literal $?, so it cannot match.
  • Every other command keeps the prompt pattern.

Verification

  • pytest tests/: 118 passed, 2 warnings in 12.62s. New TestReadToTheEnd feeds a fake channel the real vault-01 chunks and checks:
    • the refresh reads through the signature line;
    • the next command reads only its own output;
    • the echoed command does not count as the marker;
    • the device-types markers are waited for;
    • plain commands keep the prompt pattern.
  • ruff: 0 findings before and after. mypy: the same 47 pre-existing errors before and after.
  • Live gate test on searxng-01 (netOrk api container, this module injected), with printf 'x <a@b>\n'; sleep 3; printf 'after\n'; echo __NETORK_RC=$?:
    • old pattern: returned x <a@b>; left after\n__NETORK_RC=0\n<prompt> in the channel;
    • new pattern: returned everything up to __NETORK_RC=0; the next command read next-ok.
`_send` waited for any output ending in `#`, `$` or `>`. netmiko searches that pattern in everything read so far. A chunk that happened to end in such a line therefore ended the read while the command was still running. apt's bad-signature line, `... <ftpmaster@ubuntu.com>`, did exactly that: - `refresh_available_updates` returned half its output; - the rest arrived as the next command's output: the remaining lines, the exit status and the prompt; - the update read after it then failed with "no exit status". This hit nine hosts on 2026-10-06 (netOrk #615). ## Change A command that ends in `echo __NAME=$?` is now read until that marker, with a number, and the prompt line after it. That covers `__NETORK_RC=` and device-types' `__APT_RC=` and `__SVC_RC=`. - The echoed command line carries a literal `$?`, so it cannot match. - Every other command keeps the prompt pattern. ## Verification - `pytest tests/`: 118 passed, 2 warnings in 12.62s. New `TestReadToTheEnd` feeds a fake channel the real vault-01 chunks and checks: - the refresh reads through the signature line; - the next command reads only its own output; - the echoed command does not count as the marker; - the device-types markers are waited for; - plain commands keep the prompt pattern. - ruff: 0 findings before and after. mypy: the same 47 pre-existing errors before and after. - **Live gate test on searxng-01** (netOrk api container, this module injected), with `printf 'x <a@b>\n'; sleep 3; printf 'after\n'; echo __NETORK_RC=$?`: - old pattern: returned `x <a@b>`; left `after\n__NETORK_RC=0\n<prompt>` in the channel; - new pattern: returned everything up to `__NETORK_RC=0`; the next command read `next-ok`.
christianmanivong added 1 commit 2026-10-06 05:19:02 +00:00
_send waited for any output ending in "#", "$" or ">". netmiko matches that
against everything read so far, so a chunk that happened to end in such a
line ended the read while the command still ran. apt's bad-signature line,
"... <ftpmaster@ubuntu.com>", did exactly that: refresh_available_updates
returned half its output, and the rest -- exit status and prompt included --
arrived as the next command's output, so the update read after it failed
with "no exit status" (netOrk #615, seen on nine hosts on 2026-10-06).

A command that ends in "echo __NAME=$?" (__NETORK_RC=, and device-types'
__APT_RC= and __SVC_RC=) is now read until that marker, with a number, and
the prompt line after it. The echoed command line carries a literal $? and
cannot match. Every other command keeps the prompt pattern.
christianmanivong merged commit e82f99df7b into master 2026-10-06 05:29:25 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-linux#12