Skip to content

Commit 84200d3

Browse files
committed
test: split test_build.py into test_build_{disk,iso}
Split this big test into smaller files because we will run the tests in parallel via a dynamic (per-file) github matrix. This will allow faster tests and easier re-runs if a single test is flaky only a small subset will have to be retriggered.
1 parent ea517bf commit 84200d3

File tree

2 files changed

+85
-47
lines changed

2 files changed

+85
-47
lines changed

test/test_build.py renamed to test/test_build_disk.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -610,53 +610,6 @@ def test_image_build_without_se_linux_denials(image_type):
610610
f"denials in log {image_type.journal_output}"
611611

612612

613-
@pytest.mark.skipif(platform.system() != "Linux", reason="boot test only runs on linux right now")
614-
@pytest.mark.parametrize("image_type", gen_testcases("anaconda-iso"), indirect=["image_type"])
615-
def test_iso_installs(image_type):
616-
installer_iso_path = image_type.img_path
617-
test_disk_path = installer_iso_path.with_name("test-disk.img")
618-
with open(test_disk_path, "w", encoding="utf8") as fp:
619-
fp.truncate(10_1000_1000_1000)
620-
# install to test disk
621-
with QEMU(test_disk_path, cdrom=installer_iso_path) as vm:
622-
vm.start(wait_event="qmp:RESET", snapshot=False, use_ovmf=True)
623-
vm.force_stop()
624-
# boot test disk and do extremly simple check
625-
with QEMU(test_disk_path) as vm:
626-
vm.start(use_ovmf=True)
627-
exit_status, _ = vm.run("true", user=image_type.username, password=image_type.password)
628-
assert exit_status == 0
629-
assert_kernel_args(vm, image_type)
630-
631-
632-
def osinfo_for(it: ImageBuildResult, arch: str) -> str:
633-
base = "Media is an installer for OS"
634-
if it.container_ref.endswith("/centos-bootc/centos-bootc:stream9"):
635-
return f"{base} 'CentOS Stream 9 ({arch})'\n"
636-
if it.container_ref.endswith("/centos-bootc/centos-bootc:stream10"):
637-
return f"Media is an installer for OS 'CentOS Stream 10 ({arch})'\n"
638-
if "/fedora/fedora-bootc:" in it.container_ref:
639-
ver = it.container_ref.rsplit(":", maxsplit=1)[1]
640-
return f"{base} 'Fedora Server {ver} ({arch})'\n"
641-
raise ValueError(f"unknown osinfo string for '{it.container_ref}'")
642-
643-
644-
@pytest.mark.skipif(platform.system() != "Linux", reason="osinfo detect test only runs on linux right now")
645-
@pytest.mark.parametrize("image_type", gen_testcases("anaconda-iso"), indirect=["image_type"])
646-
def test_iso_os_detection(image_type):
647-
installer_iso_path = image_type.img_path
648-
arch = image_type.img_arch
649-
if not arch:
650-
arch = platform.machine()
651-
result = subprocess.run([
652-
"osinfo-detect",
653-
installer_iso_path,
654-
], capture_output=True, text=True, check=True)
655-
osinfo_output = result.stdout
656-
expected_output = f"Media is bootable.\n{osinfo_for(image_type, arch)}"
657-
assert osinfo_output == expected_output
658-
659-
660613
@pytest.mark.skipif(platform.system() != "Linux", reason="osinfo detect test only runs on linux right now")
661614
@pytest.mark.skipif(not testutil.has_executable("unsquashfs"), reason="need unsquashfs")
662615
@pytest.mark.parametrize("image_type", gen_testcases("anaconda-iso"), indirect=["image_type"])

