|
| 1 | +import os |
| 2 | +import random |
| 3 | +import json |
| 4 | +import pathlib |
| 5 | +import platform |
| 6 | +import string |
| 7 | +import subprocess |
| 8 | +import textwrap |
| 9 | +from contextlib import ExitStack |
| 10 | + |
| 11 | +import pytest |
| 12 | +# local test utils |
| 13 | +import testutil |
| 14 | +from containerbuild import build_container_fixture, make_container # pylint: disable=unused-import |
| 15 | +from testcases import gen_testcases |
| 16 | +from test_build_disk import ( |
| 17 | + assert_kernel_args, |
| 18 | + ImageBuildResult, |
| 19 | +) |
| 20 | +from test_build_disk import ( # pylint: disable=unused-import |
| 21 | + gpg_conf_fixture, |
| 22 | + image_type_fixture, |
| 23 | + registry_conf_fixture, |
| 24 | + shared_tmpdir_fixture, |
| 25 | +) |
| 26 | +from vmtest.vm import QEMU |
| 27 | + |
| 28 | + |
| 29 | +@pytest.mark.skipif(platform.system() != "Linux", reason="boot test only runs on linux right now") |
| 30 | +@pytest.mark.parametrize("container_ref", [ |
| 31 | + "quay.io/centos-bootc/centos-bootc:stream10", |
| 32 | + "quay.io/fedora/fedora-bootc:43", |
| 33 | + "quay.io/centos-bootc/centos-bootc:stream9", |
| 34 | +]) |
| 35 | +# pylint: disable=too-many-locals |
| 36 | +def test_bootc_pxe_tar_xz(tmp_path, build_container, container_ref): |
| 37 | + # XXX: duplicated from test_build_disk.py |
| 38 | + username = "test" |
| 39 | + password = "".join( |
| 40 | + random.choices(string.ascii_uppercase + string.digits, k=18)) |
| 41 | + ssh_keyfile_private_path = tmp_path / "ssh-keyfile" |
| 42 | + ssh_keyfile_public_path = ssh_keyfile_private_path.with_suffix(".pub") |
| 43 | + if not ssh_keyfile_private_path.exists(): |
| 44 | + subprocess.run([ |
| 45 | + "ssh-keygen", |
| 46 | + "-N", "", |
| 47 | + # be very conservative with keys for paramiko |
| 48 | + "-b", "2048", |
| 49 | + "-t", "rsa", |
| 50 | + "-f", os.fspath(ssh_keyfile_private_path), |
| 51 | + ], check=True) |
| 52 | + ssh_pubkey = ssh_keyfile_public_path.read_text(encoding="utf8").strip() |
| 53 | + cfg = { |
| 54 | + "customizations": { |
| 55 | + "user": [ |
| 56 | + { |
| 57 | + "name": "root", |
| 58 | + "key": ssh_pubkey, |
| 59 | + # note that we have no "home" here for ISOs |
| 60 | + }, { |
| 61 | + "name": username, |
| 62 | + "password": password, |
| 63 | + "groups": ["wheel"], |
| 64 | + }, |
| 65 | + ], |
| 66 | + "kernel": { |
| 67 | + # Use console=ttyS0 so that we see output in our debug |
| 68 | + # logs. by default anaconda prints to the last console= |
| 69 | + # from the kernel commandline |
| 70 | + "append": "console=ttyS0", |
| 71 | + }, |
| 72 | + }, |
| 73 | + } |
| 74 | + config_json_path = tmp_path / "config.json" |
| 75 | + config_json_path.write_text(json.dumps(cfg), encoding="utf-8") |
| 76 | + # create anaconda iso from base |
| 77 | + cntf_path = tmp_path / "Containerfile" |
| 78 | + cntf_path.write_text(textwrap.dedent(f"""\n |
| 79 | + FROM {container_ref} |
| 80 | + RUN dnf install -y \ |
| 81 | + dracut-live \ |
| 82 | + squashfs-tools \ |
| 83 | + && dnf clean all |
| 84 | + RUN bootc container lint |
| 85 | + """), encoding="utf8") |
| 86 | + output_path = tmp_path / "output" |
| 87 | + output_path.mkdir() |
| 88 | + pathlib.Path("/var/tmp/osbuild-test-store").mkdir(exist_ok=True, parents=True) |
| 89 | + with make_container(tmp_path) as container_tag: |
| 90 | + cmd = [ |
| 91 | + *testutil.podman_run_common, |
| 92 | + "-v", f"{config_json_path}:/config.json:ro", |
| 93 | + "-v", f"{output_path}:/output", |
| 94 | + "-v", "/var/tmp/osbuild-test-store:/store", # share the cache between builds |
| 95 | + "-v", "/var/lib/containers/storage:/var/lib/containers/storage", |
| 96 | + build_container, |
| 97 | + "--type", "pxe-tar-xz", |
| 98 | + "--rootfs", "ext4", |
| 99 | + "--installer-payload-ref", container_ref, |
| 100 | + f"localhost/{container_tag}", |
| 101 | + ] |
| 102 | + subprocess.check_call(cmd) |
| 103 | + assert os.path.exists(output_path / "xz" / "pxe.tar.xz") |
| 104 | + # TODO use lzap's pxe boot code from images to boot the result |
0 commit comments