Six open bugs, one commit each: #55, #56 and #57, then #63, #64 and #65 from the review of the first three.
ping(): destination and source go into the shell quoted (#55)
ping() typed its arguments into the interactive shell as they came: a destination such as 1.2.3.4; id ran id as the login user. destination and source now go through shlex.quote, and count, timeout, size and ttl through int(), which raises ValueError before anything is sent. The line is built in _ping.py (ping_command), next to its parser, which keeps linux.py within its recorded length (the baseline shrinks by two lines).
Without a sudo password the whole command runs as root (#56)
Without a root login and without a sudo password (NOPASSWD, netOrk's own account), _run_privileged sent sudo -n <command>. sudo covered only the first simple command, and the dnf/yum advisory query, which starts with a brace group, did not parse: bash -n reports syntax error near unexpected token '}'. No status marker came back, so netmiko waited out the 120 s read timeout and get_available_updates() failed on such hosts.
The no-password branch now sends sudo -n sh -c <quoted command>, as _as_root does with a password (_shell.sudo_without_password). A status echo at the end of the command (; echo __NETORK_RC=$?, __SVC_RC=) stays outside sh -c: it reports sh's status, which is the command's, and still arrives when sudo refuses. Without that, a refused sudo would also wait out the timeout.
Every caller was checked: reboot_host (nested sh -c, the detached reboot unchanged), refresh_available_updates, _get_updates_rpm (check-update), _rpm_security_names (dnf and yum), manage_service (SystemdServicesMixin) and the privileged get_listening_sockets (already sh -c, now nested). All of them are POSIX sh, which the password path already required. One visible difference: sudo's own refusal message is no longer swallowed by a command's 2>/dev/null, so a failed dnf check-update now names it.
get_route_to(): route types and multipath next hops (#57)
The first word of every ip route show line was taken as the destination: unreachable 10.0.0.0/8 became unreachable/32, and a multipath route's nexthop via … lines became nexthop/32 routes while the route itself had no next hop. The type word is now read as the type and reported as protocol_attributes: {"type": "blackhole"} etc., with no next hop and no outgoing interface for unreachable/blackhole/prohibit/throw (IPv6 names lo for them). nexthop lines attach to the route before them, one entry per next hop. The third point of the issue, /128 for an IPv6 host route, was already fixed with #6 (897892b).
Tests
Fixtures only, no device.
#55: the exact line sent for a destination with ;, a source with $(…), coerced numbers, and a non-number refused before anything is sent.
#56 (tests/test_sudo_without_password.py): bash -n on the line of every _run_privileged caller; the exact dnf/yum and systemctl lines with the status echo outside; and the lines run in a real bash with a stand-in sudo and dnf on PATH, read like netmiko until the expect pattern matches: the advisories are parsed, and a refusing sudo still reports its status at once (refresh says so with the NOPASSWD hint, the advisories stay unknown). Before the fix these timed out on the expect pattern.
#57: ip -4 route show / ip -6 route show from iproute2 6.1.0 (Linux 7.0), recorded in a network namespace set up with a multipath default per family and unreachable, prohibit, throw and blackhole routes; plus parser cases for a local route, an orphaned nexthop line and a single-path route.
ping: a destination or source starting with - is refused (#63). Quoting keeps -f one word, and ping still reads it as its flood option. No address or hostname starts with -, so ping_command raises ValueError before anything is sent. The other choice, -- before the destination, would not cover -I <source>.
FRR enrichment: an IPv6 host route without a length is a /128 (#64).with_length() in _routes.py completes a prefix by its family, so the vtysh route meets the kernel's /128 entry for the same host (as proto zebra) and gives it FRR's protocol, instead of adding a bogus /32. The protocol attributes moved onto IpRoute (route.attributes), which keeps the import in linux.py on one line; get_route_to shrinks (103 → 101 lines, complexity 14 → 13) and the baseline records it.
via inet6 <address> (#65). The family word after via is skipped, for multipath nexthop lines too. With the address in place, _make_entry would have reported such an IPv4 route as ipv6, since it took the family from the next hop as well; the family is now the destination's alone. Fixture: ip -4 route show from iproute2 6.1.0, recorded in a network namespace with a default route, a single-path route and a multipath route via IPv6 gateways.
Tests for the follow-ups: TestPingArguments::test_an_option_in_place_of_a_name_is_refused_before_anything_is_sent, TestFrrHostRoutes, TestIpv6NextHops (all failed before their fix).
pytest 344 passed; ruff format/check clean; mypy clean for the package; bandit clean; napalm-standard check and ratchet pass (linux.py 2142 → 2138).
Six open bugs, one commit each: #55, #56 and #57, then #63, #64 and #65 from the review of the first three.
## `ping()`: destination and source go into the shell quoted (#55)
`ping()` typed its arguments into the interactive shell as they came: a destination such as `1.2.3.4; id` ran `id` as the login user. `destination` and `source` now go through `shlex.quote`, and `count`, `timeout`, `size` and `ttl` through `int()`, which raises `ValueError` before anything is sent. The line is built in `_ping.py` (`ping_command`), next to its parser, which keeps `linux.py` within its recorded length (the baseline shrinks by two lines).
## Without a sudo password the whole command runs as root (#56)
Without a root login and without a sudo password (NOPASSWD, netOrk's own account), `_run_privileged` sent `sudo -n <command>`. sudo covered only the first simple command, and the dnf/yum advisory query, which starts with a brace group, did not parse: `bash -n` reports `syntax error near unexpected token '}'`. No status marker came back, so netmiko waited out the 120 s read timeout and `get_available_updates()` failed on such hosts.
The no-password branch now sends `sudo -n sh -c <quoted command>`, as `_as_root` does with a password (`_shell.sudo_without_password`). A status echo at the end of the command (`; echo __NETORK_RC=$?`, `__SVC_RC=`) stays outside `sh -c`: it reports sh's status, which is the command's, and still arrives when sudo refuses. Without that, a refused sudo would also wait out the timeout.
Every caller was checked: `reboot_host` (nested `sh -c`, the detached reboot unchanged), `refresh_available_updates`, `_get_updates_rpm` (check-update), `_rpm_security_names` (dnf and yum), `manage_service` (`SystemdServicesMixin`) and the privileged `get_listening_sockets` (already `sh -c`, now nested). All of them are POSIX sh, which the password path already required. One visible difference: sudo's own refusal message is no longer swallowed by a command's `2>/dev/null`, so a failed dnf check-update now names it.
## `get_route_to()`: route types and multipath next hops (#57)
The first word of every `ip route show` line was taken as the destination: `unreachable 10.0.0.0/8` became `unreachable/32`, and a multipath route's `nexthop via …` lines became `nexthop/32` routes while the route itself had no next hop. The type word is now read as the type and reported as `protocol_attributes: {"type": "blackhole"}` etc., with no next hop and no outgoing interface for unreachable/blackhole/prohibit/throw (IPv6 names `lo` for them). `nexthop` lines attach to the route before them, one entry per next hop. The third point of the issue, `/128` for an IPv6 host route, was already fixed with #6 (897892b).
## Tests
Fixtures only, no device.
- #55: the exact line sent for a destination with `;`, a source with `$(…)`, coerced numbers, and a non-number refused before anything is sent.
- #56 (`tests/test_sudo_without_password.py`): `bash -n` on the line of every `_run_privileged` caller; the exact dnf/yum and systemctl lines with the status echo outside; and the lines run in a real bash with a stand-in `sudo` and `dnf` on PATH, read like netmiko until the expect pattern matches: the advisories are parsed, and a refusing sudo still reports its status at once (refresh says so with the NOPASSWD hint, the advisories stay unknown). Before the fix these timed out on the expect pattern.
- #57: `ip -4 route show` / `ip -6 route show` from iproute2 6.1.0 (Linux 7.0), recorded in a network namespace set up with a multipath default per family and unreachable, prohibit, throw and blackhole routes; plus parser cases for a `local` route, an orphaned `nexthop` line and a single-path route.
## Follow-ups (#63, #64, #65)
- **ping: a destination or source starting with `-` is refused (#63).** Quoting keeps `-f` one word, and ping still reads it as its flood option. No address or hostname starts with `-`, so `ping_command` raises `ValueError` before anything is sent. The other choice, `--` before the destination, would not cover `-I <source>`.
- **FRR enrichment: an IPv6 host route without a length is a `/128` (#64).** `with_length()` in `_routes.py` completes a prefix by its family, so the vtysh route meets the kernel's `/128` entry for the same host (as `proto zebra`) and gives it FRR's protocol, instead of adding a bogus `/32`. The protocol attributes moved onto `IpRoute` (`route.attributes`), which keeps the import in `linux.py` on one line; `get_route_to` shrinks (103 → 101 lines, complexity 14 → 13) and the baseline records it.
- **`via inet6 <address>` (#65).** The family word after `via` is skipped, for multipath `nexthop` lines too. With the address in place, `_make_entry` would have reported such an IPv4 route as `ipv6`, since it took the family from the next hop as well; the family is now the destination's alone. Fixture: `ip -4 route show` from iproute2 6.1.0, recorded in a network namespace with a default route, a single-path route and a multipath route via IPv6 gateways.
Tests for the follow-ups: `TestPingArguments::test_an_option_in_place_of_a_name_is_refused_before_anything_is_sent`, `TestFrrHostRoutes`, `TestIpv6NextHops` (all failed before their fix).
pytest 344 passed; ruff format/check clean; mypy clean for the package; bandit clean; `napalm-standard check` and `ratchet` pass (`linux.py` 2142 → 2138).
Closes #55
Closes #56
Closes #57
Closes #63
Closes #64
Closes #65
ping() typed its arguments into the interactive shell as they came, so a
destination such as "1.2.3.4; id" ran the command after the semicolon as
the login user. destination and source now go through shlex.quote, and
count, timeout, size and ttl are coerced with int(), which refuses
anything that is not a number before a command is sent.
The command is built in _ping.py, next to its parser, which keeps
linux.py within its recorded length.
Closes#55
Without a root login and without a sudo password, _run_privileged typed
"sudo -n <command>" into the interactive shell. sudo covered only the
first simple command of the line, and dnf's and yum's advisory query,
which starts with a brace group, did not parse at all: no status marker
ever arrived, so netmiko waited out the 120 s read timeout and
get_available_updates() failed. This is the default path for netOrk's
own NOPASSWD account.
The command now goes to "sudo -n sh -c" as one argument, as _as_root
already does with a password. A status echo at its end stays outside
sh -c: it reports sh's status, which is the command's, and still
arrives when sudo refuses.
Closes#56
get_route_to took the first word of every "ip route show" line as the
destination. For unreachable, blackhole, prohibit and throw routes that
word is the route type, so they came back as "unreachable/32" and the
like; a multipath route's continuation lines became "nexthop/32"
routes, and the route itself had no next hop.
The type word is now read as the type and reported in
protocol_attributes, without a next hop or outgoing interface for the
types that forward nothing (IPv6 names lo for them). nexthop lines
attach to the route before them, one entry per next hop. The test
fixture is ip's output (iproute2 6.1.0) recorded in a network
namespace set up with these routes.
Closes#57
Quoting keeps a value one word, but ping still reads a word starting
with "-" as one of its options: ping(destination="-f") sent a flood
ping option instead of a host, and a source "-f" did the same after -I.
No address or hostname starts with "-", so ping_command now refuses
such a destination or source with ValueError before anything is sent.
Closes#63
The FRR enrichment in get_route_to completed every prefix without a
length with /32. An IPv6 host route became a different, much larger
/32 prefix, so it missed the kernel's /128 entry for the same host
(stored that way since #6) and added a bogus one instead.
with_length() in _routes.py completes a prefix by its family, /32 or
/128. The protocol attributes move onto IpRoute, which keeps the import
in linux.py on one line; get_route_to shrinks and the baseline records
it.
Closes#64
iproute2 prints an IPv4 route with an IPv6 next hop (RFC 8950, BGP
unnumbered) as "via inet6 fe80::1", and the next hop was read as the
literal "inet6". The family word after "via" is now skipped, for
multipath next hops as well.
With the address in place, get_route_to would have reported such a
route as ipv6, because it took the family from the next hop too. The
family is now the destination's alone. The test fixture is ip's output
(iproute2 6.1.0) recorded in a network namespace set up with these
routes.
Closes#65
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Six open bugs, one commit each: #55, #56 and #57, then #63, #64 and #65 from the review of the first three.
ping(): destination and source go into the shell quoted (#55)ping()typed its arguments into the interactive shell as they came: a destination such as1.2.3.4; idranidas the login user.destinationandsourcenow go throughshlex.quote, andcount,timeout,sizeandttlthroughint(), which raisesValueErrorbefore anything is sent. The line is built in_ping.py(ping_command), next to its parser, which keepslinux.pywithin its recorded length (the baseline shrinks by two lines).Without a sudo password the whole command runs as root (#56)
Without a root login and without a sudo password (NOPASSWD, netOrk's own account),
_run_privilegedsentsudo -n <command>. sudo covered only the first simple command, and the dnf/yum advisory query, which starts with a brace group, did not parse:bash -nreportssyntax error near unexpected token '}'. No status marker came back, so netmiko waited out the 120 s read timeout andget_available_updates()failed on such hosts.The no-password branch now sends
sudo -n sh -c <quoted command>, as_as_rootdoes with a password (_shell.sudo_without_password). A status echo at the end of the command (; echo __NETORK_RC=$?,__SVC_RC=) stays outsidesh -c: it reports sh's status, which is the command's, and still arrives when sudo refuses. Without that, a refused sudo would also wait out the timeout.Every caller was checked:
reboot_host(nestedsh -c, the detached reboot unchanged),refresh_available_updates,_get_updates_rpm(check-update),_rpm_security_names(dnf and yum),manage_service(SystemdServicesMixin) and the privilegedget_listening_sockets(alreadysh -c, now nested). All of them are POSIX sh, which the password path already required. One visible difference: sudo's own refusal message is no longer swallowed by a command's2>/dev/null, so a failed dnf check-update now names it.get_route_to(): route types and multipath next hops (#57)The first word of every
ip route showline was taken as the destination:unreachable 10.0.0.0/8becameunreachable/32, and a multipath route'snexthop via …lines becamenexthop/32routes while the route itself had no next hop. The type word is now read as the type and reported asprotocol_attributes: {"type": "blackhole"}etc., with no next hop and no outgoing interface for unreachable/blackhole/prohibit/throw (IPv6 nameslofor them).nexthoplines attach to the route before them, one entry per next hop. The third point of the issue,/128for an IPv6 host route, was already fixed with #6 (897892b).Tests
Fixtures only, no device.
;, a source with$(…), coerced numbers, and a non-number refused before anything is sent.tests/test_sudo_without_password.py):bash -non the line of every_run_privilegedcaller; the exact dnf/yum and systemctl lines with the status echo outside; and the lines run in a real bash with a stand-insudoanddnfon PATH, read like netmiko until the expect pattern matches: the advisories are parsed, and a refusing sudo still reports its status at once (refresh says so with the NOPASSWD hint, the advisories stay unknown). Before the fix these timed out on the expect pattern.ip -4 route show/ip -6 route showfrom iproute2 6.1.0 (Linux 7.0), recorded in a network namespace set up with a multipath default per family and unreachable, prohibit, throw and blackhole routes; plus parser cases for alocalroute, an orphanednexthopline and a single-path route.Follow-ups (#63, #64, #65)
-is refused (#63). Quoting keeps-fone word, and ping still reads it as its flood option. No address or hostname starts with-, soping_commandraisesValueErrorbefore anything is sent. The other choice,--before the destination, would not cover-I <source>./128(#64).with_length()in_routes.pycompletes a prefix by its family, so the vtysh route meets the kernel's/128entry for the same host (asproto zebra) and gives it FRR's protocol, instead of adding a bogus/32. The protocol attributes moved ontoIpRoute(route.attributes), which keeps the import inlinux.pyon one line;get_route_toshrinks (103 → 101 lines, complexity 14 → 13) and the baseline records it.via inet6 <address>(#65). The family word afterviais skipped, for multipathnexthoplines too. With the address in place,_make_entrywould have reported such an IPv4 route asipv6, since it took the family from the next hop as well; the family is now the destination's alone. Fixture:ip -4 route showfrom iproute2 6.1.0, recorded in a network namespace with a default route, a single-path route and a multipath route via IPv6 gateways.Tests for the follow-ups:
TestPingArguments::test_an_option_in_place_of_a_name_is_refused_before_anything_is_sent,TestFrrHostRoutes,TestIpv6NextHops(all failed before their fix).pytest 344 passed; ruff format/check clean; mypy clean for the package; bandit clean;
napalm-standard checkandratchetpass (linux.py2142 → 2138).Closes #55
Closes #56
Closes #57
Closes #63
Closes #64
Closes #65