Improve abort handling
This commit is contained in:
parent
081658550b
commit
cc85e3e8ed
2 changed files with 53 additions and 13 deletions
|
|
@ -147,6 +147,25 @@ class State():
|
||||||
# exe.start_thread(self.fix_tmux_layout_loop)
|
# exe.start_thread(self.fix_tmux_layout_loop)
|
||||||
exe.start_thread(self.fix_tmux_layout_loop)
|
exe.start_thread(self.fix_tmux_layout_loop)
|
||||||
|
|
||||||
|
def abort_testing(self):
|
||||||
|
"""Set unfinished tests as aborted and cleanup tmux panes."""
|
||||||
|
for details in self.tests.values():
|
||||||
|
for test in details['Objects']:
|
||||||
|
if test.status in ('Pending', 'Working'):
|
||||||
|
test.set_status('Aborted')
|
||||||
|
|
||||||
|
# Cleanup tmux
|
||||||
|
self.panes.pop('Current', None)
|
||||||
|
for key, pane_ids in self.panes.copy().items():
|
||||||
|
if key in ('Top', 'Started', 'Progress'):
|
||||||
|
continue
|
||||||
|
if isinstance(pane_ids, str):
|
||||||
|
tmux.kill_pane(self.panes.pop(key))
|
||||||
|
else:
|
||||||
|
for _id in pane_ids:
|
||||||
|
tmux.kill_pane(_id)
|
||||||
|
self.panes.pop(key)
|
||||||
|
|
||||||
def disk_safety_checks(self, prep=False, wait_for_self_tests=True):
|
def disk_safety_checks(self, prep=False, wait_for_self_tests=True):
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
"""Run disk safety checks."""
|
"""Run disk safety checks."""
|
||||||
|
|
@ -190,7 +209,7 @@ class State():
|
||||||
|
|
||||||
# Disable tests if necessary
|
# Disable tests if necessary
|
||||||
if disable_tests:
|
if disable_tests:
|
||||||
disable_disk_tests(disk)
|
disk.disable_disk_tests()
|
||||||
|
|
||||||
# Wait for self-test(s)
|
# Wait for self-test(s)
|
||||||
if self_tests_in_progress:
|
if self_tests_in_progress:
|
||||||
|
|
@ -622,9 +641,14 @@ def check_self_test_results(test_obj, aborted=False):
|
||||||
elif test_obj.status == 'TimedOut':
|
elif test_obj.status == 'TimedOut':
|
||||||
test_obj.report.append(std.color_string(' TimedOut', 'YELLOW'))
|
test_obj.report.append(std.color_string(' TimedOut', 'YELLOW'))
|
||||||
test_obj.set_status('TimedOut')
|
test_obj.set_status('TimedOut')
|
||||||
|
else:
|
||||||
|
test_obj.failed = not test_obj.passed
|
||||||
|
if test_obj.failed:
|
||||||
|
test_obj.set_status('Failed')
|
||||||
|
|
||||||
|
|
||||||
def cpu_mprime_test(state, test_objects):
|
def cpu_mprime_test(state, test_objects):
|
||||||
|
# pylint: disable=too-many-statements
|
||||||
"""CPU & cooling check using Prime95."""
|
"""CPU & cooling check using Prime95."""
|
||||||
LOG.info('CPU Test (Prime95)')
|
LOG.info('CPU Test (Prime95)')
|
||||||
aborted = False
|
aborted = False
|
||||||
|
|
@ -709,14 +733,9 @@ def cpu_mprime_test(state, test_objects):
|
||||||
tmux.kill_pane(state.panes.pop('Prime95', None))
|
tmux.kill_pane(state.panes.pop('Prime95', None))
|
||||||
tmux.kill_pane(state.panes.pop('Temps', None))
|
tmux.kill_pane(state.panes.pop('Temps', None))
|
||||||
|
|
||||||
|
# Done
|
||||||
def disable_disk_tests(disk):
|
if aborted:
|
||||||
"""Disable all tests for disk."""
|
raise std.GenericAbort('Aborted')
|
||||||
LOG.warning('Disabling all tests for: %s', disk.path)
|
|
||||||
for test in disk.tests.values():
|
|
||||||
if test.status in ('Pending', 'Working'):
|
|
||||||
test.set_status('Denied')
|
|
||||||
test.disabled = True
|
|
||||||
|
|
||||||
|
|
||||||
def disk_attribute_check(state, test_objects):
|
def disk_attribute_check(state, test_objects):
|
||||||
|
|
@ -866,6 +885,10 @@ def disk_io_benchmark(state, test_objects, skip_usb=True):
|
||||||
state.update_progress_pane()
|
state.update_progress_pane()
|
||||||
tmux.kill_pane(state.panes.pop('I/O Benchmark', None))
|
tmux.kill_pane(state.panes.pop('I/O Benchmark', None))
|
||||||
|
|
||||||
|
# Done
|
||||||
|
if aborted:
|
||||||
|
raise std.GenericAbort('Aborted')
|
||||||
|
|
||||||
|
|
||||||
def disk_self_test(state, test_objects):
|
def disk_self_test(state, test_objects):
|
||||||
# pylint: disable=too-many-statements
|
# pylint: disable=too-many-statements
|
||||||
|
|
@ -881,7 +904,6 @@ def disk_self_test(state, test_objects):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
test_obj.passed = test_obj.dev.run_self_test(log_path)
|
test_obj.passed = test_obj.dev.run_self_test(log_path)
|
||||||
test_obj.failed = not test_obj.passed
|
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
test_obj.failed = True
|
test_obj.failed = True
|
||||||
result = 'TimedOut'
|
result = 'TimedOut'
|
||||||
|
|
@ -944,11 +966,16 @@ def disk_self_test(state, test_objects):
|
||||||
tmux.kill_pane(pane)
|
tmux.kill_pane(pane)
|
||||||
state.panes.pop('SMART', None)
|
state.panes.pop('SMART', None)
|
||||||
|
|
||||||
|
# Done
|
||||||
|
if aborted:
|
||||||
|
raise std.GenericAbort('Aborted')
|
||||||
|
|
||||||
|
|
||||||
def disk_surface_scan(state, test_objects):
|
def disk_surface_scan(state, test_objects):
|
||||||
# pylint: disable=too-many-statements
|
# pylint: disable=too-many-statements
|
||||||
"""Read-only disk surface scan using badblocks."""
|
"""Read-only disk surface scan using badblocks."""
|
||||||
LOG.info('Disk Surface Scan (badblocks)')
|
LOG.info('Disk Surface Scan (badblocks)')
|
||||||
|
aborted = False
|
||||||
threads = []
|
threads = []
|
||||||
state.panes['badblocks'] = []
|
state.panes['badblocks'] = []
|
||||||
|
|
||||||
|
|
@ -1042,6 +1069,7 @@ def disk_surface_scan(state, test_objects):
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
aborted = True
|
||||||
std.sleep(0.5)
|
std.sleep(0.5)
|
||||||
# Handle aborts
|
# Handle aborts
|
||||||
for test in test_objects:
|
for test in test_objects:
|
||||||
|
|
@ -1055,6 +1083,10 @@ def disk_surface_scan(state, test_objects):
|
||||||
tmux.kill_pane(pane)
|
tmux.kill_pane(pane)
|
||||||
state.panes.pop('badblocks', None)
|
state.panes.pop('badblocks', None)
|
||||||
|
|
||||||
|
# Done
|
||||||
|
if aborted:
|
||||||
|
raise std.GenericAbort('Aborted')
|
||||||
|
|
||||||
|
|
||||||
def get_disks():
|
def get_disks():
|
||||||
"""Get disks using OS-specific methods, returns list."""
|
"""Get disks using OS-specific methods, returns list."""
|
||||||
|
|
@ -1285,10 +1317,10 @@ def run_diags(state, menu, quick_mode=False):
|
||||||
std.clear_screen()
|
std.clear_screen()
|
||||||
try:
|
try:
|
||||||
function(state, *args)
|
function(state, *args)
|
||||||
except std.GenericAbort:
|
except (KeyboardInterrupt, std.GenericAbort):
|
||||||
aborted = True
|
aborted = True
|
||||||
# Restart tmux
|
state.abort_testing()
|
||||||
state.init_tmux()
|
state.update_progress_pane()
|
||||||
break
|
break
|
||||||
|
|
||||||
# Run safety checks
|
# Run safety checks
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,14 @@ class Disk(BaseObj):
|
||||||
# Done
|
# Done
|
||||||
return attributes_ok
|
return attributes_ok
|
||||||
|
|
||||||
|
def disable_disk_tests(self):
|
||||||
|
"""Disable all tests."""
|
||||||
|
LOG.warning('Disabling all tests for: %s', self.path)
|
||||||
|
for test in self.tests.values():
|
||||||
|
if test.status in ('Pending', 'Working'):
|
||||||
|
test.set_status('Denied')
|
||||||
|
test.disabled = True
|
||||||
|
|
||||||
def enable_smart(self):
|
def enable_smart(self):
|
||||||
"""Try enabling SMART for this disk."""
|
"""Try enabling SMART for this disk."""
|
||||||
cmd = [
|
cmd = [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue