Skip to content

Commit

Permalink
tests: Attempt to update auto-prune test
Browse files Browse the repository at this point in the history
We need to look in the journal since
3d07a80

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Aug 15, 2024
1 parent 3d07a80 commit 828f722
Showing 1 changed file with 72 additions and 25 deletions.
97 changes: 72 additions & 25 deletions tests/kolainst/destructive/auto-prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,47 @@ set -xeuo pipefail

. ${KOLA_EXT_DATA}/libinsttest.sh

journal_cursor() {
journalctl -o json -n 1 | jq -r '.["__CURSOR"]'
}

assert_journal_grep() {
local cursor re
cursor=$1
shift
re=$1
shift

if ! journalctl -u ostree-finalize-staged --after-cursor "${cursor}" --grep="$re" "$@" >/dev/null; then
fatal "failed to find in journal: $re"; exit 1
fi
}

assert_not_journal_grep() {
local cursor re
cursor=$1
shift
re=$1
shift

if journalctl -u ostree-finalize-staged --after-cursor "${cursor}" --grep="$re" "$@"; then
fatal "found in journal: $re"; exit 1
fi
}

inject_no_early_prune() {
mkdir -p /run/systemd/system/ostree-finalize-staged.service.d
cat >/run/systemd/system/ostree-finalize-staged.service.d/10-no-early-prune.conf << 'EOF'
[Service]
Environment=OSTREE_SYSROOT_OPTS=no-early-prune
EOF
systemctl daemon-reload
}

remove_no_early_prune() {
rm -vf /run/systemd/system/ostree-finalize-staged.service.d/10-no-early-prune.conf
}

# make two fake ostree commits with modified kernels of about the same size
cd /root
mkdir -p rootfs/usr/lib/modules/`uname -r`
Expand Down Expand Up @@ -44,12 +85,12 @@ assert_bootfs_has_n_bootcsum_dirs 1
# the booted deployment is never pruned, so this is a hopeless case and auto-pruning can't save us
consume_bootfs_space
rpm-ostree rebase :modkernel1
if ostree admin finalize-staged |& tee out.txt; then
cursor=$(journal_cursor)
if systemctl restart ostree-finalize-staged; then
assert_not_reached "successfully wrote to filled up bootfs"
fi
assert_file_has_content out.txt "Disabling auto-prune optimization; insufficient space left in bootfs"
assert_file_has_content out.txt "No space left on device"
rm out.txt
assert_journal_grep "${cursor}" "No space left on device"
assert_journal_grep "${cursor}" "Disabling auto-prune optimization.*insufficient space"
unconsume_bootfs_space
rpm-ostree cleanup -bpr

Expand All @@ -58,9 +99,9 @@ rpm-ostree cleanup -bpr
assert_bootfs_has_n_bootcsum_dirs 1

rpm-ostree rebase :modkernel1
ostree admin finalize-staged |& tee out.txt
assert_not_file_has_content out.txt "updating bootloader in two steps"
rm out.txt
cursor=$(journal_cursor)
systemctl restart ostree-finalize-staged
assert_not_journal_grep "$cursor" "updating bootloader in two steps"

# and put it in rollback position; this is the deployment that'll get auto-pruned
rpm-ostree rollback
Expand All @@ -71,11 +112,13 @@ bootloader_orig=$(sha256sum /boot/loader/entries/*)
# now try to deploy a third deployment without early pruning; we should hit ENOSPC
consume_bootfs_space
rpm-ostree rebase :modkernel2
if OSTREE_SYSROOT_OPTS=no-early-prune ostree admin finalize-staged |& tee out.txt; then
inject_no_early_prune
cursor=$(journal_cursor)
if systemctl restart ostree-finalize-staged; then
assert_not_reached "successfully wrote kernel without auto-pruning"
fi
assert_file_has_content out.txt "No space left on device"
rm out.txt
assert_journal_grep "No space left on device"
remove_no_early_prune

# there's 3 bootcsums now because it'll also have the partially written
# bootcsum dir we were creating when we hit ENOSPC; this verifies that all the
Expand All @@ -86,9 +129,9 @@ assert_streq "$bootloader_orig" "$(sha256sum /boot/loader/entries/*)"

# now, try again but with auto-pruning enabled
rpm-ostree rebase :modkernel2
ostree admin finalize-staged |& tee out.txt
assert_file_has_content out.txt "updating bootloader in two steps"
rm out.txt
cursor=$(journal_cursor)
systemctl restart ostree-finalize-staged
assert_not_journal_grep "$cursor" "updating bootloader in two steps"

assert_bootfs_has_n_bootcsum_dirs 2
assert_not_streq "$bootloader_orig" "$(sha256sum /boot/loader/entries/*)"
Expand Down Expand Up @@ -122,17 +165,19 @@ consume_bootfs_space "$((free_blocks_kernel_and_initrd))"

rpm-ostree rebase :modkernel1
# Disable auto-pruning to verify we reproduce the bug
if OSTREE_SYSROOT_OPTS=no-early-prune ostree admin finalize-staged |& tee out.txt; then
inject_no_early_prune
cursor=$(journal_cursor)
if systemctl restart ostree-finalize-staged; then
assert_not_reached "successfully wrote kernel without auto-pruning"
fi
assert_file_has_content out.txt "No space left on device"
rm out.txt
assert_journal_grep "No space left on device"
remove_no_early_prune

# now, try again but with (now default) auto-pruning enabled
rpm-ostree rebase :modkernel1
ostree admin finalize-staged |& tee out.txt
assert_file_has_content out.txt "updating bootloader in two steps"
rm out.txt
cursor=$(journal_cursor)
systemctl restart ostree-finalize-staged
assert_journal_grep "$cursor" "updating bootloader in two steps"

# Below, we test that the size estimator is blocksize aware. This catches the
# case where the dtb contains many small files such that there's a lot of wasted
Expand All @@ -150,16 +195,18 @@ consume_bootfs_space "$((free_blocks_kernel_and_initrd - 10000))"

rpm-ostree rebase :modkernel3
# Disable auto-pruning to verify we reproduce the bug
if OSTREE_SYSROOT_OPTS=no-early-prune ostree admin finalize-staged |& tee out.txt; then
inject_no_early_prune
cursor=$(journal_cursor)
if systemctl restart ostree-finalize-staged; then
assert_not_reached "successfully wrote kernel without auto-pruning"
fi
assert_file_has_content out.txt "No space left on device"
rm out.txt
assert_journal_grep "No space left on device"
remove_no_early_prune

# now, try again but with (now default) auto-pruning enabled
rpm-ostree rebase :modkernel3
ostree admin finalize-staged |& tee out.txt
assert_file_has_content out.txt "updating bootloader in two steps"
rm out.txt
cursor=$(journal_cursor)
systemctl restart ostree-finalize-staged
assert_journal_grep "$cursor" "updating bootloader in two steps"

echo "ok bootfs auto-prune"

0 comments on commit 828f722

Please sign in to comment.