Skip to content

Commit 9c759db

Browse files
committed
Dev: unittests: Adjust unit test for previous commit
1 parent 2952faa commit 9c759db

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

test/unittests/test_bootstrap.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ def test_bootstrap_remove_self(self, mock_context, mock_init, mock_active,
18041804
mock_check_all_nodes.assert_called_once_with("removing a node from the cluster")
18051805

18061806
@mock.patch('crmsh.utils.check_all_nodes_reachable')
1807-
@mock.patch('crmsh.utils.list_cluster_nodes')
1807+
@mock.patch('crmsh.xmlutil.CrmMonXmlParser')
18081808
@mock.patch('crmsh.utils.this_node')
18091809
@mock.patch('crmsh.bootstrap.confirm')
18101810
@mock.patch('crmsh.bootstrap.get_node_canonical_hostname')
@@ -1814,13 +1814,15 @@ def test_bootstrap_remove_self(self, mock_context, mock_init, mock_active,
18141814
@mock.patch('crmsh.bootstrap.init')
18151815
@mock.patch('crmsh.bootstrap.Context')
18161816
def test_bootstrap_remove_not_in_cluster(self, mock_context, mock_init, mock_active,
1817-
mock_error, mock_qdevice, mock_hostname, mock_confirm, mock_this_node, mock_list, mock_check_all_nodes):
1817+
mock_error, mock_qdevice, mock_hostname, mock_confirm, mock_this_node, mock_crm_mon_parser, mock_check_all_nodes):
18181818
mock_context_inst = mock.Mock(cluster_node="node2", force=True, qdevice_rm_flag=None)
18191819
mock_context.return_value = mock_context_inst
18201820
mock_active.return_value = [True, True]
18211821
mock_hostname.return_value = "node2"
18221822
mock_this_node.return_value = "node1"
1823-
mock_list.return_value = ["node1", "node3"]
1823+
mock_crm_mon_parser_inst = mock.Mock()
1824+
mock_crm_mon_parser.return_value = mock_crm_mon_parser_inst
1825+
mock_crm_mon_parser_inst.get_node_list.return_value = ["node1", "node3"]
18241826
mock_error.side_effect = SystemExit
18251827

18261828
with self.assertRaises(SystemExit):
@@ -1835,13 +1837,13 @@ def test_bootstrap_remove_not_in_cluster(self, mock_context, mock_init, mock_act
18351837
mock_hostname.assert_called_once_with('node2')
18361838
mock_confirm.assert_not_called()
18371839
mock_this_node.assert_called_once_with()
1838-
mock_error.assert_called_once_with("Specified node node2 is not configured in cluster! Unable to remove.")
1840+
mock_error.assert_called_once_with("Node node2 is not configured in cluster! (valid nodes: node1, node3)")
18391841
mock_check_all_nodes.assert_called_once_with("removing a node from the cluster")
18401842

18411843
@mock.patch('crmsh.utils.check_all_nodes_reachable')
18421844
@mock.patch('crmsh.utils.fetch_cluster_node_list_from_node')
18431845
@mock.patch('crmsh.bootstrap.remove_node_from_cluster')
1844-
@mock.patch('crmsh.utils.list_cluster_nodes')
1846+
@mock.patch('crmsh.xmlutil.CrmMonXmlParser')
18451847
@mock.patch('crmsh.utils.this_node')
18461848
@mock.patch('crmsh.bootstrap.confirm')
18471849
@mock.patch('crmsh.bootstrap.get_node_canonical_hostname')
@@ -1852,13 +1854,15 @@ def test_bootstrap_remove_not_in_cluster(self, mock_context, mock_init, mock_act
18521854
@mock.patch('crmsh.bootstrap.Context')
18531855
def test_bootstrap_remove(self, mock_context, mock_init, mock_active,
18541856
mock_error, mock_qdevice, mock_hostname, mock_confirm, mock_this_node,
1855-
mock_list, mock_remove, mock_fetch, mock_check_all_nodes):
1857+
mock_crm_mon_parser, mock_remove, mock_fetch, mock_check_all_nodes):
18561858
mock_context_inst = mock.Mock(cluster_node="node2", qdevice_rm_flag=None, force=True)
18571859
mock_context.return_value = mock_context_inst
18581860
mock_active.side_effect = [True, False, True]
18591861
mock_hostname.return_value = "node2"
18601862
mock_this_node.return_value = "node1"
1861-
mock_list.return_value = ["node1", "node2"]
1863+
mock_crm_mon_parser_inst = mock.Mock()
1864+
mock_crm_mon_parser.return_value = mock_crm_mon_parser_inst
1865+
mock_crm_mon_parser_inst.get_node_list.return_value = ["node1", "node2"]
18621866
mock_fetch.return_value = ["node1", "node2"]
18631867

18641868
bootstrap.bootstrap_remove(mock_context_inst)
@@ -1956,7 +1960,11 @@ def test_stop_services(self, mock_active, mock_status, mock_stop, mock_this_node
19561960
@mock.patch('logging.Logger.info')
19571961
@mock.patch('crmsh.bootstrap.stop_services')
19581962
@mock.patch('crmsh.bootstrap.get_cluster_node_ip')
1959-
def test_remove_node_from_cluster_rm_node_failed(self, mock_get_ip, mock_stop, mock_status, mock_invoke, mock_error, mock_rm_conf_files, mock_call_delnode):
1963+
@mock.patch('crmsh.xmlutil.CrmMonXmlParser')
1964+
def test_remove_node_from_cluster_rm_node_failed(self, mock_crm_mon_parser, mock_get_ip, mock_stop, mock_status, mock_invoke, mock_error, mock_rm_conf_files, mock_call_delnode):
1965+
mock_crm_mon_parser_inst = mock.Mock()
1966+
mock_crm_mon_parser.return_value = mock_crm_mon_parser_inst
1967+
mock_crm_mon_parser_inst.is_node_remote.return_value = False
19601968
mock_get_ip.return_value = '192.0.2.100'
19611969
mock_call_delnode.return_value = False
19621970
mock_error.side_effect = SystemExit
@@ -1980,7 +1988,11 @@ def test_remove_node_from_cluster_rm_node_failed(self, mock_get_ip, mock_stop, m
19801988
@mock.patch('logging.Logger.info')
19811989
@mock.patch('crmsh.bootstrap.stop_services')
19821990
@mock.patch('crmsh.bootstrap.get_cluster_node_ip')
1983-
def test_remove_node_from_cluster_rm_csync_failed(self, mock_get_ip, mock_stop, mock_status, mock_invoke, mock_invokerc, mock_error, mock_rm_conf_files, mock_call_delnode):
1991+
@mock.patch('crmsh.xmlutil.CrmMonXmlParser')
1992+
def test_remove_node_from_cluster_rm_csync_failed(self, mock_crm_mon_parser, mock_get_ip, mock_stop, mock_status, mock_invoke, mock_invokerc, mock_error, mock_rm_conf_files, mock_call_delnode):
1993+
mock_crm_mon_parser_inst = mock.Mock()
1994+
mock_crm_mon_parser.return_value = mock_crm_mon_parser_inst
1995+
mock_crm_mon_parser_inst.is_node_remote.return_value = False
19841996
mock_get_ip.return_value = '192.0.2.100'
19851997
mock_call_delnode.return_value = True
19861998
mock_invokerc.return_value = False
@@ -2017,9 +2029,13 @@ def test_remove_node_from_cluster_rm_csync_failed(self, mock_get_ip, mock_stop,
20172029
@mock.patch('logging.Logger.info')
20182030
@mock.patch('crmsh.bootstrap.stop_services')
20192031
@mock.patch('crmsh.bootstrap.get_cluster_node_ip')
2020-
def test_remove_node_from_cluster_hostname(self, mock_get_ip, mock_stop, mock_status,
2032+
@mock.patch('crmsh.xmlutil.CrmMonXmlParser')
2033+
def test_remove_node_from_cluster_hostname(self, mock_crm_mon_parser, mock_get_ip, mock_stop, mock_status,
20212034
mock_invoke, mock_invokerc, mock_error, mock_get_values, mock_del, mock_csync2,
20222035
mock_adjust_priority, mock_adjust_fence_delay, mock_rm_conf_files, mock_is_active, mock_cal_delnode, mock_firewall, mock_cluster_shell, mock_host_user_config):
2036+
mock_crm_mon_parser_inst = mock.Mock()
2037+
mock_crm_mon_parser.return_value = mock_crm_mon_parser_inst
2038+
mock_crm_mon_parser_inst.is_node_remote.return_value = False
20232039
mock_get_ip.return_value = "10.10.10.1"
20242040
mock_cal_delnode.return_value = True
20252041
mock_invoke.side_effect = [(True, None, None)]

0 commit comments

Comments
 (0)