fix(backup): read a 126 exec start with the runtime's not-found message as an absent tool
CI (make tests, stable, publish) / make test (push) Waiting to run
CI (make tests, stable, publish) / make test (push) Waiting to run
CodeRabbit on https://github.com/kevinveenbirkenbach/backup-docker-to-local/pull/18: dockerd overwrites the exit code of every failed exec start with 126 (https://github.com/moby/moby/issues/45795, still open). Where the docker CLI does not map a missing executable to 127, has_tool() raised for a pg_dumpall probe in a MariaDB container, so container_engine() never reached mariadb-dump and main() dropped the volume from the generation. BackupError now carries the failed command's stderr, and has_tool() returns False for 127 or for 126 whose stderr carries the runtime's 'executable file ... not found' (runc and crun wording). Every other 126, such as the containerd io-pipe timeout of https://github.com/infinito-nexus/core/actions/runs/46742115623, still raises. Tests: 126 with the runc and the crun message read as absent (mocked and from a real child process); the io-pipe timeout now carries its stderr and still raises. Unit suite 283 OK; ruff clean. Against the previous has_tool the three new cases fail (3 errors). 🎯 Fix: 92 % 💥 Break: 3 % 💸 Tokens: 100 % ⏱️ Velocity: 100 % 🛡️ Security: 100 % 🏆 Score: 92 🚦 Gate: unit 283 OK + negative control; ruff clean Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
982862725e
commit
e2bdac0793
3 files changed
+55
-8
No files matched your search
@@ -7,6 +7,14 @@ from unittest.mock import patch
|
||||
from baudolo.backup import docker as docker_mod
|
||||
from baudolo.backup.shell import BackupError
|
||||
|
||||
RUNC_NOT_FOUND = (
|
||||
b"OCI runtime exec failed: exec failed: unable to start container process: "
|
||||
b'exec: "pg_dumpall": executable file not found in $PATH'
|
||||
)
|
||||
CRUN_NOT_FOUND = (
|
||||
b"crun: executable file `pg_dumpall` not found in $PATH: No such file or directory"
|
||||
)
|
||||
|
||||
|
||||
class TestImageId(unittest.TestCase):
|
||||
def test_the_id_is_returned_without_surrounding_whitespace(self) -> None:
|
||||
@@ -28,12 +36,21 @@ class TestHasTool(unittest.TestCase):
|
||||
with patch.object(docker_mod, "execute_shell_command", side_effect=not_found):
|
||||
self.assertFalse(docker_mod.has_tool("c1", "mysqldump"))
|
||||
|
||||
def test_a_missing_tool_reported_as_126_is_absent(self) -> None:
|
||||
for runtime_message in (RUNC_NOT_FOUND, CRUN_NOT_FOUND):
|
||||
with self.subTest(runtime_message=runtime_message):
|
||||
not_found = BackupError("exec failed", 126, runtime_message)
|
||||
with patch.object(
|
||||
docker_mod, "execute_shell_command", side_effect=not_found
|
||||
):
|
||||
self.assertFalse(docker_mod.has_tool("c1", "pg_dumpall"))
|
||||
|
||||
def test_a_failed_exec_is_not_read_as_a_missing_tool(self) -> None:
|
||||
"""containerd timed out on the io pipes of a mariadb that ships the tool."""
|
||||
transient = BackupError(
|
||||
"DeadlineExceeded: failed to start io pipe copy: unable to copy pipes",
|
||||
126,
|
||||
pipe_timeout = (
|
||||
b"DeadlineExceeded: failed to start io pipe copy: unable to copy pipes"
|
||||
)
|
||||
transient = BackupError(pipe_timeout.decode(), 126, pipe_timeout)
|
||||
with (
|
||||
patch.object(docker_mod, "execute_shell_command", side_effect=transient),
|
||||
self.assertRaises(BackupError),
|
||||
@@ -57,8 +74,12 @@ class TestHasTool(unittest.TestCase):
|
||||
|
||||
|
||||
class TestProbeExitCode(unittest.TestCase):
|
||||
def _probe_exiting(self, code: int) -> bool:
|
||||
argv = [sys.executable, "-c", f"import sys; sys.exit({code})"]
|
||||
def _probe_exiting(self, code: int, stderr: str = "") -> bool:
|
||||
argv = [
|
||||
sys.executable,
|
||||
"-c",
|
||||
f"import sys; sys.stderr.write({stderr!r}); sys.exit({code})",
|
||||
]
|
||||
with (
|
||||
patch.object(docker_mod, "docker_exec_argv", return_value=argv),
|
||||
contextlib.redirect_stdout(io.StringIO()),
|
||||
@@ -73,6 +94,15 @@ class TestProbeExitCode(unittest.TestCase):
|
||||
self._probe_exiting(126)
|
||||
self.assertEqual(caught.exception.returncode, 126)
|
||||
|
||||
def test_exit_126_with_the_runtime_not_found_message_reads_as_absent(
|
||||
self,
|
||||
) -> None:
|
||||
self.assertFalse(
|
||||
self._probe_exiting(
|
||||
126, 'exec: "mariadb-dump": executable file not found in $PATH'
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user