From 23acbd2f4b0079d1fab01a7dad135e3451efd6d7 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 17 Jul 2015 21:32:01 +1000 Subject: [PATCH] ctdb-tests: Add tests for filesystem usage monitoring Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- .../eventscripts/05.system.monitor.001.sh | 10 +++++++ .../eventscripts/05.system.monitor.002.sh | 10 +++++++ .../eventscripts/05.system.monitor.003.sh | 12 +++++++++ .../eventscripts/05.system.monitor.004.sh | 10 +++++++ .../eventscripts/05.system.monitor.005.sh | 12 +++++++++ .../eventscripts/05.system.monitor.006.sh | 12 +++++++++ .../eventscripts/05.system.monitor.007.sh | 10 +++++++ ctdb/tests/eventscripts/scripts/local.sh | 19 +++++++++++++ ctdb/tests/eventscripts/stubs/df | 27 +++++++++++++++++++ 9 files changed, 122 insertions(+) create mode 100755 ctdb/tests/eventscripts/05.system.monitor.001.sh create mode 100755 ctdb/tests/eventscripts/05.system.monitor.002.sh create mode 100755 ctdb/tests/eventscripts/05.system.monitor.003.sh create mode 100755 ctdb/tests/eventscripts/05.system.monitor.004.sh create mode 100755 ctdb/tests/eventscripts/05.system.monitor.005.sh create mode 100755 ctdb/tests/eventscripts/05.system.monitor.006.sh create mode 100755 ctdb/tests/eventscripts/05.system.monitor.007.sh create mode 100755 ctdb/tests/eventscripts/stubs/df diff --git a/ctdb/tests/eventscripts/05.system.monitor.001.sh b/ctdb/tests/eventscripts/05.system.monitor.001.sh new file mode 100755 index 00000000000..72262c19f14 --- /dev/null +++ b/ctdb/tests/eventscripts/05.system.monitor.001.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "Filesystem use check, error situation, no checks enabled" + +CTDB_MONITOR_FILESYSTEM_USAGE="" +setup_fscheck 100 +ok_null +simple_test diff --git a/ctdb/tests/eventscripts/05.system.monitor.002.sh b/ctdb/tests/eventscripts/05.system.monitor.002.sh new file mode 100755 index 00000000000..22b479cc947 --- /dev/null +++ b/ctdb/tests/eventscripts/05.system.monitor.002.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "Filesystem use check, good situation, 1 error check enabled" + +CTDB_MONITOR_FILESYSTEM_USAGE="/var::80" +setup_fscheck +ok_null +simple_test diff --git a/ctdb/tests/eventscripts/05.system.monitor.003.sh b/ctdb/tests/eventscripts/05.system.monitor.003.sh new file mode 100755 index 00000000000..3a0ad1aa387 --- /dev/null +++ b/ctdb/tests/eventscripts/05.system.monitor.003.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "Filesystem use check, error situation, 1 error check enabled" + +CTDB_MONITOR_FILESYSTEM_USAGE="/var::80" +setup_fscheck 90 +required_result 1 <= threshold 80% +EOF +simple_test diff --git a/ctdb/tests/eventscripts/05.system.monitor.004.sh b/ctdb/tests/eventscripts/05.system.monitor.004.sh new file mode 100755 index 00000000000..4ffd9d668ff --- /dev/null +++ b/ctdb/tests/eventscripts/05.system.monitor.004.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "Filesystem use check, warn situation, only error check enabled" + +CTDB_MONITOR_FILESYSTEM_USAGE="/var::80" +setup_fscheck 70 +ok_null +simple_test diff --git a/ctdb/tests/eventscripts/05.system.monitor.005.sh b/ctdb/tests/eventscripts/05.system.monitor.005.sh new file mode 100755 index 00000000000..98ac8abe8f5 --- /dev/null +++ b/ctdb/tests/eventscripts/05.system.monitor.005.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "Filesystem use check, warn situation, both checks enabled" + +CTDB_MONITOR_FILESYSTEM_USAGE="/var:80:90" +setup_fscheck 85 +ok <= threshold 80% +EOF +simple_test diff --git a/ctdb/tests/eventscripts/05.system.monitor.006.sh b/ctdb/tests/eventscripts/05.system.monitor.006.sh new file mode 100755 index 00000000000..830cfdf42e0 --- /dev/null +++ b/ctdb/tests/eventscripts/05.system.monitor.006.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "Filesystem use check, error situation, both checks enabled" + +CTDB_MONITOR_FILESYSTEM_USAGE="/var:80:90" +setup_fscheck 95 +required_result 1 <= threshold 90% +EOF +simple_test diff --git a/ctdb/tests/eventscripts/05.system.monitor.007.sh b/ctdb/tests/eventscripts/05.system.monitor.007.sh new file mode 100755 index 00000000000..d2a301e615b --- /dev/null +++ b/ctdb/tests/eventscripts/05.system.monitor.007.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "Filesystem use check, good situation, both checks enabled, multiple filesystems" + +CTDB_MONITOR_FILESYSTEM_USAGE="/var:80:90 /:90:95" +setup_fscheck +ok_null +simple_test diff --git a/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh index e65ad6f252b..d12713b56ec 100644 --- a/ctdb/tests/eventscripts/scripts/local.sh +++ b/ctdb/tests/eventscripts/scripts/local.sh @@ -327,6 +327,15 @@ setup_config () cat >"$FAKE_CTDB_EXTRA_CONFIG" } +validate_percentage () +{ + case "$1" in + [0-9]|[0-9][0-9]|100) return 0 ;; + *) echo "WARNING: ${1} is an invalid percentage${2:+\" in }${2}${2:+\"}" + return 1 + esac +} + setup_memcheck () { setup_ctdb @@ -372,6 +381,16 @@ Swap: 5719 246 5473" export CTDB_CHECK_SWAP_IS_NOT_USED } +setup_fscheck () +{ + export FAKE_FS_USE="${1:-10}" # Default is 10% usage + + # Causes some variables to be exported + setup_ctdb + + export CTDB_MONITOR_FILESYSTEM_USAGE +} + ctdb_get_interfaces () { # The echo/subshell forces all the output onto 1 line. diff --git a/ctdb/tests/eventscripts/stubs/df b/ctdb/tests/eventscripts/stubs/df new file mode 100755 index 00000000000..c74288f1489 --- /dev/null +++ b/ctdb/tests/eventscripts/stubs/df @@ -0,0 +1,27 @@ +#!/bin/sh + +usage () +{ + echo "usage: df -kP " + exit 1 +} + +if [ "$1" != "-kP" ] ; then + usage +fi + +shift +if [ -z "$1" ] ; then + usage +fi + +fs="$1" + +echo "Filesystem 1024-blocks Used Available Capacity Mounted on" + +blocks="1000000" +used=$(($blocks * $FAKE_FS_USE / 100)) +available=$(($blocks - $used)) + +printf "%-36s %10d %10d %10d %10d%% %s\n" \ + "/dev/sda1" "$blocks" "$used" "$available" "$FAKE_FS_USE" "$fs"