diff --git a/repo2podman/podman.py b/repo2podman/podman.py index 7cc6129..d45dccb 100644 --- a/repo2podman/podman.py +++ b/repo2podman/podman.py @@ -256,11 +256,12 @@ class PodmanContainer(Container): def __init__(self, cid, podman_executable="podman"): self.id = cid self._podman_executable = podman_executable + self.format_arg = "{{json .}}" self.reload() def reload(self): lines = exec_podman( - ["inspect", "--type", "container", "--format", "json", self.id], + ["inspect", "--type", "container", "--format", self.format_arg, self.id], capture="stdout", exe=self._podman_executable, ) @@ -374,6 +375,7 @@ class PodmanEngine(ContainerEngine): def __init__(self, *, parent): super().__init__(parent=parent) + self.format_arg = "{{json .}}" lines = exec_podman(["info"], capture="stdout", exe=self.podman_executable) log_debug(lines) @@ -483,7 +485,7 @@ def remove_local(tags): yield tag[10:] lines = exec_podman( - ["image", "list", "--format", "json"], + ["image", "list", "--format", self.format_arg], capture="stdout", exe=self.podman_executable, ) @@ -503,7 +505,7 @@ def remove_local(tags): def inspect_image(self, image): lines = exec_podman( - ["inspect", "--type", "image", "--format", "json", image], + ["inspect", "--type", "image", "--format", self.format_arg, image], capture="stdout", exe=self.podman_executable, ) diff --git a/tests/unit/test_podman.py b/tests/unit/test_podman.py index 0593592..9b9e14a 100644 --- a/tests/unit/test_podman.py +++ b/tests/unit/test_podman.py @@ -66,7 +66,8 @@ def test_run(): c.remove() with pytest.raises(PodmanCommandError) as exc: c.reload() - assert "".join(exc.value.output).strip() == "[]" + # Podman 3 returns "[]" instead of "" + assert "".join(exc.value.output).strip() in ("[]", "") def test_run_autoremove(): @@ -77,7 +78,8 @@ def test_run_autoremove(): sleep(3) with pytest.raises(PodmanCommandError) as exc: c.reload() - assert "".join(exc.value.output).strip() == "[]" + # Podman 3 returns "[]" instead of "" + assert "".join(exc.value.output).strip() in ("[]", "") def test_run_detach_wait(): @@ -93,7 +95,8 @@ def test_run_detach_wait(): c.remove() with pytest.raises(PodmanCommandError) as exc: c.reload() - assert "".join(exc.value.output).strip() == "[]" + # Podman 3 returns "[]" instead of "" + assert "".join(exc.value.output).strip() in ("[]", "") def test_run_detach_nostream(): @@ -146,8 +149,8 @@ def test_custom_executable(tmp_path): exe = tmp_path.joinpath("custom_exe.sh") with exe.open("w") as f: f.write("#!/bin/sh\n") - f.write(f"echo $@ >> {log}\n") - f.write("exec podman $@\n") + f.write(f'echo "$@" >> {log}\n') + f.write('exec podman "$@"\n') exe.chmod(0o755) client = PodmanEngine(parent=None) @@ -168,7 +171,7 @@ def test_custom_executable(tmp_path): lines = f.read().splitlines() assert lines == [ f"run --detach --log-level=debug {BUSYBOX} id -un", - f"inspect --type container --format json {cid}", + f"inspect --type container --format {{{{json .}}}} {cid}", f"logs {cid}", f"rm {cid}", ]