1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00

ctdb-tests: Add tests for filesystem usage monitoring

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2015-07-17 21:32:01 +10:00 committed by Amitay Isaacs
parent fa1050690b
commit 23acbd2f4b
9 changed files with 122 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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 <<EOF
ERROR: Filesystem /var utilization 90% >= threshold 80%
EOF
simple_test

View File

@ -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

View File

@ -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 <<EOF
WARNING: Filesystem /var utilization 85% >= threshold 80%
EOF
simple_test

View File

@ -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 <<EOF
ERROR: Filesystem /var utilization 95% >= threshold 90%
EOF
simple_test

View File

@ -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

View File

@ -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.

View File

@ -0,0 +1,27 @@
#!/bin/sh
usage ()
{
echo "usage: df -kP <mount-point>"
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"