From 518c3e272234c0a59eaac01779481fa2ef399195 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 16 May 2023 20:31:49 +0200 Subject: [PATCH] test: merge TEST-49-RUNTIME-BIND-PATHS into TEST-23-UNIT-FILE --- test/TEST-49-RUNTIME-BIND-PATHS/Makefile | 1 - test/TEST-49-RUNTIME-BIND-PATHS/test.sh | 10 ----- .../testsuite-23-namespaced.service} | 6 +-- .../testsuite-23-non-namespaced.service} | 4 +- test/units/testsuite-23.runtime-bind-paths.sh | 39 ++++++++++++++++ test/units/testsuite-49.service | 8 ---- test/units/testsuite-49.sh | 44 ------------------- 7 files changed, 44 insertions(+), 68 deletions(-) delete mode 120000 test/TEST-49-RUNTIME-BIND-PATHS/Makefile delete mode 100755 test/TEST-49-RUNTIME-BIND-PATHS/test.sh rename test/{units/testsuite-49-namespaced.service => testsuite-23.units/testsuite-23-namespaced.service} (60%) rename test/{units/testsuite-49-non-namespaced.service => testsuite-23.units/testsuite-23-non-namespaced.service} (62%) create mode 100755 test/units/testsuite-23.runtime-bind-paths.sh delete mode 100644 test/units/testsuite-49.service delete mode 100755 test/units/testsuite-49.sh diff --git a/test/TEST-49-RUNTIME-BIND-PATHS/Makefile b/test/TEST-49-RUNTIME-BIND-PATHS/Makefile deleted file mode 120000 index e9f93b1104c..00000000000 --- a/test/TEST-49-RUNTIME-BIND-PATHS/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-49-RUNTIME-BIND-PATHS/test.sh b/test/TEST-49-RUNTIME-BIND-PATHS/test.sh deleted file mode 100755 index c9f33457b32..00000000000 --- a/test/TEST-49-RUNTIME-BIND-PATHS/test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="test adding new BindPaths while unit is already running" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/units/testsuite-49-namespaced.service b/test/testsuite-23.units/testsuite-23-namespaced.service similarity index 60% rename from test/units/testsuite-49-namespaced.service rename to test/testsuite-23.units/testsuite-23-namespaced.service index 93abc31cdc3..5f30b55e00e 100644 --- a/test/units/testsuite-49-namespaced.service +++ b/test/testsuite-23.units/testsuite-23-namespaced.service @@ -7,7 +7,7 @@ Type=notify RemainAfterExit=yes MountAPIVFS=yes PrivateTmp=yes -BindPaths=/run/testservice-49-fixed:/tmp/testfile_fixed +BindPaths=/run/testsuite-23-marker-fixed:/tmp/testfile-marker-fixed InaccessiblePaths=/run/inaccessible -ExecStartPre=grep -q -F MARKER_FIXED /tmp/testfile_fixed -ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile_runtime; do sleep 0.1; done; test ! -f /run/inaccessible/testfile_fixed' +ExecStartPre=grep -q -F MARKER_FIXED /tmp/testfile-marker-fixed +ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; test ! -f /run/inaccessible/testfile-marker-fixed' diff --git a/test/units/testsuite-49-non-namespaced.service b/test/testsuite-23.units/testsuite-23-non-namespaced.service similarity index 62% rename from test/units/testsuite-49-non-namespaced.service rename to test/testsuite-23.units/testsuite-23-non-namespaced.service index db4e8d975fd..058ecb47695 100644 --- a/test/units/testsuite-49-non-namespaced.service +++ b/test/testsuite-23.units/testsuite-23-non-namespaced.service @@ -1,6 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Service] -RuntimeMaxSec=10 +RuntimeMaxSec=5 Type=notify RemainAfterExit=yes -ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile_runtime; do sleep 0.1; done; exit 0' +ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; exit 0' diff --git a/test/units/testsuite-23.runtime-bind-paths.sh b/test/units/testsuite-23.runtime-bind-paths.sh new file mode 100755 index 00000000000..c63586e1a2b --- /dev/null +++ b/test/units/testsuite-23.runtime-bind-paths.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +# shellcheck disable=SC2016 +set -eux +set -o pipefail + +# Test adding new BindPaths while unit is already running + +at_exit() { + set +e + + rm -f /run/testsuite-23-marker-{fixed,runtime} + rm -fr /run/inaccessible +} + +trap at_exit EXIT + +echo "MARKER_FIXED" >/run/testsuite-23-marker-fixed +mkdir /run/inaccessible + +systemctl start testsuite-23-namespaced.service + +# Ensure that inaccessible paths aren't bypassed by the runtime setup, +(! systemctl bind --mkdir testsuite-23-namespaced.service /run/testsuite-23-marker-fixed /run/inaccessible/testfile-marker-fixed) + +echo "MARKER_RUNTIME" >/run/testsuite-23-marker-runtime + +systemctl bind --mkdir testsuite-23-namespaced.service /run/testsuite-23-marker-runtime /tmp/testfile-marker-runtime + +timeout 10 sh -xec 'while [[ "$(systemctl show -P SubState testsuite-23-namespaced.service)" == running ]]; do sleep .5; done' +systemctl is-active testsuite-23-namespaced.service + +# Now test that systemctl bind fails when attempted on a non-namespaced unit +systemctl start testsuite-23-non-namespaced.service + +(! systemctl bind --mkdir testsuite-49-non-namespaced.service /run/testsuite-23-marker-runtime /tmp/testfile-marker-runtime) + +timeout 10 sh -xec 'while [[ "$(systemctl show -P SubState testsuite-23-non-namespaced.service)" == running ]]; do sleep .5; done' +(! systemctl is-active testsuite-23-non-namespaced.service) diff --git a/test/units/testsuite-49.service b/test/units/testsuite-49.service deleted file mode 100644 index bd4e15558f9..00000000000 --- a/test/units/testsuite-49.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-49-RUNTIME-BIND-PATHS - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-49.sh b/test/units/testsuite-49.sh deleted file mode 100755 index 1fa972552b3..00000000000 --- a/test/units/testsuite-49.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -eux - -echo "MARKER_FIXED" >/run/testservice-49-fixed -mkdir -p /run/inaccessible - -systemctl start testsuite-49-namespaced.service - -# Ensure that inaccessible paths aren't bypassed by the runtime setup -set +e -systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-fixed /run/inaccessible/testfile_fixed && exit 1 -set -e - -echo "MARKER_RUNTIME" >/run/testservice-49-runtime - -systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-runtime /tmp/testfile_runtime - -while systemctl show -P SubState testsuite-49-namespaced.service | grep -q running -do - sleep 0.1 -done - -systemctl is-active testsuite-49-namespaced.service - -# Now test that systemctl bind fails when attempted on a non-namespaced unit -systemctl start testsuite-49-non-namespaced.service - -set +e -systemctl bind --mkdir testsuite-49-non-namespaced.service /run/testservice-49-runtime /tmp/testfile_runtime && exit 1 -set -e - -while systemctl show -P SubState testsuite-49-non-namespaced.service | grep -q running -do - sleep 0.1 -done - -set +e -systemctl is-active testsuite-49-non-namespaced.service && exit 1 -set -e - -echo OK >/testok - -exit 0