Skip to content

Commit

Permalink
Dev: unittests: Adjust unit test for previous commits
Browse files Browse the repository at this point in the history
  • Loading branch information
liangxin1300 committed Nov 29, 2024
1 parent 35b1036 commit 1dedfe3
Show file tree
Hide file tree
Showing 8 changed files with 1,400 additions and 916 deletions.
1 change: 1 addition & 0 deletions data-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ test/unittests/test_sh.py
test/unittests/test_time.py
test/unittests/test_ui_cluster.py
test/unittests/test_ui_corosync.py
test/unittests/test_ui_sbd.py
test/unittests/test_upgradeuitl.py
test/unittests/test_utils.py
test/unittests/test_watchdog.py
Expand Down
23 changes: 15 additions & 8 deletions test/unittests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ def test_initialize_qdevice_with_user(self, mock_qdevice):
ctx.initialize_qdevice()
mock_qdevice.assert_called_once_with(qnetd_addr='node3', port=123, ssh_user='alice', algo=None, tie_breaker=None, tls=None, cmds=None, mode=None, is_stage=False)

@mock.patch('crmsh.utils.package_is_installed')
@mock.patch('crmsh.utils.fatal')
def test_validate_sbd_option_error_together(self, mock_error):
def test_validate_sbd_option_error_together(self, mock_error, mock_installed):
mock_installed.return_value = True
mock_error.side_effect = SystemExit
ctx = crmsh.bootstrap.Context()
ctx.sbd_devices = ["/dev/sda1"]
Expand All @@ -136,8 +138,10 @@ def test_validate_sbd_option_error_together(self, mock_error):
ctx._validate_sbd_option()
mock_error.assert_called_once_with("Can't use -s and -S options together")

@mock.patch('crmsh.utils.package_is_installed')
@mock.patch('crmsh.utils.fatal')
def test_validate_sbd_option_error_sbd_stage_no_option(self, mock_error):
def test_validate_sbd_option_error_sbd_stage_no_option(self, mock_error, mock_installed):
mock_installed.return_value = True
mock_error.side_effect = SystemExit
ctx = crmsh.bootstrap.Context()
ctx.stage = "sbd"
Expand All @@ -146,9 +150,11 @@ def test_validate_sbd_option_error_sbd_stage_no_option(self, mock_error):
ctx._validate_sbd_option()
mock_error.assert_called_once_with("Stage sbd should specify sbd device by -s or diskless sbd by -S option")

@mock.patch('crmsh.utils.package_is_installed')
@mock.patch('crmsh.utils.fatal')
@mock.patch('crmsh.service_manager.ServiceManager.service_is_active')
def test_validate_sbd_option_error_sbd_stage_service(self, mock_active, mock_error):
def test_validate_sbd_option_error_sbd_stage_service(self, mock_active, mock_error, mock_installed):
mock_installed.return_value = True
mock_error.side_effect = SystemExit
ctx = crmsh.bootstrap.Context()
ctx.stage = "sbd"
Expand All @@ -159,10 +165,12 @@ def test_validate_sbd_option_error_sbd_stage_service(self, mock_active, mock_err
mock_error.assert_called_once_with("Can't configure stage sbd: sbd.service already running! Please use crm option '-F' if need to redeploy")
mock_active.assert_called_once_with("sbd.service")

@mock.patch('crmsh.utils.package_is_installed')
@mock.patch('crmsh.utils.check_all_nodes_reachable')
@mock.patch('crmsh.service_manager.ServiceManager.service_is_active')
def test_validate_sbd_option_error_sbd_stage(self, mock_active, mock_check_all):
def test_validate_sbd_option_error_sbd_stage(self, mock_active, mock_check_all, mock_installed):
options = mock.Mock(stage="sbd", diskless_sbd=True, cluster_is_running=True)
mock_installed.return_value = True
ctx = crmsh.bootstrap.Context()
ctx.stage = "sbd"
ctx.diskless_sbd = True
Expand Down Expand Up @@ -1336,13 +1344,12 @@ def test_adjust_pcmk_delay(self, mock_cib_factory, mock_run, mock_debug):
bootstrap.adjust_pcmk_delay_max(False)
mock_run.assert_called_once_with("crm resource param res_1 delete pcmk_delay_max")

@mock.patch('crmsh.sbd.SBDTimeout')
@mock.patch('crmsh.sbd.SBDTimeout.adjust_sbd_timeout_related_cluster_configuration')
@mock.patch('crmsh.service_manager.ServiceManager.service_is_active')
def test_adjust_stonith_timeout_sbd(self, mock_is_active, mock_sbd_timeout):
def test_adjust_stonith_timeout_sbd(self, mock_is_active, mock_sbd_adjust_timeout):
mock_is_active.return_value = True
mock_sbd_timeout.adjust_sbd_timeout_related_cluster_configuration = mock.Mock()
bootstrap.adjust_stonith_timeout()
mock_sbd_timeout.adjust_sbd_timeout_related_cluster_configuration.assert_called_once_with()
mock_sbd_adjust_timeout.assert_called_once_with()

@mock.patch('crmsh.utils.set_property')
@mock.patch('crmsh.bootstrap.get_stonith_timeout_generally_expected')
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/test_qdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ def test_config_and_start_qdevice(self, mock_rm_db, mock_status_long, mock_evalu

@mock.patch('crmsh.utils.set_property')
@mock.patch('crmsh.sbd.SBDTimeout.get_stonith_timeout')
@mock.patch('crmsh.sbd.SBDManager.update_configuration')
@mock.patch('crmsh.sbd.SBDManager.get_sbd_value_from_config')
@mock.patch('crmsh.sbd.SBDManager.is_using_diskless_sbd')
@mock.patch('crmsh.sbd.SBDManager.update_sbd_configuration')
@mock.patch('crmsh.sbd.SBDUtils.get_sbd_value_from_config')
@mock.patch('crmsh.sbd.SBDUtils.is_using_diskless_sbd')
@mock.patch('crmsh.utils.check_all_nodes_reachable')
def test_adjust_sbd_watchdog_timeout_with_qdevice(self, mock_check_reachable, mock_using_diskless_sbd, mock_get_sbd_value, mock_update_config, mock_get_timeout, mock_set_property):
mock_using_diskless_sbd.return_value = True
Expand Down
8 changes: 7 additions & 1 deletion test/unittests/test_report_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_collect_sbd_info(self, mock_exists, mock_copy, mock_which, mock_run, mo
mock_open_write = mock.mock_open()
file_handle = mock_open_write.return_value.__enter__.return_value
mock_open_file.return_value = mock_open_write.return_value
mock_run.return_value = "data"
mock_run.side_effect = ["data", "data", "data"]
mock_ctx_inst = mock.Mock(work_dir="/opt")

collect.collect_sbd_info(mock_ctx_inst)
Expand All @@ -199,6 +199,12 @@ def test_collect_sbd_info(self, mock_exists, mock_copy, mock_which, mock_run, mo
file_handle.write.assert_has_calls([
mock.call("\n\n#=====[ Command ] ==========================#\n"),
mock.call("# . /etc/sysconfig/sbd;export SBD_DEVICE;sbd dump;sbd list\n"),
mock.call("data"),
mock.call("\n\n#=====[ Command ] ==========================#\n"),
mock.call("# crm sbd configure show\n"),
mock.call("data"),
mock.call("\n\n#=====[ Command ] ==========================#\n"),
mock.call("# crm sbd status\n"),
mock.call("data")
])
mock_debug.assert_called_once_with(f"Dump SBD config file into {constants.SBD_F}")
Expand Down
Loading

0 comments on commit 1dedfe3

Please sign in to comment.