2017-06-29 23:51:56 +03:00
#!/bin/bash
# Test min-free-space-percent using loopback devices
set -xeuo pipefail
2020-03-11 23:00:14 +03:00
. ${ KOLA_EXT_DATA } /libinsttest.sh
2018-03-22 23:40:35 +03:00
date
2017-06-29 23:51:56 +03:00
2018-03-22 18:36:33 +03:00
prepare_tmpdir
2023-03-14 23:51:49 +03:00
truncate -s 20MiB testblk.img
2017-06-29 23:51:56 +03:00
blkdev = $( losetup --find --show $( pwd ) /testblk.img)
2023-03-14 23:51:49 +03:00
mkfs.ext4 -m 0 ${ blkdev }
2017-06-29 23:51:56 +03:00
mkdir mnt
mount ${ blkdev } mnt
2018-06-12 00:06:31 +03:00
# first test min-free-space-percent
2017-06-29 23:51:56 +03:00
ostree --repo= mnt/repo init --mode= bare-user
2018-03-22 23:40:35 +03:00
echo 'fsync=false' >> mnt/repo/config
2017-06-29 23:51:56 +03:00
if ostree --repo= mnt/repo pull-local /ostree/repo ${ host_commit } 2>err.txt; then
fatal "succeeded in doing a pull with no free space"
fi
assert_file_has_content err.txt "min-free-space-percent"
2018-06-12 00:06:31 +03:00
echo "ok min-free-space-percent"
# now test min-free-space-size
rm -rf mnt/repo
ostree --repo= mnt/repo init --mode= bare-user
echo 'fsync=false' >> mnt/repo/config
echo 'min-free-space-size=10MB' >> mnt/repo/config
if ostree --repo= mnt/repo pull-local /ostree/repo ${ host_commit } 2>err.txt; then
fatal "succeeded in doing a pull with no free space"
fi
assert_file_has_content err.txt "min-free-space-size"
2018-06-18 18:11:21 +03:00
echo "ok min-free-space-size (error)"
2018-06-12 00:06:31 +03:00
2018-06-18 18:11:21 +03:00
# min-free-space-size success
ostree --repo= repo init --mode= bare-user
echo 'fsync=false' >> repo/config
echo 'min-free-space-size=1MB' >> repo/config
ostree --repo= repo pull-local /ostree/repo ${ host_commit }
echo "ok min-free-space-size (success)"
2018-12-06 01:56:22 +03:00
# metadata object write should succeed even if free space is lower than
# min-free-space value
rm -rf mnt/repo
ostree --repo= mnt/repo init --mode= bare-user
echo 'fsync=false' >> mnt/repo/config
echo 'min-free-space-size=10MB' >> mnt/repo/config
2020-03-11 23:00:14 +03:00
ostree --repo= mnt/repo pull-local --commit-metadata-only /ostree/repo ${ host_commit }
2018-12-06 01:56:22 +03:00
echo "ok metadata write even when free space is lower than min-free-space value"
2018-06-22 21:06:21 +03:00
rm -rf mnt/repo
# Test min-free-space-size on deltas
#helper function copied from test-delta.sh
get_assert_one_direntry_matching( ) {
local path = $1
local r = $2
local child = ""
local bn
for p in ${ path } /*; do
bn = $( basename $p )
if ! echo ${ bn } | grep -q " $r " ; then
continue
fi
if test -z " ${ child } " ; then
child = ${ bn }
else
assert_not_reached " Expected only one child matching ${ r } in ${ path } " ;
fi
done
if test -z " ${ child } " ; then
assert_not_reached " Failed to find child matching ${ r } "
fi
echo ${ child }
}
mkdir mnt/repo1 mnt/repo2
ostree --repo= mnt/repo1 init --mode= bare-user
ostree --repo= mnt/repo2 init --mode= bare-user
mkdir files
echo "hello" >> files/test.txt
truncate -s 2MB files/test.txt
host_commit = $( ostree --repo= mnt/repo1 commit -b test -s test --tree= dir = files)
origrev = $( ostree --repo= mnt/repo1 rev-parse test )
ostree --repo= mnt/repo1 static-delta generate --empty --to= ${ origrev }
echo 'fsync=false' >> mnt/repo2/config
2023-03-14 23:51:49 +03:00
echo 'min-free-space-size=14MB' >> mnt/repo2/config
2018-06-22 21:06:21 +03:00
deltaprefix = $( get_assert_one_direntry_matching mnt/repo1/deltas '.' )
deltadir = $( get_assert_one_direntry_matching mnt/repo1/deltas/${ deltaprefix } '.' )
# Try to pull delta and trigger error
if ostree --repo= mnt/repo2 static-delta apply-offline mnt/repo1/deltas/${ deltaprefix } /${ deltadir } 2>err.txt; then
fatal "succeeded in doing a delta pull with no free space"
fi
assert_file_has_content err.txt "min-free-space-size"
echo "OK min-free-space-size delta pull (error)"
# Re-adjust min-free-space-size so that delta pull succeeds
2023-03-14 23:51:49 +03:00
sed -i s/min-free-space-size= 14MB/min-free-space-size= 1MB/g mnt/repo2/config
2018-06-22 21:06:21 +03:00
rm -rf mnt/repo2/deltas
ostree --repo= mnt/repo2 static-delta apply-offline mnt/repo1/deltas/${ deltaprefix } /${ deltadir }
echo "OK min-free-space-size delta pull (success)"
rm -rf files
umount mnt
losetup -d ${ blkdev }
rm testblk.img
2018-03-22 23:40:35 +03:00
date