]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-13-NSPAWN-SMOKE/test.sh
7f7380fd6267eb77db360ac78c57ad189727fcba
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 TEST_DESCRIPTION
="systemd-nspawn smoke test"
8 .
$TEST_BASE_DIR/test-functions
12 mkdir
-p $TESTDIR/root
13 mount
${LOOPDEV}p1
$TESTDIR/root
15 # Create what will eventually be our root filesystem onto an overlay
18 eval $
(udevadm info
--export --query=env
--name=${LOOPDEV}p2
)
20 setup_basic_environment
21 dracut_install busybox
chmod rmdir unshare
23 cp create-busybox-container
$initdir/
25 .
/create-busybox-container
$initdir/nc-container
26 initdir
="$initdir/nc-container" dracut_install nc
28 # setup the testsuite service
29 cat >$initdir/etc
/systemd
/system
/testsuite.service
<<EOF
31 Description=Testsuite service
32 After=multi-user.target
35 ExecStart=/test-nspawn.sh
39 cat >$initdir/test-nspawn.sh
<<'EOF'
46 export SYSTEMD_LOG_LEVEL=debug
51 if mount -t cgroup2 cgroup2 /tmp/cgroup2; then
57 # check cgroup namespaces
59 if [[ -f /proc/1/ns/cgroup ]]; then
63 is_user_ns_supported=no
64 if unshare -U sh -c :; then
65 is_user_ns_supported=yes
68 function check_bind_tmp_path {
69 # https://github.com/systemd/systemd/issues/4789
70 local _root="/var/lib/machines/bind-tmp-path"
71 /create-busybox-container "$_root"
73 systemd-nspawn --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind'
76 function check_notification_socket {
77 # https://github.com/systemd/systemd/issues/4944
78 local _cmd='echo a | $(busybox which nc) -U -u -w 1 /run/systemd/nspawn/notify'
79 systemd-nspawn --register=no -D /nc-container /bin/sh -x -c "$_cmd"
80 systemd-nspawn --register=no -D /nc-container -U /bin/sh -x -c "$_cmd"
84 if [[ "$1" = "yes" && "$is_v2_supported" = "no" ]]; then
85 printf "Unified cgroup hierarchy is not supported. Skipping.\n" >&2
88 if [[ "$2" = "yes" && "$is_cgns_supported" = "no" ]]; then
89 printf "Cgroup namespaces are not supported. Skipping.\n" >&2
93 local _root="/var/lib/machines/unified-$1-cgns-$2-api-vfs-writable-$3"
94 /create-busybox-container "$_root"
95 UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -b
96 UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -b
98 if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -U -b; then
99 [[ "$is_user_ns_supported" = "yes" && "$3" = "network" ]] && return 1
101 [[ "$is_user_ns_supported" = "no" && "$3" = "network" ]] && return 1
104 if UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -U -b; then
105 [[ "$is_user_ns_supported" = "yes" && "$3" = "yes" ]] && return 1
107 [[ "$is_user_ns_supported" = "no" && "$3" = "yes" ]] && return 1
115 check_notification_socket
117 for api_vfs_writable in yes no network; do
118 run no no $api_vfs_writable
119 run yes no $api_vfs_writable
120 run no yes $api_vfs_writable
121 run yes yes $api_vfs_writable
127 chmod 0755 $initdir/test-nspawn.sh
131 ddebug
"umount $TESTDIR/root"