test: add smoke tests for --network-namespace-path

We create net ns with `ip netns`, pass the created ns to nspawn and
check the loopback interface is DOWN.
This commit is contained in:
Iago López Galeiras 2017-12-12 16:47:41 +00:00
parent 25fd814316
commit f3d33947ea

View file

@ -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
}