From 95a0d921c58595e05d674255344fc7cc94e6f7a0 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 18 Dec 2024 12:56:05 +0100 Subject: [PATCH] test/filesystem: support various layouts Add separate blueprint creation functions, one for each partitioning layout: - disk-plain - disk-lvm - disk-btrfs (Fedora only) The existing 'filesystem' blueprint is also kept. Each function also sets the $EXPECTED_MOUNTPOINTS variable for the mountpoint check that happens after the build. --- test/cases/filesystem.sh | 269 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 266 insertions(+), 3 deletions(-) diff --git a/test/cases/filesystem.sh b/test/cases/filesystem.sh index 96de5313c9..f5d86f2f0e 100644 --- a/test/cases/filesystem.sh +++ b/test/cases/filesystem.sh @@ -21,6 +21,8 @@ BLUEPRINT_FILE=${TEMPDIR}/blueprint.toml COMPOSE_START=${TEMPDIR}/compose-start-${IMAGE_KEY}.json COMPOSE_INFO=${TEMPDIR}/compose-info-${IMAGE_KEY}.json +CUSTOMIZATION_TYPE="${1:-filesystem}" + function cleanup_on_exit() { greenprint "๐Ÿงผ Cleaning up" # kill dangling journalctl processes to prevent GitLab CI from hanging @@ -121,7 +123,6 @@ check_result () { greenprint "๐Ÿš€ Checking custom filesystems (success case)" write_fs_blueprint() { - # Write a basic blueprint for our image. tee "$BLUEPRINT_FILE" > /dev/null << EOF name = "custom-filesystem" description = "A base system with custom mountpoints" @@ -191,9 +192,271 @@ size = 131072000 mountpoint = "/foobar" size = 131072000 EOF + EXPECTED_MOUNTPOINTS=( + "/" + "/var" + "/var/log" + "/var/log/audit" + "/usr" + "/tmp" + "/var/tmp" + "/home" + "/home/shadowman" + "/opt" + "/srv" + "/app" + "/data" + "/boot" + "/boot/firmware" + "/foobar" + ) } -write_fs_blueprint +write_plain_blueprint() { + tee "$BLUEPRINT_FILE" > /dev/null << EOF +name = "custom-partitioning-plain" +description = "A base system with custom plain partitions" +version = "0.0.1" + +[[blueprint.customizations.disk.partitions]] +mountpoint = "/data" +fs_type = "ext4" +minsize = "1 GiB" + +[[blueprint.customizations.disk.partitions]] +mountpoint = "/home" +label = "home" +fs_type = "ext4" +minsize = "2 GiB" + +[[blueprint.customizations.disk.partitions]] +mountpoint = "/home/shadowman" +fs_type = "ext4" +minsize = "500 MiB" + +[[blueprint.customizations.disk.partitions]] +mountpoint = "/foo" +fs_type = "ext4" +minsize = "1 GiB" + +[[blueprint.customizations.disk.partitions]] +mountpoint = "/var" +fs_type = "xfs" +minsize = "4 GiB" + +[[blueprint.customizations.disk.partitions]] +mountpoint = "/opt" +fs_type = "ext4" +minsize = "1 GiB" + +[[blueprint.customizations.disk.partitions]] +mountpoint = "/media" +fs_type = "ext4" +minsize = "1 GiB" + +[[blueprint.customizations.disk.partitions]] +mountpoint = "/root" +fs_type = "ext4" +minsize = "1 GiB" + +[[blueprint.customizations.disk.partitions]] +mountpoint = "/srv" +fs_type = "xfs" +minsize = "1 GiB" + +[[blueprint.customizations.disk.partitions]] +fs_type = "swap" +minsize = "1 GiB" +EOF + EXPECTED_MOUNTPOINTS=( + "/data" + "/home" + "/home/shadowman" + "/foo" + "/var" + "/opt" + "/media" + "/root" + "/srv" + "swap" + ) +} + +write_lvm_blueprint() { + tee "$BLUEPRINT_FILE" > /dev/null << EOF +name = "custom-partitioning-lvm" +description = "A base system with custom LVM partitioning" + +[blueprint.customizations.disk] +type = "gpt" + + [[blueprint.customizations.disk.partitions]] + mountpoint = "/data" + minsize = "1 GiB" + label = "data" + fs_type = "ext4" + + [[blueprint.customizations.disk.partitions]] + type = "lvm" + name = "testvg" + minsize = 10_737_418_240 + + [[blueprint.customizations.disk.partitions.logical_volumes]] + name = "homelv" + mountpoint = "/home" + label = "home" + fs_type = "ext4" + minsize = "2 GiB" + + [[blueprint.customizations.disk.partitions.logical_volumes]] + name = "shadowmanlv" + mountpoint = "/home/shadowman" + fs_type = "ext4" + minsize = "5 GiB" + + [[blueprint.customizations.disk.partitions.logical_volumes]] + name = "foolv" + mountpoint = "/foo" + fs_type = "ext4" + minsize = "1 GiB" + + [[blueprint.customizations.disk.partitions.logical_volumes]] + name = "usrlv" + mountpoint = "/usr" + fs_type = "ext4" + minsize = "4 GiB" + + [[blueprint.customizations.disk.partitions.logical_volumes]] + name = "optlv" + mountpoint = "/opt" + fs_type = "ext4" + minsize = 1_073_741_824 + + [[blueprint.customizations.disk.partitions.logical_volumes]] + name = "medialv" + mountpoint = "/media" + fs_type = "ext4" + minsize = 1_073_741_824 + + [[blueprint.customizations.disk.partitions.logical_volumes]] + name = "roothomelv" + mountpoint = "/root" + fs_type = "ext4" + minsize = "1 GiB" + + [[blueprint.customizations.disk.partitions.logical_volumes]] + name = "srvlv" + mountpoint = "/srv" + fs_type = "ext4" + minsize = 1_073_741_824 + + [[blueprint.customizations.disk.partitions.logical_volumes]] + name = "swap-lv" + fs_type = "swap" + minsize = "1 GiB" +EOF + + EXPECTED_MOUNTPOINTS=( + "/data" + "/home" + "/home/shadowman" + "/foo" + "/usr" + "/opt" + "/media" + "/root" + "/srv" + "swap" + ) +} + +write_btrfs_blueprint() { + tee "$BLUEPRINT_FILE" > /dev/null << EOF +name = "custom-partitioning-btrfs" +description = "A base system with custom btrfs partitioning" + +[[blueprint.customizations.disk.partitions]] +type = "plain" +mountpoint = "/data" +minsize = 1_073_741_824 +fs_type = "xfs" + +[[blueprint.customizations.disk.partitions]] +type = "btrfs" +minsize = "10 GiB" + + [[blueprint.customizations.disk.partitions.subvolumes]] + name = "subvol-home" + mountpoint = "/home" + + [[blueprint.customizations.disk.partitions.subvolumes]] + name = "subvol-shadowman" + mountpoint = "/home/shadowman" + + [[blueprint.customizations.disk.partitions.subvolumes]] + name = "subvol-foo" + mountpoint = "/foo" + + [[blueprint.customizations.disk.partitions.subvolumes]] + name = "subvol-usr" + mountpoint = "/usr" + + [[blueprint.customizations.disk.partitions.subvolumes]] + name = "subvol-opt" + mountpoint = "/opt" + + [[blueprint.customizations.disk.partitions.subvolumes]] + name = "subvol-media" + mountpoint = "/media" + + [[blueprint.customizations.disk.partitions.subvolumes]] + name = "subvol-root" + mountpoint = "/root" + + [[blueprint.customizations.disk.partitions.subvolumes]] + name = "subvol-srv" + mountpoint = "/srv" + +[[blueprint.customizations.disk.partitions]] +type = "plain" +fs_type = "swap" +label = "swap-part" +minsize = "1 GiB" +EOF + + EXPECTED_MOUNTPOINTS=( + "/data" + "/home" + "/home/shadowman" + "/foo" + "/usr" + "/opt" + "/media" + "/root" + "/srv" + "swap" + ) +} + +case "$CUSTOMIZATION_TYPE" in + "filesystem") + write_fs_blueprint + ;; + "disk-plain") + write_plain_blueprint + ;; + "disk-lvm") + write_lvm_blueprint + ;; + "disk-btrfs") + write_btrfs_blueprint + ;; + *) + redprint "Invalid value for CUSTOMIZATION_TYPE: ${CUSTOMIZATION_TYPE} - valid values are 'filesystem', 'disk-plain', 'disk-lvm', and 'disk-btrfs'" + exit 1 + ;; +esac + build_image "$BLUEPRINT_FILE" custom-filesystem qcow2 false @@ -210,7 +473,7 @@ if ! INFO="$(sudo /usr/libexec/osbuild-composer-test/image-info "${IMAGE_FILENAM fi FAILED_MOUNTPOINTS=() -for MOUNTPOINT in '/' '/var' '/var/log' '/var/log/audit' '/var/tmp' '/usr' '/tmp' '/home' '/opt' '/srv' '/app' '/data'; do +for MOUNTPOINT in "${EXPECTED_MOUNTPOINTS[@]}"; do EXISTS=$(jq --arg m "$MOUNTPOINT" 'any(.fstab[] | .[] == $m; .)' <<< "${INFO}") if $EXISTS; then greenprint "INFO: mountpoint $MOUNTPOINT exists"