Blob Blame History Raw
From 3905e7eac11298fc20efd567a773666f948edf61 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Mon, 3 May 2021 11:19:04 -0400
Subject: [PATCH 1/2] Feature: tools: Add OCF_CHECK_LEVEL to crm_resource
 environment.

If --validate= or --force-check= are given with a level, pass that along
as OCF_CHECK_LEVEL.  This argument is optional, and if no value is given
then the environment variable will not be set and whatever's the default
on the resource agent will be used.

See: rhbz#1955792.
---
 tools/crm_resource.c         | 29 +++++++++++++++++++++--------
 tools/crm_resource.h         |  4 ++--
 tools/crm_resource_runtime.c | 13 ++++++++++---
 3 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/tools/crm_resource.c b/tools/crm_resource.c
index 45db2b2..6ca96f8 100644
--- a/tools/crm_resource.c
+++ b/tools/crm_resource.c
@@ -100,6 +100,7 @@ struct {
     int timeout_ms;               // Parsed from --timeout value
     char *agent_spec;             // Standard and/or provider and/or agent
     gchar *xml_file;              // Value of (deprecated) --xml-file
+    int check_level;              // Optional value of --validate or --force-check
 
     // Resource configuration specified via command-line arguments
     gboolean cmdline_config;      // Resource configuration was via arguments
@@ -113,6 +114,7 @@ struct {
     GHashTable *override_params;  // Resource parameter values that override config
 } options = {
     .attr_set_type = XML_TAG_ATTR_SETS,
+    .check_level = -1,
     .cib_options = cib_sync_call,
     .require_cib = TRUE,
     .require_dataset = TRUE,
@@ -402,14 +404,15 @@ static GOptionEntry query_entries[] = {
 };
 
 static GOptionEntry command_entries[] = {
-    { "validate", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+    { "validate", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
       validate_or_force_cb,
       "Validate resource configuration by calling agent's validate-all\n"
       INDENT "action. The configuration may be specified either by giving an\n"
       INDENT "existing resource name with -r, or by specifying --class,\n"
       INDENT "--agent, and --provider arguments, along with any number of\n"
-      INDENT "--option arguments.",
-      NULL },
+      INDENT "--option arguments. An optional LEVEL argument can be given\n"
+      INDENT "to control the level of checking performed.",
+      "LEVEL" },
     { "cleanup", 'C', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, cleanup_refresh_cb,
       "If resource has any past failures, clear its history and fail\n"
       INDENT "count. Optionally filtered by --resource, --node, --operation\n"
@@ -546,11 +549,12 @@ static GOptionEntry advanced_entries[] = {
       INDENT "the cluster believes the resource is a clone instance already\n"
       INDENT "running on the local node.",
       NULL },
-    { "force-check", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+    { "force-check", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
       validate_or_force_cb,
       "(Advanced) Bypass the cluster and check the state of a resource on\n"
-      INDENT "the local node",
-      NULL },
+      INDENT "the local node. An optional LEVEL argument can be given\n"
+      INDENT "to control the level of checking performed.",
+      "LEVEL" },
 
     { NULL }
 };
@@ -910,6 +914,15 @@ validate_or_force_cb(const gchar *option_name, const gchar *optarg,
     if (options.override_params == NULL) {
         options.override_params = pcmk__strkey_table(free, free);
     }
+
+    if (optarg != NULL) {
+        if (pcmk__scan_min_int(optarg, &options.check_level, 0) != pcmk_rc_ok) {
+            g_set_error(error, G_OPTION_ERROR, CRM_EX_INVALID_PARAM,
+                        "Invalid check level setting: %s", optarg);
+            return FALSE;
+        }
+    }
+
     return TRUE;
 }
 
@@ -1826,12 +1839,12 @@ main(int argc, char **argv)
                     options.v_class, options.v_provider, options.v_agent,
                     "validate-all", options.cmdline_params,
                     options.override_params, options.timeout_ms,
-                    args->verbosity, options.force);
+                    args->verbosity, options.force, options.check_level);
             } else {
                 exit_code = cli_resource_execute(rsc, options.rsc_id,
                     options.operation, options.override_params,
                     options.timeout_ms, cib_conn, data_set,
-                    args->verbosity, options.force);
+                    args->verbosity, options.force, options.check_level);
             }
             goto done;
 
