Blame SOURCES/009-crm_resource-messages.patch

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