|
|
2aacef |
From 55e11475d421f90cc5c7290c6b5d394f952ba577 Mon Sep 17 00:00:00 2001
|
|
|
2aacef |
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
|
2aacef |
Date: Tue, 15 Nov 2022 21:52:10 +0900
|
|
|
2aacef |
Subject: [PATCH] test: add test case for sysv-generator and invalid dependency
|
|
|
2aacef |
|
|
|
2aacef |
(cherry picked from commit 5f882cc3ab32636d9242effb2cefad20d92d2ec2)
|
|
|
2aacef |
|
|
|
2aacef |
Related: #2160477
|
|
|
2aacef |
---
|
|
|
2aacef |
test/units/testsuite-26.sh | 116 ++++++++++++++++++++++++++++++++++++-
|
|
|
2aacef |
1 file changed, 114 insertions(+), 2 deletions(-)
|
|
|
2aacef |
|
|
|
2aacef |
diff --git a/test/units/testsuite-26.sh b/test/units/testsuite-26.sh
|
|
|
2aacef |
index 7c7a12b1ae..a8e7a5abaa 100755
|
|
|
2aacef |
--- a/test/units/testsuite-26.sh
|
|
|
2aacef |
+++ b/test/units/testsuite-26.sh
|
|
|
2aacef |
@@ -3,10 +3,18 @@
|
|
|
2aacef |
set -eux
|
|
|
2aacef |
set -o pipefail
|
|
|
2aacef |
|
|
|
2aacef |
+# shellcheck source=test/units/assert.sh
|
|
|
2aacef |
+. "$(dirname "$0")"/assert.sh
|
|
|
2aacef |
+
|
|
|
2aacef |
+: >/failed
|
|
|
2aacef |
+
|
|
|
2aacef |
at_exit() {
|
|
|
2aacef |
if [[ -v UNIT_NAME && -e "/usr/lib/systemd/system/$UNIT_NAME" ]]; then
|
|
|
2aacef |
rm -fv "/usr/lib/systemd/system/$UNIT_NAME"
|
|
|
2aacef |
fi
|
|
|
2aacef |
+
|
|
|
2aacef |
+ rm -f /etc/init.d/issue-24990
|
|
|
2aacef |
+ return 0
|
|
|
2aacef |
}
|
|
|
2aacef |
|
|
|
2aacef |
trap at_exit EXIT
|
|
|
2aacef |
@@ -284,6 +292,110 @@ systemctl unset-environment IMPORT_THIS IMPORT_THIS_TOO
|
|
|
2aacef |
(! systemctl show-environment | grep "^IMPORT_THIS=")
|
|
|
2aacef |
(! systemctl show-environment | grep "^IMPORT_THIS_TOO=")
|
|
|
2aacef |
|
|
|
2aacef |
-echo OK >/testok
|
|
|
2aacef |
+# test for sysv-generator (issue #24990)
|
|
|
2aacef |
+if [[ -x /usr/lib/systemd/system-generators/systemd-sysv-generator ]]; then
|
|
|
2aacef |
+
|
|
|
2aacef |
+ # invalid dependency
|
|
|
2aacef |
+ cat >/etc/init.d/issue-24990 <<\EOF
|
|
|
2aacef |
+#!/bin/bash
|
|
|
2aacef |
+
|
|
|
2aacef |
+### BEGIN INIT INFO
|
|
|
2aacef |
+# Provides:test1 test2
|
|
|
2aacef |
+# Required-Start:test1 $remote_fs $network
|
|
|
2aacef |
+# Required-Stop:test1 $remote_fs $network
|
|
|
2aacef |
+# Description:Test
|
|
|
2aacef |
+# Short-Description: Test
|
|
|
2aacef |
+### END INIT INFO
|
|
|
2aacef |
+
|
|
|
2aacef |
+case "$1" in
|
|
|
2aacef |
+ start)
|
|
|
2aacef |
+ echo "Starting issue-24990.service"
|
|
|
2aacef |
+ sleep 1000 &
|
|
|
2aacef |
+ ;;
|
|
|
2aacef |
+ stop)
|
|
|
2aacef |
+ echo "Stopping issue-24990.service"
|
|
|
2aacef |
+ sleep 10 &
|
|
|
2aacef |
+ ;;
|
|
|
2aacef |
+ *)
|
|
|
2aacef |
+ echo "Usage: service test {start|stop|restart|status}"
|
|
|
2aacef |
+ ;;
|
|
|
2aacef |
+esac
|
|
|
2aacef |
+EOF
|
|
|
2aacef |
+
|
|
|
2aacef |
+ chmod +x /etc/init.d/issue-24990
|
|
|
2aacef |
+ systemctl daemon-reload
|
|
|
2aacef |
+ [[ -L /run/systemd/generator.late/test1.service ]]
|
|
|
2aacef |
+ [[ -L /run/systemd/generator.late/test2.service ]]
|
|
|
2aacef |
+ assert_eq "$(readlink -f /run/systemd/generator.late/test1.service)" "/run/systemd/generator.late/issue-24990.service"
|
|
|
2aacef |
+ assert_eq "$(readlink -f /run/systemd/generator.late/test2.service)" "/run/systemd/generator.late/issue-24990.service"
|
|
|
2aacef |
+ output=$(systemctl cat issue-24990)
|
|
|
2aacef |
+ assert_in "SourcePath=/etc/init.d/issue-24990" "$output"
|
|
|
2aacef |
+ assert_in "Description=LSB: Test" "$output"
|
|
|
2aacef |
+ assert_in "After=test1.service" "$output"
|
|
|
2aacef |
+ assert_in "After=remote-fs.target" "$output"
|
|
|
2aacef |
+ assert_in "After=network-online.target" "$output"
|
|
|
2aacef |
+ assert_in "Wants=network-online.target" "$output"
|
|
|
2aacef |
+ assert_in "ExecStart=/etc/init.d/issue-24990 start" "$output"
|
|
|
2aacef |
+ assert_in "ExecStop=/etc/init.d/issue-24990 stop" "$output"
|
|
|
2aacef |
+ systemctl status issue-24990 || :
|
|
|
2aacef |
+ systemctl show issue-24990
|
|
|
2aacef |
+ assert_not_in "issue-24990.service" "$(systemctl show --property=After --value)"
|
|
|
2aacef |
+ assert_not_in "issue-24990.service" "$(systemctl show --property=Before --value)"
|
|
|
2aacef |
+
|
|
|
2aacef |
+ if ! systemctl is-active network-online.target; then
|
|
|
2aacef |
+ systemctl start network-online.target
|
|
|
2aacef |
+ fi
|
|
|
2aacef |
+
|
|
|
2aacef |
+ systemctl restart issue-24990
|
|
|
2aacef |
+ systemctl stop issue-24990
|
|
|
2aacef |
+
|
|
|
2aacef |
+ # valid dependency
|
|
|
2aacef |
+ cat >/etc/init.d/issue-24990 <<\EOF
|
|
|
2aacef |
+#!/bin/bash
|
|
|
2aacef |
+
|
|
|
2aacef |
+### BEGIN INIT INFO
|
|
|
2aacef |
+# Provides:test1 test2
|
|
|
2aacef |
+# Required-Start:$remote_fs
|
|
|
2aacef |
+# Required-Stop:$remote_fs
|
|
|
2aacef |
+# Description:Test
|
|
|
2aacef |
+# Short-Description: Test
|
|
|
2aacef |
+### END INIT INFO
|
|
|
2aacef |
+
|
|
|
2aacef |
+case "$1" in
|
|
|
2aacef |
+ start)
|
|
|
2aacef |
+ echo "Starting issue-24990.service"
|
|
|
2aacef |
+ sleep 1000 &
|
|
|
2aacef |
+ ;;
|
|
|
2aacef |
+ stop)
|
|
|
2aacef |
+ echo "Stopping issue-24990.service"
|
|
|
2aacef |
+ sleep 10 &
|
|
|
2aacef |
+ ;;
|
|
|
2aacef |
+ *)
|
|
|
2aacef |
+ echo "Usage: service test {start|stop|restart|status}"
|
|
|
2aacef |
+ ;;
|
|
|
2aacef |
+esac
|
|
|
2aacef |
+EOF
|
|
|
2aacef |
+
|
|
|
2aacef |
+ chmod +x /etc/init.d/issue-24990
|
|
|
2aacef |
+ systemctl daemon-reload
|
|
|
2aacef |
+ [[ -L /run/systemd/generator.late/test1.service ]]
|
|
|
2aacef |
+ [[ -L /run/systemd/generator.late/test2.service ]]
|
|
|
2aacef |
+ assert_eq "$(readlink -f /run/systemd/generator.late/test1.service)" "/run/systemd/generator.late/issue-24990.service"
|
|
|
2aacef |
+ assert_eq "$(readlink -f /run/systemd/generator.late/test2.service)" "/run/systemd/generator.late/issue-24990.service"
|
|
|
2aacef |
+ output=$(systemctl cat issue-24990)
|
|
|
2aacef |
+ assert_in "SourcePath=/etc/init.d/issue-24990" "$output"
|
|
|
2aacef |
+ assert_in "Description=LSB: Test" "$output"
|
|
|
2aacef |
+ assert_in "After=remote-fs.target" "$output"
|
|
|
2aacef |
+ assert_in "ExecStart=/etc/init.d/issue-24990 start" "$output"
|
|
|
2aacef |
+ assert_in "ExecStop=/etc/init.d/issue-24990 stop" "$output"
|
|
|
2aacef |
+ systemctl status issue-24990 || :
|
|
|
2aacef |
+ systemctl show issue-24990
|
|
|
2aacef |
+ assert_not_in "issue-24990.service" "$(systemctl show --property=After --value)"
|
|
|
2aacef |
+ assert_not_in "issue-24990.service" "$(systemctl show --property=Before --value)"
|
|
|
2aacef |
+
|
|
|
2aacef |
+ systemctl restart issue-24990
|
|
|
2aacef |
+ systemctl stop issue-24990
|
|
|
2aacef |
+fi
|
|
|
2aacef |
|
|
|
2aacef |
-exit 0
|
|
|
2aacef |
+touch /testok
|
|
|
2aacef |
+rm /failed
|