testutil: fix make_container() cleanup
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.
This commit is contained in:
parent
15e969c4c6
commit
a3f86a0736
2 changed files with 14 additions and 16 deletions
|
|
@ -9,7 +9,7 @@ import pytest
|
|||
from osbuild.testutil import has_executable, make_container, mock_command
|
||||
|
||||
|
||||
def test_make_container_bad_podman_prints_podman_output(tmp_path, capsys):
|
||||
def test_make_container_bad_podman_prints_podman_output(tmp_path, capfd):
|
||||
fake_broken_podman = textwrap.dedent("""\
|
||||
#!/bin/sh
|
||||
echo fake-broken-podman
|
||||
|
|
@ -19,11 +19,12 @@ def test_make_container_bad_podman_prints_podman_output(tmp_path, capsys):
|
|||
with pytest.raises(subprocess.CalledProcessError):
|
||||
with make_container(tmp_path, {}) as _:
|
||||
pass
|
||||
assert "fake-broken-podman" in capsys.readouterr().out
|
||||
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, capsys):
|
||||
def test_make_container_integration(tmp_path, capfd):
|
||||
with make_container(tmp_path, {"/etc/foo": "foo-content"}) as cref:
|
||||
assert len(cref) == 64
|
||||
assert "COMMIT" in capsys.readouterr().out
|
||||
# names have the form "osubild-test-<random-number-of-len12>"
|
||||
assert len(cref) == len("osbuild-test-123456789012")
|
||||
assert "COMMIT" in capfd.readouterr().out
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue