Skip to content

Commit 705ee73

Browse files
committed
Dev: unittests: Adjust unit test for previous commit
1 parent a33e4b2 commit 705ee73

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

test/unittests/test_bootstrap.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,16 +1977,17 @@ def test_remove_self_other_nodes(self, mock_this_node, mock_list, mock_run, mock
19771977
mock_run.assert_called_once_with("node2", "crm cluster remove -y -c node1")
19781978
mock_error.assert_called_once_with("Failed to remove this node from node2: err")
19791979

1980-
@mock.patch('crmsh.utils.package_is_installed')
1980+
@mock.patch('crmsh.sbd.cleanup_sbd_configurations')
1981+
@mock.patch('os.path.exists')
19811982
@mock.patch('crmsh.sh.ClusterShell.get_stdout_or_raise_error')
1982-
def test_rm_configuration_files(self, mock_run, mock_installed):
1983+
def test_rm_configuration_files(self, mock_run, mock_exists, mock_rm_sbd):
19831984
bootstrap._context = mock.Mock(rm_list=["file1", "file2"])
1984-
mock_installed.return_value = True
1985+
mock_exists.return_value = True
19851986
bootstrap.rm_configuration_files()
19861987
mock_run.assert_has_calls([
19871988
mock.call('rm -f file1 file2', None),
1988-
mock.call('cp /usr/share/fillup-templates/sysconfig.sbd /etc/sysconfig/sbd', None)
19891989
])
1990+
mock_rm_sbd.assert_called_once_with(None)
19901991

19911992
@mock.patch('crmsh.utils.get_iplist_from_name')
19921993
@mock.patch('crmsh.corosync.get_values')

test/unittests/test_sbd.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,15 +804,27 @@ def test_cleanup_existing_sbd_resource(self, mock_CrmMonXmlParser, mock_logger_i
804804
call("Remove sbd resource '%s'", 'sbd_resource')
805805
])
806806

807-
@patch('crmsh.parallax.parallax_call')
807+
@patch('logging.Logger.info')
808+
@patch('crmsh.sh.cluster_shell')
809+
def test_cleanup_sbd_configurations(self, mock_cluster_shell, mock_logger_info):
810+
mock_cluster_shell_inst = Mock()
811+
mock_cluster_shell.return_value = mock_cluster_shell_inst
812+
mock_cluster_shell_inst.get_stdout_or_raise_error = Mock()
813+
sbd.cleanup_sbd_configurations()
814+
mock_cluster_shell_inst.get_stdout_or_raise_error.assert_has_calls([
815+
call(f"test -f {sbd.SBDManager.SYSCONFIG_SBD} && mv {sbd.SBDManager.SYSCONFIG_SBD} {sbd.SBDManager.SYSCONFIG_SBD}.bak || exit 0", host=None),
816+
call(f"test -d {sbd.SBDManager.SBD_SYSTEMD_DELAY_START_DIR} && rm -rf {sbd.SBDManager.SBD_SYSTEMD_DELAY_START_DIR} && systemctl daemon-reload || exit 0", host=None),
817+
call(f"test -d {sbd.SBDManager.SBD_SYSTEMD_DELAY_START_DISABLE_DIR} && rm -rf {sbd.SBDManager.SBD_SYSTEMD_DELAY_START_DISABLE_DIR} && systemctl daemon-reload || exit 0", host=None),
818+
])
819+
820+
@patch('crmsh.sbd.cleanup_sbd_configurations')
808821
@patch('crmsh.utils.cleanup_stonith_related_properties')
809822
@patch('crmsh.sbd.sh.cluster_shell')
810-
@patch('crmsh.utils.cluster_run_cmd')
811823
@patch('logging.Logger.info')
812824
@patch('crmsh.sbd.ServiceManager')
813825
@patch('crmsh.utils.list_cluster_nodes')
814826
@patch('crmsh.sbd.cleanup_existing_sbd_resource')
815-
def test_purge_sbd_from_cluster(self, mock_cleanup_existing_sbd_resource, mock_list_cluster_nodes, mock_ServiceManager, mock_logger_info, mock_cluster_run_cmd, mock_cluster_shell, mock_cleanup_stonith_related_properties, mock_parallax_call):
827+
def test_purge_sbd_from_cluster(self, mock_cleanup_existing_sbd_resource, mock_list_cluster_nodes, mock_ServiceManager, mock_logger_info, mock_cluster_shell, mock_cleanup_stonith_related_properties, mock_rm_sbd_configuration_files):
816828
mock_list_cluster_nodes.return_value = ['node1', 'node2']
817829
mock_ServiceManager.return_value.service_is_enabled.side_effect = [True, True]
818830
stonith_data = """stonith-sbd
@@ -823,6 +835,6 @@ def test_purge_sbd_from_cluster(self, mock_cleanup_existing_sbd_resource, mock_l
823835
mock_logger_info.assert_has_calls([
824836
call("Disable %s on node %s", constants.SBD_SERVICE, 'node1'),
825837
call("Disable %s on node %s", constants.SBD_SERVICE, 'node2'),
826-
call("Move %s to %s on all nodes", sbd.SBDManager.SYSCONFIG_SBD, sbd.SBDManager.SYSCONFIG_SBD+'.bak')
827838
])
828839
mock_cleanup_stonith_related_properties.assert_called_once()
840+
mock_rm_sbd_configuration_files.assert_has_calls([call("node1"), call("node2")])

0 commit comments

Comments
 (0)