diff --git a/tools/crm_resource.h b/tools/crm_resource.h
index 3560377..5ab10d6 100644
--- a/tools/crm_resource.h
+++ b/tools/crm_resource.h
@@ -88,11 +88,11 @@ crm_exit_t cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc
                                             const char *rsc_type, const char *rsc_action,
                                             GHashTable *params, GHashTable *override_hash,
                                             int timeout_ms, int resource_verbose,
-                                            gboolean force);
+                                            gboolean force, int check_level);
 crm_exit_t cli_resource_execute(pe_resource_t *rsc, const char *requested_name,
                                 const char *rsc_action, GHashTable *override_hash,
                                 int timeout_ms, cib_t *cib, pe_working_set_t *data_set,
-                                int resource_verbose, gboolean force);
+                                int resource_verbose, gboolean force, int check_level);
 
 int cli_resource_update_attribute(pe_resource_t *rsc, const char *requested_name,
                                   const char *attr_set, const char *attr_set_type,
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
index fe0ec98..bde83b6 100644
--- a/tools/crm_resource_runtime.c
+++ b/tools/crm_resource_runtime.c
@@ -1679,7 +1679,8 @@ cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc_name,
                                  const char *rsc_class, const char *rsc_prov,
                                  const char *rsc_type, const char *action,
                                  GHashTable *params, GHashTable *override_hash,
-                                 int timeout_ms, int resource_verbose, gboolean force)
+                                 int timeout_ms, int resource_verbose, gboolean force,
+                                 int check_level)
 {
     GHashTable *params_copy = NULL;
     crm_exit_t exit_code = CRM_EX_OK;
@@ -1703,6 +1704,12 @@ cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc_name,
     /* add crm_feature_set env needed by some resource agents */
     g_hash_table_insert(params, strdup(XML_ATTR_CRM_VERSION), strdup(CRM_FEATURE_SET));
 
+    if (check_level >= 0) {
+        char *level = crm_strdup_printf("%d", check_level);
+        setenv("OCF_CHECK_LEVEL", level, 1);
+        free(level);
+    }
+
     /* resources_action_create frees the params hash table it's passed, but we
      * may need to reuse it in a second call to resources_action_create.  Thus
      * we'll make a copy here so that gets freed and the original remains for
@@ -1790,7 +1797,7 @@ crm_exit_t
 cli_resource_execute(pe_resource_t *rsc, const char *requested_name,
                      const char *rsc_action, GHashTable *override_hash,
                      int timeout_ms, cib_t * cib, pe_working_set_t *data_set,
-                     int resource_verbose, gboolean force)
+                     int resource_verbose, gboolean force, int check_level)
 {
     pcmk__output_t *out = data_set->priv;
     crm_exit_t exit_code = CRM_EX_OK;
@@ -1856,7 +1863,7 @@ cli_resource_execute(pe_resource_t *rsc, const char *requested_name,
 
     exit_code = cli_resource_execute_from_params(out, rid, rclass, rprov, rtype, action,
                                                  params, override_hash, timeout_ms,
-                                                 resource_verbose, force);
+                                                 resource_verbose, force, check_level);
     return exit_code;
 }
 
-- 
1.8.3.1


From d13ba4bd6defe0dd81fdf8ab39ae5b889513c0c0 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Thu, 20 May 2021 10:59:23 -0400
Subject: [PATCH 2/2] Fix: include: Bump feature set to 3.10.2.

This is for the OCF_CHECK_LEVEL environment variable.

See: rhbz#1955792.
---
 include/crm/crm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/crm/crm.h b/include/crm/crm.h
index 92a98fa..ee52c36 100644
--- a/include/crm/crm.h
+++ b/include/crm/crm.h
@@ -66,7 +66,7 @@ extern "C" {
  * >=3.0.13: Fail counts include operation name and interval
  * >=3.2.0:  DC supports PCMK_LRM_OP_INVALID and PCMK_LRM_OP_NOT_CONNECTED
  */
-#  define CRM_FEATURE_SET		"3.10.1"
+#  define CRM_FEATURE_SET		"3.10.2"
 
 /* Pacemaker's CPG protocols use fixed-width binary fields for the sender and
  * recipient of a CPG message. This imposes an arbitrary limit on cluster node
-- 
1.8.3.1