Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Attempt to update auto-prune test #3285

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/libostree/ostree-sysroot-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2629,8 +2629,9 @@ auto_early_prune_old_deployments (OstreeSysroot *self, GPtrArray *new_deployment
*
* An alternative is working with the block size instead, which would
* be easier to handle. */
g_printerr ("bootcsum %s size exceeds %u; disabling auto-prune optimization\n", bootdir,
G_MAXUINT);
ot_journal_print (LOG_WARNING,
"bootcsum %s size exceeds %u; disabling auto-prune optimization",
bootdir, G_MAXUINT);
return TRUE;
}

Expand Down Expand Up @@ -2663,8 +2664,9 @@ auto_early_prune_old_deployments (OstreeSysroot *self, GPtrArray *new_deployment
/* see similar logic in previous loop */
if (bootdir_size > G_MAXUINT)
{
g_printerr (
"deployment %s kernel layout size exceeds %u; disabling auto-prune optimization\n",
ot_journal_print (
LOG_WARNING,
"deployment %s kernel layout size exceeds %u; disabling auto-prune optimization",
ostree_deployment_get_csum (deployment), G_MAXUINT);
return TRUE;
}
Expand All @@ -2686,12 +2688,13 @@ auto_early_prune_old_deployments (OstreeSysroot *self, GPtrArray *new_deployment
* and old bootdirs? */
if (bootfs_has_space)
{
g_printerr ("bootfs is sufficient for calculated new size: %s\n", net_new_formatted);
ot_journal_print (LOG_INFO, "bootfs is sufficient for calculated new size: %s",
net_new_formatted);
return TRUE; /* nothing to do! */
}
}

g_printerr ("bootfs requires additional space: %s\n", net_new_formatted);
ot_journal_print (LOG_INFO, "bootfs requires additional space: %s", net_new_formatted);
/* OK, we would fail if we tried to write the new bootdirs. Is it salvageable?
* First, calculate how much space we could save with the bootcsums scheduled
* for removal. */
Expand All @@ -2704,7 +2707,7 @@ auto_early_prune_old_deployments (OstreeSysroot *self, GPtrArray *new_deployment

{
g_autofree char *to_remove_formated = g_format_size (bootcsum_dirs_to_remove_total_size);
g_printerr ("Size to prune from bootfs: %s\n", to_remove_formated);
ot_journal_print (LOG_INFO, "Size to prune from bootfs: %s", to_remove_formated);
}

if (net_new_bootcsum_dirs_total_size > bootcsum_dirs_to_remove_total_size)
Expand All @@ -2721,12 +2724,14 @@ auto_early_prune_old_deployments (OstreeSysroot *self, GPtrArray *new_deployment
{
/* Even if we auto-pruned, the new bootdirs wouldn't fit. Just let the
* code continue and let it hit ENOSPC. */
g_printerr ("Disabling auto-prune optimization; insufficient space left in bootfs\n");
ot_journal_print (LOG_WARNING,
"Disabling auto-prune optimization; insufficient space left in bootfs");
return TRUE;
}
}

g_printerr ("Insufficient space left in bootfs; updating bootloader in two steps\n");
ot_journal_print (LOG_INFO,
"Insufficient space left in bootfs; updating bootloader in two steps");

/* Auto-pruning can salvage the situation. Calculate the set of deployments in common. */
g_autoptr (GPtrArray) common_deployments = g_ptr_array_new ();
Expand Down
3 changes: 1 addition & 2 deletions src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ main (int argc, char *argv[])
/* Bind-mount /etc (at deploy path), and remount as writable. */
if (mount ("etc", tmp_sysroot_etc, NULL, MS_BIND | MS_SILENT, NULL) < 0)
err (EXIT_FAILURE, "failed to prepare /etc bind-mount at /sysroot.tmp/etc");
if (mount (tmp_sysroot_etc, tmp_sysroot_etc, NULL, MS_BIND | MS_REMOUNT | MS_SILENT,
NULL)
if (mount (tmp_sysroot_etc, tmp_sysroot_etc, NULL, MS_BIND | MS_REMOUNT | MS_SILENT, NULL)
< 0)
err (EXIT_FAILURE, "failed to make writable /etc bind-mount at /sysroot.tmp/etc");
}
Expand Down
82 changes: 57 additions & 25 deletions tests/kolainst/destructive/auto-prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ 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 -t ostree --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 -t ostree --after-cursor "${cursor}" --grep="$re" "$@"; then
fatal "found in journal: $re"; exit 1
fi
}

# 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 +72,13 @@ 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)
rm -vf err.txt
if ostree admin finalize-staged 2>err.txt; 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" "Disabling auto-prune optimization; insufficient space left in bootfs"
assert_file_has_content err.txt "No space left on device"
unconsume_bootfs_space
rpm-ostree cleanup -bpr

Expand All @@ -58,9 +87,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)
ostree admin 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 +100,12 @@ 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
cursor=$(journal_cursor)
rm -vf err.txt
if OSTREE_SYSROOT_OPTS=no-early-prune ostree admin finalize-staged 2>err.txt; 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_file_has_content err.txt "No space left on device"

# 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 +116,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)
ostree admin finalize-staged
assert_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 @@ -121,18 +151,19 @@ unshare -m bash -c \
consume_bootfs_space "$((free_blocks_kernel_and_initrd))"

rpm-ostree rebase :modkernel1
cursor=$(journal_cursor)
# Disable auto-pruning to verify we reproduce the bug
if OSTREE_SYSROOT_OPTS=no-early-prune ostree admin finalize-staged |& tee out.txt; then
rm -vf err.txt
if OSTREE_SYSROOT_OPTS=no-early-prune ostree admin finalize-staged 2>err.txt; 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_file_has_content err.txt "No space left on device"

# 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)
ostree admin 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 @@ -149,17 +180,18 @@ ostree commit --base modkernel1 -P --tree=dir=rootfs -b modkernel3
consume_bootfs_space "$((free_blocks_kernel_and_initrd - 10000))"

rpm-ostree rebase :modkernel3
cursor=$(journal_cursor)
# Disable auto-pruning to verify we reproduce the bug
if OSTREE_SYSROOT_OPTS=no-early-prune ostree admin finalize-staged |& tee out.txt; then
rm -vf err.txt
if OSTREE_SYSROOT_OPTS=no-early-prune ostree admin finalize-staged 2>err.txt; 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_file_has_content err.txt "No space left on device"

# 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)
ostree admin finalize-staged
assert_journal_grep "$cursor" "updating bootloader in two steps"

echo "ok bootfs auto-prune"
Loading