fix(disks): read a SAS disk's temperature
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 1m2s
driver / test (3.12) (pull_request) Successful in 1m1s
driver / test (3.13) (pull_request) Successful in 58s
driver / lowest (pull_request) Successful in 28s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Successful in 1m5s
CI / driver (pull_request) Successful in 2m35s
driver / publish (pull_request) Skipped

A SCSI/SAS disk prints its temperature as "Current Drive Temperature:
28 C", which matched none of the ATA and NVMe patterns, so every SAS
disk read -1. Found in the smartctl output recorded from a Proxmox host.
A QEMU disk without a sensor prints 0 C there and keeps reading -1.
This commit is contained in:
Christian Manivong committed 2026-11-01 22:15:35 +01:00
1 parent c8f4a0b1f7
commit e09af917c8
3 files changed
+38 -7

No files matched your search

+3
View File
@@ -43,6 +43,9 @@ All notable changes to this driver. The format follows
- `get_disks()` puts a disk in the md array only when the disk itself or one of its - `get_disks()` puts a disk in the md array only when the disk itself or one of its
partitions is a member: `sda` no longer joins the array of `sdaa1`, nor `nvme0n1` partitions is a member: `sda` no longer joins the array of `sdaa1`, nor `nvme0n1`
that of `nvme0n11`. `/proc/mdstat` is read once per call instead of once per disk. that of `nvme0n11`. `/proc/mdstat` is read once per call instead of once per disk.
- `get_disks()` reports a SCSI/SAS disk's temperature (`Current Drive Temperature`);
it read `-1` for every SAS disk. A disk that prints `0 C` there, as QEMU's virtual
disks do, still reads `-1`.
## [0.3.0] - 2026-10-23 ## [0.3.0] - 2026-10-23
+18 -7
View File
@@ -57,6 +57,12 @@ _SMART_VERDICT_RE = re.compile(r"^SMART overall-health self-assessment test resu
#: A SCSI/SAS disk's: ``OK``, or the failure it predicts. #: A SCSI/SAS disk's: ``OK``, or the failure it predicts.
_SMART_SCSI_STATUS_RE = re.compile(r"^SMART Health Status:\s*(.+?)\s*$", re.M) _SMART_SCSI_STATUS_RE = re.compile(r"^SMART Health Status:\s*(.+?)\s*$", re.M)
_SMART_VERDICTS = {"PASSED": "healthy", "FAILED": "failed"} _SMART_VERDICTS = {"PASSED": "healthy", "FAILED": "failed"}
#: An ATA disk's temperature attribute, an NVMe disk's ``Temperature:`` line.
_SMART_TEMP_RE = re.compile(
r"(?:Temperature_Celsius|Current Temperature|Temperature:)[^\n]*?(\d+)\s*(?:Celsius|\(|$)"
)
#: A SCSI/SAS disk's; a QEMU disk without a sensor prints ``0 C``.
_SMART_SCSI_TEMP_RE = re.compile(r"^Current Drive Temperature:\s+(\d+) C\s*$", re.M)
#: An md array's line in /proc/mdstat, and its members: ``sda1[0]``, ``sdc1[1](F)``. #: An md array's line in /proc/mdstat, and its members: ``sda1[0]``, ``sdc1[1](F)``.
_MDSTAT_ARRAY_RE = re.compile(r"^(md\d+)\s*:(.*)$", re.M) _MDSTAT_ARRAY_RE = re.compile(r"^(md\d+)\s*:(.*)$", re.M)
_MDSTAT_MEMBER_RE = re.compile(r"(\S+?)\[\d+\]") _MDSTAT_MEMBER_RE = re.compile(r"(\S+?)\[\d+\]")
@@ -77,6 +83,17 @@ def smart_health(output: str) -> str:
return "unknown" return "unknown"
def smart_temperature(output: str) -> int:
"""A disk's temperature in Celsius from ``smartctl -A`` output; ``-1`` if none."""
found = _SMART_TEMP_RE.search(output)
if found:
return int(found.group(1))
scsi = _SMART_SCSI_TEMP_RE.search(output)
if scsi and int(scsi.group(1)) > 0:
return int(scsi.group(1))
return -1
def md_members(mdstat: str) -> dict[str, str]: def md_members(mdstat: str) -> dict[str, str]:
"""Each member device in ``/proc/mdstat``, mapped to its array: ``{"sda1": "md1"}``.""" """Each member device in ``/proc/mdstat``, mapped to its array: ``{"sda1": "md1"}``."""
return { return {
@@ -296,13 +313,7 @@ class OpenMediaVaultDriver(OmvLocalAccountsMixin, StorageDriver, LinuxDriver):
try: try:
smart = self._sudo(_SMARTCTL.format(name=name), read_timeout=15) smart = self._sudo(_SMARTCTL.format(name=name), read_timeout=15)
health = smart_health(smart) health = smart_health(smart)
temp_m = re.search( temperature = smart_temperature(smart)
r"(?:Temperature_Celsius|Current Temperature|Temperature:)"
r"[^\n]*?(\d+)\s*(?:Celsius|\(|$)",
smart,
)
if temp_m:
temperature = int(temp_m.group(1))
if disk_type == "hdd": if disk_type == "hdd":
rpm_m = re.search(r"Rotation Rate:\s+(\d+)\s+rpm", smart) rpm_m = re.search(r"Rotation Rate:\s+(\d+)\s+rpm", smart)
if rpm_m: if rpm_m:
+17
View File
@@ -144,6 +144,23 @@ def test_a_passing_nvme_disk_is_healthy():
assert (disk["health"], disk["temperature"]) == ("healthy", 40) assert (disk["health"], disk["temperature"]) == ("healthy", 40)
def test_a_sas_disk_reports_its_drive_temperature():
nas = Nas({"sdb": ("", SAS_OK)})
disk = _by_slot(nas)["/dev/sdb"]
assert (disk["health"], disk["temperature"]) == ("healthy", 28)
def test_a_disk_without_smart_has_no_temperature():
# QEMU prints "Current Drive Temperature: 0 C" for a disk that has no sensor.
nas = Nas({"sda": ("", QEMU_NO_SMART)})
disk = _by_slot(nas)["/dev/sda"]
assert (disk["health"], disk["temperature"]) == ("unknown", -1)
@pytest.mark.parametrize( @pytest.mark.parametrize(
("output", "health"), ("output", "health"),
[ [