]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: add USENODESCOMMAND directive to fake ctdb
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 31 Jul 2024 20:29:44 +0000 (16:29 -0400)
committerMartin Schwenke <martins@samba.org>
Tue, 6 Aug 2024 00:43:36 +0000 (00:43 +0000)
Add a single line USENODESCOMMAND directive to the fake ctdb in order to
enable use of a nodes script instead of a nodes file. For simplicity
the fake ctdb always uses `nodes.sh` in the CTDB_BASE.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tests/src/fake_ctdbd.c

index cceba225bb9ee02e56840d1f0501a6ee48d96654..f50604d134e70aaa7e80ccef373c7b2e9e7fbb29 100644 (file)
@@ -286,14 +286,23 @@ fail:
 
 }
 
+static bool use_nodes_command;
+
 static struct ctdb_node_map *read_nodes_file(TALLOC_CTX *mem_ctx,
                                             uint32_t pnn)
 {
        struct ctdb_node_map *nodemap;
        char nodes_list[PATH_MAX];
        const char *ctdb_base;
+       const char *per_node_template = "%s/nodes.%d";
+       const char *node_template = "%s/nodes";
        int num;
 
+       if (use_nodes_command) {
+               per_node_template = "!%s/nodes.sh %d";
+               node_template = "!%s/nodes.sh";
+       }
+
        ctdb_base = getenv("CTDB_BASE");
        if (ctdb_base == NULL) {
                D_ERR("CTDB_BASE is not set\n");
@@ -302,7 +311,7 @@ static struct ctdb_node_map *read_nodes_file(TALLOC_CTX *mem_ctx,
 
        /* read optional node-specific nodes file */
        num = snprintf(nodes_list, sizeof(nodes_list),
-                      "%s/nodes.%d", ctdb_base, pnn);
+                      per_node_template, ctdb_base, pnn);
        if (num == sizeof(nodes_list)) {
                D_ERR("nodes file path too long\n");
                return NULL;
@@ -321,7 +330,7 @@ static struct ctdb_node_map *read_nodes_file(TALLOC_CTX *mem_ctx,
        }
 
        /* read normal nodes file */
-       num = snprintf(nodes_list, sizeof(nodes_list), "%s/nodes", ctdb_base);
+       num = snprintf(nodes_list, sizeof(nodes_list), node_template, ctdb_base);
        if (num == sizeof(nodes_list)) {
                D_ERR("nodes file path too long\n");
                return NULL;
@@ -1229,6 +1238,10 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx,
                        status = control_failures_parse(ctdb);
                } else if (strcmp(line, "RUNSTATE") == 0) {
                        status = runstate_parse(ctdb);
+               } else if (strcmp(line, "USENODESCOMMAND") == 0) {
+                       fprintf(stderr, "Using nodes command\n");
+                       use_nodes_command = true;
+                       status = true;
                } else {
                        fprintf(stderr, "Unknown line %s\n", line);
                        status = false;