Avoid adding duplicate attribute failure notes

This commit is contained in:
2Shirt 2022-05-14 17:51:43 -07:00
parent 0ecc4d4146
commit 5fc5cda86d
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 15 additions and 5 deletions

View file

@ -115,8 +115,10 @@ class State():
"""Check for mid-run SMART failures and failed test(s).""" """Check for mid-run SMART failures and failed test(s)."""
for dev in self.disks: for dev in self.disks:
disk_smart_status_check(dev, mid_run=True) disk_smart_status_check(dev, mid_run=True)
if any(test.failed for test in dev.tests): for test in dev.tests:
dev.disable_disk_tests() if test.failed and 'Attributes' not in test.name:
dev.disable_disk_tests()
break
def fix_tmux_layout(self, forced=True) -> None: def fix_tmux_layout(self, forced=True) -> None:
"""Fix tmux layout based on cfg.hw.TMUX_LAYOUT.""" """Fix tmux layout based on cfg.hw.TMUX_LAYOUT."""
@ -651,8 +653,8 @@ def disk_smart_status_check(dev, mid_run=True) -> None:
color = 'YELLOW' color = 'YELLOW'
# Log errors if detected # Log errors if detected
if msg: if msg and not dev.contains_note(msg):
msg = f'{msg}{" during diagnostics" if mid_run else ""}.' msg = f'{msg}{" during diagnostics" if mid_run else ""}'
LOG.warning(msg) LOG.warning(msg)
dev.add_note(msg, color) dev.add_note(msg, color)

View file

@ -17,7 +17,7 @@ from wk.hw.smart import (
generate_attribute_report, generate_attribute_report,
update_smart_details, update_smart_details,
) )
from wk.std import PLATFORM, bytes_to_string, color_string from wk.std import PLATFORM, bytes_to_string, color_string, strip_colors
# STATIC VARIABLES # STATIC VARIABLES
@ -76,6 +76,14 @@ class Disk:
self.notes.append(note) self.notes.append(note)
self.notes.sort() self.notes.sort()
def contains_note(self, note_str) -> bool:
"""Check if note is already present."""
present = False
for note in self.notes:
if note_str == strip_colors(note):
present = True
return present
def disable_disk_tests(self) -> None: def disable_disk_tests(self) -> None:
"""Disable all tests.""" """Disable all tests."""
LOG.warning('Disabling all tests for: %s', self.path) LOG.warning('Disabling all tests for: %s', self.path)