From 26022f6011bc4789c85bc569a8f3be5f0a0aaec1 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sat, 8 Oct 2022 22:07:05 -0700 Subject: [PATCH] Fix I/O benchmark graph uploads Addresses issue #22 --- scripts/wk/hw/benchmark.py | 34 +++++++++++++++++++++++++++++++--- scripts/wk/hw/diags.py | 2 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/scripts/wk/hw/benchmark.py b/scripts/wk/hw/benchmark.py index 1cc10346..4fd77722 100644 --- a/scripts/wk/hw/benchmark.py +++ b/scripts/wk/hw/benchmark.py @@ -100,7 +100,7 @@ def calc_io_dd_values(dev_size, test_mode=False) -> dict[str, int]: } -def check_io_results(test_obj, rate_list, graph_width) -> None: +def check_io_results(state, test_obj, rate_list, graph_width) -> None: """Check I/O restuls and generate report using rate_list.""" avg_read = sum(rate_list) / len(rate_list) min_read = min(rate_list) @@ -144,8 +144,36 @@ def check_io_results(test_obj, rate_list, graph_width) -> None: else: test_obj.set_status('Unknown') + # Export and upload graphs + export_and_upload_graphs(state, test_obj, rate_list) -def run_io_test(test_obj, log_path, test_mode=False) -> None: + +def export_and_upload_graphs(state, test_obj, rate_list): + """Export and upload graphs.""" + image_path = None + try: + image_path = graph.export_io_graph(test_obj.dev, state.log_dir, rate_list) + except RuntimeError: + # Failed to export PNG, skip uploads below + test_obj.report.append('Failed to export graph') + return + + # Upload PNG + if not state.ost.disabled and state.ost.ticket_id: + try: + imgur_url = graph.upload_to_imgur(image_path) + nextcloud_url = graph.upload_to_nextcloud( + image_path, state.ost.ticket_id, test_obj.dev.path.name) + test_obj.report.append(f'Imgur: {imgur_url}') + test_obj.report.append(f'Nextcloud: {nextcloud_url}') + except Exception as err: # pylint: disable=broad-except + LOG.error('%s', err) + LOG.error('Failed to upload graph') + test_obj.report.append('Failed to upload graph') + + +def run_io_test(state, test_obj, log_path, test_mode=False) -> None: + #pylint: disable=too-many-locals """Run I/O benchmark and handle exceptions.""" dev_path = test_obj.dev.path if PLATFORM == 'Darwin': @@ -214,7 +242,7 @@ def run_io_test(test_obj, log_path, test_mode=False) -> None: offset += dd_values['Read Blocks'] + skip # Check results - check_io_results(test_obj, read_rates, IO_GRAPH_WIDTH) + check_io_results(state, test_obj, read_rates, IO_GRAPH_WIDTH) diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index 76dfbf5f..b37ee1fc 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -610,7 +610,7 @@ def disk_io_benchmark( ) state.update_progress_pane() try: - hw_benchmark.run_io_test(test, test_log, test_mode=test_mode) + hw_benchmark.run_io_test(state, test, test_log, test_mode=test_mode) except KeyboardInterrupt: aborted = True except (subprocess.CalledProcessError, TypeError, ValueError) as err: