Blame SOURCES/009-crm_resource-messages.patch

6c49ac
From 5bcab230ad4c647ca78b18bd4a66e30a4bb4417f Mon Sep 17 00:00:00 2001
6c49ac
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
6c49ac
Date: Wed, 16 Jun 2021 11:19:03 +0200
6c49ac
Subject: [PATCH 1/2] Feature: crm_resource: report not supported for --force-*
6c49ac
 w/systemd, upstart, nagios and bundled resources
6c49ac
6c49ac
---
6c49ac
 tools/crm_resource.c         | 21 ++++----------
6c49ac
 tools/crm_resource_runtime.c | 67 +++++++++++++++++++++++++++++---------------
6c49ac
 2 files changed, 51 insertions(+), 37 deletions(-)
6c49ac
6c49ac
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
6c49ac
index 4abdd03..fa7902c 100644
6c49ac
--- a/tools/crm_resource.c
6c49ac
+++ b/tools/crm_resource.c
6c49ac
@@ -660,21 +660,12 @@ attr_set_type_cb(const gchar *option_name, const gchar *optarg, gpointer data, G
6c49ac
 
6c49ac
 gboolean
6c49ac
 class_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error) {
6c49ac
-    if (!(pcmk_get_ra_caps(optarg) & pcmk_ra_cap_params)) {
6c49ac
-        if (!args->quiet) {
6c49ac
-            g_set_error(error, G_OPTION_ERROR, CRM_EX_INVALID_PARAM,
6c49ac
-                        "Standard %s does not support parameters\n", optarg);
6c49ac
-        }
6c49ac
-        return FALSE;
6c49ac
-
6c49ac
-    } else {
6c49ac
-        if (options.v_class != NULL) {
6c49ac
-            free(options.v_class);
6c49ac
-        }
6c49ac
-
6c49ac
-        options.v_class = strdup(optarg);
6c49ac
+    if (options.v_class != NULL) {
6c49ac
+        free(options.v_class);
6c49ac
     }
6c49ac
 
6c49ac
+    options.v_class = strdup(optarg);
6c49ac
+
6c49ac
     options.cmdline_config = TRUE;
6c49ac
     options.require_resource = FALSE;
6c49ac
     return TRUE;
6c49ac
@@ -1422,7 +1413,7 @@ validate_cmdline_config(void)
6c49ac
     } else if (options.rsc_cmd != cmd_execute_agent) {
6c49ac
         g_set_error(&error, PCMK__EXITC_ERROR, CRM_EX_USAGE,
6c49ac
                     "--class, --agent, and --provider can only be used with "
6c49ac
-                    "--validate");
6c49ac
+                    "--validate and --force-*");
6c49ac
 
6c49ac
     // Not all of --class, --agent, and --provider need to be given.  Not all
6c49ac
     // classes support the concept of a provider.  Check that what we were given
6c49ac
@@ -1841,7 +1832,7 @@ main(int argc, char **argv)
6c49ac
             if (options.cmdline_config) {
6c49ac
                 exit_code = cli_resource_execute_from_params(out, NULL,
6c49ac
                     options.v_class, options.v_provider, options.v_agent,
6c49ac
-                    "validate-all", options.cmdline_params,
6c49ac
+                    options.operation, options.cmdline_params,
6c49ac
                     options.override_params, options.timeout_ms,
6c49ac
                     args->verbosity, options.force, options.check_level);
6c49ac
             } else {
6c49ac
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
6c49ac
index fe42e60..59e6df5 100644
6c49ac
--- a/tools/crm_resource_runtime.c
6c49ac
+++ b/tools/crm_resource_runtime.c
6c49ac
@@ -1674,24 +1674,59 @@ wait_till_stable(pcmk__output_t *out, int timeout_ms, cib_t * cib)
6c49ac
     return rc;
6c49ac
 }
6c49ac
 
6c49ac
+static const char *
6c49ac
+get_action(const char *rsc_action) {
6c49ac
+    const char *action = NULL;
6c49ac
+
6c49ac
+    if (pcmk__str_eq(rsc_action, "validate", pcmk__str_casei)) {
6c49ac
+        action = "validate-all";
6c49ac
+
6c49ac
+    } else if (pcmk__str_eq(rsc_action, "force-check", pcmk__str_casei)) {
6c49ac
+        action = "monitor";
6c49ac
+
6c49ac
+    } else if (pcmk__strcase_any_of(rsc_action, "force-start", "force-stop",
6c49ac
+                                    "force-demote", "force-promote", NULL)) {
6c49ac
+        action = rsc_action+6;
6c49ac
+    } else {
6c49ac
+        action = rsc_action;
6c49ac
+    }
6c49ac
+
6c49ac
+    return action;
6c49ac
+}
6c49ac
+
6c49ac
 crm_exit_t
6c49ac
 cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc_name,
6c49ac
                                  const char *rsc_class, const char *rsc_prov,
6c49ac
-                                 const char *rsc_type, const char *action,
6c49ac
+                                 const char *rsc_type, const char *rsc_action,
6c49ac
                                  GHashTable *params, GHashTable *override_hash,
6c49ac
                                  int timeout_ms, int resource_verbose, gboolean force,
6c49ac
                                  int check_level)
6c49ac
 {
6c49ac
+    const char *action = NULL;
6c49ac
     GHashTable *params_copy = NULL;
6c49ac
     crm_exit_t exit_code = CRM_EX_OK;
6c49ac
     svc_action_t *op = NULL;
6c49ac
 
6c49ac
     if (pcmk__str_eq(rsc_class, PCMK_RESOURCE_CLASS_STONITH, pcmk__str_casei)) {
6c49ac
         out->err(out, "Sorry, the %s option doesn't support %s resources yet",
6c49ac
-                 action, rsc_class);
6c49ac
+                 rsc_action, rsc_class);
6c49ac
+        crm_exit(CRM_EX_UNIMPLEMENT_FEATURE);
6c49ac
+    } else if (pcmk__strcase_any_of(rsc_class, PCMK_RESOURCE_CLASS_SYSTEMD,
6c49ac
+                PCMK_RESOURCE_CLASS_UPSTART, PCMK_RESOURCE_CLASS_NAGIOS, NULL)) {
6c49ac
+        out->err(out, "Sorry, the %s option doesn't support %s resources",
6c49ac
+                 rsc_action, rsc_class);
6c49ac
+        crm_exit(CRM_EX_UNIMPLEMENT_FEATURE);
6c49ac
+    } else if (pcmk__str_eq(rsc_class, PCMK_RESOURCE_CLASS_SERVICE,
6c49ac
+                pcmk__str_casei) && !pcmk__str_eq(
6c49ac
+                resources_find_service_class(rsc_name), PCMK_RESOURCE_CLASS_LSB,
6c49ac
+                pcmk__str_casei)) {
6c49ac
+        out->err(out, "Sorry, the %s option doesn't support %s resources",
6c49ac
+                 rsc_action, resources_find_service_class(rsc_name));
6c49ac
         crm_exit(CRM_EX_UNIMPLEMENT_FEATURE);
6c49ac
     }
6c49ac
 
6c49ac
+    action = get_action(rsc_action);
6c49ac
+
6c49ac
     /* If no timeout was provided, grab the default. */
