Blame SOURCES/bz1843593-01-GUI-fix-race-condition-when-removing-resource.patch

715401
From b56bf42759b18ed7b98dc98d3897b3cdf7b3ce5a Mon Sep 17 00:00:00 2001
715401
From: Ondrej Mular <omular@redhat.com>
715401
Date: Thu, 11 Jun 2020 16:53:09 +0200
715401
Subject: [PATCH 1/6] GUI: fix race-condition when removing resource
715401
715401
---
715401
 pcs/lib/cib/tools.py      | 30 ++++++++++++++++++++----------
715401
 pcs/test/test_acl.py      |  4 ++--
715401
 pcs/test/test_resource.py | 33 +++++++++++++++++++++++++++++++++
715401
 pcsd/public/js/pcsd.js    |  2 +-
715401
 4 files changed, 56 insertions(+), 13 deletions(-)
715401
715401
diff --git a/pcs/lib/cib/tools.py b/pcs/lib/cib/tools.py
715401
index ab2a9df5..e9599c43 100644
715401
--- a/pcs/lib/cib/tools.py
715401
+++ b/pcs/lib/cib/tools.py
715401
@@ -56,11 +56,14 @@ class IdProvider(object):
715401
         return report_list
715401
 
715401
 
715401
-def does_id_exist(tree, check_id):
715401
+def get_configuration_elements_by_id(tree, check_id):
715401
     """
715401
-    Checks to see if id exists in the xml dom passed
715401
-    tree cib etree node
715401
-    check_id id to check
715401
+    Return any configuration elements (not in status section of cib) with value
715401
+    of attribte id specified as 'check_id'
715401
+
715401
+    tree -- any element in xml tree, whole tree (not only its subtree) will be
715401
+        searched
715401
+    check_id -- id to find
715401
     """
715401
 
715401
     # do not search in /cib/status, it may contain references to previously
715401
@@ -70,7 +73,7 @@ def does_id_exist(tree, check_id):
715401
     #which will be named the same as the value of the remote-node attribute of
715401
     #the explicit resource. So the value of nvpair named "remote-node" is
715401
     #considered to be id
