mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
ctdb-tests: Add unit tests for LVS eventscript
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
89dc86e0fd
commit
5fc9ca91d7
55
ctdb/tests/eventscripts/91.lvs.001.sh
Executable file
55
ctdb/tests/eventscripts/91.lvs.001.sh
Executable file
@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "sanity check ipvsadm stub"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_lvs<<EOF
|
||||
EOF
|
||||
|
||||
check_ipvsadm NULL
|
||||
|
||||
ipvsadm -A -u 10.1.1.201 -s lc -p 1999999
|
||||
ipvsadm -a -u 10.1.1.201 -r 192.168.1.3 -g
|
||||
ipvsadm -a -u 10.1.1.201 -r 192.168.1.1 -g
|
||||
ipvsadm -a -u 10.1.1.201 -r 192.168.1.2:0 -g
|
||||
ipvsadm -a -u 10.1.1.201 -r 127.0.0.1
|
||||
|
||||
check_ipvsadm <<EOF
|
||||
UDP 10.1.1.201:0 lc persistent 1999999
|
||||
-> 127.0.0.1:0 Local 1 0 0
|
||||
-> 192.168.1.1:0 Route 1 0 0
|
||||
-> 192.168.1.2:0 Route 1 0 0
|
||||
-> 192.168.1.3:0 Route 1 0 0
|
||||
EOF
|
||||
|
||||
ipvsadm -A -t 10.1.1.201 -s lc -p 1999999
|
||||
ipvsadm -a -t 10.1.1.201 -r 192.168.1.3 -g
|
||||
ipvsadm -a -t 10.1.1.201 -r 192.168.1.1 -g
|
||||
ipvsadm -a -t 10.1.1.201 -r 192.168.1.2:0 -g
|
||||
|
||||
check_ipvsadm <<EOF
|
||||
TCP 10.1.1.201:0 lc persistent 1999999
|
||||
-> 192.168.1.1:0 Route 1 0 0
|
||||
-> 192.168.1.2:0 Route 1 0 0
|
||||
-> 192.168.1.3:0 Route 1 0 0
|
||||
UDP 10.1.1.201:0 lc persistent 1999999
|
||||
-> 127.0.0.1:0 Local 1 0 0
|
||||
-> 192.168.1.1:0 Route 1 0 0
|
||||
-> 192.168.1.2:0 Route 1 0 0
|
||||
-> 192.168.1.3:0 Route 1 0 0
|
||||
EOF
|
||||
|
||||
ipvsadm -D -u 10.1.1.201
|
||||
|
||||
check_ipvsadm <<EOF
|
||||
TCP 10.1.1.201:0 lc persistent 1999999
|
||||
-> 192.168.1.1:0 Route 1 0 0
|
||||
-> 192.168.1.2:0 Route 1 0 0
|
||||
-> 192.168.1.3:0 Route 1 0 0
|
||||
EOF
|
||||
|
||||
ipvsadm -D -t 10.1.1.201
|
||||
|
||||
check_ipvsadm NULL
|
15
ctdb/tests/eventscripts/91.lvs.ipreallocated.011.sh
Executable file
15
ctdb/tests/eventscripts/91.lvs.ipreallocated.011.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "configured, no nodes in config"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_lvs "10.1.1.201" "eth0" <<EOF
|
||||
EOF
|
||||
|
||||
ok_null
|
||||
simple_test
|
||||
|
||||
check_ipvsadm NULL
|
||||
check_lvs_ip host
|
18
ctdb/tests/eventscripts/91.lvs.ipreallocated.012.sh
Executable file
18
ctdb/tests/eventscripts/91.lvs.ipreallocated.012.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "nodes in config, no master (e.g. all inactive)"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_lvs "10.1.1.201" "eth0" <<EOF
|
||||
192.168.1.1
|
||||
192.168.1.2
|
||||
192.168.1.3
|
||||
EOF
|
||||
|
||||
ok_null
|
||||
simple_test
|
||||
|
||||
check_ipvsadm NULL
|
||||
check_lvs_ip host
|
18
ctdb/tests/eventscripts/91.lvs.ipreallocated.013.sh
Executable file
18
ctdb/tests/eventscripts/91.lvs.ipreallocated.013.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "nodes in config, other node is master"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_lvs "10.1.1.201" "eth0" <<EOF
|
||||
192.168.1.1
|
||||
192.168.1.2 master
|
||||
192.168.1.3
|
||||
EOF
|
||||
|
||||
ok_null
|
||||
simple_test
|
||||
|
||||
check_ipvsadm NULL
|
||||
check_lvs_ip host
|
28
ctdb/tests/eventscripts/91.lvs.ipreallocated.014.sh
Executable file
28
ctdb/tests/eventscripts/91.lvs.ipreallocated.014.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "nodes in config, this is master"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_lvs "10.1.1.201" "eth0" <<EOF
|
||||
192.168.1.1 master
|
||||
192.168.1.2
|
||||
192.168.1.3
|
||||
EOF
|
||||
|
||||
ok_null
|
||||
simple_test
|
||||
|
||||
check_ipvsadm <<EOF
|
||||
TCP 10.1.1.201:0 lc persistent 1999999
|
||||
-> 127.0.0.1:0 Local 1 0 0
|
||||
-> 192.168.1.2:0 Route 1 0 0
|
||||
-> 192.168.1.3:0 Route 1 0 0
|
||||
UDP 10.1.1.201:0 lc persistent 1999999
|
||||
-> 127.0.0.1:0 Local 1 0 0
|
||||
-> 192.168.1.2:0 Route 1 0 0
|
||||
-> 192.168.1.3:0 Route 1 0 0
|
||||
EOF
|
||||
|
||||
check_lvs_ip global
|
12
ctdb/tests/eventscripts/91.lvs.shutdown.001.sh
Executable file
12
ctdb/tests/eventscripts/91.lvs.shutdown.001.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "not configured"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_lvs <<EOF
|
||||
EOF
|
||||
|
||||
ok_null
|
||||
simple_test
|
19
ctdb/tests/eventscripts/91.lvs.shutdown.002.sh
Executable file
19
ctdb/tests/eventscripts/91.lvs.shutdown.002.sh
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "configured"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_lvs "10.1.1.201" "eth0" <<EOF
|
||||
EOF
|
||||
|
||||
ipvsadm -A -t "$CTDB_LVS_PUBLIC_IP" -s lc -p 1999999
|
||||
ipvsadm -A -u "$CTDB_LVS_PUBLIC_IP" -s lc -p 1999999
|
||||
ip addr add $CTDB_LVS_PUBLIC_IP/32 dev lo
|
||||
|
||||
ok_null
|
||||
simple_test
|
||||
|
||||
check_ipvsadm NULL
|
||||
check_lvs_ip NULL
|
12
ctdb/tests/eventscripts/91.lvs.startup.001.sh
Executable file
12
ctdb/tests/eventscripts/91.lvs.startup.001.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "not configured"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_lvs <<EOF
|
||||
EOF
|
||||
|
||||
ok_null
|
||||
simple_test
|
15
ctdb/tests/eventscripts/91.lvs.startup.002.sh
Executable file
15
ctdb/tests/eventscripts/91.lvs.startup.002.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "configured"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_lvs "10.1.1.201" "eth0" <<EOF
|
||||
EOF
|
||||
|
||||
ok_null
|
||||
simple_test
|
||||
|
||||
check_ipvsadm NULL
|
||||
check_lvs_ip "host"
|
@ -541,6 +541,82 @@ EOF
|
||||
|
||||
######################################################################
|
||||
|
||||
setup_ctdb_lvs ()
|
||||
{
|
||||
export CTDB_LVS_PUBLIC_IP="$1"
|
||||
export CTDB_PUBLIC_INTERFACE="$2"
|
||||
|
||||
lvs_state_dir="${EVENTSCRIPTS_TESTS_VAR_DIR}/lvs"
|
||||
mkdir -p "$lvs_state_dir"
|
||||
|
||||
export FAKE_LVS_STATE_DIR="${lvs_state_dir}/state"
|
||||
mkdir "$FAKE_LVS_STATE_DIR"
|
||||
|
||||
lvs_header=$(ipvsadm -l -n)
|
||||
|
||||
# Not an official configuration file, just used by the ctdb
|
||||
# tool stub
|
||||
export CTDB_LVS_NODES=$(mktemp --tmpdir="$lvs_state_dir")
|
||||
export FAKE_CTDB_LVS_MASTER=""
|
||||
|
||||
# Read from stdin
|
||||
_pnn=0
|
||||
while read _ip _opts ; do
|
||||
case "$_opts" in
|
||||
master)
|
||||
FAKE_CTDB_LVS_MASTER="$_pnn"
|
||||
echo "$_ip"
|
||||
;;
|
||||
slave-only)
|
||||
printf "%s\tslave-only\n" "$_ip"
|
||||
;;
|
||||
*)
|
||||
echo "$_ip"
|
||||
;;
|
||||
esac
|
||||
_pnn=$(($_pnn + 1))
|
||||
done >"$CTDB_LVS_NODES"
|
||||
}
|
||||
|
||||
check_ipvsadm ()
|
||||
{
|
||||
if [ "$1" = "NULL" ] ; then
|
||||
required_result 0 <<EOF
|
||||
$lvs_header
|
||||
EOF
|
||||
else
|
||||
required_result 0 <<EOF
|
||||
$lvs_header
|
||||
$(cat)
|
||||
EOF
|
||||
fi
|
||||
|
||||
simple_test_command ipvsadm -l -n
|
||||
}
|
||||
|
||||
check_lvs_ip ()
|
||||
{
|
||||
_scope="$1"
|
||||
|
||||
if [ "$_scope" = "NULL" ] ; then
|
||||
required_result 0 <<EOF
|
||||
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
|
||||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
||||
EOF
|
||||
else
|
||||
required_result 0 <<EOF
|
||||
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
|
||||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
||||
inet ${CTDB_LVS_PUBLIC_IP}/32 scope ${_scope} lo
|
||||
valid_lft forever preferred_lft forever
|
||||
EOF
|
||||
fi
|
||||
|
||||
simple_test_command ip addr show dev lo
|
||||
}
|
||||
|
||||
######################################################################
|
||||
|
||||
ctdb_catdb_format_pairs ()
|
||||
{
|
||||
_count=0
|
||||
|
Loading…
Reference in New Issue
Block a user