]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Simplify nodes file handling in tool tests
authorMartin Schwenke <martin@meltin.net>
Wed, 14 Mar 2018 04:10:45 +0000 (15:10 +1100)
committerAmitay Isaacs <amitay@samba.org>
Mon, 19 Mar 2018 01:23:20 +0000 (02:23 +0100)
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>
ctdb/tests/src/fake_ctdbd.c
ctdb/tests/tool/ctdb.listnodes.001.sh
ctdb/tests/tool/ctdb.reloadnodes.003.sh
ctdb/tests/tool/scripts/local.sh

index 2f4e87f6f6c31da0f31b1b3b816c02e48bb7592b..623f6df85e3535c3b8857d39f18ded80a9702fdc 100644 (file)
@@ -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)
index faf99c89a2b60cd402e12469650c42eb00c94e1a..5a494ee8c9e0f6f6ff68024effa98d262960c0ea 100755 (executable)
@@ -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
index 88e105f2047251e96ef607a1f70543bb94d8bffc..99974d072dd40c61a0f3ca8daa0464412c5d01c5 100755 (executable)
@@ -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
index 42eabd16fe329678f47b733bbda82da03de32533..0d86eca49cc379cbb27432b3b5d1f41918439a34 100644 (file)
@@ -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 ()