diff options
author | Luca Boccassi <bluca@debian.org> | 2022-02-09 11:50:19 +0000 |
---|---|---|
committer | Luca Boccassi <bluca@debian.org> | 2022-03-10 14:43:14 +0000 |
commit | c19c4ab14840e93ebd4d5650a16453daa7dd872d (patch) | |
tree | 80d773fbe2d8d7716260bbb56bc043fb981b25fd /test | |
parent | 95c81c55b2eb6063d79ad343738a6240bbccd100 (diff) | |
download | systemd-c19c4ab14840e93ebd4d5650a16453daa7dd872d.tar.gz |
test: cover template OnFailure/OnSuccess handlers in TEST-68-PROPAGATE-EXIT-STATUS
Diffstat (limited to 'test')
-rwxr-xr-x | test/units/testsuite-68.sh | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/test/units/testsuite-68.sh b/test/units/testsuite-68.sh index d9584e4539..aa02d66dcf 100755 --- a/test/units/testsuite-68.sh +++ b/test/units/testsuite-68.sh @@ -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 |