summaryrefslogtreecommitdiff
path: root/test/units
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2022-02-09 11:48:30 +0000
committerLuca Boccassi <bluca@debian.org>2022-03-10 14:43:14 +0000
commit95c81c55b2eb6063d79ad343738a6240bbccd100 (patch)
tree36d16e4ba22f12c9e8e85f6773c8f53823623ecc /test/units
parentbd844eae233b74ebf151ceefa0a5f026978bebab (diff)
downloadsystemd-95c81c55b2eb6063d79ad343738a6240bbccd100.tar.gz
core: split $MONITOR_METADATA and return it only if a single unit triggers OnFailure/OnSuccess
Remove the list logic, and simply skip passing metadata if more than one unit triggered an OnFailure/OnSuccess handler. Instead of a single env var to loop over, provide each separate item as its own variable. Fixes https://github.com/systemd/systemd/issues/22370
Diffstat (limited to 'test/units')
-rwxr-xr-xtest/units/testsuite-68.sh176
1 files changed, 52 insertions, 124 deletions
diff --git a/test/units/testsuite-68.sh b/test/units/testsuite-68.sh
index 15e2e0353f..d9584e4539 100755
--- a/test/units/testsuite-68.sh
+++ b/test/units/testsuite-68.sh
@@ -36,16 +36,6 @@ OnFailure=testservice-failure-exit-handler-68.service
ExecStart=/bin/bash -c "exit 1"
EOF
-# Another service which triggers testservice-failure-exit-handler-68.service
-cat >/run/systemd/system/testservice-failure-68-additional.service <<EOF
-[Unit]
-Description=TEST-68-PROPAGATE-EXIT-STATUS Additional service with OnFailure= trigger
-OnFailure=testservice-failure-exit-handler-68.service
-
-[Service]
-ExecStart=/bin/bash -c "exit 1"
-EOF
-
# Trigger testservice-success-exit-handler-68.service
cat >/run/systemd/system/testservice-success-68.service <<EOF
[Unit]
@@ -56,67 +46,37 @@ OnSuccess=testservice-success-exit-handler-68.service
ExecStart=/bin/bash -c "exit 0"
EOF
-# Trigger testservice-success-exit-handler-68.service
-cat >/run/systemd/system/testservice-success-68-additional.service <<EOF
-[Unit]
-Description=TEST-68-PROPAGATE-EXIT-STATUS Addition service with OnSuccess= trigger
-OnSuccess=testservice-success-exit-handler-68.service
-
-[Service]
-ExecStart=/bin/bash -c "exit 0"
-EOF
-
# Script to check that when an OnSuccess= dependency fires, the correct
-# MONITOR* env variables are passed. This script handles the case where
-# multiple services triggered the unit that calls this script. In this
-# case we need to check the MONITOR_METADATA variable for >= 1 service
-# details since jobs may merge.
+# MONITOR* env variables are passed.
cat >/tmp/check_on_success.sh <<EOF
#!/usr/bin/env bash
set -ex
-
-echo "MONITOR_METADATA=\$MONITOR_METADATA"
-
-IFS=';' read -ra ALL_SERVICE_MD <<< "\$MONITOR_METADATA"
-for SERVICE_MD in "\${ALL_SERVICE_MD[@]}"; do
- IFS=',' read -ra METADATA <<< "\$SERVICE_MD"
- IFS='=' read -ra SERVICE_RESULT <<< "\${METADATA[0]}"
- SERVICE_RESULT=\${SERVICE_RESULT[1]}
- IFS='=' read -ra EXIT_CODE <<< "\${METADATA[1]}"
- EXIT_CODE=\${EXIT_CODE[1]}
- IFS='=' read -ra EXIT_STATUS <<< "\${METADATA[2]}"
- EXIT_STATUS=\${EXIT_STATUS[1]}
- IFS='=' read -ra INVOCATION_ID <<< "\${METADATA[3]}"
- INVOCATION_ID=\${INVOCATION_ID[1]}
- IFS='=' read -ra UNIT <<< "\${METADATA[4]}"
- UNIT=\${UNIT[1]}
-
- if [ "\$SERVICE_RESULT" != "success" ]; then
- echo 'SERVICE_RESULT was "\$SERVICE_RESULT", expected "success"';
- exit 1;
- fi
-
- if [ "\$EXIT_CODE" != "exited" ]; then
- echo 'EXIT_CODE was "\$EXIT_CODE", expected "exited"';
- exit 1;
- fi
-
- if [ "\$EXIT_STATUS" != "0" ]; then
- echo 'EXIT_STATUS was "\$EXIT_STATUS", expected "0"';
- exit 1;
- fi
-
- if [ -z "\$INVOCATION_ID" ]; then
- echo 'INVOCATION_ID unset';
- exit 1;
- fi
-
- if [[ "\$UNIT" != "testservice-success-68.service" && "\$UNIT" != "testservice-success-68-additional.service" && "\$UNIT" != "testservice-transient-success-68.service" ]]; then
- echo 'UNIT was "\$UNIT", expected "testservice-success-68{-additional,-transient}.service"';
- exit 1;
- fi
-done
+env
+if [ "\$MONITOR_SERVICE_RESULT" != "success" ]; then
+ echo "MONITOR_SERVICE_RESULT was \"\$MONITOR_SERVICE_RESULT\", expected \"success\"";
+ exit 1;
+fi
+
+if [ "\$MONITOR_EXIT_CODE" != "exited" ]; then
+ echo "MONITOR_EXIT_CODE was \"\$MONITOR_EXIT_CODE\", expected \"exited\"";
+ exit 1;
+fi
+
+if [ "\$MONITOR_EXIT_STATUS" != "0" ]; then
+ echo "MONITOR_EXIT_STATUS was \"\$MONITOR_EXIT_STATUS\", expected \"0\"";
+ exit 1;
+fi
+
+if [ -z "\$MONITOR_INVOCATION_ID" ]; then
+ echo "MONITOR_INVOCATION_ID unset";
+ exit 1;
+fi
+
+if [[ "\$MONITOR_UNIT" != "testservice-success-68.service" && "\$MONITOR_UNIT" != "testservice-transient-success-68.service" ]]; then
+ echo "MONITOR_UNIT was \"\$MONITOR_UNIT\", expected \"testservice-success-68{-transient}.service\"";
+ exit 1;
+fi
exit 0;
EOF
@@ -133,56 +93,36 @@ ExecStart=/tmp/check_on_success.sh
EOF
# Script to check that when an OnFailure= dependency fires, the correct
-# MONITOR* env variables are passed. This script handles the case where
-# multiple services triggered the unit that calls this script. In this
-# case we need to check the MONITOR_METADATA variable for >=1 service
-# details since jobs may merge.
+# MONITOR* env variables are passed.
cat >/tmp/check_on_failure.sh <<EOF
#!/usr/bin/env bash
set -ex
-
-echo "MONITOR_METADATA=\$MONITOR_METADATA"
-
-IFS=';' read -ra ALL_SERVICE_MD <<< "\$MONITOR_METADATA"
-for SERVICE_MD in "\${ALL_SERVICE_MD[@]}"; do
- IFS=',' read -ra METADATA <<< "\$SERVICE_MD"
- IFS='=' read -ra SERVICE_RESULT <<< "\${METADATA[0]}"
- SERVICE_RESULT=\${SERVICE_RESULT[1]}
- IFS='=' read -ra EXIT_CODE <<< "\${METADATA[1]}"
- EXIT_CODE=\${EXIT_CODE[1]}
- IFS='=' read -ra EXIT_STATUS <<< "\${METADATA[2]}"
- EXIT_STATUS=\${EXIT_STATUS[1]}
- IFS='=' read -ra INVOCATION_ID <<< "\${METADATA[3]}"
- INVOCATION_ID=\${INVOCATION_ID[1]}
- IFS='=' read -ra UNIT <<< "\${METADATA[4]}"
- UNIT=\${UNIT[1]}
-
- if [ "\$SERVICE_RESULT" != "exit-code" ]; then
- echo 'SERVICE_RESULT was "\$SERVICE_RESULT", expected "exit-code"';
- exit 1;
- fi
-
- if [ "\$EXIT_CODE" != "exited" ]; then
- echo 'EXIT_CODE was "\$EXIT_CODE", expected "exited"';
- exit 1;
- fi
-
- if [ "\$EXIT_STATUS" != "1" ]; then
- echo 'EXIT_STATUS was "\$EXIT_STATUS", expected "1"';
- exit 1;
- fi
-
- if [ -z "\$INVOCATION_ID" ]; then
- echo 'INVOCATION_ID unset';
- exit 1;
- fi
-
- if [[ "\$UNIT" != "testservice-failure-68.service" && "\$UNIT" != "testservice-failure-68-additional.service" && "\$UNIT" != "testservice-transient-failure-68.service" ]]; then
- echo 'UNIT was "\$UNIT", expected "testservice-failure-68{-additional,-transient}.service"';
- exit 1;
- fi
-done
+env
+if [ "\$MONITOR_SERVICE_RESULT" != "exit-code" ]; then
+ echo "MONITOR_SERVICE_RESULT was \"\$MONITOR_SERVICE_RESULT\", expected \"exit-code\"";
+ exit 1;
+fi
+
+if [ "\$MONITOR_EXIT_CODE" != "exited" ]; then
+ echo "MONITOR_EXIT_CODE was \"\$MONITOR_EXIT_CODE\", expected \"exited\"";
+ exit 1;
+fi
+
+if [ "\$MONITOR_EXIT_STATUS" != "1" ]; then
+ echo "MONITOR_EXIT_STATUS was \"\$MONITOR_EXIT_STATUS\", expected \"1\"";
+ exit 1;
+fi
+
+if [ -z "\$MONITOR_INVOCATION_ID" ]; then
+ echo "MONITOR_INVOCATION_ID unset";
+ exit 1;
+fi
+
+if [[ "\$MONITOR_UNIT" != "testservice-failure-68.service" && "\$MONITOR_UNIT" != "testservice-transient-failure-68.service" ]]; then
+ echo "MONITOR_UNIT was \"\$MONITOR_UNIT\", expected \"testservice-failure-68{-transient}.service\"";
+ exit 1;
+fi
exit 0;
EOF
@@ -201,16 +141,10 @@ EOF
systemctl daemon-reload
-# The running of the OnFailure= and OnSuccess= jobs for all of these services
-# may result in jobs being merged.
systemctl start testservice-failure-68.service
wait_on_state_or_fail "testservice-failure-exit-handler-68.service" "inactive" "10"
-systemctl start testservice-failure-68-additional.service
-wait_on_state_or_fail "testservice-failure-exit-handler-68.service" "inactive" "10"
systemctl start testservice-success-68.service
wait_on_state_or_fail "testservice-success-exit-handler-68.service" "inactive" "10"
-systemctl start testservice-success-68-additional.service
-wait_on_state_or_fail "testservice-success-exit-handler-68.service" "inactive" "10"
# Test some transient units since these exit very quickly.
systemd-run --unit=testservice-transient-success-68 --property=OnSuccess=testservice-success-exit-handler-68.service /bin/bash -c "exit 0;"
@@ -218,12 +152,6 @@ wait_on_state_or_fail "testservice-success-exit-handler-68.service" "inactive" "
systemd-run --unit=testservice-transient-failure-68 --property=OnFailure=testservice-failure-exit-handler-68.service /bin/bash -c "exit 1;"
wait_on_state_or_fail "testservice-failure-exit-handler-68.service" "inactive" "10"
-# These yield a higher chance of resulting in jobs merging.
-systemctl start testservice-failure-68.service testservice-failure-68-additional.service --no-block
-wait_on_state_or_fail "testservice-failure-exit-handler-68.service" "inactive" "10"
-systemctl start testservice-success-68.service testservice-success-68-additional.service --no-block
-wait_on_state_or_fail "testservice-success-exit-handler-68.service" "inactive" "10"
-
systemd-analyze log-level info
echo OK >/testok