Skip to content

Commit 080b36e

Browse files
committed
Dev: unittests: Adjust unit test for previous commit
1 parent 7f1c776 commit 080b36e

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
@@ -1964,16 +1964,17 @@ def test_remove_self_other_nodes(self, mock_this_node, mock_list, mock_run, mock
19641964
mock_run.assert_called_once_with("node2", "crm cluster remove -y -c node1")
19651965
mock_error.assert_called_once_with("Failed to remove this node from node2: err")
19661966

1967-
@mock.patch('crmsh.utils.package_is_installed')
1967+
@mock.patch('crmsh.sbd.cleanup_sbd_configurations')
1968+
@mock.patch('os.path.exists')
19681969
@mock.patch('crmsh.sh.ClusterShell.get_stdout_or_raise_error')
1969-
def test_rm_configuration_files(self, mock_run, mock_installed):
1970+
def test_rm_configuration_files(self, mock_run, mock_exists, mock_rm_sbd):
19701971
bootstrap._context = mock.Mock(rm_list=["file1", "file2"])
1971-
mock_installed.return_value = True
1972+
mock_exists.return_value = True
19721973
bootstrap.rm_configuration_files()
19731974
mock_run.assert_has_calls([
19741975
mock.call('rm -f file1 file2', None),
1975-
mock.call('cp /usr/share/fillup-templates/sysconfig.sbd /etc/sysconfig/sbd', None)
19761976
])
1977+
mock_rm_sbd.assert_called_once_with(None)
19771978

19781979
@mock.patch('crmsh.utils.get_iplist_from_name')
19791980
@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
@@ -811,15 +811,27 @@ def test_cleanup_existing_sbd_resource(self, mock_CrmMonXmlParser, mock_logger_i
811811
call("Remove sbd resource '%s'", 'sbd_resource')
812812
])
813813

814-
@patch('crmsh.parallax.parallax_call')
814+
@patch('logging.Logger.info')
815+
@patch('crmsh.sh.cluster_shell')
816+
def test_cleanup_sbd_configurations(self, mock_cluster_shell, mock_logger_info):
817+
mock_cluster_shell_inst = Mock()
818+
mock_cluster_shell.return_value = mock_cluster_shell_inst
819+
mock_cluster_shell_inst.get_stdout_or_raise_error = Mock()
820+
sbd.cleanup_sbd_configurations()
821+
mock_cluster_shell_inst.get_stdout_or_raise_error.assert_has_calls([
822+
call(f"test -f {sbd.SBDManager.SYSCONFIG_SBD} && mv {sbd.SBDManager.SYSCONFIG_SBD} {sbd.SBDManager.SYSCONFIG_SBD}.bak || exit 0", host=None),
823+
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),
824+
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),
825+
])
826+
827+
@patch('crmsh.sbd.cleanup_sbd_configurations')
815828
@patch('crmsh.utils.cleanup_stonith_related_properties')
816829
@patch('crmsh.sbd.sh.cluster_shell')
817-
@patch('crmsh.utils.cluster_run_cmd')
818830
@patch('logging.Logger.info')
819831
@patch('crmsh.sbd.ServiceManager')
820832
@patch('crmsh.utils.list_cluster_nodes')
821833
@patch('crmsh.sbd.cleanup_existing_sbd_resource')
822-
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):
834+
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):
823835
mock_list_cluster_nodes.return_value = ['node1', 'node2']
824836
mock_ServiceManager.return_value.service_is_enabled.side_effect = [True, True]
825837
stonith_data = """stonith-sbd
@@ -830,6 +842,6 @@ def test_purge_sbd_from_cluster(self, mock_cleanup_existing_sbd_resource, mock_l
830842
mock_logger_info.assert_has_calls([
831843
call("Disable %s on node %s", constants.SBD_SERVICE, 'node1'),
832844
call("Disable %s on node %s", constants.SBD_SERVICE, 'node2'),
833-
call("Move %s to %s on all nodes", sbd.SBDManager.SYSCONFIG_SBD, sbd.SBDManager.SYSCONFIG_SBD+'.bak')
834845
])
835846
mock_cleanup_stonith_related_properties.assert_called_once()
847+
mock_rm_sbd_configuration_files.assert_has_calls([call("node1"), call("node2")])

0 commit comments

Comments
 (0)