summaryrefslogtreecommitdiffstats
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-03-17 13:42:35 +1100
committerAmitay Isaacs <amitay@samba.org>2014-03-23 04:20:14 +0100
commit79d28000043bd463beecaeac47855d3a4970eaf2 (patch)
treeb15970341536986b5a047cae261b5feab457dac0 /ctdb
parent9bede494743f0ce13493fe718ed8f0c3c5f2959c (diff)
downloadsamba-79d28000043bd463beecaeac47855d3a4970eaf2.tar.gz
samba-79d28000043bd463beecaeac47855d3a4970eaf2.tar.xz
samba-79d28000043bd463beecaeac47855d3a4970eaf2.zip
ctdb-tests: Add "ctdb listnodes" and "ctdb xpnn" stub tests
Tests for xpnn need to implement a stub for ctdb_sys_have_ip(). The cheapest way of doing this is to read a fake nodemap using the existing code and check if the IP of the "current" node is the one being asked about. However, the fake state initialisation isn't currently available to without_daemon commands because it is meant to represent daemon state. However, it can be made available by moving the relevant code into a new stub for tevent_context_init(). The stub still needs to initialise a tevent context - this can be done by calling a lower level function. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/tests/src/ctdb_test.c8
-rw-r--r--ctdb/tests/src/ctdb_test_stubs.c36
-rw-r--r--ctdb/tests/tool/scripts/local.sh11
-rwxr-xr-xctdb/tests/tool/stubby.listnodes.001.sh20
-rwxr-xr-xctdb/tests/tool/stubby.listnodes.002.sh20
-rwxr-xr-xctdb/tests/tool/stubby.xpnn.001.sh20
-rwxr-xr-xctdb/tests/tool/stubby.xpnn.002.sh20
-rwxr-xr-xctdb/tests/tool/stubby.xpnn.003.sh24
8 files changed, 158 insertions, 1 deletions
diff --git a/ctdb/tests/src/ctdb_test.c b/ctdb/tests/src/ctdb_test.c
index bbb51bd877c..68a82823b2c 100644
--- a/ctdb/tests/src/ctdb_test.c
+++ b/ctdb/tests/src/ctdb_test.c
@@ -30,6 +30,8 @@
#define ctdb_cmdline_client(x, y) \
ctdb_cmdline_client_stub(x, y)
+#define tevent_context_init(x) \
+ tevent_context_init_stub(x)
#define ctdb_ctrl_getnodemap(ctdb, timelimit, pnn, tmp_ctx, nodemap) \
ctdb_ctrl_getnodemap_stub(ctdb, timelimit, pnn, tmp_ctx, nodemap)
#define ctdb_ctrl_get_ifaces(ctdb, timelimit, pnn, tmp_ctx, ifaces) \
@@ -48,6 +50,8 @@
ctdb_client_check_message_handlers_stub(ctdb, ids, argc, result)
#define ctdb_ctrl_getcapabilities(ctdb, timeout, destnode, capabilities) \
ctdb_ctrl_getcapabilities_stub(ctdb, timeout, destnode, capabilities)
+#define ctdb_sys_have_ip(addr) \
+ ctdb_sys_have_ip_stub(addr)
#include "tools/ctdb.c"
@@ -57,6 +61,9 @@
#endif /* CTDB_TEST_USE_MAIN */
#undef ctdb_cmdline_client
+#undef tevent_context_init
+/* This is called in client/ctdb_client.c so needs a declaration... */
+struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx);
#include "common/cmdline.c"
@@ -69,6 +76,7 @@
#undef ctdb_ctrl_getdebseqnum
#undef ctdb_client_check_message_handlers
#undef ctdb_ctrl_getcapabilities
+#undef ctdb_sys_have_ip
#undef TIMELIMIT
#include "tools/ctdb_vacuum.c"
diff --git a/ctdb/tests/src/ctdb_test_stubs.c b/ctdb/tests/src/ctdb_test_stubs.c
index 3ca7b9112ea..1edbe6aee77 100644
--- a/ctdb/tests/src/ctdb_test_stubs.c
+++ b/ctdb/tests/src/ctdb_test_stubs.c
@@ -17,6 +17,9 @@
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+/* Useful for functions that don't get struct ctdb_context passed */
+static struct ctdb_context *ctdb_global;
+
/* Read a nodemap from stdin. Each line looks like:
* <PNN> <FLAGS> [RECMASTER] [CURRENT] [CAPABILITIES]
* EOF or a blank line terminates input.
@@ -336,6 +339,11 @@ static bool current_node_is_connected (struct ctdb_context *ctdb)
struct ctdb_context *ctdb_cmdline_client_stub(struct tevent_context *ev,
struct timeval req_timeout)
{
+ return ctdb_global;
+}
+
+struct tevent_context *tevent_context_init_stub(TALLOC_CTX *mem_ctx)
+{
struct ctdb_context *ctdb;
ctdb = talloc_zero(NULL, struct ctdb_context);
@@ -344,7 +352,9 @@ struct ctdb_context *ctdb_cmdline_client_stub(struct tevent_context *ev,
ctdb_test_stubs_fake_setup(ctdb);
- return ctdb;
+ ctdb_global = ctdb;
+
+ return tevent_context_init_byname(mem_ctx, NULL);
}
/* Copied from ctdb_recover.c */
@@ -543,3 +553,27 @@ int ctdb_ctrl_getcapabilities_stub(struct ctdb_context *ctdb,
*capabilities = ctdb->nodes[destnode]->capabilities;
return 0;
}
+
+/* This is to support testing ctdb xpnn */
+
+bool ctdb_sys_have_ip_stub(ctdb_sock_addr *addr)
+{
+ int i;
+ struct ctdb_context *ctdb = ctdb_global;
+
+ for (i = 0; i < ctdb->num_nodes; i++) {
+ ctdb_sock_addr node_addr;
+
+ if (ctdb->pnn == ctdb->nodes[i]->pnn) {
+ if (!parse_ip(ctdb->nodes[i]->address.address, NULL, 0,
+ &node_addr)) {
+ continue;
+ }
+ if (ctdb_same_ip(addr, &node_addr)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
diff --git a/ctdb/tests/tool/scripts/local.sh b/ctdb/tests/tool/scripts/local.sh
index 6cad929e85e..8d7d56c0c62 100644
--- a/ctdb/tests/tool/scripts/local.sh
+++ b/ctdb/tests/tool/scripts/local.sh
@@ -42,6 +42,17 @@ setup_natgw ()
cat >"$CTDB_NATGW_NODES"
}
+setup_nodes ()
+{
+ debug "Setting up CTDB_NODES"
+
+ # These will accumulate, 1 per test... but will be cleaned up at
+ # the end.
+ export CTDB_NODES=$(mktemp --tmpdir="$TEST_VAR_DIR")
+
+ cat >"$CTDB_NODES"
+}
+
simple_test ()
{
_out=$($VALGRIND $test_prog "$@" 2>&1)
diff --git a/ctdb/tests/tool/stubby.listnodes.001.sh b/ctdb/tests/tool/stubby.listnodes.001.sh
new file mode 100755
index 00000000000..35a0c14b8eb
--- /dev/null
+++ b/ctdb/tests/tool/stubby.listnodes.001.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "missing nodes file"
+
+setup_nodes <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
+rm -f "$CTDB_NODES"
+
+required_result 255 <<EOF
+DATE TIME [PID]: Failed to read nodes file
+EOF
+
+simple_test <<EOF
+EOF
diff --git a/ctdb/tests/tool/stubby.listnodes.002.sh b/ctdb/tests/tool/stubby.listnodes.002.sh
new file mode 100755
index 00000000000..d807e1ee268
--- /dev/null
+++ b/ctdb/tests/tool/stubby.listnodes.002.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "missing nodes file"
+
+setup_nodes <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
+required_result 0 <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
+simple_test <<EOF
+EOF
diff --git a/ctdb/tests/tool/stubby.xpnn.001.sh b/ctdb/tests/tool/stubby.xpnn.001.sh
new file mode 100755
index 00000000000..e59e40cbb9e
--- /dev/null
+++ b/ctdb/tests/tool/stubby.xpnn.001.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "3 nodes, current is 0"
+
+setup_nodes <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
+required_result 0 "PNN:0"
+
+simple_test <<EOF
+NODEMAP
+0 192.168.20.41 0x0 CURRENT
+1 192.168.20.42 0x0
+2 192.168.20.43 0x0
+EOF
diff --git a/ctdb/tests/tool/stubby.xpnn.002.sh b/ctdb/tests/tool/stubby.xpnn.002.sh
new file mode 100755
index 00000000000..cc4f38ca009
--- /dev/null
+++ b/ctdb/tests/tool/stubby.xpnn.002.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "3 nodes, current is 2"
+
+setup_nodes <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
+required_result 0 "PNN:2"
+
+simple_test <<EOF
+NODEMAP
+0 192.168.20.41 0x0
+1 192.168.20.42 0x0
+2 192.168.20.43 0x0 CURRENT
+EOF
diff --git a/ctdb/tests/tool/stubby.xpnn.003.sh b/ctdb/tests/tool/stubby.xpnn.003.sh
new file mode 100755
index 00000000000..152d2300233
--- /dev/null
+++ b/ctdb/tests/tool/stubby.xpnn.003.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "missing nodes file"
+
+setup_nodes <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
+rm -f "$CTDB_NODES"
+
+required_result 255 <<EOF
+DATE TIME [PID]: Failed to read nodes file
+EOF
+
+simple_test <<EOF
+NODEMAP
+0 192.168.20.41 0x0 CURRENT
+1 192.168.20.42 0x0
+2 192.168.20.43 0x0
+EOF