Blob Blame History Raw
From 3cd35ed8e5b190c2e8203acd68a0100b84ed3bb4 Mon Sep 17 00:00:00 2001
From: Ondrej Mular <omular@redhat.com>
Date: Tue, 31 Jan 2023 17:44:16 +0100
Subject: [PATCH] fix update of stonith-watchdog-timeout when cluster is not
 running

---
 pcs/lib/communication/sbd.py                  |  4 +-
 .../lib/commands/sbd/test_disable_sbd.py      | 10 ++--
 .../tier0/lib/commands/sbd/test_enable_sbd.py | 49 ++++++++++---------
 pcsd/pcs.rb                                   | 17 +++++--
 4 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/pcs/lib/communication/sbd.py b/pcs/lib/communication/sbd.py
index 4762245c..633312a4 100644
--- a/pcs/lib/communication/sbd.py
+++ b/pcs/lib/communication/sbd.py
@@ -98,8 +98,8 @@ class StonithWatchdogTimeoutAction(
         )
         if report_item is None:
             self._on_success()
-            return []
-        self._report(report_item)
+        else:
+            self._report(report_item)
         return self._get_next_list()
 
 
diff --git a/pcs_test/tier0/lib/commands/sbd/test_disable_sbd.py b/pcs_test/tier0/lib/commands/sbd/test_disable_sbd.py
index 13135fb2..f8f165bf 100644
--- a/pcs_test/tier0/lib/commands/sbd/test_disable_sbd.py
+++ b/pcs_test/tier0/lib/commands/sbd/test_disable_sbd.py
@@ -19,7 +19,7 @@ class DisableSbd(TestCase):
         self.config.corosync_conf.load(filename=self.corosync_conf_name)
         self.config.http.host.check_auth(node_labels=self.node_list)
         self.config.http.pcmk.set_stonith_watchdog_timeout_to_zero(
-            node_labels=self.node_list[:1]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.disable_sbd(node_labels=self.node_list)
         disable_sbd(self.env_assist.get_env())
@@ -56,7 +56,7 @@ class DisableSbd(TestCase):
         self.config.corosync_conf.load(filename=self.corosync_conf_name)
         self.config.http.host.check_auth(node_labels=self.node_list)
         self.config.http.pcmk.set_stonith_watchdog_timeout_to_zero(
-            node_labels=self.node_list[:1]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.disable_sbd(node_labels=self.node_list)
 
@@ -158,7 +158,9 @@ class DisableSbd(TestCase):
             ]
         )
         self.config.http.pcmk.set_stonith_watchdog_timeout_to_zero(
-            node_labels=online_nodes_list[:1]
+            communication_list=[
+                [dict(label=node)] for node in self.node_list[1:]
+            ],
         )
         self.config.http.sbd.disable_sbd(node_labels=online_nodes_list)
         disable_sbd(self.env_assist.get_env(), ignore_offline_nodes=True)
