diff options
author | Martin Schwenke <martin@meltin.net> | 2018-03-14 15:10:45 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2018-03-19 02:23:20 +0100 |
commit | 480c586c7dbc5ffef832c6a0be2c4e6b70f98514 (patch) | |
tree | a1799e07557331567da5fb504f6186754ef43a8f | |
parent | 3a7c49dfbc9ce579876d5cd680ede1f30c11c950 (diff) | |
download | samba-480c586c7dbc5ffef832c6a0be2c4e6b70f98514.tar.gz |
ctdb-tests: Simplify nodes file handling in tool tests
Instead of using an intermediate environment variable for nodes files,
just create "node" or "nodes.<pnn>" in CTDB_BASE. This makes the
nodes file loading in fake_ctdb slightly repetitive but simplifies the
test scripts a lot. It also remove several instance of the CTDB_NODES
variable from the code base, so it is no longer found by "git grep".
Use an empty nodes file to indicate that fake_ctdbd should fail to
read it.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
-rw-r--r-- | ctdb/tests/src/fake_ctdbd.c | 51 | ||||
-rwxr-xr-x | ctdb/tests/tool/ctdb.listnodes.001.sh | 5 | ||||
-rwxr-xr-x | ctdb/tests/tool/ctdb.reloadnodes.003.sh | 6 | ||||
-rw-r--r-- | ctdb/tests/tool/scripts/local.sh | 16 |
4 files changed, 41 insertions, 37 deletions
diff --git a/ctdb/tests/src/fake_ctdbd.c b/ctdb/tests/src/fake_ctdbd.c index 2f4e87f6f6c..623f6df85e3 100644 --- a/ctdb/tests/src/fake_ctdbd.c +++ b/ctdb/tests/src/fake_ctdbd.c @@ -380,28 +380,49 @@ static struct ctdb_node_map *read_nodes_file(TALLOC_CTX *mem_ctx, uint32_t pnn) { struct ctdb_node_map *nodemap; - char nodepath[PATH_MAX]; - const char *nodes_list; - - /* read the nodes file */ - sprintf(nodepath, "CTDB_NODES_%u", pnn); - nodes_list = getenv(nodepath); - if (nodes_list == NULL) { - nodes_list = getenv("CTDB_NODES"); - if (nodes_list == NULL) { - DEBUG(DEBUG_INFO, ("Nodes file not defined\n")); + char nodes_list[PATH_MAX]; + const char *ctdb_base; + int num; + + ctdb_base = getenv("CTDB_BASE"); + if (ctdb_base == NULL) { + D_ERR("CTDB_BASE is not set\n"); + return NULL; + } + + /* read optional node-specific nodes file */ + num = snprintf(nodes_list, sizeof(nodes_list), + "%s/nodes.%d", ctdb_base, pnn); + if (num == sizeof(nodes_list)) { + D_ERR("nodes file path too long\n"); + return NULL; + } + nodemap = ctdb_read_nodes_file(mem_ctx, nodes_list); + if (nodemap != NULL) { + /* Fake a load failure for an empty nodemap */ + if (nodemap->num == 0) { + talloc_free(nodemap); + + D_ERR("Failed to read nodes file \"%s\"\n", nodes_list); return NULL; } + + return nodemap; } - nodemap = ctdb_read_nodes_file(mem_ctx, nodes_list); - if (nodemap == NULL) { - DEBUG(DEBUG_INFO, ("Failed to read nodes file \"%s\"\n", - nodes_list)); + /* read normal nodes file */ + num = snprintf(nodes_list, sizeof(nodes_list), "%s/nodes", ctdb_base); + if (num == sizeof(nodes_list)) { + D_ERR("nodes file path too long\n"); return NULL; } + nodemap = ctdb_read_nodes_file(mem_ctx, nodes_list); + if (nodemap != NULL) { + return nodemap; + } - return nodemap; + DBG_ERR("Failed to read nodes file \"%s\"\n", nodes_list); + return NULL; } static struct interface_map *interfaces_init(TALLOC_CTX *mem_ctx) diff --git a/ctdb/tests/tool/ctdb.listnodes.001.sh b/ctdb/tests/tool/ctdb.listnodes.001.sh index faf99c89a2b..5a494ee8c9e 100755 --- a/ctdb/tests/tool/ctdb.listnodes.001.sh +++ b/ctdb/tests/tool/ctdb.listnodes.001.sh @@ -10,10 +10,11 @@ setup_nodes <<EOF 192.168.20.43 EOF -rm -f "$CTDB_NODES" +f="${CTDB_BASE}/nodes" +rm -f "$f" required_result 1 <<EOF -${TEST_DATE_STAMP}Failed to read nodes file "${CTDB_NODES}" +${TEST_DATE_STAMP}Failed to read nodes file "${f}" EOF simple_test diff --git a/ctdb/tests/tool/ctdb.reloadnodes.003.sh b/ctdb/tests/tool/ctdb.reloadnodes.003.sh index 88e105f2047..99974d072dd 100755 --- a/ctdb/tests/tool/ctdb.reloadnodes.003.sh +++ b/ctdb/tests/tool/ctdb.reloadnodes.003.sh @@ -10,14 +10,10 @@ setup_nodes <<EOF 192.168.20.43 EOF +# fake_ctdbd returns error for empty file setup_nodes 1 <<EOF -192.168.20.41 -#192.168.20.42 -192.168.20.43 EOF -rm "$CTDB_NODES_1" - setup_ctdbd <<EOF NODEMAP 0 192.168.20.41 0x0 CURRENT RECMASTER diff --git a/ctdb/tests/tool/scripts/local.sh b/ctdb/tests/tool/scripts/local.sh index 42eabd16fe3..0d86eca49cc 100644 --- a/ctdb/tests/tool/scripts/local.sh +++ b/ctdb/tests/tool/scripts/local.sh @@ -92,23 +92,9 @@ setup_nodes () { _pnn="$1" - _v="CTDB_NODES${_pnn:+_}${_pnn}" - debug "Setting up ${_v}" + _f="${CTDB_BASE}/nodes${_pnn:+.}${_pnn}" - eval export "${_v}"=$(mktemp --tmpdir="$TEST_VAR_DIR") - - eval _f="\${${_v}}" - test_cleanup "rm -f ${_f}" cat >"$_f" - - # You can't be too careful about what might be in the - # environment... so clean up when setting the default variable. - if [ -z "$_pnn" ] ; then - _n=$(wc -l "$CTDB_NODES" | awk '{ print $1 }') - for _i in $(seq 0 $_n) ; do - eval unset "CTDB_NODES_${_i}" - done - fi } simple_test_other () |