diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-09 13:08:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-09 13:08:38 +0000 |
commit | 9fe063bb3ef278a591e344caa78bee679536b7ee (patch) | |
tree | f589ace33354785090116341f7c702b6035b0868 /debian/tests/systemd-service-test.sh | |
parent | Adding upstream version 1.0.9. (diff) | |
download | nftables-9fe063bb3ef278a591e344caa78bee679536b7ee.tar.xz nftables-9fe063bb3ef278a591e344caa78bee679536b7ee.zip |
Adding debian version 1.0.9-1.debian/1.0.9-1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | debian/tests/systemd-service-test.sh | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/debian/tests/systemd-service-test.sh b/debian/tests/systemd-service-test.sh new file mode 100644 index 0000000..83461bc --- /dev/null +++ b/debian/tests/systemd-service-test.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +set -ex + +SERVICE=nftables.service + +# The testsuite requires kernel at least 5.x +if [ "$(uname -r | cut -d. -f1)" -lt 5 ] ; then + : WARNING this testsuite is likely to produce many fails because of old kernel, ending now + exit 0 +fi + +systemctl_call() +{ + if systemctl $1 $SERVICE ; then + return 0 + else + journalctl -u $SERVICE + return 1 + fi +} + +# package ships service disabled by default +if ! systemctl_call enable ; then + : WARNING enabling the service failed +fi + +if systemctl -q is-active $SERVICE ; then + : WARNING initial service running, stopping now + if ! systemctl_call stop ; then + : ERROR unable to stop the initial service + exit 1 + fi +fi + +if [ $(nft list ruleset | wc -l) -ne 0 ] ; then + : WARNING initial ruleset is not empty, flushing now + nft flush ruleset +fi + +if ! systemctl_call start ; then + : ERROR failed to start systemd service + exit 1 +fi +if [ $(nft list ruleset | wc -l) -eq 0 ] ; then + : ERROR no ruleset loaded after systemd service start + exit 1 +fi + +systemctl_call status +nft list ruleset + +if ! systemctl_call stop ; then + : ERROR failed to stop systemd service + exit 1 +fi +if [ $(nft list ruleset | wc -l) -ne 0 ] ; then + : ERROR ruleset still loaded after systemd service stop + exit 1 +fi + +if ! systemctl_call restart ; then + : ERROR failed to restart systemd service + exit 1 +fi +if [ $(nft list ruleset | wc -l) -eq 0 ] ; then + : ERROR no ruleset loaded after systemd service restart + exit 1 +fi + +: INFO test was OK +exit 0 |