]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add smoke tests for `--network-namespace-path` 7469/head
authorIago López Galeiras <iago@kinvolk.io>
Tue, 12 Dec 2017 16:47:41 +0000 (16:47 +0000)
committerIago López Galeiras <iago@kinvolk.io>
Thu, 14 Dec 2017 16:34:26 +0000 (17:34 +0100)
We create net ns with `ip netns`, pass the created ns to nspawn and
check the loopback interface is DOWN.

test/TEST-13-NSPAWN-SMOKE/test.sh

index 3b572a767774ddc95fa1e1e9dbf239d26d22631c..239c7e0731e648c9131bab3531d9e16bc0abee6b 100755 (executable)
@@ -18,12 +18,12 @@ test_setup() {
         eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
 
         setup_basic_environment
-        dracut_install busybox chmod rmdir unshare
+        dracut_install busybox chmod rmdir unshare ip
 
         cp create-busybox-container $initdir/
 
         ./create-busybox-container $initdir/nc-container
-        initdir="$initdir/nc-container" dracut_install nc
+        initdir="$initdir/nc-container" dracut_install nc ip
 
         # setup the testsuite service
         cat >$initdir/etc/systemd/system/testsuite.service <<EOF
@@ -34,6 +34,8 @@ After=multi-user.target
 [Service]
 ExecStart=/test-nspawn.sh
 Type=oneshot
+StandardOutput=tty
+StandardError=tty
 EOF
 
         cat >$initdir/test-nspawn.sh <<'EOF'
@@ -142,6 +144,17 @@ function run {
        return 1
     fi
 
+    # test --network-namespace-path works with a network namespace created by "ip netns"
+    ip netns add nspawn_test
+    _netns_opt="--network-namespace-path=/run/netns/nspawn_test"
+    UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" ip a | grep -E '^1: lo.*DOWN'
+    local r=$?
+    ip netns del nspawn_test
+
+    if [ $r -ne 0 ]; then
+       return 1
+    fi
+
     return 0
 }