Added volume report to hw diags

This commit is contained in:
2Shirt 2020-01-16 20:29:07 -07:00
parent efac71eb63
commit d3597f339e
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -14,6 +14,7 @@ from collections import OrderedDict
from docopt import docopt from docopt import docopt
from wk import cfg, debug, exe, graph, log, net, osticket, std, tmux from wk import cfg, debug, exe, graph, log, net, osticket, std, tmux
from wk import os as wk_os
from wk.hw import obj as hw_obj from wk.hw import obj as hw_obj
from wk.hw import sensors as hw_sensors from wk.hw import sensors as hw_sensors
@ -95,6 +96,10 @@ STATUS_COLORS = {
'Failed': 'RED', 'Failed': 'RED',
'TimedOut': 'RED', 'TimedOut': 'RED',
} }
VOLUME_REGEX = re.compile(
r'^(?P<dev>.*?) (?P<result>Failed to mount|Mounted on|\S+$)'
r'($| (?P<path>.*) \((?P<details>.*)\))'
)
# Error Classes # Error Classes
@ -735,6 +740,7 @@ def cpu_mprime_test(state, test_objects):
# Post results to osTicket # Post results to osTicket
if not state.ost.disabled: if not state.ost.disabled:
std.print_info('Posting results to osTicket...')
CPU_MAX_TEMP = sensors.cpu_max_temp() # pylint: disable=invalid-name,redefined-outer-name,unused-variable CPU_MAX_TEMP = sensors.cpu_max_temp() # pylint: disable=invalid-name,redefined-outer-name,unused-variable
state.ost.post_response( state.ost.post_response(
ost_build_report(state.cpu, 'CPU'), ost_build_report(state.cpu, 'CPU'),
@ -1258,6 +1264,11 @@ def ost_build_report(dev, dev_type):
# Spacer # Spacer
report.append('') report.append('')
# Volume report
if dev_type == 'Disk' and len(dev.tests) == NUM_DISK_TESTS:
report.append('Volumes:')
report.extend(ost_generate_volume_report(dev))
# Remove last line if empty # Remove last line if empty
if not report[-1].strip(): if not report[-1].strip():
report.pop(-1) report.pop(-1)
@ -1312,6 +1323,42 @@ def ost_convert_report(original_report, start_index):
return report return report
def ost_generate_volume_report(dev):
"""Generate volume report for dev, returns list."""
report = []
# OS Check
if PLATFORM != 'Linux':
# TODO: Add macOS volume report
return report
# Convert mount_volume report
vol_report = wk_os.linux.mount_volumes(
device_path=dev.path,
read_write=False,
scan_corestorage=not dev.any_test_failed(),
)
for line in vol_report:
line = std.strip_colors(line)
match = VOLUME_REGEX.match(line)
if match:
if match.group('result') == 'Mounted on':
report.append(
f'... {match.group("dev")}'
f'... Mounted on {match.group("path")}'
f'... ({match.group("details")})'
)
else:
# Assuming either failed to mount or info line about a skipped dev
report.append(f'... {match.group("dev")}... {match.group("result")}')
else:
# Unknown result, just print the whole line
report.append(f'... {line}')
# Done
return report
def ost_post_disk_results(state): def ost_post_disk_results(state):
"""Post disk test results for all disks.""" """Post disk test results for all disks."""
disk_tests_enabled = [data['Enabled'] for name, data in state.tests.items() disk_tests_enabled = [data['Enabled'] for name, data in state.tests.items()
@ -1322,6 +1369,7 @@ def ost_post_disk_results(state):
return return
# Post disk results # Post disk results
std.print_info('Posting results to osTicket...')
for disk in state.disks: for disk in state.disks:
state.ost.post_response( state.ost.post_response(
ost_build_report(disk, 'Disk'), ost_build_report(disk, 'Disk'),