715401
-    existing = get_root(tree).xpath("""
715401
+    return get_root(tree).xpath("""
715401
         (
715401
             /cib/*[name()!="status"]
715401
             |
715401
@@ -96,7 +99,15 @@ def does_id_exist(tree, check_id):
715401
             )
715401
         ]
715401
     """.format(check_id))
715401
-    return len(existing) > 0
715401
+
715401
+
715401
+def does_id_exist(tree, check_id):
715401
+    """
715401
+    Checks to see if id exists in the xml dom passed
715401
+    tree cib etree node
715401
+    check_id id to check
715401
+    """
715401
+    return len(get_configuration_elements_by_id(tree, check_id)) > 0
715401
 
715401
 def validate_id_does_not_exist(tree, id):
715401
     """
715401
@@ -155,11 +166,10 @@ def find_element_by_tag_and_id(
715401
     if element_list:
715401
         return element_list[0]
715401
 
715401
-    element = get_root(context_element).find(
715401
-        './/*[@id="{0}"]'.format(element_id)
715401
-    )
715401
+    elements = get_configuration_elements_by_id(context_element, element_id)
715401
 
715401
-    if element is not None:
715401
+    if elements:
715401
+        element = elements[0]
715401
         raise LibraryError(
715401
             reports.id_belongs_to_unexpected_type(
715401
                 element_id,
715401
diff --git a/pcs/test/test_acl.py b/pcs/test/test_acl.py
715401
index a59beb0a..2a3b6d66 100644
715401
--- a/pcs/test/test_acl.py
715401
+++ b/pcs/test/test_acl.py
715401
@@ -395,7 +395,7 @@ Group: group2
715401
 
715401
         o,r = pcs("acl group delete user1")
715401
         assert r == 1
715401
-        ac(o,"Error: 'user1' is not an ACL group\n")
715401
+        ac(o,"Error: ACL group 'user1' does not exist\n")
715401
 
715401
         o,r = pcs("acl")
715401
         ac(o, """\
715401
@@ -861,7 +861,7 @@ Role: role4
715401
         self.assert_pcs_success("acl user create user1")
715401
         self.assert_pcs_fail(
715401
             "acl role assign role1 to group user1",
715401
-            "Error: 'user1' is not an ACL group\n"
715401
+            "Error: ACL group 'user1' does not exist\n"
715401
         )
715401
 
715401
     def test_assign_unassign_role_to_group_with_to(self):
715401
diff --git a/pcs/test/test_resource.py b/pcs/test/test_resource.py
715401
index 972323f9..fd1a0731 100644
715401
--- a/pcs/test/test_resource.py
715401
+++ b/pcs/test/test_resource.py
715401
@@ -3542,6 +3542,39 @@ Error: Cannot remove more than one resource from cloned group
715401
             )
715401
         )
715401
 
715401
+    def testResourceDisableNonExistingWithFailedAction(self):
715401
+        with open(temp_cib, "w") as f:
715401
+            f.truncate()
715401
+            f.write(
715401
+                """
715401
+                <cib epoch="557" num_updates="122" admin_epoch="0" crm_feature_set="3.0.14" validate-with="pacemaker-2.10" update-origin="rh7-3" update-client="crmd" cib-last-written="Thu Aug 23 16:49:17 2012" have-quorum="0" dc-uuid="2">
715401
+                  <configuration>
715401
+                    <crm_config/>
715401
+                    <nodes>
715401
+                    </nodes>
715401
+                    <resources/>
715401
+                    <constraints/>
715401
+                  </configuration>
715401
+                  <status>
715401
+                    <node_state id="1" uname="rh7-1" in_ccm="true" crmd="online" crm-debug-origin="do_update_resource" join="member" expected="member">
715401
+                      <lrm id="1">
715401
+                        <lrm_resources>
715401
+                          <lrm_resource id="A" type="apache" class="ocf" provider="heartbeat">
715401
+                            <lrm_rsc_op id="A_last_0" operation_key="A_monitor_0" operation="monitor" crm-debug-origin="do_update_resource" crm_feature_set="3.0.14" transition-key="1:1104:7:817ee250-d179-483a-819e-9be9cb0e06df" transition-magic="0:7;1:1104:7:817ee250-d179-483a-819e-9be9cb0e06df" exit-reason="" on_node="rh7-1" call-id="1079" rc-code="7" op-status="0" interval="0" last-run="1591791198" last-rc-change="1591791198" exec-time="275" queue-time="0" op-digest="f2317cad3d54cec5d7d7aa7d0bf35cf8"/>
715401
+                          </lrm_resource>
715401
+                        </lrm_resources>
715401
+                      </lrm>
715401
+                    </node_state>
715401
+                  </status>
715401
+                </cib>
715401
+                """
715401
+            )
715401
+        self.assert_pcs_fail(
715401
+            "resource disable A",
715401
+            "Error: bundle/clone/group/master/resource 'A' does not exist\n"
715401
+        )
715401
+
715401
+
715401
     def testResourceEnable(self):
715401
         # These tests were moved to
715401
         # pcs/lib/commands/test/resource/test_resource_enable_disable.py .
715401
diff --git a/pcsd/public/js/pcsd.js b/pcsd/public/js/pcsd.js
715401
index 20c19434..60c3da59 100644
715401
--- a/pcsd/public/js/pcsd.js
715401
+++ b/pcsd/public/js/pcsd.js
715401
@@ -1441,7 +1441,7 @@ function remove_resource(ids, force) {
715401
         error == "timeout" ||
715401
         xhr.responseText == '{"noresponse":true}'
715401
       ) {
715401
-        message = "Operation takes longer to complete than expected.";
715401
+        message = "Operation takes longer to complete than expected but it will continue in the background.";
715401
       } else {
715401
         message = "Unable to remove resources (" + error + ")";
715401
         if (
715401
-- 
715401
2.21.0
715401