dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
ff6046
From 91bd0b915aa17f44625a0c0ce84ed73b6d33968e Mon Sep 17 00:00:00 2001
ff6046
From: Evgeny Vereshchagin <evvers@ya.ru>
ff6046
Date: Thu, 30 Aug 2018 07:01:18 +0300
ff6046
Subject: [PATCH] tests: also run TEST-01-BASIC in an unprivileged container
ff6046
 (#9957)
ff6046
ff6046
This should make it much easier to catch regressions like
ff6046
https://github.com/systemd/systemd/issues/9914 and
ff6046
https://github.com/systemd/systemd/issues/8535.
ff6046
ff6046
(cherry picked from commit 746fbd9c34af5ed8b6d9aa7a9cbd7cac63a3afce)
ff6046
---
ff6046
 test/TEST-01-BASIC/test.sh |  1 +
ff6046
 test/test-functions        | 23 +++++++++++++++++------
ff6046
 2 files changed, 18 insertions(+), 6 deletions(-)
ff6046
ff6046
diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh
ff6046
index 8b21ba05d3..1d2f833478 100755
ff6046
--- a/test/TEST-01-BASIC/test.sh
ff6046
+++ b/test/TEST-01-BASIC/test.sh
ff6046
@@ -3,6 +3,7 @@
ff6046
 # ex: ts=8 sw=4 sts=4 et filetype=sh
ff6046
 set -e
ff6046
 TEST_DESCRIPTION="Basic systemd setup"
ff6046
+RUN_IN_UNPRIVILEGED_CONTAINER=yes
ff6046
 
ff6046
 . $TEST_BASE_DIR/test-functions
ff6046
 
ff6046
diff --git a/test/test-functions b/test/test-functions
ff6046
index 8164858c2a..670c2625f7 100644
ff6046
--- a/test/test-functions
ff6046
+++ b/test/test-functions
ff6046
@@ -190,7 +190,7 @@ $KERNEL_APPEND \
ff6046
 run_nspawn() {
ff6046
     [[ -d /run/systemd/system ]] || return 1
ff6046
 
ff6046
-    local _nspawn_cmd="$BUILD_DIR/systemd-nspawn $NSPAWN_ARGUMENTS --register=no --kill-signal=SIGKILL --directory=$TESTDIR/nspawn-root $PATH_TO_INIT $KERNEL_APPEND"
ff6046
+    local _nspawn_cmd="$BUILD_DIR/systemd-nspawn $NSPAWN_ARGUMENTS --register=no --kill-signal=SIGKILL --directory=$TESTDIR/$1 $PATH_TO_INIT $KERNEL_APPEND"
ff6046
     if [[ "$NSPAWN_TIMEOUT" != "infinity" ]]; then
ff6046
         _nspawn_cmd="timeout --foreground $NSPAWN_TIMEOUT $_nspawn_cmd"
ff6046
     fi
ff6046
@@ -450,9 +450,9 @@ EOF
ff6046
 
ff6046
 check_result_nspawn() {
ff6046
     ret=1
ff6046
-    [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
ff6046
-    [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
ff6046
-    cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
ff6046
+    [[ -e $TESTDIR/$1/testok ]] && ret=0
ff6046
+    [[ -f $TESTDIR/$1/failed ]] && cp -a $TESTDIR/$1/failed $TESTDIR
ff6046
+    cp -a $TESTDIR/$1/var/log/journal $TESTDIR
ff6046
     [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
ff6046
     ls -l $TESTDIR/journal/*/*.journal
ff6046
     test -s $TESTDIR/failed && ret=$(($ret+1))
ff6046
@@ -662,6 +662,9 @@ setup_nspawn_root() {
ff6046
     cp -ar $initdir $TESTDIR/nspawn-root
ff6046
     # we don't mount in the nspawn root
ff6046
     rm -f $TESTDIR/nspawn-root/etc/fstab
ff6046
+    if [[ "$RUN_IN_UNPRIVILEGED_CONTAINER" = "yes" ]]; then
ff6046
+        cp -ar $TESTDIR/nspawn-root $TESTDIR/unprivileged-nspawn-root
ff6046
+    fi
ff6046
 }
ff6046
 
ff6046
 setup_basic_dirs() {
ff6046
@@ -1478,11 +1481,19 @@ test_run() {
ff6046
         fi
ff6046
     fi
ff6046
     if [ -z "$TEST_NO_NSPAWN" ]; then
ff6046
-        if run_nspawn; then
ff6046
-            check_result_nspawn || return 1
ff6046
+        if run_nspawn "nspawn-root"; then
ff6046
+            check_result_nspawn "nspawn-root" || return 1
ff6046
         else
ff6046
             dwarn "can't run systemd-nspawn, skipping"
ff6046
         fi
ff6046
+
ff6046
+        if [[ "$RUN_IN_UNPRIVILEGED_CONTAINER" = "yes" ]]; then
ff6046
+            if NSPAWN_ARGUMENTS="-U --private-network $NSPAWN_ARGUMENTS" run_nspawn "unprivileged-nspawn-root"; then
ff6046
+                check_result_nspawn "unprivileged-nspawn-root" || return 1
ff6046
+            else
ff6046
+                dwarn "can't run systemd-nspawn, skipping"
ff6046
+            fi
ff6046
+	fi
ff6046
     fi
ff6046
     return 0
ff6046
 }