Allowing controller to restart itself.

This commit is contained in:
Roland 2025-12-25 09:29:01 -07:00
parent 5c8f164c1a
commit 0d155c9311
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
4 changed files with 41 additions and 2 deletions

View file

@ -219,6 +219,26 @@ class TestServiceActions:
assert result["action"] == expected_action
class TestControllerSelfRestart:
"""Tests for controller self-restart behavior."""
def test_controller_restart_uses_popen(self):
"""Controller restart should use Popen to avoid blocking on self-termination."""
with mock.patch("subprocess.Popen") as mock_popen:
result = restart_service("wrolpi-controller")
mock_popen.assert_called_once_with(["systemctl", "restart", "wrolpi-controller"])
assert result["success"] is True
assert result["pending"] is True
assert result["action"] == "restart"
def test_controller_restart_handles_exception(self):
"""Controller restart should handle exceptions gracefully."""
with mock.patch("subprocess.Popen", side_effect=Exception("popen failed")):
result = restart_service("wrolpi-controller")
assert result["success"] is False
assert "popen failed" in result["error"]
class TestGetServiceLogs:
"""Tests for get_service_logs function."""