During the work on PR#1752 Florian discovered that make_containers()
is broken for nested containers like:
```
with make_container(tmp_path, {"file1": "file1 from base"}) as base_tag:
with make_container(tmp_path, {"file1": "file1 from final layer"}, base_tag) as cont_tag:
```
It errors with:
```
Error: 5b947de461ee21b858dd5b4224e80442b2f65b6410189147f2445884d9e4e3d8: image not known
```
The reason is that we work with hashes for the image and then call
`podman image rm` which by default will also remove all dangling
references. Those are defined by not having a tag and not referenced
anymore. So the inner container cleanup also removes the outter.
There are many ways to fix this, I went with re-adding tags to the
test containers because it also makes it easy for the user to see if
we left any containers (accidently) around.
30 lines
997 B
Python
30 lines
997 B
Python
#
|
|
# Tests for the 'osbuild.util.testutil.make_container'.
|
|
#
|
|
import subprocess
|
|
import textwrap
|
|
|
|
import pytest
|
|
|
|
from osbuild.testutil import has_executable, make_container, mock_command
|
|
|
|
|
|
def test_make_container_bad_podman_prints_podman_output(tmp_path, capfd):
|
|
fake_broken_podman = textwrap.dedent("""\
|
|
#!/bin/sh
|
|
echo fake-broken-podman
|
|
exit 1
|
|
""")
|
|
with mock_command("podman", fake_broken_podman):
|
|
with pytest.raises(subprocess.CalledProcessError):
|
|
with make_container(tmp_path, {}) as _:
|
|
pass
|
|
assert "fake-broken-podman" in capfd.readouterr().out
|
|
|
|
|
|
@pytest.mark.skipif(not has_executable("podman"), reason="no podman executable")
|
|
def test_make_container_integration(tmp_path, capfd):
|
|
with make_container(tmp_path, {"/etc/foo": "foo-content"}) as cref:
|
|
# names have the form "osubild-test-<random-number-of-len12>"
|
|
assert len(cref) == len("osbuild-test-123456789012")
|
|
assert "COMMIT" in capfd.readouterr().out
|