Avoid crashing if a device disconnects mid-diags
This commit is contained in:
parent
21da84e5e2
commit
f008546565
4 changed files with 25 additions and 0 deletions
|
|
@ -642,6 +642,11 @@ def disk_smart_status_check(dev, mid_run=True) -> None:
|
||||||
color = None
|
color = None
|
||||||
disable_tests = False
|
disable_tests = False
|
||||||
|
|
||||||
|
# Bail if dev is missing
|
||||||
|
if not dev.present:
|
||||||
|
dev.disable_disk_tests()
|
||||||
|
return
|
||||||
|
|
||||||
# Check SMART status and attributes
|
# Check SMART status and attributes
|
||||||
if not hw_smart.smart_status_ok(dev):
|
if not hw_smart.smart_status_ok(dev):
|
||||||
msg = 'Critical SMART error detected'
|
msg = 'Critical SMART error detected'
|
||||||
|
|
|
||||||
|
|
@ -151,12 +151,23 @@ class Disk:
|
||||||
|
|
||||||
return aligned
|
return aligned
|
||||||
|
|
||||||
|
@property
|
||||||
|
def present(self) -> bool:
|
||||||
|
"""Verify this device is still present, returns bool."""
|
||||||
|
if not self.path.exists():
|
||||||
|
self.add_note('Device disconnected', 'RED')
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def update_details(self, skip_children=True) -> None:
|
def update_details(self, skip_children=True) -> None:
|
||||||
"""Update disk details using OS specific methods.
|
"""Update disk details using OS specific methods.
|
||||||
|
|
||||||
Required details default to generic descriptions
|
Required details default to generic descriptions
|
||||||
and are converted to the correct type.
|
and are converted to the correct type.
|
||||||
"""
|
"""
|
||||||
|
if not self.present:
|
||||||
|
return
|
||||||
|
|
||||||
if PLATFORM == 'Darwin':
|
if PLATFORM == 'Darwin':
|
||||||
self.raw_details = get_disk_details_macos(
|
self.raw_details = get_disk_details_macos(
|
||||||
self.path, skip_children=skip_children,
|
self.path, skip_children=skip_children,
|
||||||
|
|
|
||||||
|
|
@ -380,6 +380,11 @@ def update_smart_details(dev) -> None:
|
||||||
"""Update SMART details via smartctl."""
|
"""Update SMART details via smartctl."""
|
||||||
updated_attributes = {}
|
updated_attributes = {}
|
||||||
|
|
||||||
|
# Bail if device was disconnected
|
||||||
|
if not dev.present:
|
||||||
|
dev.add_note('Device disconnected', 'RED')
|
||||||
|
return
|
||||||
|
|
||||||
# Get SMART data
|
# Get SMART data
|
||||||
cmd = [
|
cmd = [
|
||||||
'sudo',
|
'sudo',
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,10 @@ def mount_volumes(device_path=None, read_write=False, scan_corestorage=False):
|
||||||
cmd.append(device_path)
|
cmd.append(device_path)
|
||||||
json_data = get_json_from_command(cmd)
|
json_data = get_json_from_command(cmd)
|
||||||
|
|
||||||
|
# Bail if json_data is empty
|
||||||
|
if not json_data:
|
||||||
|
return
|
||||||
|
|
||||||
# Build list of volumes
|
# Build list of volumes
|
||||||
for dev in json_data.get('blockdevices', [{}]):
|
for dev in json_data.get('blockdevices', [{}]):
|
||||||
volumes.extend(_get_volumes(dev))
|
volumes.extend(_get_volumes(dev))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue