Skip to content

Commit

Permalink
test/filesystem: support various layouts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
achilleas-k committed Dec 18, 2024
1 parent 4c09586 commit 95a0d92
Showing 1 changed file with 266 additions and 3 deletions.
269 changes: 266 additions & 3 deletions test/cases/filesystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand All @@ -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"
Expand Down

0 comments on commit 95a0d92

Please sign in to comment.