Skip to content

Commit bee702b

Browse files
alexlarssonachilleas-k
authored andcommitted
Add test for aboot support
This adds a test that a write-device stage is correctly generated if the partition table contains the right partition and an aboot.img in the modules dir.
1 parent 3598602 commit bee702b

File tree

1 file changed

+74
-6
lines changed

1 file changed

+74
-6
lines changed

test/test_manifest.py

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# pylint: disable=too-many-lines
2+
13
import base64
24
import hashlib
35
import json
@@ -651,7 +653,7 @@ def test_manifest_disk_customization_dos(tmp_path, build_container):
651653
build_container,
652654
"manifest", f"{container_ref}",
653655
])
654-
st = find_sfdisk_stage_from(output)
656+
st = find_stage_options_from(output, "org.osbuild.sfdisk")
655657
assert st["label"] == "dos"
656658

657659

@@ -852,14 +854,14 @@ def test_manifest_customization_custom_file_smoke(tmp_path, build_container):
852854
',"options":{"filename":"disk.raw"') in output
853855

854856

855-
def find_sfdisk_stage_from(manifest_str):
857+
def find_stage_options_from(manifest_str, stage_type):
856858
manifest = json.loads(manifest_str)
857859
for pipl in manifest["pipelines"]:
858860
if pipl["name"] == "image":
859861
for st in pipl["stages"]:
860-
if st["type"] == "org.osbuild.sfdisk":
862+
if st["type"] == stage_type:
861863
return st["options"]
862-
raise ValueError(f"cannot find sfdisk stage manifest:\n{manifest_str}")
864+
raise ValueError(f"cannot find {stage_type} stage manifest:\n{manifest_str}")
863865

864866

865867
def test_manifest_image_customize_filesystem(tmp_path, build_container):
@@ -900,7 +902,7 @@ def test_manifest_image_customize_filesystem(tmp_path, build_container):
900902
"manifest",
901903
f"localhost/{container_tag}",
902904
], encoding="utf8")
903-
sfdisk_options = find_sfdisk_stage_from(manifest_str)
905+
sfdisk_options = find_stage_options_from(manifest_str, "org.osbuild.sfdisk")
904906
assert sfdisk_options["partitions"][2]["size"] == 3 * 1024 * 1024 * 1024 / 512
905907

906908

@@ -946,5 +948,71 @@ def test_manifest_image_customize_disk(tmp_path, build_container):
946948
"manifest",
947949
f"localhost/{container_tag}",
948950
], encoding="utf8")
949-
sfdisk_options = find_sfdisk_stage_from(manifest_str)
951+
sfdisk_options = find_stage_options_from(manifest_str, "org.osbuild.sfdisk")
950952
assert sfdisk_options["partitions"][2]["size"] == 3 * 1024 * 1024 * 1024 / 512
953+
954+
955+
def test_manifest_image_aboot(tmp_path, build_container):
956+
# no need to parameterize this test, overrides behaves same for all containers
957+
container_ref = "quay.io/centos-bootc/centos-bootc:stream9"
958+
testutil.pull_container(container_ref)
959+
960+
cfg = {
961+
"blueprint": {
962+
"customizations": {
963+
"disk": {
964+
"partitions": [
965+
{
966+
"part_label": "ukiboot_a",
967+
"part_uuid": "DF331E4D-BE00-463F-B4A7-8B43E18FB53A",
968+
"fs_type": "none",
969+
"minsize": "1 GiB",
970+
},
971+
{
972+
"part_label": "ukiboot_b",
973+
"part_uuid": "DF331E4D-BE00-463F-B4A7-8B43E18FB53A",
974+
"fs_type": "none",
975+
"minsize": "1 GiB",
976+
},
977+
{
978+
"part_label": "ukibootctl",
979+
"part_uuid": "FEFD9070-346F-4C9A-85E6-17F07F922773",
980+
"fs_type": "none",
981+
"minsize": "1 GiB",
982+
},
983+
],
984+
},
985+
},
986+
},
987+
}
988+
989+
config_json_path = tmp_path / "config.json"
990+
config_json_path.write_text(json.dumps(cfg), encoding="utf-8")
991+
992+
testdata_path = tmp_path / "testdata"
993+
testdata_path.write_text("some test data", encoding="utf-8")
994+
995+
# Create derived container with the custom partitioning with an aboot
996+
# partition and a kernel module dir with an aboot.img file
997+
cntf_path = tmp_path / "Containerfile"
998+
cntf_path.write_text(textwrap.dedent(f"""\n
999+
FROM {container_ref}
1000+
RUN mkdir -p -m 0755 /usr/lib/bootc-image-builder
1001+
COPY config.json /usr/lib/bootc-image-builder/
1002+
RUN rm -rf /usr/lib/modules/*
1003+
RUN mkdir -p -m 0755 /usr/lib/modules/5.0-x86_64/
1004+
COPY testdata /usr/lib/modules/5.0-x86_64/vmlinuz
1005+
COPY testdata /usr/lib/modules/5.0-x86_64/aboot.img
1006+
"""), encoding="utf8")
1007+
1008+
print(f"building filesystem customize container from {container_ref}")
1009+
with make_container(tmp_path) as container_tag:
1010+
print(f"using {container_tag}")
1011+
manifest_str = subprocess.check_output([
1012+
*testutil.podman_run_common,
1013+
build_container,
1014+
"manifest",
1015+
f"localhost/{container_tag}",
1016+
], encoding="utf8")
1017+
write_device_options = find_stage_options_from(manifest_str, "org.osbuild.write-device")
1018+
assert write_device_options["from"] == "input://tree/usr/lib/modules/5.0-x86_64/aboot.img"

0 commit comments

Comments
 (0)