Skip to content

Commit

Permalink
Merge pull request #898 from liangxin1300/20211203_check_qdevice_start
Browse files Browse the repository at this point in the history
Dev: ui_cluster: check if qdevice service started when starting cluster if qdevice configured
  • Loading branch information
liangxin1300 authored Dec 6, 2021
2 parents 5b4e12b + 5d47b02 commit 95d4351
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions crmsh/ui_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,21 @@ def do_start(self, context, *args):
'''
Starts the cluster services on all nodes or specific node(s)
'''
service_check_list = ["pacemaker.service"]
start_qdevice = False
if utils.is_qdevice_configured():
start_qdevice = True
service_check_list.append("corosync-qdevice.service")

node_list = parse_option_for_nodes(context, *args)
for node in node_list[:]:
if utils.service_is_active("pacemaker.service", remote_addr=node):
if all([utils.service_is_active(srv, remote_addr=node) for srv in service_check_list]):
logger.info("Cluster services already started on {}".format(node))
node_list.remove(node)
if not node_list:
return

if utils.is_qdevice_configured():
if start_qdevice:
utils.start_service("corosync-qdevice", node_list=node_list)
bootstrap.start_pacemaker(node_list)
for node in node_list:
Expand Down
11 changes: 8 additions & 3 deletions test/unittests/test_ui_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def tearDownClass(cls):
@mock.patch('logging.Logger.info')
@mock.patch('crmsh.utils.service_is_active')
@mock.patch('crmsh.ui_cluster.parse_option_for_nodes')
def test_do_start_already_started(self, mock_parse_nodes, mock_active, mock_info):
@mock.patch('crmsh.utils.is_qdevice_configured')
def test_do_start_already_started(self, mock_qdevice_configured, mock_parse_nodes, mock_active, mock_info):
mock_qdevice_configured.return_value = False
context_inst = mock.Mock()
mock_parse_nodes.return_value = ["node1", "node2"]
mock_active.side_effect = [True, True]
Expand All @@ -63,12 +65,15 @@ def test_do_start_already_started(self, mock_parse_nodes, mock_active, mock_info
def test_do_start(self, mock_parse_nodes, mock_active, mock_start, mock_qdevice_configured, mock_info, mock_start_pacemaker):
context_inst = mock.Mock()
mock_parse_nodes.return_value = ["node1"]
mock_active.return_value = False
mock_active.side_effect = [False, False]
mock_qdevice_configured.return_value = True

self.ui_cluster_inst.do_start(context_inst, "node1")

mock_active.assert_called_once_with("pacemaker.service", remote_addr="node1")
mock_active.assert_has_calls([
mock.call("pacemaker.service", remote_addr="node1"),
mock.call("corosync-qdevice.service", remote_addr="node1")
])
mock_start.assert_called_once_with("corosync-qdevice", node_list=["node1"])
mock_qdevice_configured.assert_called_once_with()
mock_info.assert_called_once_with("Cluster services started on node1")
Expand Down

0 comments on commit 95d4351

Please sign in to comment.