From b20056aad7976a7f1cf8e52fe2f82b1354525f4a 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 Reviewed-by: Amitay Isaacs (cherry picked from commit a600d467e2842ab05e429c5a67be5b222ddd1c12) --- ctdb/tools/ctdb.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 050906c..57974fd 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -5663,11 +5663,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.9.4 From 8d3ea3da882b0ffb558aa1d23f147b5a3fea229b 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 Reviewed-by: Amitay Isaacs (cherry picked from commit 1d10c8e9e637619b754b4a273d3c714fbca7d503) --- ctdb/tools/ctdb.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 57974fd..93e4802 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"); @@ -5650,6 +5654,7 @@ static int control_nodestatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, const char *nodestring = NULL; struct ctdb_node_map *nodemap; int ret, i; + bool print_hdr = false; if (argc > 1) { usage("nodestatus"); @@ -5657,6 +5662,9 @@ static int control_nodestatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, if (argc == 1) { nodestring = argv[0]; + if (strcmp(nodestring, "all") == 0) { + print_hdr = true; + } } if (! parse_nodestring(mem_ctx, ctdb, nodestring, &nodemap)) { @@ -5666,7 +5674,7 @@ 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); + print_nodemap(mem_ctx, ctdb, nodemap, ctdb->cmd_pnn, print_hdr); } ret = 0; -- 2.9.4 From 347d79aad7db7cb8d6043b7a0112e3013111f188 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 Reviewed-by: Amitay Isaacs Autobuild-User(master): Martin Schwenke Autobuild-Date(master): Fri May 26 05:24:34 CEST 2017 on sn-devel-144 (cherry picked from commit ade535371b86294c12ca3f7eb98d8ef7ecd29caa) --- 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 | 40 ++++++++++++++++++++++++++++++++++ 4 files changed, 129 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 0000000..5912e65 --- /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 <