fix(disks): raise on a failed lsblk, warn on failed smartctl calls (#16) #17

Merged
christianmanivong merged 1 commits from fix/bugs-2026-11-02 into main 2026-11-02 08:23:46 +00:00
Owner

What

get_disks() no longer reports a failed read as "no disks", and tells a failed smartctl call apart from a disk without SMART.

  • lsblk: a failed or garbled lsblk -J (empty output, sudo: …, an lsblk error, JSON that is not a device list) raises CommandErrorException with the output's tail. [] now only means lsblk listed no disk.
  • /proc/mdstat: a failed read raises instead of silently dropping every disk's pool. A host without the md driver (no /proc/mdstat) still has no members.
  • smartctl: the call goes through _sudo_status, so the exit status is known. A transport error (timeout) or an exit status with bit 0 or 1 set (command line not parsed — sudo's own refusal exits 1 as well — or device not opened) is logged at warning level with host, disk and reason; the disk stays in the inventory as unknown. The disk-state bits 2–7 are not a failed call: a disk that fails its verdict (bit 3) still reads failed, without a warning in the log. PhysicalDiskDict has no per-disk error field, so "reported per disk" would be a contract change; the warning log is the option the issue names.
  • warning health: a disk whose verdict passed but that counts lost or unreadable sectors reads warning, as the contract (healthy/warning/failed/unknown) allows:
    • ATA: raw value > 0 of Reallocated_Sector_Ct (5), Current_Pending_Sector (197) or Offline_Uncorrectable (198);
    • NVMe: Critical Warning ≠ 0x00, or Media and Data Integrity Errors > 0;
    • SAS: Elements in grown defect list > 0.
      A failed verdict outranks the counters.

get_disks shrinks (lsblk read moved into _lsblk), so its two baseline entries are tightened (lines 87 → 83, complexity 12 → 11).

netOrk

netOrk's poll (netork/jobs/tasks/poll/_collect.py, the storage loop) catches each storage getter's exception and logs get_disks() failed: …; the other storage parts are still collected. The UI's storage tab already colours warning (yellow).

Tests

Fixtures only, reusing the recorded smartctl -iHA outputs (ATA SATA DOM, NVMe, SAS, QEMU) from #15. No degraded disk was at hand, so the warning cases put a count in place of a recorded zero in those recordings (as the existing FAILED! case does for the verdict). Red first: the new parser cases, the lsblk/mdstat failures and the two smartctl warning tests failed against main. pytest (70 passed), ruff format/check, mypy (no errors in the package), napalm-standard check and ratchet green; coverage 62.5 % (floor 15).

Closes #16

## What `get_disks()` no longer reports a failed read as "no disks", and tells a failed `smartctl` call apart from a disk without SMART. - **lsblk**: a failed or garbled `lsblk -J` (empty output, `sudo: …`, an lsblk error, JSON that is not a device list) raises `CommandErrorException` with the output's tail. `[]` now only means lsblk listed no disk. - **/proc/mdstat**: a failed read raises instead of silently dropping every disk's pool. A host without the md driver (no `/proc/mdstat`) still has no members. - **smartctl**: the call goes through `_sudo_status`, so the exit status is known. A transport error (timeout) or an exit status with bit 0 or 1 set (command line not parsed — sudo's own refusal exits 1 as well — or device not opened) is logged at **warning** level with host, disk and reason; the disk stays in the inventory as `unknown`. The disk-state bits 2–7 are not a failed call: a disk that fails its verdict (bit 3) still reads `failed`, without a warning in the log. `PhysicalDiskDict` has no per-disk error field, so "reported per disk" would be a contract change; the warning log is the option the issue names. - **`warning` health**: a disk whose verdict passed but that counts lost or unreadable sectors reads `warning`, as the contract (`healthy`/`warning`/`failed`/`unknown`) allows: - ATA: raw value > 0 of `Reallocated_Sector_Ct` (5), `Current_Pending_Sector` (197) or `Offline_Uncorrectable` (198); - NVMe: `Critical Warning` ≠ `0x00`, or `Media and Data Integrity Errors` > 0; - SAS: `Elements in grown defect list` > 0. A failed verdict outranks the counters. `get_disks` shrinks (lsblk read moved into `_lsblk`), so its two baseline entries are tightened (lines 87 → 83, complexity 12 → 11). ## netOrk netOrk's poll (`netork/jobs/tasks/poll/_collect.py`, the storage loop) catches each storage getter's exception and logs `get_disks() failed: …`; the other storage parts are still collected. The UI's storage tab already colours `warning` (yellow). ## Tests Fixtures only, reusing the recorded `smartctl -iHA` outputs (ATA SATA DOM, NVMe, SAS, QEMU) from #15. No degraded disk was at hand, so the `warning` cases put a count in place of a recorded zero in those recordings (as the existing `FAILED!` case does for the verdict). Red first: the new parser cases, the lsblk/mdstat failures and the two smartctl warning tests failed against main. pytest (70 passed), ruff format/check, mypy (no errors in the package), `napalm-standard check` and `ratchet` green; coverage 62.5 % (floor 15). Closes #16
christianmanivong added 1 commit 2026-11-02 07:43:05 +00:00
fix(disks): raise on a failed lsblk, warn on failed smartctl calls
driver / standard (pull_request) Successful in 21s
driver / lint (pull_request) Successful in 18s
driver / types (pull_request) Successful in 1m17s
driver / test (3.12) (pull_request) Successful in 1m12s
driver / test (3.13) (pull_request) Successful in 1m7s
driver / lowest (pull_request) Successful in 42s
driver / build (pull_request) Successful in 51s
driver / security (pull_request) Successful in 1m35s
CI / driver (pull_request) Successful in 3m26s
driver / publish (pull_request) Skipped
deb233617c
get_disks swallowed a failed or garbled lsblk and returned [], the
answer for a NAS without disks, so every disk vanished on a transient
error. It now raises CommandErrorException; a failed /proc/mdstat read
raises too instead of dropping every pool.

A smartctl call that timed out, was refused by sudo or could not open
the device was logged at debug level and read like a disk without
SMART. It is now logged as a warning with the reason (exit status bits
0 and 1; the disk-state bits 2-7 are not a failed call).

A disk whose verdict passed but that counts reallocated, pending or
offline-uncorrectable sectors (ATA), grown defects (SAS), or sets a
critical warning or counts media errors (NVMe) is reported as
"warning", as the contract allows.

get_disks shrinks below its baseline entries, which are tightened.

Closes #16
christianmanivong merged commit a0d28fc939 into main 2026-11-02 08:23:46 +00:00
christianmanivong deleted branch fix/bugs-2026-11-02 2026-11-02 08:23:46 +00:00
Sign in to join this conversation.