From: Martin Schwenke Date: Wed, 14 Mar 2018 04:10:45 +0000 (+1100) Subject: ctdb-tests: Simplify nodes file handling in tool tests X-Git-Tag: talloc-2.1.12~104 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=480c586c7dbc5ffef832c6a0be2c4e6b70f98514;p=thirdparty%2Fsamba.git ctdb-tests: Simplify nodes file handling in tool tests Instead of using an intermediate environment variable for nodes files, just create "node" or "nodes." 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 Reviewed-by: Amitay Isaacs --- 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 <"$_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 ()