Skip to content

Commit bb7951f

Browse files
alexlarssonachilleas-k
authored andcommitted
test_manifest: Add test for embedded disk and filesystem customization
1 parent 6dafa01 commit bb7951f

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ By default, the following modules are enabled for all Anaconda ISOs:
534534
The `disable` list is processed after the `enable` list and therefore takes priority. In other words, adding the same module in both `enable` and `disable` will result in the module being **disabled**.
535535
Furthermore, adding a module that is enabled by default to `disable` will result in the module being **disabled**.
536536

537-
538537
## Building
539538

540539
To build the container locally you can run

test/test_manifest.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,101 @@ def test_manifest_customization_custom_file_smoke(tmp_path, build_container):
826826
'[{"path":"/etc/custom_dir","exist_ok":true}]},'
827827
'"devices":{"disk":{"type":"org.osbuild.loopback"'
828828
',"options":{"filename":"disk.raw"') in output
829+
830+
831+
def find_sfdisk_stage_from(manifest_str):
832+
manifest = json.loads(manifest_str)
833+
for pipl in manifest["pipelines"]:
834+
if pipl["name"] == "image":
835+
for st in pipl["stages"]:
836+
if st["type"] == "org.osbuild.sfdisk":
837+
return st["options"]
838+
raise ValueError(f"cannot find sfdisk stage manifest:\n{manifest_str}")
839+
840+
841+
def test_manifest_image_customize_filesystem(tmp_path, build_container):
842+
# no need to parameterize this test, overrides behaves same for all containers
843+
container_ref = "quay.io/centos-bootc/centos-bootc:stream9"
844+
testutil.pull_container(container_ref)
845+
846+
cfg = {
847+
"blueprint": {
848+
"customizations": {
849+
"filesystem": [
850+
{
851+
"mountpoint": "/boot",
852+
"minsize": "3GiB"
853+
}
854+
]
855+
},
856+
},
857+
}
858+
859+
config_json_path = tmp_path / "config.json"
860+
config_json_path.write_text(json.dumps(cfg), encoding="utf-8")
861+
862+
# create derrived container with filesystem customization
863+
cntf_path = tmp_path / "Containerfile"
864+
cntf_path.write_text(textwrap.dedent(f"""\n
865+
FROM {container_ref}
866+
RUN mkdir -p -m 0755 /usr/lib/bootc-image-builder
867+
COPY config.json /usr/lib/bootc-image-builder/
868+
"""), encoding="utf8")
869+
870+
print(f"building filesystem customize container from {container_ref}")
871+
with make_container(tmp_path) as container_tag:
872+
print(f"using {container_tag}")
873+
manifest_str = subprocess.check_output([
874+
*testutil.podman_run_common,
875+
build_container,
876+
"manifest",
877+
f"localhost/{container_tag}",
878+
], encoding="utf8")
879+
sfdisk_options = find_sfdisk_stage_from(manifest_str)
880+
assert sfdisk_options["partitions"][2]["size"] == 3 * 1024 * 1024 * 1024 / 512
881+
882+
883+
def test_manifest_image_customize_disk(tmp_path, build_container):
884+
# no need to parameterize this test, overrides behaves same for all containers
885+
container_ref = "quay.io/centos-bootc/centos-bootc:stream9"
886+
testutil.pull_container(container_ref)
887+
888+
cfg = {
889+
"blueprint": {
890+
"customizations": {
891+
"disk": {
892+
"partitions": [
893+
{
894+
"label": "var",
895+
"mountpoint": "/var",
896+
"fs_type": "ext4",
897+
"minsize": "3 GiB",
898+
},
899+
],
900+
},
901+
},
902+
},
903+
}
904+
905+
config_json_path = tmp_path / "config.json"
906+
config_json_path.write_text(json.dumps(cfg), encoding="utf-8")
907+
908+
# create derrived container with disk customization
909+
cntf_path = tmp_path / "Containerfile"
910+
cntf_path.write_text(textwrap.dedent(f"""\n
911+
FROM {container_ref}
912+
RUN mkdir -p -m 0755 /usr/lib/bootc-image-builder
913+
COPY config.json /usr/lib/bootc-image-builder/
914+
"""), encoding="utf8")
915+
916+
print(f"building filesystem customize container from {container_ref}")
917+
with make_container(tmp_path) as container_tag:
918+
print(f"using {container_tag}")
919+
manifest_str = subprocess.check_output([
920+
*testutil.podman_run_common,
921+
build_container,
922+
"manifest",
923+
f"localhost/{container_tag}",
924+
], encoding="utf8")
925+
sfdisk_options = find_sfdisk_stage_from(manifest_str)
926+
assert sfdisk_options["partitions"][2]["size"] == 3 * 1024 * 1024 * 1024 / 512

0 commit comments

Comments
 (0)