]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: Run qemu/nspawn tests with "set -e" 6475/head
authorMartin Pitt <martin@piware.de>
Mon, 7 Aug 2017 19:09:21 +0000 (21:09 +0200)
committerMartin Pitt <martin@piware.de>
Thu, 10 Aug 2017 06:43:13 +0000 (08:43 +0200)
This catches errors like "ninja not found", missing programs etc. early,
instead of silently ignoring them and trying to boot a broken VM.

In install_config_files(), allow some distro specific files to be absent
(such as /etc/sysconfig/init).

17 files changed:
test/TEST-01-BASIC/test.sh
test/TEST-02-CRYPTSETUP/test.sh
test/TEST-03-JOBS/test-jobs.sh
test/TEST-03-JOBS/test.sh
test/TEST-04-JOURNAL/test.sh
test/TEST-05-RLIMITS/test.sh
test/TEST-06-SELINUX/test.sh
test/TEST-07-ISSUE-1981/test.sh
test/TEST-08-ISSUE-2730/test.sh
test/TEST-09-ISSUE-2691/test.sh
test/TEST-10-ISSUE-2467/test.sh
test/TEST-11-ISSUE-3166/test.sh
test/TEST-12-ISSUE-3171/test.sh
test/TEST-13-NSPAWN-SMOKE/test.sh
test/TEST-14-MACHINE-ID/test.sh
test/TEST-15-DROPIN/test.sh
test/test-functions

index b1d6e1931bdc9b4cb304f87cf9e96928a9a5c307..8b21ba05d3e29f31da450817fec870464be34254 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="Basic systemd setup"
 
 . $TEST_BASE_DIR/test-functions
index 31eced5809683684c001d93b754ef5aa4d84bae9..1280148b58717ab1ad7f37d056ce621199036e02 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="cryptsetup systemd setup"
 TEST_NO_NSPAWN=1
 
