fix(sudo): run the whole command as root without a sudo password
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
This commit is contained in:
1 parent
c2d7c4d1b4
commit
d3134c83b8
5 files changed
+232
-7
No files matched your search
+2
-2
@@ -1601,7 +1601,7 @@ class TestManageService:
|
||||
|
||||
driver.manage_service("cron", "enable")
|
||||
|
||||
assert self._sent(driver)[1].startswith("sudo -n timeout 45 systemctl")
|
||||
assert self._sent(driver)[1].startswith("sudo -n sh -c 'timeout 45 systemctl")
|
||||
|
||||
def test_a_missing_sudo_password_is_explained(self, driver):
|
||||
driver._device.send_command.side_effect = [
|
||||
@@ -1832,7 +1832,7 @@ class TestRefreshAvailableUpdates:
|
||||
result = driver.refresh_available_updates()
|
||||
|
||||
assert result["success"] is False
|
||||
assert self._sent(driver)[1].startswith("sudo -n apt-get update")
|
||||
assert self._sent(driver)[1].startswith("sudo -n sh -c 'apt-get update")
|
||||
|
||||
def test_dnf_refreshes_its_metadata(self, driver):
|
||||
driver._pkg_manager = "dnf"
|
||||
|
||||
Reference in new issue
Block a user