diff --git a/scripts/wk/hw/cpu.py b/scripts/wk/hw/cpu.py index 8d495ff5..541c2861 100644 --- a/scripts/wk/hw/cpu.py +++ b/scripts/wk/hw/cpu.py @@ -9,7 +9,11 @@ from typing import TextIO from wk import exe from wk.cfg.hw import CPU_TEMPS -from wk.graph import export_cpu_graph +from wk.graph import ( + export_cpu_graph, + upload_to_imgur, + upload_to_nextcloud, + ) from wk.os.mac import set_fans as macos_set_fans from wk.std import PLATFORM from wk.ui import ansi @@ -21,8 +25,9 @@ SysbenchType = tuple[subprocess.Popen, TextIO] # Functions -def check_cooling_results(cpu_description, log_dir, sensors, test_object) -> None: +def check_cooling_results(state, test_object) -> None: """Check cooling result via sensor data.""" + sensors = state.sensors idle_temp = sensors.get_cpu_temp('Idle') cooldown_temp = sensors.get_cpu_temp('Cooldown') max_temp = sensors.get_cpu_temp('Max') @@ -85,12 +90,36 @@ def check_cooling_results(cpu_description, log_dir, sensors, test_object) -> Non *report_labels, only_cpu=True, include_avg_for=average_labels): test_object.report.append(f' {line}') - # Export graph - export_cpu_graph( - cpu_description = cpu_description, - log_dir = log_dir, - sensor_history = sensors.history, - ) + # Export and upload graph + export_and_upload_graphs(state, test_object) + + +def export_and_upload_graphs(state, test_object): + """Export and upload graphs.""" + image_path = None + try: + image_path = export_cpu_graph( + cpu_description = state.system.cpu_description, + log_dir = state.log_dir, + sensor_history = state.sensors.history, + ) + except RuntimeError as err: + # Failed to export PNG, skip uploads below + LOG.error('Failed to export graph: %s', err) + test_object.report.append('Failed to export graph') + return + + # Upload PNG + if not state.ost.disabled and state.ost.ticket_id: + try: + imgur_url = upload_to_imgur(image_path) + nextcloud_url = upload_to_nextcloud(image_path, state.ost.ticket_id, 'cpu') + test_object.report.append(f'Imgur: {imgur_url}') + test_object.report.append(f'Nextcloud: {nextcloud_url}') + except Exception as err: + LOG.error('%s', err) + LOG.error('Failed to upload graph') + test_object.report.append('Failed to upload graph') def check_mprime_results(test_obj, working_dir) -> None: diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index 1bebbb20..6da3331d 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -413,12 +413,7 @@ def cpu_test_cooling(state: State, test_object, test_mode=False) -> None: if test_object.disabled: return - hw_cpu.check_cooling_results( - state.system.cpu_description, - state.log_dir, - state.sensors, - test_object, - ) + hw_cpu.check_cooling_results(state, test_object) state.update_progress_file()