From 97113adc42f15ba04630c2808f14cd01aff22ed9 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Tue, 1 Sep 2020 14:51:54 -0700 Subject: [PATCH 96/97] tests: Add a test for resizepart on a busy partition This makes sure that the resizepart on a busy partition with the size on the cmdline will work. (cherry picked from commit dfc611bd5126840d68493ad0e761511a71325af7) Related: rhbz#1861804 --- tests/t3200-resize-partition.sh | 44 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/tests/t3200-resize-partition.sh b/tests/t3200-resize-partition.sh index dcf1775..2200977 100755 --- a/tests/t3200-resize-partition.sh +++ b/tests/t3200-resize-partition.sh @@ -2,7 +2,7 @@ # exercise the resize sub-command # based on t3000-resize-fs.sh test -# Copyright (C) 2009-2011 Free Software Foundation, Inc. +# Copyright (C) 2009-2020 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -66,8 +66,8 @@ sleep 1 # Running it without end should not core-dump or prompt parted -s $dev resizepart 1 > out 2> err || fail=1 -# extend the filesystem to end on sector 4096 -new_end=4096s +# extend the filesystem to end on sector 2048 +new_end=2048s parted -s $dev resizepart 1 $new_end > out 2> err || fail=1 # expect no output compare /dev/null out || fail=1 @@ -77,9 +77,45 @@ compare /dev/null err || fail=1 parted -m -s $dev u s p > out 2>&1 || fail=1 sed -n 3p out > k && mv k out || fail=1 -printf "1:$default_start:$new_end:3073s:::$ms;\n" > exp || fail=1 +printf "1:$default_start:$new_end:1025s:::$ms;\n" > exp || fail=1 compare exp out || fail=1 +## Make sure resizing a busy partition works when user answers 'yes' +# Format the partition and mount it for the busy check +mkfs.ext4 "${dev}1" || skip_ mkfs.ext4 failed + +# be sure to unmount upon interrupt, failure, etc. +cleanup_fn_() { umount "${dev}1" > /dev/null 2>&1; } + +mount_point=$(pwd)/mnt + +mkdir $mount_point || fail=1 +mount "${dev}1" "$mount_point" || fail=1 + +# extend the filesystem to end on sector 4096 +new_end=4096s +echo yes | parted ---pretend-input-tty $dev resizepart 1 $new_end > out 2>&1 +cat > exp < out +compare exp out || fail=1 + +# print partition table +parted -m -s $dev u s p > out 2>&1 || fail=1 + +sed -n 3p out > k && mv k out || fail=1 +printf "1:$default_start:$new_end:3073s:ext2::$ms;\n" > exp || fail=1 +compare exp out || fail=1 + +umount "${dev}1" || fail=1 + # Remove the partition explicitly, so that mklabel doesn't evoke a warning. parted -s $dev rm 1 || fail=1 -- 2.31.1