Blob Blame History Raw
From 8058591d0d79942bf6c61f105a180592bac7cf69 Mon Sep 17 00:00:00 2001
From: Ondrej Mular <omular@redhat.com>
Date: Thu, 28 Nov 2019 16:57:24 +0100
Subject: [PATCH 2/3] fix error msg when cluster is not set up

---
 CHANGELOG.md                                |  4 +++
 pcs/cluster.py                              |  3 +++
 pcs/lib/commands/qdevice.py                 |  2 ++
 pcs_test/tier0/lib/commands/test_qdevice.py | 27 +++++++++++++++++++--
 4 files changed, 34 insertions(+), 2 deletions(-)

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