From c26c9951d863e83126f811ee5b91a174fe0cc991 Mon Sep 17 00:00:00 2001 From: Oyvind Albrigtsen Date: Mon, 15 Feb 2021 14:52:53 +0100 Subject: [PATCH] Feature: crmadmin: tweaks - use seconds for timeout, and support ISO 8601 duration - update cts tests to use seconds - update -S output to "Controller on NODE in state FSA_STATE: HEALTH_STATUS" - add example value for parameters to help text - remove --election/--kill parameters --- cts/patterns.py | 2 +- include/pcmki/pcmki_cluster_queries.h | 4 -- lib/pacemaker/pcmk_cluster_queries.c | 46 ------------------- lib/pacemaker/pcmk_output.c | 6 +-- tools/crmadmin.c | 66 +++++++++++---------------- 5 files changed, 31 insertions(+), 93 deletions(-) diff --git a/cts/patterns.py b/cts/patterns.py index d030b21954a..0ea8ab826d0 100644 --- a/cts/patterns.py +++ b/cts/patterns.py @@ -26,7 +26,7 @@ def __init__(self, name): self.BadNews = [] self.components = {} self.commands = { - "StatusCmd" : "crmadmin -t 60000 -S %s 2>/dev/null", + "StatusCmd" : "crmadmin -t 60 -S %s 2>/dev/null", "CibQuery" : "cibadmin -Ql", "CibAddXml" : "cibadmin --modify -c --xml-text %s", "CibDelXpath" : "cibadmin --delete --xpath %s", diff --git a/include/pcmki/pcmki_cluster_queries.h b/include/pcmki/pcmki_cluster_queries.h index 955eea35a68..e5fbb92c460 100644 --- a/include/pcmki/pcmki_cluster_queries.h +++ b/include/pcmki/pcmki_cluster_queries.h @@ -9,7 +9,3 @@ int pcmk__controller_status(pcmk__output_t *out, char *dest_node, guint message_ int pcmk__designated_controller(pcmk__output_t *out, guint message_timeout_ms); int pcmk__pacemakerd_status(pcmk__output_t *out, char *ipc_name, guint message_timeout_ms); int pcmk__list_nodes(pcmk__output_t *out, char *node_types, gboolean BASH_EXPORT); - -// remove when parameters removed from tools/crmadmin.c -int pcmk__shutdown_controller(pcmk__output_t *out, char *dest_node); -int pcmk__start_election(pcmk__output_t *out); diff --git a/lib/pacemaker/pcmk_cluster_queries.c b/lib/pacemaker/pcmk_cluster_queries.c index 6e6acdac740..0bb399edaee 100644 --- a/lib/pacemaker/pcmk_cluster_queries.c +++ b/lib/pacemaker/pcmk_cluster_queries.c @@ -497,49 +497,3 @@ pcmk_list_nodes(xmlNodePtr *xml, char *node_types) pcmk__out_epilogue(out, xml, rc); return rc; } - -// remove when parameters removed from tools/crmadmin.c -int -pcmk__shutdown_controller(pcmk__output_t *out, char *dest_node) -{ - data_t data = { - .out = out, - .mainloop = NULL, - .rc = pcmk_rc_ok, - }; - pcmk_ipc_api_t *controld_api = ipc_connect(&data, pcmk_ipc_controld, NULL); - - if (controld_api != NULL) { - int rc = pcmk_controld_api_shutdown(controld_api, dest_node); - if (rc != pcmk_rc_ok) { - out->err(out, "error: Command failed: %s", pcmk_rc_str(rc)); - data.rc = rc; - } - pcmk_free_ipc_api(controld_api); - } - - return data.rc; -} - -int -pcmk__start_election(pcmk__output_t *out) -{ - data_t data = { - .out = out, - .mainloop = NULL, - .rc = pcmk_rc_ok, - }; - pcmk_ipc_api_t *controld_api = ipc_connect(&data, pcmk_ipc_controld, NULL); - - if (controld_api != NULL) { - int rc = pcmk_controld_api_start_election(controld_api); - if (rc != pcmk_rc_ok) { - out->err(out, "error: Command failed: %s", pcmk_rc_str(rc)); - data.rc = rc; - } - - pcmk_free_ipc_api(controld_api); - } - - return data.rc; -} diff --git a/lib/pacemaker/pcmk_output.c b/lib/pacemaker/pcmk_output.c index 655b7239273..db407b920a8 100644 --- a/lib/pacemaker/pcmk_output.c +++ b/lib/pacemaker/pcmk_output.c @@ -376,14 +376,14 @@ PCMK__OUTPUT_ARGS("health", "const char *", "const char *", "const char *", "con static int health_text(pcmk__output_t *out, va_list args) { - const char *sys_from = va_arg(args, const char *); + const char *sys_from G_GNUC_UNUSED = va_arg(args, const char *); const char *host_from = va_arg(args, const char *); const char *fsa_state = va_arg(args, const char *); const char *result = va_arg(args, const char *); if (!out->is_quiet(out)) { - out->info(out, "Status of %s@%s: %s (%s)", crm_str(sys_from), - crm_str(host_from), crm_str(fsa_state), crm_str(result)); + out->info(out, "Controller on %s in state %s: %s", crm_str(host_from), + crm_str(fsa_state), crm_str(result)); } else if (fsa_state != NULL) { out->info(out, "%s", fsa_state); } diff --git a/tools/crmadmin.c b/tools/crmadmin.c index 04d35f41d95..e754a8acca8 100644 --- a/tools/crmadmin.c +++ b/tools/crmadmin.c @@ -25,9 +25,7 @@ static enum { cmd_none, - cmd_shutdown, cmd_health, - cmd_elect_dc, cmd_whois_dc, cmd_list_nodes, cmd_pacemakerd_health, @@ -50,36 +48,28 @@ gboolean command_cb(const gchar *option_name, const gchar *optarg, gpointer data static GOptionEntry command_options[] = { { "status", 'S', 0, G_OPTION_ARG_CALLBACK, command_cb, "Display the status of the specified node." - "\n Result is state of node's internal finite state" - "\n machine, which can be useful for debugging", - NULL + "\n Result is state of node's internal finite state" + "\n machine, which can be useful for debugging", + "NODE" }, { "pacemakerd", 'P', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb, "Display the status of local pacemakerd." - "\n Result is the state of the sub-daemons watched" - "\n by pacemakerd.", + "\n Result is the state of the sub-daemons watched" + "\n by pacemakerd.", NULL }, { "dc_lookup", 'D', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb, "Display the uname of the node co-ordinating the cluster." - "\n This is an internal detail rarely useful to" - "\n administrators except when deciding on which" - "\n node to examine the logs.", + "\n This is an internal detail rarely useful to" + "\n administrators except when deciding on which" + "\n node to examine the logs.", NULL }, { "nodes", 'N', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, command_cb, "Display the uname of all member nodes [optionally filtered by type (comma-separated)]" - "\n Types: all (default), cluster, guest, remote", + "\n Types: all (default), cluster, guest, remote", "TYPE" }, - { "election", 'E', G_OPTION_FLAG_HIDDEN|G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb, - "(Advanced) Start an election for the cluster co-ordinator", - NULL - }, - { "kill", 'K', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, command_cb, - "(Advanced) Stop controller (not rest of cluster stack) on specified node", - NULL - }, { "health", 'H', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &options.health, NULL, NULL @@ -89,18 +79,18 @@ static GOptionEntry command_options[] = { }; static GOptionEntry additional_options[] = { - { "timeout", 't', 0, G_OPTION_ARG_INT, &options.timeout, - "Time (in milliseconds) to wait before declaring the" - "\n operation failed", - NULL + { "timeout", 't', 0, G_OPTION_ARG_CALLBACK, command_cb, + "Time to wait before declaring the operation" + "\n failed", + "TIMESPEC" }, { "bash-export", 'B', 0, G_OPTION_ARG_NONE, &options.BASH_EXPORT, "Display nodes as shell commands of the form 'export uname=uuid'" - "\n (valid with -N/--nodes)", + "\n (valid with -N/--nodes)", }, { "ipc-name", 'i', 0, G_OPTION_ARG_STRING, &options.ipc_name, "Name to use for ipc instead of 'crmadmin' (with -P/--pacemakerd).", - NULL + "NAME" }, { NULL } @@ -126,13 +116,12 @@ command_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError command = cmd_list_nodes; } - if (!strcmp(option_name, "--election") || !strcmp(option_name, "-E")) { - command = cmd_elect_dc; - } - - if (!strcmp(option_name, "--kill") || !strcmp(option_name, "-K")) { - command = cmd_shutdown; - crm_trace("Option %c => %s", 'K', optarg); + if (!strcmp(option_name, "--timeout") || !strcmp(option_name, "-t")) { + options.timeout = crm_parse_interval_spec(optarg); + if (errno == EINVAL) { + return FALSE; + } + return TRUE; } if (optarg) { @@ -155,7 +144,12 @@ static GOptionContext * build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { GOptionContext *context = NULL; - const char *description = "Report bugs to users@clusterlabs.org"; + const char *description = "Notes:\n\n" + "Time Specification:\n\n" + "The TIMESPEC in any command line option can be specified in many different\n" + "formats. It can be just an integer number of seconds, a number plus units\n" + "(ms/msec/us/usec/s/sec/m/min/h/hr), or an ISO 8601 period specification.\n\n" + "Report bugs to users@clusterlabs.org"; GOptionEntry extra_prog_entries[] = { { "quiet", 'q', 0, G_OPTION_ARG_NONE, &(args->quiet), @@ -257,12 +251,6 @@ main(int argc, char **argv) case cmd_whois_dc: rc = pcmk__designated_controller(out, options.timeout); break; - case cmd_shutdown: - rc = pcmk__shutdown_controller(out, options.optarg); - break; - case cmd_elect_dc: - rc = pcmk__start_election(out); - break; case cmd_none: rc = pcmk_rc_error; break;