Skip to content

Commit

Permalink
Feature: crmadmin: tweaks
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
oalbrigt committed Feb 16, 2021
1 parent a4892cc commit c26c995
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 93 deletions.
2 changes: 1 addition & 1 deletion cts/patterns.py
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions include/pcmki/pcmki_cluster_queries.h
Expand Up @@ -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);
46 changes: 0 additions & 46 deletions lib/pacemaker/pcmk_cluster_queries.c
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions lib/pacemaker/pcmk_output.c
Expand Up @@ -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);
}
Expand Down
66 changes: 27 additions & 39 deletions tools/crmadmin.c
Expand Up @@ -25,9 +25,7 @@

static enum {
cmd_none,
cmd_shutdown,
cmd_health,
cmd_elect_dc,
cmd_whois_dc,
cmd_list_nodes,
cmd_pacemakerd_health,
Expand All @@ -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
Expand All @@ -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 }
Expand All @@ -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) {
Expand All @@ -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),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c26c995

Please sign in to comment.