ryantimwilson / rpms / systemd

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