@@ -291,7 +293,7 @@ class DisableSbd(TestCase):
         self.config.corosync_conf.load(filename=self.corosync_conf_name)
         self.config.http.host.check_auth(node_labels=self.node_list)
         self.config.http.pcmk.set_stonith_watchdog_timeout_to_zero(
-            node_labels=self.node_list[:1]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.disable_sbd(
             communication_list=[
diff --git a/pcs_test/tier0/lib/commands/sbd/test_enable_sbd.py b/pcs_test/tier0/lib/commands/sbd/test_enable_sbd.py
index 57e680e0..f192f429 100644
--- a/pcs_test/tier0/lib/commands/sbd/test_enable_sbd.py
+++ b/pcs_test/tier0/lib/commands/sbd/test_enable_sbd.py
@@ -130,7 +130,7 @@ class OddNumOfNodesSuccess(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.node_list)
         enable_sbd(
@@ -164,7 +164,7 @@ class OddNumOfNodesSuccess(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.node_list)
         enable_sbd(
@@ -218,7 +218,7 @@ class OddNumOfNodesDefaultsSuccess(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.node_list)
         enable_sbd(
@@ -248,7 +248,7 @@ class OddNumOfNodesDefaultsSuccess(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.node_list)
         enable_sbd(
@@ -351,7 +351,7 @@ class WatchdogValidations(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.node_list)
         enable_sbd(
@@ -407,7 +407,7 @@ class EvenNumOfNodes(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.node_list)
         enable_sbd(
@@ -443,7 +443,7 @@ class EvenNumOfNodes(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.node_list)
         enable_sbd(
@@ -480,7 +480,7 @@ class EvenNumOfNodes(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.node_list)
         enable_sbd(
@@ -513,7 +513,7 @@ class EvenNumOfNodes(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.node_list)
         enable_sbd(
@@ -604,7 +604,9 @@ class OfflineNodes(TestCase):
             node_labels=self.online_node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.online_node_list[0]]
+            communication_list=[
+                [dict(label=node)] for node in self.online_node_list
+            ],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.online_node_list)
         enable_sbd(
@@ -644,7 +646,9 @@ class OfflineNodes(TestCase):
             node_labels=self.online_node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.online_node_list[0]]
+            communication_list=[
+                [dict(label=node)] for node in self.online_node_list
+            ],
         )
         self.config.http.sbd.enable_sbd(node_labels=self.online_node_list)
         enable_sbd(
@@ -1226,7 +1230,7 @@ class FailureHandling(TestCase):
             node_labels=self.node_list,
         )
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
-            node_labels=[self.node_list[0]]
+            communication_list=[[dict(label=node)] for node in self.node_list],
         )
 
     def _remove_calls(self, count):
@@ -1302,7 +1306,8 @@ class FailureHandling(TestCase):
         )
 
     def test_removing_stonith_wd_timeout_failure(self):
-        self._remove_calls(2)
+        self._remove_calls(len(self.node_list) + 1)
+
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
             communication_list=[
                 self.communication_list_failure[:1],
@@ -1331,7 +1336,7 @@ class FailureHandling(TestCase):
         )
 
     def test_removing_stonith_wd_timeout_not_connected(self):
-        self._remove_calls(2)
+        self._remove_calls(len(self.node_list) + 1)
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
             communication_list=[
                 self.communication_list_not_connected[:1],
@@ -1360,7 +1365,7 @@ class FailureHandling(TestCase):
         )
 
     def test_removing_stonith_wd_timeout_complete_failure(self):
-        self._remove_calls(2)
+        self._remove_calls(len(self.node_list) + 1)
         self.config.http.pcmk.remove_stonith_watchdog_timeout(
             communication_list=[
                 self.communication_list_not_connected[:1],
@@ -1406,7 +1411,7 @@ class FailureHandling(TestCase):
         )
 
     def test_set_sbd_config_failure(self):
-        self._remove_calls(4)
+        self._remove_calls(len(self.node_list) + 1 + 2)
         self.config.http.sbd.set_sbd_config(
             communication_list=[
                 dict(
@@ -1453,7 +1458,7 @@ class FailureHandling(TestCase):
         )
 
     def test_set_corosync_conf_failed(self):
-        self._remove_calls(5)
+        self._remove_calls(len(self.node_list) + 1 + 3)
         self.config.env.push_corosync_conf(
             corosync_conf_text=_get_corosync_conf_text_with_atb(
                 self.corosync_conf_name
@@ -1477,7 +1482,7 @@ class FailureHandling(TestCase):
         )
 
     def test_check_sbd_invalid_data_format(self):
-        self._remove_calls(7)
+        self._remove_calls(len(self.node_list) + 1 + 5)
         self.config.http.sbd.check_sbd(
             communication_list=[
                 dict(
@@ -1516,7 +1521,7 @@ class FailureHandling(TestCase):
         )
 
     def test_check_sbd_failure(self):
-        self._remove_calls(7)
+        self._remove_calls(len(self.node_list) + 1 + 5)
         self.config.http.sbd.check_sbd(
             communication_list=[
                 dict(
@@ -1558,7 +1563,7 @@ class FailureHandling(TestCase):
         )
 
     def test_check_sbd_not_connected(self):
-        self._remove_calls(7)
+        self._remove_calls(len(self.node_list) + 1 + 5)
         self.config.http.sbd.check_sbd(
             communication_list=[
                 dict(
@@ -1601,7 +1606,7 @@ class FailureHandling(TestCase):
         )
 
     def test_get_online_targets_failed(self):
-        self._remove_calls(9)
+        self._remove_calls(len(self.node_list) + 1 + 7)
         self.config.http.host.check_auth(
             communication_list=self.communication_list_failure
         )
@@ -1626,7 +1631,7 @@ class FailureHandling(TestCase):
         )
 
     def test_get_online_targets_not_connected(self):
-        self._remove_calls(9)
+        self._remove_calls(len(self.node_list) + 1 + 7)
         self.config.http.host.check_auth(
             communication_list=self.communication_list_not_connected
         )
diff --git a/pcsd/pcs.rb b/pcsd/pcs.rb
index 452de97f..e3397c25 100644
--- a/pcsd/pcs.rb
+++ b/pcsd/pcs.rb
@@ -1838,13 +1838,22 @@ end
 def set_cluster_prop_force(auth_user, prop, val)
   cmd = ['property', 'set', "#{prop}=#{val}"]
   flags = ['--force']
+  sig_file = "#{CIB_PATH}.sig"
+  retcode = 0
+
   if pacemaker_running?
-    user = auth_user
+    _, _, retcode = run_cmd(auth_user, PCS, *flags, "--", *cmd)
   else
-    user = PCSAuth.getSuperuserAuth()
-    flags += ['-f', CIB_PATH]
+    if File.exist?(CIB_PATH)
+      flags += ['-f', CIB_PATH]
+      _, _, retcode = run_cmd(PCSAuth.getSuperuserAuth(), PCS, *flags, "--", *cmd)
+      begin
+        File.delete(sig_file)
+      rescue => e
+        $logger.debug("Cannot delete file '#{sig_file}': #{e.message}")
+      end
+    end
   end
-    _, _, retcode = run_cmd(user, PCS, *flags, "--", *cmd)
   return (retcode == 0)
 end
 
-- 
2.39.0