Don't export/upload graphs for skipped tests

* e.g. USB device which USB benchmarks disabled
This commit is contained in:
2Shirt 2020-01-22 19:51:01 -07:00
parent 701d647a91
commit fd8f46be13
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 27 additions and 21 deletions

View file

@ -47,9 +47,8 @@ THRESH_GREAT = 750 * 1024**2
# Functions
def export_io_graph(disk, log_dir):
def export_io_graph(disk, log_dir, read_rates):
"""Exports PNG graph using gnuplot, returns pathlib.Path obj."""
read_rates = disk.tests['Disk I/O Benchmark'].read_rates
# Safety check
if not read_rates:

View file

@ -538,7 +538,8 @@ def check_cooling_results(test_obj, sensors):
test_obj.report.append(f' {line}')
def check_io_benchmark_results(test_obj, rate_list, graph_width):
def check_io_benchmark_results(test_obj, rate_list, graph_width, state):
# pylint: disable=too-many-branches
"""Generate colored report using rate_list, returns list of str."""
avg_read = sum(rate_list) / len(rate_list)
min_read = min(rate_list)
@ -582,6 +583,26 @@ def check_io_benchmark_results(test_obj, rate_list, graph_width):
else:
test_obj.set_status('Unknown')
# osTicket - Export PNG
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 upload steps below
test_obj.report.append('Failed to export graph')
return
# osTicket - 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 RuntimeError:
test_obj.report.append('Failed to upload graph')
def check_mprime_results(test_obj, working_dir):
"""Check mprime log files and update test_obj."""
@ -748,7 +769,7 @@ def cpu_mprime_test(state, test_objects):
std.print_info('Posting results to osTicket...')
test_cooling_obj.cpu_max_temp = sensors.cpu_max_temp()
state.ost.post_response(
ost_build_report(state.cpu, 'CPU', state),
ost_build_report(state.cpu, 'CPU'),
color='Diags FAIL' if state.cpu.any_test_failed() else 'Diags',
)
@ -858,10 +879,7 @@ def disk_io_benchmark(state, test_objects, skip_usb=True):
offset += dd_values['Read Blocks'] + skip
# Check results
check_io_benchmark_results(test_obj, read_rates, IO_GRAPH_WIDTH)
# osTicket
test_obj.read_rates = read_rates
check_io_benchmark_results(test_obj, read_rates, IO_GRAPH_WIDTH, state)
# Run benchmarks
state.update_top_pane(
@ -1231,8 +1249,7 @@ def network_test():
std.pause('Press Enter to return to main menu...')
def ost_build_report(dev, dev_type, state):
# pylint: disable=too-many-branches
def ost_build_report(dev, dev_type):
"""Build report for posting to osTicket, returns str."""
report = []
@ -1283,16 +1300,6 @@ def ost_build_report(dev, dev_type, state):
)
else:
report.extend(ost_convert_report(test.report, start_index=1))
if name == 'Disk I/O Benchmark':
try:
image_path = graph.export_io_graph(dev, state.log_dir)
imgur_url = graph.upload_to_imgur(image_path)
nextcloud_url = graph.upload_to_nextcloud(
image_path, state.ost.ticket_id, dev.path.name)
report.append(f'Imgur: {imgur_url}')
report.append(f'Nextcloud: {nextcloud_url}')
except (AttributeError, RuntimeError):
report.append('Error(s) exporting graph')
# Spacer
report.append('')
@ -1405,7 +1412,7 @@ def ost_post_disk_results(state):
std.print_info('Posting results to osTicket...')
for disk in state.disks:
state.ost.post_response(
ost_build_report(disk, 'Disk', state),
ost_build_report(disk, 'Disk'),
color='Diags FAIL' if disk.any_test_failed() else 'Diags',
)