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

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