From 5fc5cda86df4a94e30d57c5b6ea359427e8953c4 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sat, 14 May 2022 17:51:43 -0700 Subject: [PATCH] Avoid adding duplicate attribute failure notes --- scripts/wk/hw/diags.py | 10 ++++++---- scripts/wk/hw/disk.py | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index 05fef3e3..93980c37 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -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) diff --git a/scripts/wk/hw/disk.py b/scripts/wk/hw/disk.py index 9325dbb3..07f4da2e 100644 --- a/scripts/wk/hw/disk.py +++ b/scripts/wk/hw/disk.py @@ -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)