ctdb-tests: Test stub for ctrl_getnodesfile()
authorMartin Schwenke <martin@meltin.net>
Tue, 24 Feb 2015 05:13:09 +0000 (16:13 +1100)
committerAmitay Isaacs <amitay@samba.org>
Mon, 23 Mar 2015 11:23:12 +0000 (12:23 +0100)
Also stub support for CTDB_CONTROL_GET_NODES_FILE

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/src/ctdb_test.c
ctdb/tests/src/ctdb_test_stubs.c

index 0ff1803fcb6c1e75cb7f6b15b57dda2bd7dbdf2b..f8cdd4c16f64cc921e27f02b8aad0661fb0e9736 100644 (file)
@@ -35,6 +35,8 @@ int main_foobar(int argc, const char **argv);
        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_getnodesfile(ctdb, timeout, destnode, mem_ctx, nodemap) \
+       ctdb_ctrl_getnodesfile_stub(ctdb, timeout, destnode, mem_ctx, nodemap)
 #define ctdb_ctrl_get_ifaces(ctdb, timelimit, pnn, tmp_ctx, ifaces) \
        ctdb_ctrl_get_ifaces_stub(ctdb, timelimit, pnn, tmp_ctx, ifaces)
 #define ctdb_ctrl_getpnn(ctdb, timelimit, pnn) \
@@ -82,6 +84,7 @@ struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx);
 #include "common/cmdline.c"
 
 #undef ctdb_ctrl_getnodemap
+#undef ctdb_ctrl_getnodesfile
 #undef ctdb_ctrl_get_ifaces 
 #undef ctdb_ctrl_getpnn
 #undef ctdb_ctrl_getrecmode
@@ -101,6 +104,10 @@ struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx);
 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb,
                    struct timeval timeout, uint32_t destnode,
                    TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
+int ctdb_ctrl_getnodesfile(struct ctdb_context *ctdb,
+                          struct timeval timeout, uint32_t destnode,
+                          TALLOC_CTX *mem_ctx,
+                          struct ctdb_node_map **nodemap);
 int ctdb_ctrl_get_ifaces(struct ctdb_context *ctdb,
                         struct timeval timeout, uint32_t destnode,
                         TALLOC_CTX *mem_ctx,
index 526a6257bf36ba8a12a68e685c9c0908407e46fd..3ea508a0f320bc56b4f0f23c3e7bec4c796b464e 100644 (file)
@@ -482,6 +482,26 @@ ctdb_ctrl_getnodemap_stub(struct ctdb_context *ctdb,
        return ret;
 }
 
+int
+ctdb_ctrl_getnodesfile_stub(struct ctdb_context *ctdb,
+                           struct timeval timeout, uint32_t destnode,
+                           TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap)
+{
+       char *v, *f;
+
+       /* If there's an environment variable for a node-specific file
+        * then use it.  Otherwise use the global file. */
+       v = talloc_asprintf(mem_ctx, "CTDB_NODES_%u", destnode);
+       f = getenv(v);
+       if (f == NULL) {
+               f = getenv("CTDB_NODES");
+       }
+
+       *nodemap = ctdb_read_nodes_file(mem_ctx, f);
+
+       return *nodemap == NULL ? -1 : 0;
+}
+
 int
 ctdb_ctrl_getvnnmap_stub(struct ctdb_context *ctdb,
                         struct timeval timeout, uint32_t destnode,
@@ -826,6 +846,16 @@ ctdb_client_async_control_stub(struct ctdb_context *ctdb,
                        DEBUG(DEBUG_NOTICE, ("Fake reload public IPs on node %u\n", pnn));
                        res = 0;
                        break;
+               case CTDB_CONTROL_GET_NODES_FILE: {
+                       struct ctdb_node_map *nodemap;
+                       res = ctdb_ctrl_getnodesfile_stub(ctdb, timeout, pnn,
+                                                         tmp_ctx, &nodemap);
+                       if (res == 0) {
+                               outdata.dsize = talloc_get_size(nodemap);
+                               outdata.dptr = (uint8_t *) nodemap;
+                       }
+               }
+                       break;
                default:
                        DEBUG(DEBUG_ERR, (__location__ " Control not implemented %u\n",
                                          opcode));