feat: reboot_host (0.5.0)
CI / test (3.10) (push) Successful in 26s
CI / test (3.11) (push) Successful in 23s
CI / test (3.12) (push) Successful in 26s
CI / test (3.10) (pull_request) Successful in 25s
CI / test (3.11) (pull_request) Successful in 24s
CI / test (3.12) (pull_request) Successful in 25s
CI / test (3.10) (push) Successful in 26s
CI / test (3.11) (push) Successful in 23s
CI / test (3.12) (push) Successful in 26s
CI / test (3.10) (pull_request) Successful in 25s
CI / test (3.11) (pull_request) Successful in 24s
CI / test (3.12) (pull_request) Successful in 25s
HostRebootMixin's reboot_host over the command channel: reboot detached and two seconds late, so the answer comes back before the session goes down, and a refusal is raised instead of being mistaken for the dropped session. netOrk sent /sbin/reboot through the private _send_command and could not tell the two apart (netOrk #1113). A login other than root is refused before anything runs.
This commit is contained in:
1 parent
5169d2438f
commit
d89bb38688
3 files changed
+52
-1
No files matched your search
@@ -77,3 +77,33 @@ def test_no_warnings_of_its_own():
|
||||
for c in OpenWrtDriver.__mro__
|
||||
if c.__module__.startswith("napalm_openwrt")
|
||||
)
|
||||
|
||||
|
||||
class TestRebootHost:
|
||||
"""``reboot_host`` (napalm-device-types ``HostRebootMixin``): netOrk sent
|
||||
``/sbin/reboot`` through the private ``_send_command`` and could not tell a
|
||||
refusal from the session dropping (netOrk #1113)."""
|
||||
|
||||
def test_detached_so_the_answer_comes_back_first(self):
|
||||
drv = _driver()
|
||||
with patch("napalm_openwrt.openwrt.run_on_transport", return_value=CommandResult("", "", 0)) as run:
|
||||
drv.reboot_host()
|
||||
|
||||
command = run.call_args.args[1]
|
||||
assert "reboot" in command and command.rstrip().endswith("&'")
|
||||
assert "trap" in command and "sleep" in command
|
||||
|
||||
def test_a_refusal_is_raised(self):
|
||||
drv = _driver()
|
||||
failed = CommandResult("", "reboot: Operation not permitted", 1)
|
||||
with patch("napalm_openwrt.openwrt.run_on_transport", return_value=failed), pytest.raises(
|
||||
RuntimeError, match="not permitted"
|
||||
):
|
||||
drv.reboot_host()
|
||||
|
||||
def test_a_login_other_than_root_is_refused(self):
|
||||
drv = _driver(username="admin")
|
||||
with patch("napalm_openwrt.openwrt.run_on_transport") as run, pytest.raises(RuntimeError):
|
||||
drv.reboot_host()
|
||||
|
||||
run.assert_not_called()
|
||||
Reference in new issue
Block a user