]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: cover template OnFailure/OnSuccess handlers in TEST-68-PROPAGATE-EXIT-STATUS
authorLuca Boccassi <bluca@debian.org>
Wed, 9 Feb 2022 11:50:19 +0000 (11:50 +0000)
committerLuca Boccassi <bluca@debian.org>
Thu, 10 Mar 2022 14:43:14 +0000 (14:43 +0000)
test/units/testsuite-68.sh

index d9584e4539bc507d0c105914767e2ccd03ac474b..aa02d66dcfadb2fd91f573026e4de1c62908aeed 100755 (executable)
@@ -36,6 +36,15 @@ OnFailure=testservice-failure-exit-handler-68.service
 ExecStart=/bin/bash -c "exit 1"
 EOF
 
+cat >/run/systemd/system/testservice-failure-68-template.service <<EOF
+[Unit]
+Description=TEST-68-PROPAGATE-EXIT-STATUS with OnFailure= trigger (template)
+OnFailure=testservice-failure-exit-handler-68-template@%n.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]
@@ -46,6 +55,15 @@ OnSuccess=testservice-success-exit-handler-68.service
 ExecStart=/bin/bash -c "exit 0"
 EOF
 
+cat >/run/systemd/system/testservice-success-68-template.service <<EOF
+[Unit]
+Description=TEST-68-PROPAGATE-EXIT-STATUS with OnSuccess= trigger (template)
+OnSuccess=testservice-success-exit-handler-68-template@%n.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.
 cat >/tmp/check_on_success.sh <<EOF
@@ -73,7 +91,7 @@ if [ -z "\$MONITOR_INVOCATION_ID" ]; then
     exit 1;
 fi
 
-if [[ "\$MONITOR_UNIT" != "testservice-success-68.service" && "\$MONITOR_UNIT" != "testservice-transient-success-68.service" ]]; then
+if [[ "\$MONITOR_UNIT" != "testservice-success-68.service" && "\$UNIT" != "testservice-success-68-template.service" && "\$MONITOR_UNIT" != "testservice-transient-success-68.service" ]]; then
     echo "MONITOR_UNIT was \"\$MONITOR_UNIT\", expected \"testservice-success-68{-transient}.service\"";
     exit 1;
 fi
@@ -92,6 +110,17 @@ ExecStartPre=/tmp/check_on_success.sh
 ExecStart=/tmp/check_on_success.sh
 EOF
 
+# Template version.
+cat >/run/systemd/system/testservice-success-exit-handler-68-template@.service <<EOF
+[Unit]
+Description=TEST-68-PROPAGATE-EXIT-STATUS handle service exiting in success (template)
+
+[Service]
+ExecStartPre=echo "triggered by %i"
+ExecStartPre=/tmp/check_on_success.sh
+ExecStart=/tmp/check_on_success.sh
+EOF
+
 # Script to check that when an OnFailure= dependency fires, the correct
 # MONITOR* env variables are passed.
 cat >/tmp/check_on_failure.sh <<EOF
@@ -119,7 +148,7 @@ if [ -z "\$MONITOR_INVOCATION_ID" ]; then
     exit 1;
 fi
 
-if [[ "\$MONITOR_UNIT" != "testservice-failure-68.service" && "\$MONITOR_UNIT" != "testservice-transient-failure-68.service" ]]; then
+if [[ "\$MONITOR_UNIT" != "testservice-failure-68.service" && "\$UNIT" != "testservice-failure-68-template.service" && "\$MONITOR_UNIT" != "testservice-transient-failure-68.service" ]]; then
     echo "MONITOR_UNIT was \"\$MONITOR_UNIT\", expected \"testservice-failure-68{-transient}.service\"";
     exit 1;
 fi
@@ -139,6 +168,17 @@ ExecStartPre=/tmp/check_on_failure.sh
 ExecStart=/tmp/check_on_failure.sh
 EOF
 
+# Template version.
+cat >/run/systemd/system/testservice-failure-exit-handler-68-template@.service <<EOF
+[Unit]
+Description=TEST-68-PROPAGATE-EXIT-STATUS handle service exiting in failure (template)
+
+[Service]
+ExecStartPre=echo "triggered by %i"
+ExecStartPre=/tmp/check_on_failure.sh
+ExecStart=/tmp/check_on_failure.sh
+EOF
+
 systemctl daemon-reload
 
 systemctl start testservice-failure-68.service
@@ -152,6 +192,12 @@ 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"
 
+# Test template handlers too
+systemctl start testservice-failure-68-template.service
+wait_on_state_or_fail "testservice-failure-exit-handler-68-template@testservice-failure-68-template.service.service" "inactive" "10"
+systemctl start testservice-success-68-template.service
+wait_on_state_or_fail "testservice-success-exit-handler-68-template@testservice-success-68-template.service.service" "inactive" "10"
+
 systemd-analyze log-level info
 echo OK >/testok