dff8d99
From: "Gao,Yan" <ygao@suse.com>
dff8d99
Date: Wed, 30 Sep 2015 16:59:43 +0200
dff8d99
Subject: [PATCH] Fix: crm_resource: Correctly delete existing meta attributes
dff8d99
 regardless of their position in the heirarchy
dff8d99
dff8d99
Use the same logics as "--set-parameter" for "--delete-parameter".
dff8d99
dff8d99
(cherry picked from commit cdee10c7310ab433b006126bc087f6b8dff3843e)
dff8d99
dff8d99
Conflicts:
dff8d99
	tools/crm_resource_runtime.c
dff8d99
---
dff8d99
 tools/crm_resource_runtime.c | 109 ++++++++++++++++++++++---------------------
dff8d99
 1 file changed, 55 insertions(+), 54 deletions(-)
dff8d99
dff8d99
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
dff8d99
index 878fd0b..2d51e88 100644
dff8d99
--- a/tools/crm_resource_runtime.c
dff8d99
+++ b/tools/crm_resource_runtime.c
dff8d99
@@ -190,47 +190,20 @@ find_resource_attr(cib_t * the_cib, const char *attr, const char *rsc, const cha
dff8d99
     return rc;
dff8d99
 }
dff8d99
 
dff8d99
-int
dff8d99
-cli_resource_update_attribute(const char *rsc_id, const char *attr_set, const char *attr_id,
dff8d99
-                  const char *attr_name, const char *attr_value, bool recursive,
dff8d99
-                  cib_t * cib, pe_working_set_t * data_set)
dff8d99
+static resource_t *
dff8d99
+find_matching_attr_resource(resource_t * rsc, const char * rsc_id, const char * attr_set, const char * attr_id,
dff8d99
+                            const char * attr_name, cib_t * cib, const char * cmd)
dff8d99
 {
dff8d99
     int rc = pcmk_ok;
dff8d99
-    static bool need_init = TRUE;
dff8d99
-
dff8d99
     char *lookup_id = NULL;
dff8d99
     char *local_attr_id = NULL;
dff8d99
-    char *local_attr_set = NULL;
dff8d99
-
dff8d99
-    xmlNode *xml_top = NULL;
dff8d99
-    xmlNode *xml_obj = NULL;
dff8d99
-
dff8d99
-    bool use_attributes_tag = FALSE;
dff8d99
-    resource_t *rsc = find_rsc_or_clone(rsc_id, data_set);
dff8d99
-
dff8d99
-    if (rsc == NULL) {
dff8d99
-        return -ENXIO;
dff8d99
-    }
dff8d99
-
dff8d99
-    if (safe_str_eq(attr_set_type, XML_TAG_ATTR_SETS)) {
dff8d99
-       if (do_force == FALSE) {
dff8d99
-            rc = find_resource_attr(cib, XML_ATTR_ID, uber_parent(rsc)->id,
dff8d99
-                                    XML_TAG_META_SETS, attr_set, attr_id,
dff8d99
-                                    attr_name, &local_attr_id);
dff8d99
-            if (rc == pcmk_ok && BE_QUIET == FALSE) {
dff8d99
-                printf("WARNING: There is already a meta attribute for '%s' called '%s' (id=%s)\n",
dff8d99
-                       uber_parent(rsc)->id, attr_name, local_attr_id);
dff8d99
-                printf("         Delete '%s' first or use --force to override\n", local_attr_id);
dff8d99
-            }
dff8d99
-            return -ENOTUNIQ;
dff8d99
-        }
dff8d99
 
dff8d99
-    } else if(rsc->parent && do_force == FALSE) {
dff8d99
+    if(rsc->parent && do_force == FALSE) {
dff8d99
 
dff8d99
         switch(rsc->parent->variant) {
dff8d99
             case pe_group:
dff8d99
                 if (BE_QUIET == FALSE) {
dff8d99
-                    printf("Updating '%s' for '%s' will not apply to its peers in '%s'\n", attr_name, rsc_id, rsc->parent->id);
dff8d99
+                    printf("Performing %s of '%s' for '%s' will not apply to its peers in '%s'\n", cmd, attr_name, rsc_id, rsc->parent->id);
dff8d99
                 }
dff8d99
                 break;
dff8d99
             case pe_master:
dff8d99
@@ -242,7 +215,7 @@ cli_resource_update_attribute(const char *rsc_id, const char *attr_set, const ch
dff8d99
                 if(rc != pcmk_ok) {
dff8d99
                     rsc = rsc->parent;
dff8d99
                     if (BE_QUIET == FALSE) {
dff8d99
-                        printf("Updating '%s' on '%s', the parent of '%s'\n", attr_name, rsc->id, rsc_id);
dff8d99
+                        printf("Performing %s of '%s' on '%s', the parent of '%s'\n", cmd, attr_name, rsc->id, rsc_id);
dff8d99
                     }
dff8d99
                 }
dff8d99
                 break;
dff8d99
@@ -251,7 +224,7 @@ cli_resource_update_attribute(const char *rsc_id, const char *attr_set, const ch
dff8d99
         }
dff8d99
 
dff8d99
     } else if (rsc->parent && BE_QUIET == FALSE) {
dff8d99
-        printf("Forcing update of '%s' for '%s' instead of '%s'\n", attr_name, rsc_id, rsc->parent->id);
dff8d99
+        printf("Forcing %s of '%s' for '%s' instead of '%s'\n", cmd, attr_name, rsc_id, rsc->parent->id);
dff8d99
 
dff8d99
     } else if(rsc->parent == NULL && rsc->children) {
dff8d99
         resource_t *child = rsc->children->data;
dff8d99
@@ -263,7 +236,7 @@ cli_resource_update_attribute(const char *rsc_id, const char *attr_set, const ch
dff8d99
             if(rc == pcmk_ok) {
dff8d99
                 rsc = child;
dff8d99
                 if (BE_QUIET == FALSE) {
dff8d99
-                    printf("A value for '%s' already exists in child '%s', updating that instead of '%s'\n", attr_name, lookup_id, rsc_id);
dff8d99
+                    printf("A value for '%s' already exists in child '%s', performing %s on that instead of '%s'\n", attr_name, lookup_id, cmd, rsc_id);
dff8d99
                 }
dff8d99
             }
dff8d99
 
dff8d99
@@ -272,6 +245,51 @@ cli_resource_update_attribute(const char *rsc_id, const char *attr_set, const ch
dff8d99
         }
dff8d99
     }
dff8d99
 
dff8d99
+    return rsc;
dff8d99
+}
dff8d99
+
dff8d99
+int
dff8d99
+cli_resource_update_attribute(const char *rsc_id, const char *attr_set, const char *attr_id,
dff8d99
+                  const char *attr_name, const char *attr_value, bool recursive,
dff8d99
+                  cib_t * cib, pe_working_set_t * data_set)
dff8d99
+{
dff8d99
+    int rc = pcmk_ok;
dff8d99
+    static bool need_init = TRUE;
dff8d99
+
dff8d99
+    char *lookup_id = NULL;
dff8d99
+    char *local_attr_id = NULL;
dff8d99
+    char *local_attr_set = NULL;
dff8d99
+
dff8d99
+    xmlNode *xml_top = NULL;
dff8d99
+    xmlNode *xml_obj = NULL;
dff8d99
+
dff8d99
+    bool use_attributes_tag = FALSE;
dff8d99
+    resource_t *rsc = find_rsc_or_clone(rsc_id, data_set);
dff8d99
+
dff8d99
+    if (rsc == NULL) {
dff8d99
+        return -ENXIO;
dff8d99
+    }
dff8d99
+
dff8d99
+    if (safe_str_eq(attr_set_type, XML_TAG_ATTR_SETS)) {
dff8d99
+        if (do_force == FALSE) {
dff8d99
+            rc = find_resource_attr(cib, XML_ATTR_ID, uber_parent(rsc)->id,
dff8d99
+                                    XML_TAG_META_SETS, attr_set, attr_id,
dff8d99
+                                    attr_name, &local_attr_id);
dff8d99
+            if (rc == pcmk_ok && BE_QUIET == FALSE) {
dff8d99
+                printf("WARNING: There is already a meta attribute for '%s' called '%s' (id=%s)\n",
dff8d99
+                       uber_parent(rsc)->id, attr_name, local_attr_id);
dff8d99
+                printf("         Delete '%s' first or use --force to override\n", local_attr_id);
dff8d99
+            }
dff8d99
+            free(local_attr_id);
dff8d99
+            if (rc == pcmk_ok) {
dff8d99
+                return -ENOTUNIQ;
dff8d99
+            }
dff8d99
+        }
dff8d99
+
dff8d99
+    } else {
dff8d99
+        rsc = find_matching_attr_resource(rsc, rsc_id, attr_set, attr_id, attr_name, cib, "update");
dff8d99
+    }
dff8d99
+
dff8d99
     lookup_id = clone_strip(rsc->id); /* Could be a cloned group! */
dff8d99
     rc = find_resource_attr(cib, XML_ATTR_ID, lookup_id, attr_set_type, attr_set, attr_id, attr_name,
dff8d99
                             &local_attr_id);
dff8d99
@@ -401,25 +419,8 @@ cli_resource_delete_attribute(const char *rsc_id, const char *attr_set, const ch
dff8d99
         return -ENXIO;
dff8d99
     }
dff8d99
 
dff8d99
-    if(rsc->parent && safe_str_eq(attr_set_type, XML_TAG_META_SETS)) {
dff8d99
-
dff8d99
-        switch(rsc->parent->variant) {
dff8d99
-            case pe_group:
dff8d99
-                if (BE_QUIET == FALSE) {
dff8d99
-                    printf("Removing '%s' for '%s' will not apply to its peers in '%s'\n", attr_name, rsc_id, rsc->parent->id);
dff8d99
-                }
dff8d99
-                break;
dff8d99
-            case pe_master:
dff8d99
-            case pe_clone:
dff8d99
-                rsc = rsc->parent;
dff8d99
-                if (BE_QUIET == FALSE) {
dff8d99
-                    printf("Removing '%s' from '%s' for '%s'...\n", attr_name, rsc->id, rsc_id);
dff8d99
-                }
dff8d99
-                break;
dff8d99
-            default:
dff8d99
-                break;
dff8d99
-        }
dff8d99
-
dff8d99
+    if(safe_str_eq(attr_set_type, XML_TAG_META_SETS)) {
dff8d99
+        rsc = find_matching_attr_resource(rsc, rsc_id, attr_set, attr_id, attr_name, cib, "delete");
dff8d99
     }
dff8d99
 
dff8d99
     lookup_id = clone_strip(rsc->id);