_sudo: use sudo -n when no sudo password is configured #10

Closed
opened 2026-10-05 11:45:12 +00:00 by christianmanivong · 1 comment
Owner

_sudo() sends a plain sudo <cmd> when no sudo_password is set. If sudo then wants a password, its prompt does not match netmiko's expect_string. The call hangs until read_timeout (100 s by default) and then raises.

_run_service_command (#9) already uses sudo -n in that case: it fails at once with "a password is required". Doing the same in _sudo() would give every other caller the same behaviour: package install/uninstall, updates, crontabs, VPN tunnels. That would make the two sudo -n true pre-checks in _action_apt_update_upgrade and _action_fix_snmp unnecessary.

`_sudo()` sends a plain `sudo <cmd>` when no `sudo_password` is set. If sudo then wants a password, its prompt does not match netmiko's `expect_string`. The call hangs until `read_timeout` (100 s by default) and then raises. `_run_service_command` (#9) already uses `sudo -n` in that case: it fails at once with "a password is required". Doing the same in `_sudo()` would give every other caller the same behaviour: package install/uninstall, updates, crontabs, VPN tunnels. That would make the two `sudo -n true` pre-checks in `_action_apt_update_upgrade` and `_action_fix_snmp` unnecessary.
Author
Owner

Already fixed on main by cf8ee38 (2026-10-12): without a sudo password _as_root uses sudo -n sh -c …, which fails at once instead of prompting (test test_without_a_password_sudo_never_waits_for_one). The sudo -n true pre-checks went with run_device_action (272bf21).

Already fixed on main by cf8ee38 (2026-10-12): without a sudo password `_as_root` uses `sudo -n sh -c …`, which fails at once instead of prompting (test `test_without_a_password_sudo_never_waits_for_one`). The `sudo -n true` pre-checks went with `run_device_action` (272bf21).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-linux#10