mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
test: stop caching loopdev
It is more trouble than it is worth. The setup is of a loopback device is very quick, so it's better to always create it when needed and immediately drop afterwards.
This commit is contained in:
parent
693ad298e9
commit
1506edca91
@ -8,16 +8,15 @@ TEST_NO_NSPAWN=1
|
|||||||
|
|
||||||
check_result_qemu() {
|
check_result_qemu() {
|
||||||
ret=1
|
ret=1
|
||||||
mkdir -p $initdir
|
mount_initdir
|
||||||
mount ${LOOPDEV}p1 $initdir
|
|
||||||
[[ -e $initdir/testok ]] && ret=0
|
[[ -e $initdir/testok ]] && ret=0
|
||||||
[[ -f $initdir/failed ]] && cp -a $initdir/failed $TESTDIR
|
[[ -f $initdir/failed ]] && cp -a $initdir/failed $TESTDIR
|
||||||
cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
|
cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
|
||||||
mount /dev/mapper/varcrypt $initdir/var
|
mount /dev/mapper/varcrypt $initdir/var
|
||||||
cp -a $initdir/var/log/journal $TESTDIR
|
cp -a $initdir/var/log/journal $TESTDIR
|
||||||
rm -r $initdir/var/log/journal/*
|
rm -r $initdir/var/log/journal/*
|
||||||
umount $initdir/var
|
_umount_dir $initdir/var
|
||||||
umount $initdir
|
_umount_dir $initdir
|
||||||
cryptsetup luksClose /dev/mapper/varcrypt
|
cryptsetup luksClose /dev/mapper/varcrypt
|
||||||
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
|
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
|
||||||
ls -l $TESTDIR/journal/*/*.journal
|
ls -l $TESTDIR/journal/*/*.journal
|
||||||
|
@ -24,7 +24,7 @@ check_result_nspawn() {
|
|||||||
fi
|
fi
|
||||||
cp -a $1/var/log/journal $TESTDIR
|
cp -a $1/var/log/journal $TESTDIR
|
||||||
rm -r $1/var/log/journal/*
|
rm -r $1/var/log/journal/*
|
||||||
umount_initdir
|
_umount_dir $initdir
|
||||||
[[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
|
[[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
|
||||||
return $_ret
|
return $_ret
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ check_result_qemu() {
|
|||||||
fi
|
fi
|
||||||
cp -a $initdir/var/log/journal $TESTDIR
|
cp -a $initdir/var/log/journal $TESTDIR
|
||||||
rm -r $initdir/var/log/journal/*
|
rm -r $initdir/var/log/journal/*
|
||||||
umount_initdir
|
_umount_dir $initdir
|
||||||
[[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
|
[[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
|
||||||
return $_ret
|
return $_ret
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ EFI_MOUNT="${EFI_MOUNT:-$(bootctl -x 2>/dev/null || echo /boot)}"
|
|||||||
QEMU_MEM="${QEMU_MEM:-512M}"
|
QEMU_MEM="${QEMU_MEM:-512M}"
|
||||||
IMAGE_NAME=${IMAGE_NAME:-default}
|
IMAGE_NAME=${IMAGE_NAME:-default}
|
||||||
TEST_REQUIRE_INSTALL_TESTS="${TEST_REQUIRE_INSTALL_TESTS:-1}"
|
TEST_REQUIRE_INSTALL_TESTS="${TEST_REQUIRE_INSTALL_TESTS:-1}"
|
||||||
|
LOOPDEV=
|
||||||
|
|
||||||
# Decide if we can (and want to) run QEMU with KVM acceleration.
|
# Decide if we can (and want to) run QEMU with KVM acceleration.
|
||||||
# Check if nested KVM is explicitly enabled (TEST_NESTED_KVM). If not,
|
# Check if nested KVM is explicitly enabled (TEST_NESTED_KVM). If not,
|
||||||
@ -284,7 +285,7 @@ run_qemu() {
|
|||||||
find_qemu_bin || return 1
|
find_qemu_bin || return 1
|
||||||
|
|
||||||
# Umount initdir to avoid concurrent access to the filesystem
|
# Umount initdir to avoid concurrent access to the filesystem
|
||||||
umount_initdir
|
_umount_dir $initdir
|
||||||
|
|
||||||
local _cgroup_args
|
local _cgroup_args
|
||||||
if [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" ]]; then
|
if [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" ]]; then
|
||||||
@ -667,6 +668,15 @@ install_missing_libraries() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup_loopdev() {
|
||||||
|
if [ -n "${LOOPDEV}" ]; then
|
||||||
|
ddebug "losetup -d $LOOPDEV"
|
||||||
|
losetup -d "${LOOPDEV}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup_loopdev EXIT
|
||||||
|
|
||||||
create_empty_image() {
|
create_empty_image() {
|
||||||
if [ -z "$IMAGE_NAME" ]; then
|
if [ -z "$IMAGE_NAME" ]; then
|
||||||
echo "create_empty_image: \$IMAGE_NAME not set"
|
echo "create_empty_image: \$IMAGE_NAME not set"
|
||||||
@ -689,7 +699,6 @@ create_empty_image() {
|
|||||||
|
|
||||||
LOOPDEV=$(losetup --show -P -f "$public")
|
LOOPDEV=$(losetup --show -P -f "$public")
|
||||||
[ -b "$LOOPDEV" ] || return 1
|
[ -b "$LOOPDEV" ] || return 1
|
||||||
echo "LOOPDEV=$LOOPDEV" >>$STATEFILE
|
|
||||||
sfdisk "$LOOPDEV" <<EOF
|
sfdisk "$LOOPDEV" <<EOF
|
||||||
,$((_size-50))M
|
,$((_size-50))M
|
||||||
,
|
,
|
||||||
@ -700,7 +709,8 @@ EOF
|
|||||||
local _label="-L systemd.${name}"
|
local _label="-L systemd.${name}"
|
||||||
# mkfs.reiserfs doesn't know -L. so, use --label instead
|
# mkfs.reiserfs doesn't know -L. so, use --label instead
|
||||||
[[ "$FSTYPE" == "reiserfs" ]] && _label="--label systemd.${name}"
|
[[ "$FSTYPE" == "reiserfs" ]] && _label="--label systemd.${name}"
|
||||||
if ! mkfs -t "${FSTYPE}" ${_label} "${LOOPDEV}p1" -q; then
|
mkfs -t "${FSTYPE}" ${_label} "${LOOPDEV}p1" -q; ret=$?
|
||||||
|
if [ $ret -ne 0 ] ; then
|
||||||
dfatal "Failed to mkfs -t ${FSTYPE}"
|
dfatal "Failed to mkfs -t ${FSTYPE}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -711,22 +721,15 @@ mount_initdir() {
|
|||||||
image="${IMAGESTATEDIR}/${IMAGE_NAME}.img"
|
image="${IMAGESTATEDIR}/${IMAGE_NAME}.img"
|
||||||
LOOPDEV=$(losetup --show -P -f "$image")
|
LOOPDEV=$(losetup --show -P -f "$image")
|
||||||
[ -b "$LOOPDEV" ] || return 1
|
[ -b "$LOOPDEV" ] || return 1
|
||||||
echo "LOOPDEV=$LOOPDEV" >>$STATEFILE
|
|
||||||
|
udevadm settle
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! mountpoint -q $initdir; then
|
||||||
mkdir -p $initdir
|
mkdir -p $initdir
|
||||||
mount ${LOOPDEV}p1 $initdir
|
mount ${LOOPDEV}p1 $initdir
|
||||||
TEST_SETUP_CLEANUP_ROOTDIR=1
|
TEST_SETUP_CLEANUP_ROOTDIR=1
|
||||||
}
|
|
||||||
|
|
||||||
umount_initdir() {
|
|
||||||
_umount_dir $initdir
|
|
||||||
if [[ $LOOPDEV && -b $LOOPDEV ]]; then
|
|
||||||
ddebug "losetup -d $LOOPDEV"
|
|
||||||
losetup -d $LOOPDEV
|
|
||||||
fi
|
fi
|
||||||
LOOPDEV=
|
|
||||||
sed -i /LOOPDEV=/d $STATEFILE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup_initdir() {
|
cleanup_initdir() {
|
||||||
@ -800,7 +803,7 @@ check_result_nspawn() {
|
|||||||
test -s $TESTDIR/failed && ret=$(($ret+1))
|
test -s $TESTDIR/failed && ret=$(($ret+1))
|
||||||
[ -n "$TIMED_OUT" ] && ret=$(($ret+1))
|
[ -n "$TIMED_OUT" ] && ret=$(($ret+1))
|
||||||
check_asan_reports "$1" || ret=$(($ret+1))
|
check_asan_reports "$1" || ret=$(($ret+1))
|
||||||
umount_initdir
|
_umount_dir $initdir
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -813,7 +816,7 @@ check_result_qemu() {
|
|||||||
cp -a $initdir/var/log/journal $TESTDIR
|
cp -a $initdir/var/log/journal $TESTDIR
|
||||||
rm -r $initdir/var/log/journal/*
|
rm -r $initdir/var/log/journal/*
|
||||||
check_asan_reports "$initdir" || ret=$(($ret+1))
|
check_asan_reports "$initdir" || ret=$(($ret+1))
|
||||||
umount $initdir
|
_umount_dir $initdir
|
||||||
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
|
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
|
||||||
ls -l $TESTDIR/journal/*/*.journal
|
ls -l $TESTDIR/journal/*/*.journal
|
||||||
test -s $TESTDIR/failed && ret=$(($ret+1))
|
test -s $TESTDIR/failed && ret=$(($ret+1))
|
||||||
@ -1164,7 +1167,10 @@ inst_libs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
import_testdir() {
|
import_testdir() {
|
||||||
|
# make sure we don't get a stale LOOPDEV value from old times
|
||||||
|
__LOOPDEV=$LOOPDEV
|
||||||
[[ -e $STATEFILE ]] && . $STATEFILE
|
[[ -e $STATEFILE ]] && . $STATEFILE
|
||||||
|
LOOPDEV=$__LOOPDEV
|
||||||
if [[ ! -d "$TESTDIR" ]]; then
|
if [[ ! -d "$TESTDIR" ]]; then
|
||||||
if [[ -z "$TESTDIR" ]]; then
|
if [[ -z "$TESTDIR" ]]; then
|
||||||
TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
|
TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
|
||||||
@ -1174,7 +1180,6 @@ import_testdir() {
|
|||||||
|
|
||||||
cat >$STATEFILE<<EOF
|
cat >$STATEFILE<<EOF
|
||||||
TESTDIR="$TESTDIR"
|
TESTDIR="$TESTDIR"
|
||||||
LOOPDEV="$LOOPDEV"
|
|
||||||
EOF
|
EOF
|
||||||
export TESTDIR
|
export TESTDIR
|
||||||
fi
|
fi
|
||||||
@ -1926,7 +1931,7 @@ _test_cleanup() {
|
|||||||
# (post-test) cleanup should always ignore failure and cleanup as much as possible
|
# (post-test) cleanup should always ignore failure and cleanup as much as possible
|
||||||
(
|
(
|
||||||
set +e
|
set +e
|
||||||
umount_initdir
|
_umount_dir $initdir
|
||||||
rm -vf "${IMAGESTATEDIR}/${IMAGE_NAME}.img"
|
rm -vf "${IMAGESTATEDIR}/${IMAGE_NAME}.img"
|
||||||
rm -vfr "$TESTDIR"
|
rm -vfr "$TESTDIR"
|
||||||
rm -vf "$STATEFILE"
|
rm -vf "$STATEFILE"
|
||||||
@ -1941,7 +1946,7 @@ test_cleanup() {
|
|||||||
test_cleanup_again() {
|
test_cleanup_again() {
|
||||||
[ -n "$TESTDIR" ] || return
|
[ -n "$TESTDIR" ] || return
|
||||||
rm -rf "$TESTDIR/unprivileged-nspawn-root"
|
rm -rf "$TESTDIR/unprivileged-nspawn-root"
|
||||||
umount_initdir
|
_umount_dir $initdir
|
||||||
}
|
}
|
||||||
|
|
||||||
test_create_image() {
|
test_create_image() {
|
||||||
|
Loading…
Reference in New Issue
Block a user