Blame SOURCES/bz1346852-01-fix-bad-request-when-resource-removal-t.patch

15f218
From 4949b387cbec0b79976ca87fbde41e441c21c197 Mon Sep 17 00:00:00 2001
15f218
From: Ondrej Mular <omular@redhat.com>
15f218
Date: Mon, 27 Jun 2016 11:49:43 +0200
15f218
Subject: [PATCH] bz1346852-01-fix bad request when resource removal takes
15f218
 longer than pcs expects
15f218
15f218
---
15f218
 pcs/cluster.py          | 19 +++++++++++--
15f218
 pcs/pcs.8               |  4 +--
15f218
 pcs/resource.py         |  3 ++-
15f218
 pcs/settings_default.py |  1 +
15f218
 pcs/usage.py            |  5 ++--
15f218
 pcsd/remote.rb          | 71 ++++++++++++++++++++++++++++++++++++++++++-------
15f218
 pcsd/views/main.erb     | 13 ++++++---
15f218
 pcsd/views/nodes.erb    | 14 +++++-----
15f218
 8 files changed, 102 insertions(+), 28 deletions(-)
15f218
15f218
diff --git a/pcs/cluster.py b/pcs/cluster.py
15f218
index 988ab75..9d4798c 100644
15f218
--- a/pcs/cluster.py
15f218
+++ b/pcs/cluster.py
15f218
@@ -1171,6 +1171,9 @@ def cluster_push(argv):
15f218
 
15f218
     filename = None
15f218
     scope = None
15f218
+    timeout = None
15f218
+    if "--wait" in utils.pcs_options:
15f218
+        timeout = utils.validate_wait_get_timeout()
15f218
     for arg in argv:
15f218
         if "=" not in arg:
15f218
             filename = arg
15f218
@@ -1206,8 +1209,20 @@ def cluster_push(argv):
15f218
     output, retval = utils.run(command)
15f218
     if retval != 0:
15f218
         utils.err("unable to push cib\n" + output)
15f218
-    else:
15f218
-        print("CIB updated")
15f218
+    print("CIB updated")
15f218
+    if "--wait" not in utils.pcs_options:
15f218
+        return
15f218
+    cmd = ["crm_resource", "--wait"]
15f218
+    if timeout:
15f218
+        cmd.extend(["--timeout", timeout])
15f218
+    output, retval = utils.run(cmd)
15f218
+    if retval != 0:
15f218
+        msg = []
15f218
+        if retval == settings.pacemaker_wait_timeout_status:
15f218
+            msg.append("waiting timeout")
15f218
+        if output:
15f218
+            msg.append("\n" + output)
15f218
+        utils.err("\n".join(msg).strip())
15f218
 
15f218
 def cluster_edit(argv):
15f218
     if 'EDITOR' in os.environ:
