tests/installed: Use temporary directories more consistently

This is prep for splitting off "nondestructive" tests which
we can run in parallel from the destructive/invasive ones which
e.g. change the host refspec, do deployments.

The `cd` invocation in `prepare_tmpdir` wasn't working because we were running
it in a subshell. Fix this by dropping the subshell.

Closes: #1509
Approved by: jlebon
This commit is contained in:
Colin Walters 2018-03-22 11:36:33 -04:00 committed by Atomic Bot
parent dca1cfa60f
commit bb9cd1eb72
7 changed files with 32 additions and 47 deletions

View File

@ -15,14 +15,7 @@ dn=$(dirname $0)
export G_TEST_SRCDIR=$(realpath $dn/../..)
# Use /var/tmp to hopefully use XFS + O_TMPFILE etc.
tempdir=$(mktemp -d /var/tmp/tap-test.XXXXXX)
touch ${tempdir}/.testtmp
function cleanup () {
if test -f ${tempdir}/.testtmp; then
rm "${tempdir}" -rf
fi
}
trap cleanup EXIT
cd ${tempdir}
prepare_tmpdir /var/tmp
trap _tmpdir_cleanup EXIT
/usr/libexec/installed-tests/libostree/test-basic.sh
/usr/libexec/installed-tests/libostree/test-basic-c

View File

@ -10,9 +10,8 @@ set -xeuo pipefail
dn=$(dirname $0)
. ${dn}/libinsttest.sh
test_tmpdir=$(prepare_tmpdir)
prepare_tmpdir
trap _tmpdir_cleanup EXIT
cd ${test_tmpdir}
mkdir mnt
mount -t tmpfs tmpfs mnt

View File

@ -26,8 +26,9 @@ dn=$(dirname $0)
echo "1..1"
cd /var/srv
mkdir repo
# Use /var/tmp so we have O_TMPFILE etc.
prepare_tmpdir /var/tmp
trap _tmpdir_cleanup EXIT
ostree --repo=repo init --mode=archive
echo -e '[archive]\nzlib-level=1\n' >> repo/config
host_nonremoteref=$(echo ${host_refspec} | sed 's,[^:]*:,,')
@ -39,12 +40,10 @@ run_tmp_webserver $(pwd)/repo
origin=$(cat ${test_tmpdir}/httpd-address)
cleanup() {
cd ${oldpwd}
cd ${test_tmpdir}
umount mnt || true
test -n "${blkdev}" && losetup -d ${blkdev} || true
rm -rf mnt testblk.img
test -n "${blkdev:-}" && losetup -d ${blkdev} || true
}
oldpwd=`pwd`
trap cleanup EXIT
mkdir mnt
@ -57,29 +56,25 @@ fi
mkfs.xfs -m reflink=1 ${blkdev}
mount ${blkdev} mnt
cd mnt
test_tmpdir=$(pwd)/mnt
cd ${test_tmpdir}
# Test that coreutils will do reflink
touch a
if cp --reflink a b; then
mkdir repo
ostree --repo=repo init
ostree config --repo=repo set core.payload-link-threshold 0
ostree --repo=repo remote add origin --set=gpg-verify=false ${origin}
ostree --repo=repo pull --disable-static-deltas origin ${host_nonremoteref}
find repo -type l -name '*.payload-link' >payload-links.txt
assert_not_streq "$(wc -l < payload-links.txt)" "0"
cp --reflink a b
mkdir repo
ostree --repo=repo init
ostree config --repo=repo set core.payload-link-threshold 0
ostree --repo=repo remote add origin --set=gpg-verify=false ${origin}
ostree --repo=repo pull --disable-static-deltas origin ${host_nonremoteref}
find repo -type l -name '*.payload-link' >payload-links.txt
assert_not_streq "$(wc -l < payload-links.txt)" "0"
# Disable logging for inner loop, otherwise it'd be enormous
set +x
cat payload-links.txt | while read i; do
payload_checksum=$(basename $(dirname $i))$(basename $i .payload-link)
payload_checksum_calculated=$(sha256sum $(readlink -f $i) | cut -d ' ' -f 1)
assert_streq "${payload_checksum}" "${payload_checksum_calculated}"
done
set -x
echo "ok pull creates .payload-link"
else
echo "ok # SKIP no reflink support in the file system"
fi
# Disable logging for inner loop, otherwise it'd be enormous
set +x
cat payload-links.txt | while read i; do
payload_checksum=$(basename $(dirname $i))$(basename $i .payload-link)
payload_checksum_calculated=$(sha256sum $(readlink -f $i) | cut -d ' ' -f 1)
assert_streq "${payload_checksum}" "${payload_checksum_calculated}"
done
set -x
echo "ok pull creates .payload-link"

View File

@ -6,7 +6,7 @@ set -xeuo pipefail
dn=$(dirname $0)
. ${dn}/libinsttest.sh
test_tmpdir=$(prepare_tmpdir)
prepare_tmpdir
trap _tmpdir_cleanup EXIT
cd ${test_tmpdir}

View File

@ -7,12 +7,10 @@ set -xeuo pipefail
dn=$(dirname $0)
. ${dn}/libinsttest.sh
test_tmpdir=$(prepare_tmpdir)
prepare_tmpdir /var/tmp
trap _tmpdir_cleanup EXIT
# Take the host's ostree, and make it archive
cd /var/srv
rm repo bare-repo -rf
mkdir repo
ostree --repo=repo init --mode=archive
echo -e '[archive]\nzlib-level=1\n' >> repo/config

View File

@ -7,7 +7,7 @@ set -xeuo pipefail
dn=$(dirname $0)
. ${dn}/libinsttest.sh
test_tmpdir=$(prepare_tmpdir)
prepare_tmpdir
trap _tmpdir_cleanup EXIT
ostree remote list > remotes.txt

View File

@ -30,10 +30,10 @@ function _tmpdir_cleanup () {
fi
}
prepare_tmpdir() {
test_tmpdir=$(mktemp -d)
local tmpdir=${1:-/tmp}
test_tmpdir=$(mktemp -p ${tmpdir} -d ostree-insttest.XXXXXXXX)
touch ${test_tmpdir}/.testtmp
cd ${test_tmpdir}
echo ${test_tmpdir}
}
# This is copied from flatpak/flatpak/tests/test-webserver.sh