Skip to content

Commit

Permalink
test: manifest test for filesystem customizations
Browse files Browse the repository at this point in the history
Add a test that checks that filesystem customizations appear in the
manifest in the fstab stage.  Checks that:
- All filesystems, where appropriate, have the same type as the desired
  rootfs.
- All filesystems listed in the customizations appear in the fstab
  stage.
  • Loading branch information
achilleas-k committed Aug 14, 2024
1 parent 592e940 commit 996e8e9
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,67 @@ def test_manifest_anaconda_module_customizations(tmpdir_factory, build_container
assert "org.fedoraproject.Anaconda.Modules.Localization" in st["options"]["activatable-modules"]
assert "org.fedoraproject.Anaconda.Modules.Users" not in st["options"]["activatable-modules"]
assert "org.fedoraproject.Anaconda.Modules.Timezone" not in st["options"]["activatable-modules"]


def find_fstab_stage_from(manifest_str):
manifest = json.loads(manifest_str)
for pipeline in manifest["pipelines"]:
# the fstab stage in cross-arch manifests is in the "ostree-deployment" pipeline
if pipeline["name"] in ("image", "ostree-deployment"):
for st in pipeline["stages"]:
if st["type"] == "org.osbuild.fstab":
return st
raise ValueError(f"cannot find fstab stage in manifest:\n{manifest_str}")


@pytest.mark.parametrize("fscustomizations,rootfs", [
({"/var/data": "2 GiB", "/var/stuff": "10 GiB"}, "xfs"),
({"/var/data": "2 GiB", "/var/stuff": "10 GiB"}, "ext4"),
({"/": "2 GiB", "/boot": "1 GiB"}, "ext4"),
({"/": "2 GiB", "/boot": "1 GiB", "/var/data": "42 GiB"}, "ext4"),
({"/": "2 GiB"}, "btrfs"),
])
def test_manifest_fs_customizations(tmp_path, build_container, fscustomizations, rootfs):
container_ref = "quay.io/centos-bootc/centos-bootc:stream9"

config = {
"customizations": {
"filesystem": [{"mountpoint": mnt, "minsize": minsize} for mnt, minsize in fscustomizations.items()],
},
}
config_path = tmp_path / "config.json"
with config_path.open("w") as config_file:
json.dump(config, config_file)
output = subprocess.check_output([
*testutil.podman_run_common,
"-v", f"{config_path}:/config.json:ro",
"--entrypoint=/usr/bin/bootc-image-builder",
build_container,
f"--rootfs={rootfs}",
"manifest", f"{container_ref}",
])
assert_fs_customizations(fscustomizations, rootfs, output)


def assert_fs_customizations(customizations, fstype, manifest):
# use the fstab stage to get filesystem types for each mountpoint
fstab_stage = find_fstab_stage_from(manifest)
filesystems = fstab_stage["options"]["filesystems"]

manifest_mountpoints = set()
for fs in filesystems:
manifest_mountpoints.add(fs["path"])
if fs["path"] == "/boot/efi":
assert fs["vfs_type"] == "vfat"
continue

if fstype == "btrfs" and fs["path"] == "/boot":
# /boot keeps its default fstype when using btrfs
assert fs["vfs_type"] == "ext4"
continue

assert fs["vfs_type"] == fstype, f"incorrect filesystem type for {fs['path']}"

# check that all fs customizations appear in fstab
for custom_mountpoint in customizations:
assert custom_mountpoint in manifest_mountpoints

0 comments on commit 996e8e9

Please sign in to comment.