6c49ac
     if (timeout_ms == 0) {
6c49ac
         timeout_ms = crm_get_msec(CRM_DEFAULT_OP_TIMEOUT_S);
6c49ac
@@ -1766,7 +1801,7 @@ cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc_name,
6c49ac
         exit_code = op->rc;
6c49ac
 
6c49ac
         out->message(out, "resource-agent-action", resource_verbose, rsc_class,
6c49ac
-                     rsc_prov, rsc_type, rsc_name, action, override_hash, op->rc,
6c49ac
+                     rsc_prov, rsc_type, rsc_name, rsc_action, override_hash, op->rc,
6c49ac
                      op->status, op->stdout_data, op->stderr_data);
6c49ac
     } else {
6c49ac
         exit_code = op->rc == 0 ? CRM_EX_ERROR : op->rc;
6c49ac
@@ -1790,27 +1825,15 @@ cli_resource_execute(pe_resource_t *rsc, const char *requested_name,
6c49ac
     const char *rtype = NULL;
6c49ac
     const char *rprov = NULL;
6c49ac
     const char *rclass = NULL;
6c49ac
-    const char *action = NULL;
6c49ac
     GHashTable *params = NULL;
6c49ac
 
6c49ac
-    if (pcmk__str_eq(rsc_action, "validate", pcmk__str_casei)) {
6c49ac
-        action = "validate-all";
6c49ac
-
6c49ac
-    } else if (pcmk__str_eq(rsc_action, "force-check", pcmk__str_casei)) {
6c49ac
-        action = "monitor";
6c49ac
-
6c49ac
-    } else if (pcmk__str_eq(rsc_action, "force-stop", pcmk__str_casei)) {
6c49ac
-        action = rsc_action+6;
6c49ac
-
6c49ac
-    } else if (pcmk__strcase_any_of(rsc_action, "force-start", "force-demote",
6c49ac
+    if (pcmk__strcase_any_of(rsc_action, "force-start", "force-demote",
6c49ac
                                     "force-promote", NULL)) {
6c49ac
-        action = rsc_action+6;
6c49ac
-
6c49ac
         if(pe_rsc_is_clone(rsc)) {
6c49ac
             GList *nodes = cli_resource_search(rsc, requested_name, data_set);
6c49ac
             if(nodes != NULL && force == FALSE) {
6c49ac
                 out->err(out, "It is not safe to %s %s here: the cluster claims it is already active",
6c49ac
-                         action, rsc->id);
6c49ac
+                         rsc_action, rsc->id);
6c49ac
                 out->err(out, "Try setting target-role=Stopped first or specifying "
6c49ac
                          "the force option");
6c49ac
                 return CRM_EX_UNSAFE;
6c49ac
@@ -1818,9 +1841,6 @@ cli_resource_execute(pe_resource_t *rsc, const char *requested_name,
6c49ac
 
6c49ac
             g_list_free_full(nodes, free);
6c49ac
         }
6c49ac
-
6c49ac
-    } else {
6c49ac
-        action = rsc_action;
6c49ac
     }
6c49ac
 
6c49ac
     if(pe_rsc_is_clone(rsc)) {
6c49ac
@@ -1831,6 +1851,9 @@ cli_resource_execute(pe_resource_t *rsc, const char *requested_name,
6c49ac
     if(rsc->variant == pe_group) {
6c49ac
         out->err(out, "Sorry, the %s option doesn't support group resources", rsc_action);
6c49ac
         return CRM_EX_UNIMPLEMENT_FEATURE;
6c49ac
+    } else if (rsc->variant == pe_container || pe_rsc_is_bundled(rsc)) {
6c49ac
+        out->err(out, "Sorry, the %s option doesn't support bundled resources", rsc_action);
6c49ac
+        return CRM_EX_UNIMPLEMENT_FEATURE;
6c49ac
     }
6c49ac
 
6c49ac
     rclass = crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS);
6c49ac
@@ -1841,12 +1864,12 @@ cli_resource_execute(pe_resource_t *rsc, const char *requested_name,
6c49ac
                                       data_set);
6c49ac
 
6c49ac
     if (timeout_ms == 0) {
6c49ac
-        timeout_ms = pe_get_configured_timeout(rsc, action, data_set);
6c49ac
+        timeout_ms = pe_get_configured_timeout(rsc, get_action(rsc_action), data_set);
6c49ac
     }
6c49ac
 
6c49ac
     rid = pe_rsc_is_anon_clone(rsc->parent)? requested_name : rsc->id;
6c49ac
 
6c49ac
-    exit_code = cli_resource_execute_from_params(out, rid, rclass, rprov, rtype, action,
6c49ac
+    exit_code = cli_resource_execute_from_params(out, rid, rclass, rprov, rtype, rsc_action,
6c49ac
                                                  params, override_hash, timeout_ms,
6c49ac
                                                  resource_verbose, force, check_level);
6c49ac
     return exit_code;
6c49ac
-- 
6c49ac
1.8.3.1
6c49ac
6c49ac
6c49ac
From 289cd231186755d99c1262eb9f968dc852409588 Mon Sep 17 00:00:00 2001
6c49ac
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
6c49ac
Date: Fri, 16 Jul 2021 13:20:55 +0200
6c49ac
Subject: [PATCH 2/2] Refactor: crm_resource: remove duplicate Overriding
6c49ac
 message that's handled elsewhere
6c49ac
6c49ac
---
6c49ac
 tools/crm_resource_runtime.c | 2 --
6c49ac
 1 file changed, 2 deletions(-)
6c49ac
6c49ac
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
6c49ac
index 59e6df5..ce037c5 100644
6c49ac
--- a/tools/crm_resource_runtime.c
6c49ac
+++ b/tools/crm_resource_runtime.c
6c49ac
@@ -1791,8 +1791,6 @@ cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc_name,
6c49ac
 
6c49ac
         g_hash_table_iter_init(&iter, override_hash);
6c49ac
         while (g_hash_table_iter_next(&iter, (gpointer *) & name, (gpointer *) & value)) {
6c49ac
-            out->info(out, "Overriding the cluster configuration for '%s' with '%s' = '%s'",
6c49ac
-                      rsc_name, name, value);
6c49ac
             g_hash_table_replace(op->params, strdup(name), strdup(value));
6c49ac
         }
6c49ac
     }
6c49ac
-- 
6c49ac
1.8.3.1
6c49ac