Blame SOURCES/bz1743731-01-fix-error-msg-when-cluster-is-not-set-up.patch

bc4e95
From 8058591d0d79942bf6c61f105a180592bac7cf69 Mon Sep 17 00:00:00 2001
bc4e95
From: Ondrej Mular <omular@redhat.com>
bc4e95
Date: Thu, 28 Nov 2019 16:57:24 +0100
bc4e95
Subject: [PATCH 2/3] fix error msg when cluster is not set up
bc4e95
bc4e95
---
bc4e95
 CHANGELOG.md                                |  4 +++
bc4e95
 pcs/cluster.py                              |  3 +++
bc4e95
 pcs/lib/commands/qdevice.py                 |  2 ++
bc4e95
 pcs_test/tier0/lib/commands/test_qdevice.py | 27 +++++++++++++++++++--
bc4e95
 4 files changed, 34 insertions(+), 2 deletions(-)
bc4e95
bc4e95
diff --git a/CHANGELOG.md b/CHANGELOG.md
bc4e95
index 889436c3..5a7ec377 100644
bc4e95
--- a/CHANGELOG.md
bc4e95
+++ b/CHANGELOG.md
bc4e95
@@ -6,7 +6,11 @@
bc4e95
 - It is possible to configure a disaster-recovery site and display its status
bc4e95
   ([rhbz#1676431])
bc4e95
 
bc4e95
+### Fixed
bc4e95
+- Error messages in cases when cluster is not set up ([rhbz#1743731])
bc4e95
+
bc4e95
 [rhbz#1676431]: https://bugzilla.redhat.com/show_bug.cgi?id=1676431
bc4e95
+[rhbz#1743731]: https://bugzilla.redhat.com/show_bug.cgi?id=1743731
bc4e95
 
bc4e95
 
bc4e95
 ## [0.10.4] - 2019-11-28
bc4e95
diff --git a/pcs/cluster.py b/pcs/cluster.py
bc4e95
index 9473675f..0e9b3365 100644
bc4e95
--- a/pcs/cluster.py
bc4e95
+++ b/pcs/cluster.py
bc4e95
@@ -190,6 +190,9 @@ def start_cluster(argv):
bc4e95
             wait_for_nodes_started(nodes, wait_timeout)
bc4e95
         return
bc4e95
 
bc4e95
+    if not utils.hasCorosyncConf():
bc4e95
+        utils.err("cluster is not currently configured on this node")
bc4e95
+
bc4e95
     print("Starting Cluster...")
bc4e95
     service_list = ["corosync"]
bc4e95
     if utils.need_to_handle_qdevice_service():
bc4e95
diff --git a/pcs/lib/commands/qdevice.py b/pcs/lib/commands/qdevice.py
bc4e95
index 3d7af234..41f7c296 100644
bc4e95
--- a/pcs/lib/commands/qdevice.py
bc4e95
+++ b/pcs/lib/commands/qdevice.py
bc4e95
@@ -81,6 +81,8 @@ def qdevice_start(lib_env, model):
bc4e95
     start qdevice now on local host
bc4e95
     """
bc4e95
     _check_model(model)
bc4e95
+    if not qdevice_net.qdevice_initialized():
bc4e95
+        raise LibraryError(reports.qdevice_not_initialized(model))
bc4e95
     _service_start(lib_env, qdevice_net.qdevice_start)
bc4e95
 
bc4e95
 def qdevice_stop(lib_env, model, proceed_if_used=False):
bc4e95
diff --git a/pcs_test/tier0/lib/commands/test_qdevice.py b/pcs_test/tier0/lib/commands/test_qdevice.py
bc4e95
index b2c83ca4..af23db61 100644
bc4e95
--- a/pcs_test/tier0/lib/commands/test_qdevice.py
bc4e95
+++ b/pcs_test/tier0/lib/commands/test_qdevice.py
bc4e95
@@ -689,6 +689,7 @@ class QdeviceNetDisableTest(QdeviceTestCase):
bc4e95
         )
bc4e95
 
bc4e95
 
bc4e95
+@mock.patch("pcs.lib.corosync.qdevice_net.qdevice_initialized")
bc4e95
 @mock.patch("pcs.lib.external.start_service")
bc4e95
 @mock.patch.object(
bc4e95
     LibraryEnvironment,
bc4e95
@@ -696,9 +697,11 @@ class QdeviceNetDisableTest(QdeviceTestCase):
bc4e95
     lambda self: "mock_runner"
bc4e95
 )
bc4e95
 class QdeviceNetStartTest(QdeviceTestCase):
bc4e95
-    def test_success(self, mock_net_start):
bc4e95
+    def test_success(self, mock_net_start, mock_qdevice_initialized):
bc4e95
+        mock_qdevice_initialized.return_value = True
bc4e95
         lib.qdevice_start(self.lib_env, "net")
bc4e95
         mock_net_start.assert_called_once_with("mock_runner", "corosync-qnetd")
bc4e95
+        mock_qdevice_initialized.assert_called_once_with()
bc4e95
         assert_report_item_list_equal(
bc4e95
             self.mock_reporter.report_item_list,
bc4e95
             [
bc4e95
@@ -719,11 +722,12 @@ class QdeviceNetStartTest(QdeviceTestCase):
bc4e95
             ]
bc4e95
         )
bc4e95
 
bc4e95
-    def test_failed(self, mock_net_start):
bc4e95
+    def test_failed(self, mock_net_start, mock_qdevice_initialized):
bc4e95
         mock_net_start.side_effect = StartServiceError(
bc4e95
             "test service",
bc4e95
             "test error"
bc4e95
         )
bc4e95
+        mock_qdevice_initialized.return_value = True
bc4e95
 
bc4e95
         assert_raise_library_error(
bc4e95
             lambda: lib.qdevice_start(self.lib_env, "net"),
bc4e95
@@ -737,6 +741,7 @@ class QdeviceNetStartTest(QdeviceTestCase):
bc4e95
             )
bc4e95
         )
bc4e95
         mock_net_start.assert_called_once_with("mock_runner", "corosync-qnetd")
bc4e95
+        mock_qdevice_initialized.assert_called_once_with()
bc4e95
         assert_report_item_list_equal(
bc4e95
             self.mock_reporter.report_item_list,
bc4e95
             [
bc4e95
@@ -750,6 +755,24 @@ class QdeviceNetStartTest(QdeviceTestCase):
bc4e95
             ]
bc4e95
         )
bc4e95
 
bc4e95
+    def test_qdevice_not_initialized(
bc4e95
+        self, mock_net_start, mock_qdevice_initialized
bc4e95
+    ):
bc4e95
+        mock_qdevice_initialized.return_value = False
bc4e95
+
bc4e95
+        assert_raise_library_error(
bc4e95
+            lambda: lib.qdevice_start(self.lib_env, "net"),
bc4e95
+            (
bc4e95
+                severity.ERROR,
bc4e95
+                report_codes.QDEVICE_NOT_INITIALIZED,
bc4e95
+                {
bc4e95
+                    "model": "net",
bc4e95
+                }
bc4e95
+            )
bc4e95
+        )
bc4e95
+        mock_net_start.assert_not_called()
bc4e95
+        mock_qdevice_initialized.assert_called_once_with()
bc4e95
+
bc4e95
 
bc4e95
 @mock.patch("pcs.lib.corosync.qdevice_net.qdevice_status_cluster_text")
bc4e95
 @mock.patch("pcs.lib.external.stop_service")
bc4e95
-- 
bc4e95
2.21.0
bc4e95