summaryrefslogtreecommitdiff
path: root/ctdb/tests
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2016-04-07 06:18:21 +1000
committerAmitay Isaacs <amitay@samba.org>2016-04-15 05:57:17 +0200
commit5fc9ca91d7cdc3a641065f2606188a25485e4ccb (patch)
tree1e9ba1a08869325b40665360c219fb828d6223bb /ctdb/tests
parent89dc86e0fd77857926d78bb6b0bd4f4c72a718f4 (diff)
downloadsamba-5fc9ca91d7cdc3a641065f2606188a25485e4ccb.tar.gz
ctdb-tests: Add unit tests for LVS eventscript
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tests')
-rwxr-xr-xctdb/tests/eventscripts/91.lvs.001.sh55
-rwxr-xr-xctdb/tests/eventscripts/91.lvs.ipreallocated.011.sh15
-rwxr-xr-xctdb/tests/eventscripts/91.lvs.ipreallocated.012.sh18
-rwxr-xr-xctdb/tests/eventscripts/91.lvs.ipreallocated.013.sh18
-rwxr-xr-xctdb/tests/eventscripts/91.lvs.ipreallocated.014.sh28
-rwxr-xr-xctdb/tests/eventscripts/91.lvs.shutdown.001.sh12
-rwxr-xr-xctdb/tests/eventscripts/91.lvs.shutdown.002.sh19
-rwxr-xr-xctdb/tests/eventscripts/91.lvs.startup.001.sh12
-rwxr-xr-xctdb/tests/eventscripts/91.lvs.startup.002.sh15
-rw-r--r--ctdb/tests/eventscripts/scripts/local.sh76
10 files changed, 268 insertions, 0 deletions
diff --git a/ctdb/tests/eventscripts/91.lvs.001.sh b/ctdb/tests/eventscripts/91.lvs.001.sh
new file mode 100755
index 00000000000..7c5554d077c
--- /dev/null
+++ b/ctdb/tests/eventscripts/91.lvs.001.sh
@@ -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
diff --git a/ctdb/tests/eventscripts/91.lvs.ipreallocated.011.sh b/ctdb/tests/eventscripts/91.lvs.ipreallocated.011.sh
new file mode 100755
index 00000000000..595c2c97725
--- /dev/null
+++ b/ctdb/tests/eventscripts/91.lvs.ipreallocated.011.sh
@@ -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
diff --git a/ctdb/tests/eventscripts/91.lvs.ipreallocated.012.sh b/ctdb/tests/eventscripts/91.lvs.ipreallocated.012.sh
new file mode 100755
index 00000000000..4c5ae529e18
--- /dev/null
+++ b/ctdb/tests/eventscripts/91.lvs.ipreallocated.012.sh
@@ -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
diff --git a/ctdb/tests/eventscripts/91.lvs.ipreallocated.013.sh b/ctdb/tests/eventscripts/91.lvs.ipreallocated.013.sh
new file mode 100755
index 00000000000..7ac4b618cf9
--- /dev/null
+++ b/ctdb/tests/eventscripts/91.lvs.ipreallocated.013.sh
@@ -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
diff --git a/ctdb/tests/eventscripts/91.lvs.ipreallocated.014.sh b/ctdb/tests/eventscripts/91.lvs.ipreallocated.014.sh
new file mode 100755
index 00000000000..757637a890b
--- /dev/null
+++ b/ctdb/tests/eventscripts/91.lvs.ipreallocated.014.sh
@@ -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
diff --git a/ctdb/tests/eventscripts/91.lvs.shutdown.001.sh b/ctdb/tests/eventscripts/91.lvs.shutdown.001.sh
new file mode 100755
index 00000000000..3710d85f314
--- /dev/null
+++ b/ctdb/tests/eventscripts/91.lvs.shutdown.001.sh
@@ -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
diff --git a/ctdb/tests/eventscripts/91.lvs.shutdown.002.sh b/ctdb/tests/eventscripts/91.lvs.shutdown.002.sh
new file mode 100755
index 00000000000..db43d424d2c
--- /dev/null
+++ b/ctdb/tests/eventscripts/91.lvs.shutdown.002.sh
@@ -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
diff --git a/ctdb/tests/eventscripts/91.lvs.startup.001.sh b/ctdb/tests/eventscripts/91.lvs.startup.001.sh
new file mode 100755
index 00000000000..3710d85f314
--- /dev/null
+++ b/ctdb/tests/eventscripts/91.lvs.startup.001.sh
@@ -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
diff --git a/ctdb/tests/eventscripts/91.lvs.startup.002.sh b/ctdb/tests/eventscripts/91.lvs.startup.002.sh
new file mode 100755
index 00000000000..9e90dd33c86
--- /dev/null
+++ b/ctdb/tests/eventscripts/91.lvs.startup.002.sh
@@ -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"
diff --git a/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh
index fcb751901b8..0f15be4edb9 100644
--- a/ctdb/tests/eventscripts/scripts/local.sh
+++ b/ctdb/tests/eventscripts/scripts/local.sh
@@ -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