File pacemaker-tools-clean-up-dry-run-correctly.patch of Package pacemaker.8397

commit f0c29a2301c5feeb9d3fbd576bc5161ec71acf9f
Author: Ken Gaillot <kgaillot@redhat.com>
Date:   Thu Nov 2 15:02:02 2017 -0500

    Low: tools: implement clean-up dry-run correctly
    
    047a6611 implemented a dry-run for clean-ups using cli_resource_delete(), but
    overlooked that crmd_channel is independently needed by atomic-attrd
    host clean-ups and --fail.

Index: pacemaker/tools/crm_resource.c
===================================================================
--- pacemaker.orig/tools/crm_resource.c
+++ pacemaker/tools/crm_resource.c
@@ -399,6 +399,7 @@ main(int argc, char **argv)
     const char *prop_set = NULL;
     const char *rsc_long_cmd = NULL;
     const char *longname = NULL;
+    const char *cib_file = getenv("CIB_file");
     GHashTable *override_params = NULL;
 
     char *xml_file = NULL;
@@ -597,7 +598,9 @@ main(int argc, char **argv)
             case 'P':
                 crm_log_args(argc, argv);
                 require_resource = FALSE;
-                require_crmd = TRUE;
+                if (cib_file == NULL) {
+                    require_crmd = TRUE;
+                }
                 rsc_cmd = 'C';
                 break;
 
@@ -763,7 +766,7 @@ main(int argc, char **argv)
     }
 
     /* Establish a connection to the CRMd if needed */
-    if (getenv("CIB_file") == NULL && require_crmd) {
+    if (require_crmd) {
         xmlNode *xml = NULL;
         mainloop_io_t *source =
             mainloop_add_ipc_client(CRM_SYSTEM_CRMD, G_PRIORITY_DEFAULT, 0, NULL, &crm_callbacks);
@@ -1128,6 +1131,13 @@ main(int argc, char **argv)
             }
         }
 
+        if (crmd_channel == NULL) {
+            printf("Dry run: skipping clean-up of %s due to CIB_file\n",
+                   host_uname? host_uname : "all nodes");
+            rc = pcmk_ok;
+            goto bail;
+        }
+
         msg_data = create_xml_node(NULL, "crm-resource-reprobe-op");
         crm_xml_add(msg_data, XML_LRM_ATTR_TARGET, host_uname);
         if (safe_str_neq(router_node, host_uname)) {
Index: pacemaker/tools/crm_resource_runtime.c
===================================================================
--- pacemaker.orig/tools/crm_resource_runtime.c
+++ pacemaker/tools/crm_resource_runtime.c
@@ -639,8 +639,9 @@ cli_resource_delete(cib_t *cib_conn, crm
         return pcmk_ok;
     }
 
-    if(getenv("CIB_file") != NULL) {
-        printf("Would have cleaned up %s on %s\n", rsc->id, host_uname);
+    if (crmd_channel == NULL) {
+        printf("Dry run: skipping clean-up of %s on %s due to CIB_file\n",
+               rsc->id, host_uname);
         return rc;
     }
 
openSUSE Build Service is sponsored by