Skip to content

Commit

Permalink
Dev: unittest: adjust unit tests for previous changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyang2022 committed Feb 26, 2024
1 parent 1f69ce9 commit 9510a00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
36 changes: 17 additions & 19 deletions test/unittests/test_report_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,35 +346,33 @@ def test_consume_cib_in_workdir(self, mock_isfile, mock_run, mock_str2file):
mock.call("data2", f"/workdir/{constants.CRM_VERIFY_F}")
])

@mock.patch('crmsh.report.collect.logger', spec=crmsh.log.DEBUG2Logger)
@mock.patch('crmsh.report.collect.sh.cluster_shell')
def test_collect_ratraces_return(self, mock_run, mock_logger):
mock_run_inst = mock.Mock()
mock_run.return_value = mock_run_inst
mock_run_inst.get_rc_stdout_stderr_without_input.return_value = (0, "data", None)
mock_ctx_inst = mock.Mock(node_list=["node1"])
collect.collect_ratraces(mock_ctx_inst)
mock_logger.debug2.assert_not_called()

@mock.patch('crmsh.report.utils.real_path')
@mock.patch('crmsh.report.collect.logger', spec=crmsh.log.DEBUG2Logger)
@mock.patch('shutil.copy2')
@mock.patch('crmsh.utils.mkdirp')
@mock.patch('crmsh.report.utils.find_files_in_timespan')
@mock.patch('crmsh.report.collect.sh.cluster_shell')
def test_collect_ratraces(self, mock_run, mock_find, mock_mkdirp, mock_copy, mock_logger, mock_real_path):
def test_collect_ratraces(self, mock_find, mock_mkdirp, mock_copy, mock_logger, mock_real_path):
mock_real_path.return_value = "/var/log"
mock_run_inst = mock.Mock()
mock_run.return_value = mock_run_inst
data = "INFO: Trace for .* is written to /var/log/cluster/pacemaker.log"
mock_run_inst.get_rc_stdout_stderr_without_input.return_value = (0, data, None)
mock_ctx_inst = mock.Mock(node_list=["node1"], work_dir="/opt/work")
mock_find.return_value = ["/var/log/cluster"]
mock_ctx_inst = mock.Mock(
work_dir="/opt/work",
trace_dir_list="/var/lib/heartbeat/trace_ra",
)
mock_find.return_value = [
"/var/lib/heartbeat/trace_ra/IPaddr2/admin-ip.monitor.2024-02-26.15:21:39",
"/var/lib/heartbeat/trace_ra/IPaddr2/admin-ip.start.2024-02-26.15:21:39",
"/var/lib/heartbeat/trace_ra/IPaddr2/admin-ip.stop.2024-02-26.15:21:46",
]

collect.collect_ratraces(mock_ctx_inst)

mock_logger.debug2.assert_called_once_with('Looking for RA trace files in "%s"', '/var/log/cluster')
mock_logger.debug.assert_called_once_with(f'Dump RA trace files into {mock_real_path.return_value}')
mock_mkdirp.assert_called_with('/opt/work/trace_ra/IPaddr2')
mock_copy.assert_has_calls([
mock.call("/var/lib/heartbeat/trace_ra/IPaddr2/admin-ip.monitor.2024-02-26.15:21:39", '/opt/work/trace_ra/IPaddr2'),
mock.call("/var/lib/heartbeat/trace_ra/IPaddr2/admin-ip.start.2024-02-26.15:21:39", '/opt/work/trace_ra/IPaddr2'),
mock.call("/var/lib/heartbeat/trace_ra/IPaddr2/admin-ip.stop.2024-02-26.15:21:46", '/opt/work/trace_ra/IPaddr2'),
])
mock_logger.debug.assert_called_with(f'Dump RA trace files into {mock_real_path.return_value}')

@mock.patch('crmsh.report.collect.ShellUtils')
def test_lsof_ocfs2_device(self, mock_run):
Expand Down
4 changes: 3 additions & 1 deletion test/unittests/test_report_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,14 @@ def test_run_impl_collector(self, mock_context, mock_collector, mock_load, mock_

@mock.patch('crmsh.report.core.process_results')
@mock.patch('crmsh.report.core.collect_for_nodes')
@mock.patch('crmsh.report.core.load_context_trace_dir_list')
@mock.patch('crmsh.report.core.find_ssh_user')
@mock.patch('crmsh.report.core.setup_workdir')
@mock.patch('crmsh.report.core.load_context_attributes')
@mock.patch('crmsh.report.core.parse_arguments')
@mock.patch('crmsh.report.core.is_collector')
@mock.patch('crmsh.report.core.Context')
def test_run_impl(self, mock_context, mock_collector, mock_parse, mock_load, mock_setup, mock_find_ssh, mock_collect, mock_process_results):
def test_run_impl(self, mock_context, mock_collector, mock_parse, mock_load, mock_setup, mock_find_ssh, mock_load_context_trace_dir_list, mock_collect, mock_process_results):
mock_context.return_value = mock.Mock()
mock_ctx_inst = mock_context.return_value
mock_collector.side_effect = [False, False]
Expand All @@ -320,6 +321,7 @@ def test_run_impl(self, mock_context, mock_collector, mock_parse, mock_load, moc
mock_load.assert_called_once_with(mock_ctx_inst)
mock_setup.assert_called_once_with(mock_ctx_inst)
mock_find_ssh.assert_called_once_with(mock_ctx_inst)
mock_load_context_trace_dir_list.assert_called_once_with(mock_ctx_inst)
mock_collect.assert_called_once_with(mock_ctx_inst)
mock_process_results.assert_called_once_with(mock_ctx_inst)

Expand Down

0 comments on commit 9510a00

Please sign in to comment.