15f218
diff --git a/pcs/pcs.8 b/pcs/pcs.8
15f218
index a72a9bd..949d918 100644
15f218
--- a/pcs/pcs.8
15f218
+++ b/pcs/pcs.8
15f218
@@ -259,8 +259,8 @@ Sync corosync configuration to all nodes found from current corosync.conf file (
15f218
 cib [filename] [scope=<scope> | \fB\-\-config\fR]
15f218
 Get the raw xml from the CIB (Cluster Information Base).  If a filename is provided, we save the CIB to that file, otherwise the CIB is printed.  Specify scope to get a specific section of the CIB.  Valid values of the scope are: configuration, nodes, resources, constraints, crm_config, rsc_defaults, op_defaults, status.  \fB\-\-config\fR is the same as scope=configuration.  Do not specify a scope if you want to edit the saved CIB using pcs (pcs -f <command>).
15f218
 .TP
15f218
-cib-push <filename> [scope=<scope> | \fB\-\-config\fR]
15f218
-Push the raw xml from <filename> to the CIB (Cluster Information Base).  You can obtain the CIB by running the 'pcs cluster cib' command, which is recommended first step when you want to perform desired modifications (pcs \fB\-f\fR <command>) for the one-off push.  Specify scope to push a specific section of the CIB.  Valid values of the scope are: configuration, nodes, resources, constraints, crm_config, rsc_defaults, op_defaults.  \fB\-\-config\fR is the same as scope=configuration.  Use of \fB\-\-config\fR is recommended.  Do not specify a scope if you need to push the whole CIB or be warned in the case of outdated CIB.  WARNING: the selected scope of the CIB will be overwritten by the current content of the specified file.
15f218
+cib-push <filename> [scope=<scope> | \fB\-\-config\fR] [\fB\-\-wait\fR[=<n>]]
15f218
+Push the raw xml from <filename> to the CIB (Cluster Information Base).  You can obtain the CIB by running the 'pcs cluster cib' command, which is recommended first step when you want to perform desired modifications (pcs \fB\-f\fR <command>) for the one-off push.  Specify scope to push a specific section of the CIB.  Valid values of the scope are: configuration, nodes, resources, constraints, crm_config, rsc_defaults, op_defaults.  \fB\-\-config\fR is the same as scope=configuration.  Use of \fB\-\-config\fR is recommended.  Do not specify a scope if you need to push the whole CIB or be warned in the case of outdated CIB.  If --wait is specified wait up to 'n' seconds for changes to be applied.  WARNING: the selected scope of the CIB will be overwritten by the current content of the specified file.
15f218
 .TP
15f218
 cib\-upgrade
15f218
 Upgrade the CIB to conform to the latest version of the document schema.
15f218
diff --git a/pcs/resource.py b/pcs/resource.py
15f218
index 284bdb2..9384a21 100644
15f218
--- a/pcs/resource.py
15f218
+++ b/pcs/resource.py
15f218
@@ -21,6 +21,8 @@ from pcs import (
15f218
     constraint,
15f218
     settings,
15f218
 )
15f218
+from pcs.settings import pacemaker_wait_timeout_status as \
15f218
+    PACEMAKER_WAIT_TIMEOUT_STATUS
15f218
 import pcs.lib.cib.acl as lib_acl
15f218
 import pcs.lib.pacemaker as lib_pacemaker
15f218
 from pcs.lib.external import get_systemd_services
15f218
@@ -31,7 +33,6 @@ from pcs.lib.pacemaker_values import timeout_to_seconds
15f218
 import pcs.lib.resource_agent as lib_ra
15f218
 
15f218
 
15f218
-PACEMAKER_WAIT_TIMEOUT_STATUS = 62
15f218
 RESOURCE_RELOCATE_CONSTRAINT_PREFIX = "pcs-relocate-"
15f218
 
15f218
 def resource_cmd(argv):
15f218
diff --git a/pcs/settings_default.py b/pcs/settings_default.py
15f218
index 9d44918..15421fd 100644
15f218
--- a/pcs/settings_default.py
15f218
+++ b/pcs/settings_default.py
15f218
@@ -40,3 +40,4 @@ ocf_resources = os.path.join(ocf_root, "resource.d/")
15f218
 nagios_metadata_path = "/usr/share/pacemaker/nagios/plugins-metadata/"
15f218
 sbd_watchdog_default = "/dev/watchdog"
15f218
 sbd_config = "/etc/sysconfig/sbd"
15f218
+pacemaker_wait_timeout_status = 62
15f218
diff --git a/pcs/usage.py b/pcs/usage.py
15f218
index 42e03e6..542f806 100644
15f218
--- a/pcs/usage.py
15f218
+++ b/pcs/usage.py
15f218
@@ -653,7 +653,7 @@ Commands:
15f218
         scope=configuration.  Do not specify a scope if you want to edit
15f218
         the saved CIB using pcs (pcs -f <command>).
15f218
 
15f218
-    cib-push <filename> [scope=<scope> | --config]
15f218
+    cib-push <filename> [scope=<scope> | --config] [--wait[=<n>]]
15f218
         Push the raw xml from <filename> to the CIB (Cluster Information Base).
15f218
         You can obtain the CIB by running the 'pcs cluster cib' command, which
15f218
         is recommended first step when you want to perform desired
15f218
@@ -663,7 +663,8 @@ Commands:
15f218
         crm_config, rsc_defaults, op_defaults.  --config is the same as
15f218
         scope=configuration.  Use of --config is recommended.  Do not specify
15f218
         a scope if you need to push the whole CIB or be warned in the case
15f218
-        of outdated CIB.
15f218
+        of outdated CIB. If --wait is specified wait up to 'n' seconds for
15f218
+        changes to be applied.
15f218
         WARNING: the selected scope of the CIB will be overwritten by the
15f218
         current content of the specified file.
15f218
 
15f218
diff --git a/pcsd/remote.rb b/pcsd/remote.rb
15f218
index 0b2dc61..b1e00fa 100644
15f218
--- a/pcsd/remote.rb
15f218
+++ b/pcsd/remote.rb
15f218
@@ -5,6 +5,7 @@ require 'set'
15f218
 require 'timeout'
15f218
 require 'rexml/document'
15f218
 require 'base64'
15f218
+require 'tempfile'
15f218
 
15f218
 require 'pcs.rb'
15f218
 require 'resource.rb'
15f218
@@ -1523,23 +1524,73 @@ def remove_resource(params, request, auth_user)
15f218
     return 403, 'Permission denied'
15f218
   end
15f218
   force = params['force']
15f218
+  user = PCSAuth.getSuperuserAuth()
15f218
   no_error_if_not_exists = params.include?('no_error_if_not_exists')
15f218
-  errors = ""
15f218
-  params.each { |k,v|
15f218
-    if k.index("resid-") == 0
15f218
-      resid = k.gsub('resid-', '')
15f218
-      command = [PCS, 'resource', 'delete', resid]
15f218
-      command << '--force' if force
15f218
-      out, errout, retval = run_cmd(auth_user, *command)
15f218
+  resource_list = []
15f218
+  errors = ''
15f218
+  resource_to_remove = []
15f218
+  params.each { |param,_|
15f218
+    if param.start_with?('resid-')
15f218
+      resource_list << param.split('resid-', 2)[1]
15f218
+    end
15f218
+  }
15f218
+  tmp_file = nil
15f218
+  if force
15f218
+    resource_to_remove = resource_list
15f218
+  else
15f218
+    begin
15f218
+      tmp_file = Tempfile.new('temp_cib')
15f218
+      _, err, retval = run_cmd(user, PCS, 'cluster', 'cib', tmp_file.path)
15f218
       if retval != 0
15f218
-        unless out.index(" does not exist.") != -1 and no_error_if_not_exists
15f218
-          errors += errout.join(' ').strip + "\n"
15f218
+        return [400, 'Unable to stop resource(s).']
15f218
+      end
15f218
+      cmd = [PCS, '-f', tmp_file.path, 'resource', 'disable']
15f218
+      resource_list.each { |resource|
15f218
+        _, err, retval = run_cmd(user, *cmd, resource)
15f218
+        if retval != 0
15f218
+          unless (
15f218
+            err.join('').index('unable to find a resource') != -1 and
15f218
+            no_error_if_not_exists
15f218
+          )
15f218
+            errors += "Unable to stop resource '#{resource}': #{err.join('')}"
15f218
+          end
15f218
+        else
15f218
+          resource_to_remove << resource
15f218
         end
15f218
+      }
15f218
+      _, _, retval = run_cmd(
15f218
+        user, PCS, 'cluster', 'cib-push', tmp_file.path, '--config', '--wait'
15f218
+      )
15f218
+      if retval != 0
15f218
+        return [400, 'Unable to stop resource(s).']
15f218
+      end
15f218
+      errors.strip!
15f218
+      unless errors.empty?
15f218
+        $logger.info("Stopping resource(s) errors:\n#{errors}")
15f218
+        return [400, errors]
15f218
+      end
15f218
+    rescue IOError
15f218
+      return [400, 'Unable to stop resource(s).']
15f218
+    ensure
15f218
+      if tmp_file
15f218
+        tmp_file.close!
15f218
+      end
15f218
+    end
15f218
+  end
15f218
+  resource_to_remove.each { |resource|
15f218
+    cmd = [PCS, 'resource', 'delete', resource]
15f218
+    if force
15f218
+      cmd << '--force'
15f218
+    end
15f218
+    out, err, retval = run_cmd(auth_user, *cmd)
15f218
+    if retval != 0
15f218
+      unless out.index(' does not exist.') != -1 and no_error_if_not_exists
15f218
+        errors += err.join(' ').strip + "\n"
15f218
       end
15f218
     end
15f218
   }
15f218
   errors.strip!
15f218
-  if errors == ""
15f218
+  if errors.empty?
15f218
     return 200
15f218
   else
15f218
     $logger.info("Remove resource errors:\n"+errors)
15f218
diff --git a/pcsd/views/main.erb b/pcsd/views/main.erb
15f218
index b14c327..5461515 100644
15f218
--- a/pcsd/views/main.erb
15f218
+++ b/pcsd/views/main.erb
15f218
@@ -298,14 +298,19 @@
15f218
         {{meta_attributes-table resource=resource}}
15f218
         {{#if utilization_support}}
15f218
           {{#if resource.is_primitive}}
15f218
-            {{utilization-table entity=resource utilization=resource.utilization type="resource"}}
15f218
+            {{utilization-table
15f218
+                entity=resource
15f218
+                utilization=resource.utilization
15f218
+                type="resource"
15f218
+                table_id="resource_utilization_attributes"
15f218
+            }}
15f218
           {{/if}}
15f218
         {{/if}}
15f218
         
15f218
       {{/unless}}
15f218
     
15f218
     {{#if stonith}}
15f218
-      
15f218
+      
15f218
         {{fence-form
15f218
             resource=resource
15f218
             agent=resource.resource_agent
15f218
@@ -314,7 +319,7 @@
15f218
       
15f218
     {{else}}
15f218
     {{#if resource.is_primitive}}
15f218
-      
15f218
+      
15f218
         {{resource-form
15f218
             resource=resource
15f218
             agent=resource.resource_agent
15f218
@@ -725,7 +730,7 @@ Use the 'Add' button to submit the form.">
15f218
       
15f218
         
15f218
             {{action toggleBody}}
15f218
-            id="utilization_attributes"
15f218
+            {{bind-attr id=table_id}}
15f218
             class="datatable_header hover-pointer"
15f218
         >
15f218
           {{#if show_content}}
15f218
diff --git a/pcsd/views/nodes.erb b/pcsd/views/nodes.erb
15f218
index 478e0f6..8fccd25 100644
15f218
--- a/pcsd/views/nodes.erb
15f218
+++ b/pcsd/views/nodes.erb
15f218
@@ -247,9 +247,8 @@
15f218
               
15f218
             
15f218
             
15f218
-              Node Attributes ({{#if Pcs.nodesController.cur_node_attr.length}}{{Pcs.nodesController.cur_node_attr.length}}{{else}}0{{/if}})
15f218
+              Node Attributes ({{#if Pcs.nodesController.cur_node_attr.length}}{{Pcs.nodesController.cur_node_attr.length}}{{else}}0{{/if}})
15f218
               
15f218
-                
15f218
                   
15f218
                     AttributeValueRemove
15f218
                     {{#each attr in Pcs.nodesController.cur_node_attr}}
15f218
@@ -268,14 +267,12 @@
15f218
                       <button type="button" onclick="add_node_attr('#new_node_attr_col');" name="add">Add</button>
15f218
                     
15f218
                   
15f218
-                
15f218
               
15f218
               
15f218
             
15f218
             
15f218
-              Fence Levels ({{#if Pcs.nodesController.cur_node_fence_levels.length}}{{Pcs.nodesController.cur_node_fence_levels.length}}{{else}}0{{/if}})
15f218
+              Fence Levels ({{#if Pcs.nodesController.cur_node_fence_levels.length}}{{Pcs.nodesController.cur_node_fence_levels.length}}{{else}}0{{/if}})
15f218
               
15f218
-                
15f218
                   
15f218
                     LevelFence DevicesRemove
15f218
                     {{#each Pcs.nodesController.cur_node_fence_levels}}
15f218
@@ -301,13 +298,16 @@
15f218
                       <button type="button" onclick="add_remove_fence_level($(this).parent());" name="add">Add</button>
15f218
                     
15f218
                   
15f218
-                
15f218
               
15f218
               
15f218
             
15f218
             {{#if Pcs.nodesController.utilization_support}}
15f218
             
15f218
-            {{utilization-table entity=Pcs.nodesController.cur_node utilization=Pcs.nodesController.cur_node.utilization}}
15f218
+            {{utilization-table
15f218
+                entity=Pcs.nodesController.cur_node
15f218
+                utilization=Pcs.nodesController.cur_node.utilization
15f218
+                table_id="node_utilization_attributes"
15f218
+            }}
15f218
             
15f218
             {{/if}}
15f218
     
15f218
-- 
15f218
1.8.3.1
15f218