1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

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>
This commit is contained in:
Martin Schwenke 2014-03-17 13:42:35 +11:00 committed by Amitay Isaacs
parent 9bede49474
commit 79d2800004
8 changed files with 158 additions and 1 deletions

View File

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

View File

@ -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.
@ -335,6 +338,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;
@ -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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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