|
| 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