Catch CTRL+c aborts and show results

This commit is contained in:
2Shirt 2018-12-15 18:56:41 -07:00
parent 8b936f5413
commit ef42b596d9
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -747,10 +747,13 @@ def run_badblocks_test(state, test):
# Start badblocks # Start badblocks
print_standard('Running badblocks test...') print_standard('Running badblocks test...')
test.badblocks_proc = popen_program( try:
['sudo', 'hw-diags-badblocks', test.dev.path, test.badblocks_out], test.badblocks_proc = popen_program(
pipe=True) ['sudo', 'hw-diags-badblocks', test.dev.path, test.badblocks_out],
test.badblocks_proc.wait() pipe=True)
test.badblocks_proc.wait()
except KeyboardInterrupt:
raise GenericAbort('Aborted')
# Check result and create report # Check result and create report
try: try:
@ -833,11 +836,31 @@ def run_hw_tests(state):
# Run tests # Run tests
## Because state.tests is an OrderedDict and the disks were added ## Because state.tests is an OrderedDict and the disks were added
## in order, the tests will be run in order. ## in order, the tests will be run in order.
for k, v in state.tests.items(): try:
if v['Enabled']: for k, v in state.tests.items():
f = v['Function'] if v['Enabled']:
for test_obj in v['Objects']: f = v['Function']
f(state, test_obj) for test_obj in v['Objects']:
f(state, test_obj)
except GenericAbort:
# Cleanup
tmux_kill_pane(*state.panes.values())
# Rebuild panes
update_progress_pane(state)
build_outer_panes(state)
# Mark unfinished tests as aborted
for k, v in state.tests.items():
if v['Enabled']:
for test_obj in v['Objects']:
if re.search(r'(Pending|Working)', test_obj.status):
test_obj.update_status('Aborted')
test_obj.report.append(' {YELLOW}Aborted{CLEAR}'.format(
**COLORS))
# Update side pane
update_progress_pane(state)
# Done # Done
show_results(state) show_results(state)
@ -1130,27 +1153,30 @@ def run_nvme_smart_tests(state, test):
run_program(cmd, check=False) run_program(cmd, check=False)
# Monitor progress (in 5 second increments) # Monitor progress (in 5 second increments)
for iteration in range(int(test.timeout*60/5)): try:
sleep(5) for iteration in range(int(test.timeout*60/5)):
sleep(5)
# Update SMART data # Update SMART data
test.dev.get_smart_details() test.dev.get_smart_details()
if _self_test_started: if _self_test_started:
# Update progress file # Update progress file
with open(test.smart_out, 'w') as f: with open(test.smart_out, 'w') as f:
f.write('SMART self-test status:\n {}'.format( f.write('SMART self-test status:\n {}'.format(
test.dev.smart_self_test['status'].get( test.dev.smart_self_test['status'].get(
'string', 'UNKNOWN').capitalize())) 'string', 'UNKNOWN').capitalize()))
# Check if test has finished # Check if test has finished
if 'remaining_percent' not in test.dev.smart_self_test['status']: if 'remaining_percent' not in test.dev.smart_self_test['status']:
break break
else: else:
# Check if test has started # Check if test has started
if 'remaining_percent' in test.dev.smart_self_test['status']: if 'remaining_percent' in test.dev.smart_self_test['status']:
_self_test_started = True _self_test_started = True
except KeyboardInterrupt:
raise GenericAbort('Aborted')
# Check if timed out # Check if timed out
if test.dev.smart_self_test['status'].get('passed', False): if test.dev.smart_self_test['status'].get('passed', False):