@@ -78,9 +79,9 @@ EOF
 }
 
 test_cleanup() {
-    umount $TESTDIR/root/var 2>/dev/null
+    [ -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
+    umount $TESTDIR/root 2>/dev/null || true
     [[ $LOOPDEV ]] && losetup -d $LOOPDEV
     return 0
 }
index 48926290a673a2810fa7053b194a4fff109a1519..4c954d039739b1caad7fa8162484e92dfbfe1c71 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash -x
+#!/bin/bash -e
 
 # Test merging of a --job-mode=ignore-dependencies job into a previously
 # installed job.
@@ -10,7 +10,7 @@ while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
     systemctl list-jobs > /root/list-jobs.txt
 done
 
-grep 'hello\.service.*waiting' /root/list-jobs.txt || exit 1
+grep 'hello\.service.*waiting' /root/list-jobs.txt
 
 # This is supposed to finish quickly, not wait for sleep to finish.
 START_SEC=$(date -u '+%s')
@@ -18,36 +18,36 @@ systemctl start --job-mode=ignore-dependencies hello
 END_SEC=$(date -u '+%s')
 ELAPSED=$(($END_SEC-$START_SEC))
 
-[ "$ELAPSED" -lt 3 ] || exit 1
+[ "$ELAPSED" -lt 3 ]
 
 # sleep should still be running, hello not.
 systemctl list-jobs > /root/list-jobs.txt
-grep 'sleep\.service.*running' /root/list-jobs.txt || exit 1
+grep 'sleep\.service.*running' /root/list-jobs.txt
 grep 'hello\.service' /root/list-jobs.txt && exit 1
-systemctl stop sleep.service hello-after-sleep.target || exit 1
+systemctl stop sleep.service hello-after-sleep.target
 
 # Test for a crash when enqueuing a JOB_NOP when other job already exists
-systemctl start --no-block hello-after-sleep.target || exit 1
+systemctl start --no-block hello-after-sleep.target
 # hello.service should still be waiting, so these try-restarts will collapse
 # into NOPs.
-systemctl try-restart --job-mode=fail hello.service || exit 1
-systemctl try-restart hello.service || exit 1
-systemctl stop hello.service sleep.service hello-after-sleep.target || exit 1
+systemctl try-restart --job-mode=fail hello.service
+systemctl try-restart hello.service
+systemctl stop hello.service sleep.service hello-after-sleep.target
 
 # TODO: add more job queueing/merging tests here.
 
 # Test for irreversible jobs
-systemctl start unstoppable.service || exit 1
+systemctl start unstoppable.service
 
 # This is expected to fail with 'job cancelled'
 systemctl stop unstoppable.service && exit 1
 # But this should succeed
-systemctl stop --job-mode=replace-irreversibly unstoppable.service || exit 1
+systemctl stop --job-mode=replace-irreversibly unstoppable.service
 
 # We're going to shutdown soon. Let's see if it succeeds when
 # there's an active service that tries to be unstoppable.
 # Shutdown of the container/VM will hang if not.
-systemctl start unstoppable.service || exit 1
+systemctl start unstoppable.service
 
 # Test waiting for a started unit(s) to terminate again
 cat <<EOF >  /run/systemd/system/wait2.service
@@ -65,7 +65,7 @@ EOF
 
 # wait2 succeeds
 START_SEC=$(date -u '+%s')
-systemctl start --wait wait2.service || exit 1
+systemctl start --wait wait2.service
 END_SEC=$(date -u '+%s')
 ELAPSED=$(($END_SEC-$START_SEC))
 [[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1
index a3755a7a7a9d387e517fed70ab261f05395ea04c..88bbf3cdac4d82aef772439a01d5c1e5e2faa9d1 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="Job-related tests"
 
 . $TEST_BASE_DIR/test-functions
index 66fc5af3d25497884c1195b0a9eccb5871476e36..30e7b181b2f1cd5d06acde31c360f268f393f5d9 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="Journal-related tests"
 
 . $TEST_BASE_DIR/test-functions
index e684b6dd2d36f42762fc48482313dd0cd4651495..a1b855c5fbea44564a04cea238424e564e2e6f91 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="Resource limits-related tests"
 
 . $TEST_BASE_DIR/test-functions
index ab4bb435dcd841460a825de13551c07b2632b0ab..e0c4c10e1ceb857c0ff17bb29a33831b9781a1f6 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="SELinux tests"
 TEST_NO_NSPAWN=1
 
index a55c691a6293c54591b690f1386976b1b87e9c96..88d143e4792a49149f7ca28bcd1418f5381c0a6a 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/1981"
 TEST_NO_QEMU=1
 
index f7f34007f9af4c9f1070034c841f3cf4f2c25c13..68159c331f901f81c214ff90d6a06cd5da696de6 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2730"
 TEST_NO_NSPAWN=1
 
index 1bd620a2679d6b06ca2539d474c0f5df7bf321c3..4c3e9496b4467bfb4a2a57555566906fca4202e4 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2691"
 TEST_NO_NSPAWN=1
 
index dfc7cbe52d0d04c116d24e1c41dfdd70c3f6c1cb..e7eb1cb303c2aa1fbf9b26f564de969bf9460e25 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2467"
 TEST_NO_NSPAWN=1
 
index 12bf84252b04d4e079aa1fe123d0b3daabf198d0..4602bdfc9816066974a4d21957d0bf4fb4a44a30 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/3166"
 TEST_NO_NSPAWN=1
 
index 7837f639a16f5d56e981f8ead25c4ff6af0ead04..559fa469cd82aeb6cb7a293b3e1f29220f6e4bd1 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/3171"
 TEST_NO_QEMU=1
 
index 84a3af30a3b8ea80c9afe49b7cd65fedcca7d1d5..7f7380fd6267eb77db360ac78c57ad189727fcba 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="systemd-nspawn smoke test"
 TEST_NO_NSPAWN=1
 SKIP_INITRD=yes
index c406205c513fd0a1ac65c68755390f3014aa7fd2..b932060bc2d26fb00eac2ed19c8a5d8b9ca5d5fb 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
 TEST_DESCRIPTION="Basic systemd setup"
 TEST_NO_NSPAWN=1
 SKIP_INITRD=yes
index 536b379f642f8282f0acecb98c790539ed5b3e83..b85bffafafb7c2882cdfad6e649a535d4b538112 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
-
+set -e
 TEST_DESCRIPTION="Dropin tests"
 TEST_NO_QEMU=1
 
index 169dd46f7343676c7591b1aba753c8ce386dd78f..67fe5e19b87f366c2827f66a5f3007ed101c2787 100644 (file)
@@ -4,9 +4,9 @@
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 export PATH
 
-LOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes)
-LOOKS_LIKE_ARCH=$(source /etc/os-release && [[ "$ID" = "arch" ]] && echo yes)
-LOOKS_LIKE_SUSE=$(source /etc/os-release && [[ "$ID_LIKE" = "suse" ]] && echo yes)
+LOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes || true)
+LOOKS_LIKE_ARCH=$(source /etc/os-release && [[ "$ID" = "arch" ]] && echo yes || true)
+LOOKS_LIKE_SUSE=$(source /etc/os-release && [[ "$ID_LIKE" = "suse" ]] && echo yes || true)
 KERNEL_VER=${KERNEL_VER-$(uname -r)}
 KERNEL_MODS="/lib/modules/$KERNEL_VER/"
 QEMU_TIMEOUT="${QEMU_TIMEOUT:-infinity}"
@@ -427,7 +427,8 @@ install_execs() {
     egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/{$systemdsystemunitdir,$systemduserunitdir}/*.service \
          | while read i; do
          i=${i##Exec*=}; i=${i##-}
-         inst $i
+         # some {rc,halt}.local scripts and programs are okay to not exist, the rest should
+         inst $i || [ "${i%.local}" != "$i" ] || [ "${i%systemd-update-done}" != "$i" ]
      done
     )
 }
@@ -462,15 +463,15 @@ install_ld_so_conf() {
 }
 
 install_config_files() {
-    inst /etc/sysconfig/init
+    inst /etc/sysconfig/init || true
     inst /etc/passwd
     inst /etc/shadow
     inst /etc/login.defs
     inst /etc/group
     inst /etc/shells
     inst /etc/nsswitch.conf
-    inst /etc/pam.conf
-    inst /etc/securetty
+    inst /etc/pam.conf || true
+    inst /etc/securetty || true
     inst /etc/os-release
     inst /etc/localtime
     # we want an empty environment
@@ -520,12 +521,12 @@ install_dbus() {
 
 install_pam() {
     (
-    [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null && find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f
-    find \
-        /etc/pam.d \
-        /etc/security \
-        /lib64/security \
-        /lib/security -xtype f \
+    if [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null; then
+        find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f
+    else
+        find /lib*/security -xtype f
+    fi
+    find /etc/pam.d /etc/security -xtype f
     ) | while read file; do
         inst $file
     done
@@ -923,7 +924,7 @@ inst_library() {
 
     # Create additional symlinks.  See rev_symlinks description.
     for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
-        [[ ! -e $initdir/$_symlink ]] && {
+        [[ -e $initdir/$_symlink ]] || {
             ddebug "Creating extra symlink: $_symlink"
             inst_symlink $_symlink
         }
@@ -1387,7 +1388,7 @@ setup_suse() {
 # can be overridden in specific test
 test_cleanup() {
     umount $TESTDIR/root 2>/dev/null || true
-    [[ $LOOPDEV ]] && losetup -d $LOOPDEV
+    [[ $LOOPDEV ]] && losetup -d $LOOPDEV || true
     return 0
 }
 
@@ -1433,9 +1434,7 @@ do_test() {
         case $1 in
             --run)
                 echo "TEST RUN: $TEST_DESCRIPTION"
-                test_run
-                ret=$?
-                if [ $ret -eq 0 ]; then
+                if test_run; then
                     echo "TEST RUN: $TEST_DESCRIPTION [OK]"
                 else
                     echo "TEST RUN: $TEST_DESCRIPTION [FAILED]"
@@ -1444,14 +1443,15 @@ do_test() {
             --setup)
                 echo "TEST SETUP: $TEST_DESCRIPTION"
                 test_setup
-                exit $?;;
+                ;;
             --clean)
                 echo "TEST CLEANUP: $TEST_DESCRIPTION"
                 test_cleanup
                 rm -fr "$TESTDIR"
                 rm -f "$STATEFILE"
-                exit $?;;
+                ;;
             --all)
+                ret=0
                 echo -n "TEST: $TEST_DESCRIPTION ";
                 (
                     test_setup && test_run
@@ -1460,8 +1460,7 @@ do_test() {
                     rm -fr "$TESTDIR"
                     rm -f "$STATEFILE"
                     exit $ret
-                ) </dev/null >"$TESTLOG" 2>&1
-                ret=$?
+                ) </dev/null >"$TESTLOG" 2>&1 || ret=$?
                 if [ $ret -eq 0 ]; then
                     rm "$TESTLOG"
                     echo "[OK]"