summaryrefslogtreecommitdiffstats
path: root/test/TEST-02-CRYPTSETUP
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@canonical.com>2019-07-12 17:47:26 +0200
committerDan Streetman <ddstreet@canonical.com>2019-07-17 00:05:15 +0200
commitec4cab49c95d03d23cad9741685f3837a8ccaab4 (patch)
tree315c884c2c3e9e09af252b54297e2dca2d1a26cd /test/TEST-02-CRYPTSETUP
parentMerge pull request #13069 from yuwata/network-do-not-set-routes-when-carrier-... (diff)
downloadsystemd-ec4cab49c95d03d23cad9741685f3837a8ccaab4.tar.xz
systemd-ec4cab49c95d03d23cad9741685f3837a8ccaab4.zip
test: add create_empty_image_rootdir() to simplify testcase setup
Almost all tests were manually mounting/unmounting $TESTDIR/root from the loopback image; this moves all that into test-functions so the test setup functions are simplier. Also add test_setup_cleanup() function, to cleanup what is mounted by create_empty_image_rootdir()
Diffstat (limited to 'test/TEST-02-CRYPTSETUP')
-rwxr-xr-xtest/TEST-02-CRYPTSETUP/test.sh24
1 files changed, 12 insertions, 12 deletions
diff --git a/test/TEST-02-CRYPTSETUP/test.sh b/test/TEST-02-CRYPTSETUP/test.sh
index 9d25e94250..e28cec0340 100755
--- a/test/TEST-02-CRYPTSETUP/test.sh
+++ b/test/TEST-02-CRYPTSETUP/test.sh
@@ -25,13 +25,11 @@ check_result_qemu() {
test_setup() {
- create_empty_image
+ create_empty_image_rootdir
echo -n test >$TESTDIR/keyfile
cryptsetup -q luksFormat --pbkdf pbkdf2 --pbkdf-force-iterations 1000 ${LOOPDEV}p2 $TESTDIR/keyfile
cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
mkfs.ext4 -L var /dev/mapper/varcrypt
- mkdir -p $TESTDIR/root
- mount ${LOOPDEV}p1 $TESTDIR/root
mkdir -p $TESTDIR/root/var
mount /dev/mapper/varcrypt $TESTDIR/root/var
@@ -76,20 +74,22 @@ EOF
/dev/mapper/varcrypt /var ext4 defaults 0 1
EOF
)
+}
+cleanup_root_var() {
ddebug "umount $TESTDIR/root/var"
- umount $TESTDIR/root/var
- cryptsetup luksClose /dev/mapper/varcrypt
- ddebug "umount $TESTDIR/root"
- umount $TESTDIR/root
+ mountpoint $TESTDIR/root/var && umount $TESTDIR/root/var
+ [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt
}
test_cleanup() {
- [ -d $TESTDIR/root/var ] && mountpoint $TESTDIR/root/var && umount $TESTDIR/root/var
- [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt
- umount $TESTDIR/root 2>/dev/null || true
- [[ $LOOPDEV ]] && losetup -d $LOOPDEV
- return 0
+ cleanup_root_var
+ _test_cleanup
+}
+
+test_setup_cleanup() {
+ cleanup_root_var
+ _test_setup_cleanup
}
do_test "$@"