fix(updates): report a failed apply_updates as a failure

apt-get ran with "|| true" and the result was always success, so a
failed upgrade read as done. The exit status is read now and a failure
names it.

Closes #20
This commit is contained in:
Christian Manivong committed 2026-11-01 21:48:48 +01:00
1 parent 8f10bef7c5
commit 037a725b74
3 files changed
+41 -4

No files matched your search

+29
View File
@@ -104,6 +104,35 @@ class TestRefresh:
assert result == {"success": False, "output": "403 Permission check failed"}
class TestApplyUpdates:
def test_a_clean_upgrade_succeeds(self, driver):
with patch.object(driver, "_exec_ssh_command", return_value="Done.\n__PVE_RC=0") as exec_:
result = driver.apply_updates(["curl"])
assert "apt-get install --only-upgrade -y curl" in exec_.call_args[0][0]
assert result == {"success": True, "output": "Done."}
def test_a_failed_upgrade_is_a_failure(self, driver):
out = "E: Could not get lock /var/lib/dpkg/lock-frontend\n__PVE_RC=100"
with patch.object(driver, "_exec_ssh_command", return_value=out):
result = driver.apply_updates(["curl"])
assert result["success"] is False
assert result["output"] == "E: Could not get lock /var/lib/dpkg/lock-frontend"
assert result["error"] == "apt-get exited with status 100"
def test_an_unread_exit_status_is_no_success(self, driver):
with patch.object(driver, "_exec_ssh_command", return_value=""):
result = driver.apply_updates(["curl"])
assert result["success"] is False
assert result["error"] == "apt-get's exit status could not be read"
def test_a_name_that_is_no_package_name_is_refused(self, driver):
with pytest.raises(ValueError):
driver.apply_updates(["curl;reboot"])
class TestHostStatus:
def test_the_node_is_read_over_the_exec_path(self, driver):
report = (