From 9c12dacfb2f2c5191feff20e583618b736db747a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sat, 11 Jan 2020 20:31:39 -0700 Subject: [PATCH] Post CPU/Disk results to osTicket --- scripts/wk/hw/diags.py | 47 ++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index bb11f6a8..04da9158 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -76,11 +76,11 @@ MENU_TOGGLES = ( 'osTicket Note (optional)', 'Skip USB Benchmarks', ) -NUM_DISK_TESTS = sum([s for s in MENU_OPTIONS if s.startswith('Disk')]) +NUM_DISK_TESTS = len([s for s in MENU_OPTIONS if s.startswith('Disk')]) PLATFORM = std.PLATFORM REGEX_BLOCK_GRAPH = re.compile(r'(▁|▂|▃|▄|▅|▆|▇|█)') REGEX_SMART_ATTRIBUTES = re.compile( - r'^\s*(?P\d+) / (?P\w\w): (?P.*)$', + r'^\s*(?P\d+) / (?P\w\w): (?P.*)$', ) STATUS_COLORS = { 'Passed': 'GREEN', @@ -1225,7 +1225,7 @@ def ost_build_report(dev, dev_type): # Description report.append(dev.description) if hasattr(dev, 'ram_total'): - report.append(f'{dev.ram_total} ({", ".join(dev.ramm_dimms)})') + report.append(f'{dev.ram_total} ({", ".join(dev.ram_dimms)})') report.append('') # Notes @@ -1236,13 +1236,7 @@ def ost_build_report(dev, dev_type): # Tests for name, test in dev.tests.items(): - # Name and result - result = 'UNKNOWN' - if test.failed: - result = 'FAILED' - elif test.passed: - result = 'PASSED' - report.append(f'{name} ({result})') + report.append(f'{name} ({test.status})') # Report if name == 'Disk Attributes' and dev.attributes: @@ -1250,7 +1244,7 @@ def ost_build_report(dev, dev_type): ost_convert_report(dev.generate_attribute_report(), start_index=0), ) else: - report.extend(ost_convert_report(dev.report), start_index=1) + report.extend(ost_convert_report(test.report, start_index=1)) # Spacer report.append('') @@ -1308,6 +1302,23 @@ def ost_convert_report(original_report, start_index): return report +def ost_post_disk_results(state): + """Post disk test results for all disks.""" + disk_tests_enabled = [data['Enabled'] for name, data in state.tests.items() + if name.startswith('Disk')] + + # Bail if no disk tests were run + if not any(disk_tests_enabled) or state.ost.disabled: + return + + # Post disk results + for disk in state.disks: + state.ost.post_response( + ost_build_report(disk, 'Disk'), + color='Diags FAIL' if disk.any_test_failed() else 'Diags', + ) + + def print_countdown(proc, seconds): """Print countdown to screen while proc is alive.""" for i in range(seconds): @@ -1335,6 +1346,7 @@ def print_countdown(proc, seconds): def run_diags(state, menu, quick_mode=False): + # pylint: disable=too-many-branches """Run selected diagnostics.""" aborted = False atexit.register(state.save_debug_reports) @@ -1385,6 +1397,16 @@ def run_diags(state, menu, quick_mode=False): aborted = True state.abort_testing() state.update_progress_pane() + + # Post CPU results + if name.startswith('CPU') and not state.ost.disabled: + state.ost.post_response( + ost_build_report(state.cpu, 'CPU'), + color='Diags FAIL' if state.cpu.any_test_failed() else 'Diags', + ) + + # Exit if aborted + if aborted: break # Run safety checks @@ -1398,6 +1420,9 @@ def run_diags(state, menu, quick_mode=False): if test_obj.status == 'Pending': test_obj.set_status('Aborted') + # Post disk results + ost_post_disk_results(state) + # Show results show_results(state)