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:
parent
6fec975c30
commit
a1f02113cd
2 changed files with 30 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import subprocess
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -43,3 +44,17 @@ def stage_schema(request: pytest.FixtureRequest) -> osbuild.meta.Schema:
|
||||||
root = caller_dir.parent.parent
|
root = caller_dir.parent.parent
|
||||||
mod_info = osbuild.meta.ModuleInfo.load(root, "Stage", stage_name)
|
mod_info = osbuild.meta.ModuleInfo.load(root, "Stage", stage_name)
|
||||||
return osbuild.meta.Schema(mod_info.get_schema(version=schema_version), 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)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import pytest
|
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:
|
with pytest.raises(subprocess.CalledProcessError) as ex:
|
||||||
stage_module.main(fake_inputs, tmp_path, options)
|
stage_module.main(fake_inputs, tmp_path, options)
|
||||||
assert "exit status 2" in str(ex.value)
|
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))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue