]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-13-NSPAWN-SMOKE/test.sh
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 TEST_DESCRIPTION
="systemd-nspawn smoke test"
6 .
$TEST_BASE_DIR/test-functions
10 mkdir
-p $TESTDIR/root
11 mount
${LOOPDEV}p1
$TESTDIR/root
12 [[ -e $TESTDIR/root
/testok
]] && ret
=0
13 [[ -f $TESTDIR/root
/failed
]] && cp -a $TESTDIR/root
/failed
$TESTDIR
14 cp -a $TESTDIR/root
/var
/log
/journal
$TESTDIR
16 [[ -f $TESTDIR/failed
]] && cat $TESTDIR/failed
17 ls -l $TESTDIR/journal
/*/*.journal
18 test -s $TESTDIR/failed
&& ret
=$
(($ret+1))
24 check_result_qemu ||
return 1
26 dwarn
"can't run QEMU, skipping"
33 mkdir
-p $TESTDIR/root
34 mount
${LOOPDEV}p1
$TESTDIR/root
36 # Create what will eventually be our root filesystem onto an overlay
39 eval $
(udevadm info
--export --query=env
--name=${LOOPDEV}p2
)
41 setup_basic_environment
42 dracut_install busybox
chmod rmdir unshare
44 cp create-busybox-container
$initdir/
46 .
/create-busybox-container
$initdir/nc-container
47 initdir
="$initdir/nc-container" dracut_install nc
49 # setup the testsuite service
50 cat >$initdir/etc
/systemd
/system
/testsuite.service
<<EOF
52 Description=Testsuite service
53 After=multi-user.target
56 ExecStart=/test-nspawn.sh
60 cat >$initdir/test-nspawn.sh
<<'EOF'
67 export SYSTEMD_LOG_LEVEL=debug
72 if mount -t cgroup2 cgroup2 /tmp/cgroup2; then
78 # check cgroup namespaces
80 if [[ -f /proc/1/ns/cgroup ]]; then
84 is_user_ns_supported=no
85 if unshare -U sh -c :; then
86 is_user_ns_supported=yes
89 function check_bind_tmp_path {
90 # https://github.com/systemd/systemd/issues/4789
91 local _root="/var/lib/machines/bind-tmp-path"
92 /create-busybox-container "$_root"
94 systemd-nspawn --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind'
97 function check_notification_socket {
98 # https://github.com/systemd/systemd/issues/4944
99 local _cmd='echo a | $(busybox which nc) -U -u -w 1 /run/systemd/nspawn/notify'
100 systemd-nspawn --register=no -D /nc-container /bin/sh -x -c "$_cmd"
101 systemd-nspawn --register=no -D /nc-container -U /bin/sh -x -c "$_cmd"
105 if [[ "$1" = "yes" && "$is_v2_supported" = "no" ]]; then
106 printf "Unified cgroup hierarchy is not supported. Skipping.\n" >&2
109 if [[ "$2" = "yes" && "$is_cgns_supported" = "no" ]]; then
110 printf "Cgroup namespaces are not supported. Skipping.\n" >&2
114 local _root="/var/lib/machines/unified-$1-cgns-$2-api-vfs-writable-$3"
115 /create-busybox-container "$_root"
116 UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -b
117 UNIFIED_CGROUP_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -b
119 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
120 [[ "$is_user_ns_supported" = "yes" && "$3" = "network" ]] && return 1
122 [[ "$is_user_ns_supported" = "no" && "$3" = "network" ]] && return 1
125 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
126 [[ "$is_user_ns_supported" = "yes" && "$3" = "yes" ]] && return 1
128 [[ "$is_user_ns_supported" = "no" && "$3" = "yes" ]] && return 1
136 check_notification_socket
138 for api_vfs_writable in yes no network; do
139 run no no $api_vfs_writable
140 run yes no $api_vfs_writable
141 run no yes $api_vfs_writable
142 run yes yes $api_vfs_writable
148 chmod 0755 $initdir/test-nspawn.sh
152 ddebug
"umount $TESTDIR/root"
157 umount
$TESTDIR/root
2>/dev
/null
158 [[ $LOOPDEV ]] && losetup
-d $LOOPDEV