stages/org.osbuild.tar: implement disk-full test

this should be an example environment
for more stages to test if they return a proper error
in a "disk full scenario"
This commit is contained in:
Florian Schüller 2024-10-22 16:32:16 +02:00 committed by Achilleas Koutsou
parent 6fec975c30
commit a1f02113cd
2 changed files with 30 additions and 0 deletions

View file

@ -1,5 +1,6 @@
import os
import pathlib
import subprocess
from types import ModuleType
import pytest
@ -43,3 +44,17 @@ def stage_schema(request: pytest.FixtureRequest) -> osbuild.meta.Schema:
root = caller_dir.parent.parent
mod_info = osbuild.meta.ModuleInfo.load(root, "Stage", stage_name)
return osbuild.meta.Schema(mod_info.get_schema(version=schema_version), stage_name)
@pytest.fixture
def tmp_path_disk_full(tmp_path, tmp_path_disk_full_size):
small_dir = tmp_path / "small-dir"
small_dir.mkdir()
subprocess.run(["mount",
"-t", "tmpfs",
"-o", f"size={tmp_path_disk_full_size}",
"tmpfs",
small_dir
], check=True)
yield small_dir
subprocess.run(["umount", small_dir], check=True)

View file

@ -1,6 +1,7 @@
#!/usr/bin/python3
import os.path
import re
import subprocess
import pytest
@ -145,3 +146,17 @@ def test_tar_transform_no_sh(tmp_path, stage_module, fake_inputs):
with pytest.raises(subprocess.CalledProcessError) as ex:
stage_module.main(fake_inputs, tmp_path, options)
assert "exit status 2" in str(ex.value)
@pytest.mark.parametrize('tmp_path_disk_full_size', [5 * 1024])
@pytest.mark.skipif(os.getuid() != 0, reason="needs root")
def test_tar_disk_full(stage_module, fake_inputs, tmp_path_disk_full, capfd):
options = {
"filename": "out.tar",
}
with pytest.raises(subprocess.CalledProcessError) as ex:
stage_module.main(fake_inputs, tmp_path_disk_full, options)
assert ex.value.returncode == 2
assert re.match(r".*Wrote only \d+ of \d+ bytes.*", str(capfd.readouterr().err))