richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
984f77
From e393372ad5ba67acb9b397f044efdb1c9a100644 Mon Sep 17 00:00:00 2001
984f77
From: Daan De Meyer <daan.j.demeyer@gmail.com>
984f77
Date: Tue, 24 Aug 2021 16:46:47 +0100
984f77
Subject: [PATCH] core: Check unit start rate limiting earlier
984f77
984f77
[dtardon: This adds the test that's been left out by commit
984f77
471eda89a25a3ceac91a2d05e39a54aae78038ed]
984f77
984f77
(cherry picked from commit 9727f2427ff6b2e1f4ab927cc57ad8e888f04e95)
984f77
984f77
Related: #2114005
984f77
---
984f77
 test/TEST-10-ISSUE-2467/test.sh            |  3 ++
984f77
 test/TEST-63-ISSUE-17433/Makefile          |  1 +
984f77
 test/TEST-63-ISSUE-17433/test.sh           | 42 ++++++++++++++++++++++
984f77
 test/TEST-63-ISSUE-17433/test63.path       |  2 ++
984f77
 test/TEST-63-ISSUE-17433/test63.service    |  5 +++
984f77
 test/TEST-63-ISSUE-17433/testsuite.service | 17 +++++++++
984f77
 6 files changed, 70 insertions(+)
984f77
 create mode 120000 test/TEST-63-ISSUE-17433/Makefile
984f77
 create mode 100755 test/TEST-63-ISSUE-17433/test.sh
984f77
 create mode 100644 test/TEST-63-ISSUE-17433/test63.path
984f77
 create mode 100644 test/TEST-63-ISSUE-17433/test63.service
984f77
 create mode 100644 test/TEST-63-ISSUE-17433/testsuite.service
984f77
984f77
diff --git a/test/TEST-10-ISSUE-2467/test.sh b/test/TEST-10-ISSUE-2467/test.sh
984f77
index 0e61236686..a839ef79de 100755
984f77
--- a/test/TEST-10-ISSUE-2467/test.sh
984f77
+++ b/test/TEST-10-ISSUE-2467/test.sh
984f77
@@ -42,6 +42,9 @@ EOF
984f77
 [Unit]
984f77
 Requires=test.socket
984f77
 ConditionPathExistsGlob=/tmp/nonexistent
984f77
+# Make sure we hit the socket trigger limit in the test and not the service start limit.
984f77
+StartLimitInterval=1000
984f77
+StartLimitBurst=1000
984f77
 
984f77
 [Service]
984f77
 ExecStart=/bin/true
984f77
diff --git a/test/TEST-63-ISSUE-17433/Makefile b/test/TEST-63-ISSUE-17433/Makefile
984f77
new file mode 120000
984f77
index 0000000000..e9f93b1104
984f77
--- /dev/null
984f77
+++ b/test/TEST-63-ISSUE-17433/Makefile
984f77
@@ -0,0 +1 @@
984f77
+../TEST-01-BASIC/Makefile
984f77
\ No newline at end of file
984f77
diff --git a/test/TEST-63-ISSUE-17433/test.sh b/test/TEST-63-ISSUE-17433/test.sh
984f77
new file mode 100755
984f77
index 0000000000..406a1e214c
984f77
--- /dev/null
984f77
+++ b/test/TEST-63-ISSUE-17433/test.sh
984f77
@@ -0,0 +1,42 @@
984f77
+#!/usr/bin/env bash
984f77
+set -e
984f77
+
984f77
+TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/17433"
984f77
+
984f77
+# shellcheck source=test/test-functions
984f77
+. "${TEST_BASE_DIR:?}/test-functions"
984f77
+
984f77
+test_setup() {
984f77
+    create_empty_image
984f77
+    mkdir -p $TESTDIR/root
984f77
+    mount ${LOOPDEV}p1 $TESTDIR/root
984f77
+
984f77
+    # Create what will eventually be our root filesystem onto an overlay
984f77
+    (
984f77
+        LOG_LEVEL=5
984f77
+        eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
984f77
+
984f77
+        setup_basic_environment
984f77
+
984f77
+        # setup the testsuite service
984f77
+        cp testsuite.service $initdir/etc/systemd/system/testsuite.service
984f77
+
984f77
+        cp test63.path $initdir/etc/systemd/system/test63.path
984f77
+        cp test63.service $initdir/etc/systemd/system/test63.service
984f77
+
984f77
+        setup_testsuite
984f77
+    ) || return 1
984f77
+    setup_nspawn_root
984f77
+
984f77
+    # mask some services that we do not want to run in these tests
984f77
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service
984f77
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service
984f77
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service
984f77
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
984f77
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service
984f77
+
984f77
+    ddebug "umount $TESTDIR/root"
984f77
+    umount $TESTDIR/root
984f77
+}
984f77
+
984f77
+do_test "$@"
984f77
diff --git a/test/TEST-63-ISSUE-17433/test63.path b/test/TEST-63-ISSUE-17433/test63.path
984f77
new file mode 100644
984f77
index 0000000000..a6573bda0a
984f77
--- /dev/null
984f77
+++ b/test/TEST-63-ISSUE-17433/test63.path
984f77
@@ -0,0 +1,2 @@
984f77
+[Path]
984f77
+PathExists=/tmp/test63
984f77
diff --git a/test/TEST-63-ISSUE-17433/test63.service b/test/TEST-63-ISSUE-17433/test63.service
984f77
new file mode 100644
984f77
index 0000000000..c83801874d
984f77
--- /dev/null
984f77
+++ b/test/TEST-63-ISSUE-17433/test63.service
984f77
@@ -0,0 +1,5 @@
984f77
+[Unit]
984f77
+ConditionPathExists=!/tmp/nonexistent
984f77
+
984f77
+[Service]
984f77
+ExecStart=true
984f77
diff --git a/test/TEST-63-ISSUE-17433/testsuite.service b/test/TEST-63-ISSUE-17433/testsuite.service
984f77
new file mode 100644
984f77
index 0000000000..d3ca5b002b
984f77
--- /dev/null
984f77
+++ b/test/TEST-63-ISSUE-17433/testsuite.service
984f77
@@ -0,0 +1,17 @@
984f77
+[Unit]
984f77
+Description=TEST-63-ISSUE-17433
984f77
+
984f77
+[Service]
984f77
+ExecStartPre=rm -f /failed /testok
984f77
+Type=oneshot
984f77
+ExecStart=rm -f /tmp/nonexistent
984f77
+ExecStart=systemctl start test63.path
984f77
+ExecStart=touch /tmp/test63
984f77
+# Make sure systemd has sufficient time to hit the start limit for test63.service.
984f77
+ExecStart=sleep 2
984f77
+ExecStart=sh -x -c 'test "$(systemctl show test63.service --value -p ActiveState)" = failed'
984f77
+ExecStart=sh -x -c 'test "$(systemctl show test63.service --value -p Result)" = start-limit-hit'
984f77
+# FIXME: The path remains active, which it should not
984f77
+# ExecStart=sh -x -c 'test "$(systemctl show test63.path --value -p ActiveState)" = failed'
984f77
+# ExecStart=sh -x -c 'test "$(systemctl show test63.path --value -p Result)" = unit-start-limit-hit'
984f77
+ExecStart=sh -x -c 'echo OK >/testok'