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)."""
for dev in self.disks:
disk_smart_status_check(dev, mid_run=True)
if any(test.failed for test in dev.tests):
dev.disable_disk_tests()
for test in dev.tests:
if test.failed and 'Attributes' not in test.name:
dev.disable_disk_tests()
break
def fix_tmux_layout(self, forced=True) -> None:
"""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'
# Log errors if detected
if msg:
msg = f'{msg}{" during diagnostics" if mid_run else ""}.'
if msg and not dev.contains_note(msg):
msg = f'{msg}{" during diagnostics" if mid_run else ""}'
LOG.warning(msg)
dev.add_note(msg, color)

View file

@ -17,7 +17,7 @@ from wk.hw.smart import (
generate_attribute_report,
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
@ -76,6 +76,14 @@ class Disk:
self.notes.append(note)
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:
"""Disable all tests."""
LOG.warning('Disabling all tests for: %s', self.path)