test/test_build_iso.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import os
2+
import platform
3+
import subprocess
4+
from contextlib import ExitStack
5+
6+
import pytest
7+
# local test utils
8+
import testutil
9+
from containerbuild import build_container_fixture # pylint: disable=unused-import
10+
from testcases import gen_testcases
11+
from vm import QEMU
12+
13+
from test_build_disk import (
14+
assert_kernel_args,
15+
ImageBuildResult,
16+
)
17+
from test_build_disk import ( # pylint: disable=unused-import
18+
gpg_conf_fixture,
19+
image_type_fixture,
20+
registry_conf_fixture,
21+
shared_tmpdir_fixture,
22+
)
23+
24+
25+
@pytest.mark.skipif(platform.system() != "Linux", reason="boot test only runs on linux right now")
26+
@pytest.mark.parametrize("image_type", gen_testcases("anaconda-iso"), indirect=["image_type"])
27+
def test_iso_installs(image_type):
28+
installer_iso_path = image_type.img_path
29+
test_disk_path = installer_iso_path.with_name("test-disk.img")
30+
with open(test_disk_path, "w", encoding="utf8") as fp:
31+
fp.truncate(10_1000_1000_1000)
32+
# install to test disk
33+
with QEMU(test_disk_path, cdrom=installer_iso_path) as vm:
34+
vm.start(wait_event="qmp:RESET", snapshot=False, use_ovmf=True)
35+
vm.force_stop()
36+
# boot test disk and do extremly simple check
37+
with QEMU(test_disk_path) as vm:
38+
vm.start(use_ovmf=True)
39+
exit_status, _ = vm.run("true", user=image_type.username, password=image_type.password)
40+
assert exit_status == 0
41+
assert_kernel_args(vm, image_type)
42+
43+
44+
def osinfo_for(it: ImageBuildResult, arch: str) -> str:
45+
base = "Media is an installer for OS"
46+
if it.container_ref.endswith("/centos-bootc/centos-bootc:stream9"):
47+
return f"{base} 'CentOS Stream 9 ({arch})'\n"
48+
if it.container_ref.endswith("/centos-bootc/centos-bootc:stream10"):
49+
return f"Media is an installer for OS 'CentOS Stream 10 ({arch})'\n"
50+
if "/fedora/fedora-bootc:" in it.container_ref:
51+
ver = it.container_ref.rsplit(":", maxsplit=1)[1]
52+
return f"{base} 'Fedora Server {ver} ({arch})'\n"
53+
raise ValueError(f"unknown osinfo string for '{it.container_ref}'")
54+
55+
56+
@pytest.mark.skipif(platform.system() != "Linux", reason="osinfo detect test only runs on linux right now")
57+
@pytest.mark.parametrize("image_type", gen_testcases("anaconda-iso"), indirect=["image_type"])
58+
def test_iso_os_detection(image_type):
59+
installer_iso_path = image_type.img_path
60+
arch = image_type.img_arch
61+
if not arch:
62+
arch = platform.machine()
63+
result = subprocess.run([
64+
"osinfo-detect",
65+
installer_iso_path,
66+
], capture_output=True, text=True, check=True)
67+
osinfo_output = result.stdout
68+
expected_output = f"Media is bootable.\n{osinfo_for(image_type, arch)}"
69+
assert osinfo_output == expected_output
70+
71+
72+
@pytest.mark.skipif(platform.system() != "Linux", reason="osinfo detect test only runs on linux right now")
73+
@pytest.mark.skipif(not testutil.has_executable("unsquashfs"), reason="need unsquashfs")
74+
@pytest.mark.parametrize("image_type", gen_testcases("anaconda-iso"), indirect=["image_type"])
75+
def test_iso_install_img_is_squashfs(tmp_path, image_type):
76+
installer_iso_path = image_type.img_path
77+
with ExitStack() as cm:
78+
mount_point = tmp_path / "cdrom"
79+
mount_point.mkdir()
80+
subprocess.check_call(["mount", installer_iso_path, os.fspath(mount_point)])
81+
cm.callback(subprocess.check_call, ["umount", os.fspath(mount_point)])
82+
# ensure install.img is the "flat" squashfs, before PR#777 the content
83+
# was an intermediate ext4 image "squashfs-root/LiveOS/rootfs.img"
84+
output = subprocess.check_output(["unsquashfs", "-ls", mount_point / "images/install.img"], text=True)
85+
assert "usr/bin/bootc" in output

0 commit comments

Comments
 (0)