From 8fc36696f7e3c8e1b0663bac1b3980bf7df22edd Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 24 May 2017 20:24:54 +1000 Subject: [PATCH 1/3] ctdb-tools: Stop "ctdb nodestatus" from always showing all nodes Exit code should only reflect current or specified nodes too. Drop an unwanted call to get_nodemap() that overwrites the previously calculated node map. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12802 Signed-off-by: Martin Schwenke --- ctdb/tools/ctdb.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index ae74ef818cb..14b6957e1f0 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -5664,11 +5664,6 @@ static int control_nodestatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, return 1; } - nodemap = get_nodemap(ctdb, false); - if (nodemap == NULL) { - return 1; - } - if (options.machinereadable) { print_nodemap_machine(mem_ctx, ctdb, nodemap, ctdb->cmd_pnn); } else { -- 2.11.0 From fb7aad28f84d8985e220e7d4ce293c76eab117de Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 24 May 2017 20:27:58 +1000 Subject: [PATCH 2/3] ctdb-tools: "ctdb nodestatus" should only display header for "all" The "Number of nodes:" header should only be displayed when "all" is specified. This is how the command behaved in Samba <= 4.4. Printing the number of nodes is not helpful and is rather confusing in the default case where only the status of the current node is printed. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12802 Signed-off-by: Martin Schwenke --- ctdb/tools/ctdb.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 14b6957e1f0..e0a3e0ccc97 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -802,7 +802,8 @@ static void print_nodemap_machine(TALLOC_CTX *mem_ctx, } static void print_nodemap(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, - struct ctdb_node_map *nodemap, uint32_t mypnn) + struct ctdb_node_map *nodemap, uint32_t mypnn, + bool print_header) { struct ctdb_node_and_flags *node; int num_deleted_nodes = 0; @@ -814,11 +815,14 @@ static void print_nodemap(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, } } - if (num_deleted_nodes == 0) { - printf("Number of nodes:%d\n", nodemap->num); - } else { - printf("Number of nodes:%d (including %d deleted nodes)\n", - nodemap->num, num_deleted_nodes); + if (print_header) { + if (num_deleted_nodes == 0) { + printf("Number of nodes:%d\n", nodemap->num); + } else { + printf("Number of nodes:%d " + "(including %d deleted nodes)\n", + nodemap->num, num_deleted_nodes); + } } for (i=0; inum; i++) { @@ -844,7 +848,7 @@ static void print_status(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, { int i; - print_nodemap(mem_ctx, ctdb, nodemap, mypnn); + print_nodemap(mem_ctx, ctdb, nodemap, mypnn, true); if (vnnmap->generation == INVALID_GENERATION) { printf("Generation:INVALID\n"); @@ -5667,7 +5671,8 @@ static int control_nodestatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, if (options.machinereadable) { print_nodemap_machine(mem_ctx, ctdb, nodemap, ctdb->cmd_pnn); } else { - print_nodemap(mem_ctx, ctdb, nodemap, ctdb->cmd_pnn); + bool print_hdr = (argc == 1 && strcmp(argv[0], "all") == 0); + print_nodemap(mem_ctx, ctdb, nodemap, ctdb->cmd_pnn, print_hdr); } ret = 0; -- 2.11.0 From 6909f76813e5c8060823d707387bfd417f2ea96d Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 24 May 2017 20:21:55 +1000 Subject: [PATCH 3/3] ctdb-tests: Add some extra tests for "ctdb nodestatus" BUG: https://bugzilla.samba.org/show_bug.cgi?id=12802 Signed-off-by: Martin Schwenke --- ctdb/tests/tool/ctdb.nodestatus.003.sh | 33 +++++++++++++++++++++++++++++++++ ctdb/tests/tool/ctdb.nodestatus.004.sh | 28 ++++++++++++++++++++++++++++ ctdb/tests/tool/ctdb.nodestatus.005.sh | 28 ++++++++++++++++++++++++++++ ctdb/tests/tool/ctdb.nodestatus.006.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100755 ctdb/tests/tool/ctdb.nodestatus.003.sh create mode 100755 ctdb/tests/tool/ctdb.nodestatus.004.sh create mode 100755 ctdb/tests/tool/ctdb.nodestatus.005.sh create mode 100755 ctdb/tests/tool/ctdb.nodestatus.006.sh diff --git a/ctdb/tests/tool/ctdb.nodestatus.003.sh b/ctdb/tests/tool/ctdb.nodestatus.003.sh new file mode 100755 index 00000000000..5912e6501aa --- /dev/null +++ b/ctdb/tests/tool/ctdb.nodestatus.003.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "all, 3 nodes, 1 unhealthy" + +setup_ctdbd <