diff options
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/tests/tool/scripts/local.sh | 30 | ||||
-rwxr-xr-x | ctdb/tests/tool/stubby.natgwlist.006.sh | 6 | ||||
-rwxr-xr-x | ctdb/tests/tool/stubby.natgwlist.007.sh | 14 | ||||
-rw-r--r-- | ctdb/tools/ctdb.c | 174 |
4 files changed, 43 insertions, 181 deletions
diff --git a/ctdb/tests/tool/scripts/local.sh b/ctdb/tests/tool/scripts/local.sh index 68a25d2dad7..f85262b117f 100644 --- a/ctdb/tests/tool/scripts/local.sh +++ b/ctdb/tests/tool/scripts/local.sh @@ -38,16 +38,26 @@ define_test () setup_natgw () { - debug "Setting up NAT gateway" - - natgw_config_dir="${TEST_VAR_DIR}/natgw_config" - mkdir -p "$natgw_config_dir" - - # These will accumulate, 1 per test... but will be cleaned up at - # the end. - export CTDB_NATGW_NODES=$(mktemp --tmpdir="$natgw_config_dir") - - cat >"$CTDB_NATGW_NODES" + debug "Setting up NAT gateway" + + # Use in-tree binaries if running against local daemons. + # Otherwise CTDB need to be installed on all nodes. + if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then + if [ -z "$CTDB_NATGW_HELPER" ] ; then + export CTDB_NATGW_HELPER="${ctdb_dir}/tools/ctdb_natgw" + fi + # Only want to find functions file, so this is OK + export CTDB_BASE="${ctdb_dir}/config" + fi + + natgw_config_dir="${TEST_VAR_DIR}/natgw_config" + mkdir -p "$natgw_config_dir" + + # These will accumulate, 1 per test... but will be cleaned up + # at the end. + export CTDB_NATGW_NODES=$(mktemp --tmpdir="$natgw_config_dir") + + cat >"$CTDB_NATGW_NODES" } setup_nodes () diff --git a/ctdb/tests/tool/stubby.natgwlist.006.sh b/ctdb/tests/tool/stubby.natgwlist.006.sh index 4ed95ca071e..6de8e121a53 100755 --- a/ctdb/tests/tool/stubby.natgwlist.006.sh +++ b/ctdb/tests/tool/stubby.natgwlist.006.sh @@ -2,10 +2,10 @@ . "${TEST_SCRIPTS_DIR}/unit.sh" -define_test "3 nodes, node 0 missing NATGW capability, all stopped" +define_test "3 nodes, node 0 is slave-only, all stopped" setup_natgw <<EOF -192.168.20.41 +192.168.20.41 slave-only 192.168.20.42 192.168.20.43 EOF @@ -20,7 +20,7 @@ EOF simple_test <<EOF NODEMAP -0 192.168.20.41 0x20 -CTDB_CAP_NATGW +0 192.168.20.41 0x20 1 192.168.20.42 0x20 CURRENT RECMASTER 2 192.168.20.43 0x20 diff --git a/ctdb/tests/tool/stubby.natgwlist.007.sh b/ctdb/tests/tool/stubby.natgwlist.007.sh index 855dcc6bd3c..563d86737fc 100755 --- a/ctdb/tests/tool/stubby.natgwlist.007.sh +++ b/ctdb/tests/tool/stubby.natgwlist.007.sh @@ -2,12 +2,12 @@ . "${TEST_SCRIPTS_DIR}/unit.sh" -define_test "3 nodes, node 0 missing NATGW capability, all stopped" +define_test "3 nodes, all nodes are slave-only, all stopped" setup_natgw <<EOF -192.168.20.41 -192.168.20.42 -192.168.20.43 +192.168.20.41 slave-only +192.168.20.42 slave-only +192.168.20.43 slave-only EOF required_result 2 <<EOF @@ -20,9 +20,9 @@ EOF simple_test <<EOF NODEMAP -0 192.168.20.41 0x20 -CTDB_CAP_NATGW -1 192.168.20.42 0x20 CURRENT RECMASTER -CTDB_CAP_NATGW -2 192.168.20.43 0x20 -CTDB_CAP_NATGW +0 192.168.20.41 0x20 +1 192.168.20.42 0x20 CURRENT RECMASTER +2 192.168.20.43 0x20 VNNMAP 654321 diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 5874df2b35d..5a5bcbc4910 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -1150,31 +1150,6 @@ static int control_nodestatus(struct ctdb_context *ctdb, int argc, const char ** return ret; } -static struct ctdb_node_map_old *read_natgw_nodes_file(struct ctdb_context *ctdb, - TALLOC_CTX *mem_ctx) -{ - const char *natgw_list; - struct ctdb_node_map_old *natgw_nodes = NULL; - - natgw_list = getenv("CTDB_NATGW_NODES"); - if (natgw_list == NULL) { - natgw_list = talloc_asprintf(mem_ctx, "%s/natgw_nodes", - getenv("CTDB_BASE")); - if (natgw_list == NULL) { - DEBUG(DEBUG_ALERT,(__location__ " Out of memory\n")); - exit(1); - } - } - /* The PNNs/flags will be junk but they're not used */ - natgw_nodes = ctdb_read_nodes_file(mem_ctx, natgw_list); - if (natgw_nodes == NULL) { - DEBUG(DEBUG_ERR, - ("Failed to load natgw node list '%s'\n", natgw_list)); - } - return natgw_nodes; -} - - /* talloc off the existing nodemap... */ static struct ctdb_node_map_old *talloc_nodemap(struct ctdb_node_map_old *nodemap) { @@ -1184,37 +1159,6 @@ static struct ctdb_node_map_old *talloc_nodemap(struct ctdb_node_map_old *nodema } static struct ctdb_node_map_old * -filter_nodemap_by_addrs(struct ctdb_context *ctdb, - struct ctdb_node_map_old *nodemap, - struct ctdb_node_map_old *natgw_nodes) -{ - int i, j; - struct ctdb_node_map_old *ret; - - ret = talloc_nodemap(nodemap); - CTDB_NO_MEMORY_NULL(ctdb, ret); - - ret->num = 0; - - for (i = 0; i < nodemap->num; i++) { - for(j = 0; j < natgw_nodes->num ; j++) { - if (nodemap->nodes[j].flags & NODE_FLAGS_DELETED) { - continue; - } - if (ctdb_same_ip(&natgw_nodes->nodes[j].addr, - &nodemap->nodes[i].addr)) { - - ret->nodes[ret->num] = nodemap->nodes[i]; - ret->num++; - break; - } - } - } - - return ret; -} - -static struct ctdb_node_map_old * filter_nodemap_by_capabilities(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodemap, uint32_t required_capabilities, @@ -1290,116 +1234,24 @@ filter_nodemap_by_flags(struct ctdb_context *ctdb, */ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **argv) { - TALLOC_CTX *tmp_ctx = talloc_new(ctdb); - int i, ret; - struct ctdb_node_map_old *natgw_nodes = NULL; - struct ctdb_node_map_old *orig_nodemap=NULL; - struct ctdb_node_map_old *nodemap; - uint32_t mypnn, pnn; - const char *ip; - - /* When we have some nodes that could be the NATGW, make a - * series of attempts to find the first node that doesn't have - * certain status flags set. - */ - uint32_t exclude_flags[] = { - /* Look for a nice healthy node */ - NODE_FLAGS_DISCONNECTED|NODE_FLAGS_STOPPED|NODE_FLAGS_DELETED|NODE_FLAGS_BANNED|NODE_FLAGS_UNHEALTHY, - /* If not found, an UNHEALTHY/BANNED node will do */ - NODE_FLAGS_DISCONNECTED|NODE_FLAGS_STOPPED|NODE_FLAGS_DELETED, - /* If not found, a STOPPED node will do */ - NODE_FLAGS_DISCONNECTED|NODE_FLAGS_DELETED, - 0, - }; - - /* read the natgw nodes file into a linked list */ - natgw_nodes = read_natgw_nodes_file(ctdb, tmp_ctx); - if (natgw_nodes == NULL) { - ret = -1; - goto done; - } - - ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, - tmp_ctx, &orig_nodemap); - if (ret != 0) { - DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node.\n")); - talloc_free(tmp_ctx); - return -1; - } + static char prog[PATH_MAX+1] = ""; - /* Get a nodemap that includes only the nodes in the NATGW - * group */ - nodemap = filter_nodemap_by_addrs(ctdb, orig_nodemap, natgw_nodes); - if (nodemap == NULL) { - ret = -1; - goto done; - } - - ret = 2; /* matches ENOENT */ - pnn = -1; - ip = "0.0.0.0"; - /* For each flag mask... */ - for (i = 0; exclude_flags[i] != 0; i++) { - /* ... get a nodemap that excludes nodes with with - * masked flags... */ - struct ctdb_node_map_old *t = - filter_nodemap_by_flags(ctdb, nodemap, - exclude_flags[i]); - if (t == NULL) { - /* No memory */ - ret = -1; - goto done; - } - if (t->num > 0) { - /* ... and find the first node with the NATGW - * capability */ - struct ctdb_node_map_old *n; - n = filter_nodemap_by_capabilities(ctdb, t, - CTDB_CAP_NATGW, - true); - if (n == NULL) { - /* No memory */ - ret = -1; - goto done; - } - if (n->num > 0) { - ret = 0; - pnn = n->nodes[0].pnn; - ip = ctdb_addr_to_str(&n->nodes[0].addr); - break; - } - } - talloc_free(t); + if (argc != 0) { + usage(); } - if (options.machinereadable) { - printm(":Node:IP:\n"); - printm(":%d:%s:\n", pnn, ip); - } else { - printf("%d %s\n", pnn, ip); + if (!ctdb_set_helper("NAT gateway helper", prog, sizeof(prog), + "CTDB_NATGW_HELPER", CTDB_HELPER_BINDIR, + "ctdb_natgw")) { + DEBUG(DEBUG_ERR, ("Unable to set NAT gateway helper\n")); + exit(1); } - /* print the pruned list of nodes belonging to this natgw list */ - mypnn = getpnn(ctdb); - if (options.machinereadable) { - control_status_header_machine(); - } else { - printf("Number of nodes:%d\n", nodemap->num); - } - for(i=0;i<nodemap->num;i++){ - if (nodemap->nodes[i].flags & NODE_FLAGS_DELETED) { - continue; - } - if (options.machinereadable) { - control_status_1_machine(ctdb, mypnn, &(nodemap->nodes[i])); - } else { - control_status_1_human(ctdb, mypnn, &(nodemap->nodes[i])); - } - } + execl(prog, prog, "natgwlist", NULL); -done: - talloc_free(tmp_ctx); - return ret; + DEBUG(DEBUG_ERR, + ("Unable to run NAT gateway helper %s\n", strerror(errno))); + exit(1); } /* @@ -6558,7 +6410,7 @@ static const struct { { "scriptstatus", control_scriptstatus, true, false, "show the status of the monitoring scripts (or all scripts)", "[all]"}, { "enablescript", control_enablescript, true, false, "enable an eventscript", "<script>"}, { "disablescript", control_disablescript, true, false, "disable an eventscript", "<script>"}, - { "natgwlist", control_natgwlist, true, false, "show the nodes belonging to this natgw configuration"}, + { "natgwlist", control_natgwlist, false, true, "show the nodes belonging to this natgw configuration"}, { "xpnn", control_xpnn, false, true, "find the pnn of the local node without talking to the daemon (unreliable)" }, { "getreclock", control_getreclock, true, false, "Show the reclock file of a node"}, { "setreclock", control_setreclock, true, false, "Set/clear the reclock file of a node", "[filename]"}, |