Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Rebuild SMART scan fixtures from real --scan output

rcourtman9449a5631897
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 264dabcdf2..5cdb0d8a15 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -2185,6 +2185,20 @@ Agent` secondary handoff against the live setup wizard instead of relying
coverage: `TestSATABehindSASControllerClassifiesAsSATA` in
`internal/hostagent/issue1595_sas_collection_test.go`.
+24. `smartctl --scan` device types are hints, not ground truth, and discovery
+ fixtures must come from the command actually being run. The non-opening
+ scan cannot interrogate a device, so on a real host every libata disk is
+ reported as `-d scsi` (captured from Unraid, smartctl 7.5, 2026-07-24),
+ never `-d sat`. Probe selection therefore has to reject a scan type that
+ contradicts the sysfs transport evidence and still reach `-d sat`, or every
+ SATA array member is probed as SCSI. Fixtures relabelled from `--scan-open`
+ to `--scan` describe a scan shape that never occurs and cannot prove this.
+ Regression coverage:
+ `TestScanReportedSCSITypeStillProbesSATADisksAsSAT` in
+ `internal/hostagent/issue1595_sas_collection_test.go` and
+ `TestParseSmartctlScanTargetsRealScanOutput` in
+ `internal/hostagent/smartctl_discovery_test.go`.
+
## Current State
### PBS connection health does not create agent lifecycle evidence
diff --git a/internal/hostagent/issue1595_sas_collection_test.go b/internal/hostagent/issue1595_sas_collection_test.go
index 6f1db2f994..010c99883c 100644
--- a/internal/hostagent/issue1595_sas_collection_test.go
+++ b/internal/hostagent/issue1595_sas_collection_test.go
@@ -348,3 +348,73 @@ func TestSATABehindSASControllerClassifiesAsSATA(t *testing.T) {
t.Fatalf("inferred device types = %v, want the sat hint first", types)
}
}
+
+// TestScanReportedSCSITypeStillProbesSATADisksAsSAT drives the real Unraid
+// discovery shape end to end.
+//
+// Captured from tower (Unraid 6.18.33, smartctl 7.5 2025-04-30 r5714,
+// 2026-07-24). The non-opening `smartctl --scan` cannot interrogate a device,
+// so every libata disk is reported as a generic SCSI device:
+//
+// /dev/sdb -d scsi # /dev/sdb, SCSI device
+// /dev/nvme0 -d nvme # /dev/nvme0, NVMe device
+//
+// and sysfs on the same host carries no protocol/transport/sas_address for
+// those disks, only vendor "ATA" under an /ataN/ path. Discovery must therefore
+// treat the scan's "scsi" as the hint it is and still reach "-d sat", otherwise
+// every SATA disk on an Unraid array gets probed as SCSI, which is exactly what
+// the #1612 work set out to stop.
+func TestScanReportedSCSITypeStillProbesSATADisksAsSAT(t *testing.T) {
+ origRead := smartctlReadFile
+ origEval := smartctlEvalSymlinks
+ origGOOS := runtimeGOOS
+ t.Cleanup(func() {
+ smartctlReadFile = origRead
+ smartctlEvalSymlinks = origEval
+ runtimeGOOS = origGOOS
+ })
+ runtimeGOOS = "linux"
+
+ // Exactly what tower reports for an array member.
+ smartctlReadFile = func(path string) ([]byte, error) {
+ if filepath.ToSlash(path) == "/sys/block/sdb/device/vendor" {
+ return []byte("ATA "), nil
+ }
+ return nil, fs.ErrNotExist
+ }
+ smartctlEvalSymlinks = func(string) (string, error) {
+ return "/sys/devices/pci0000:00/0000:00:11.0/ata1/host0/target0:0:0/0:0:0:0", nil
+ }
+
+ target := smartctlTarget{Path: "/dev/sdb", DeviceType: "scsi"}
+
+ if got := linuxSMARTTargetTransport(target); got != "sata" {
+ t.Fatalf("transport = %q, want %q", got, "sata")
+ }
+ if smartctlDeviceTypeMatchesTransport(target.DeviceType, "sata") {
+ t.Fatal("the scan's generic scsi type must not be accepted for a SATA transport")
+ }
+
+ attempts := smartctlProbeAttempts(target)
+ if len(attempts) == 0 {
+ t.Fatal("no probe attempts for a scan-discovered SATA disk")
+ }
+
+ var sawSAT bool
+ for _, attempt := range attempts {
+ for i, arg := range attempt {
+ if arg != "-d" || i+1 >= len(attempt) {
+ continue
+ }
+ if attempt[i+1] == "scsi" {
+ t.Fatalf("SATA disk probed as scsi: %v", attempt)
+ }
+ if attempt[i+1] == "sat" {
+ sawSAT = true
+ }
+ }
+ }
+ if !sawSAT {
+ t.Fatalf("no -d sat probe attempted for a SATA disk: %v", attempts)
+ }
+}
diff --git a/internal/hostagent/smartctl_discovery_test.go b/internal/hostagent/smartctl_discovery_test.go
index c7e5a9e637..180f2b239b 100644
--- a/internal/hostagent/smartctl_discovery_test.go
+++ b/internal/hostagent/smartctl_discovery_test.go
@@ -23,9 +23,20 @@ const scanOpenPVENVMeOnly = `/dev/nvme0 -d nvme # /dev/nvme0, NVMe device
/dev/nvme1 -d nvme # /dev/nvme1, NVMe device
`
-// scanOpenPVESATA is verbatim `smartctl --scan` output from a PVE 9.1.9
-// host with a single SATA SSD (minipc, 2026-06-10).
-const scanOpenPVESATA = `/dev/sda -d sat # /dev/sda [SAT], ATA device
+// scanSATA is the shape `smartctl --scan` really returns for a libata disk.
+//
+// Captured from Unraid (tower, smartctl 7.5 2025-04-30 r5714, 2026-07-24):
+// the non-opening scan cannot interrogate the device, so every SATA disk is
+// reported as a generic SCSI device, never as `-d sat`:
+//
+// /dev/sdb -d scsi # /dev/sdb, SCSI device
+//
+// The previous value here carried `-d sat # /dev/sda [SAT], ATA device`, which
+// is `--scan-open` output relabelled when discovery moved to `--scan`. Probe
+// selection discards this mismatched hint via smartctlDeviceTypeMatchesTransport
+// and falls back to untyped plus the inferred `-d sat`, which is what makes the
+// real scan usable. See TestScanReportedSCSITypeStillProbesSATADisksAsSAT.
+const scanSATA = `/dev/sda -d scsi # /dev/sda, SCSI device
`
// smartctlSATAProbeJSON carries the key fields of a real
@@ -51,15 +62,17 @@ const smartctlNVMeProbeJSON = `{
"temperature": {"current": 37}
}`
-func TestParseSmartctlScanOpenTargetsRealPVEOutput(t *testing.T) {
- targets := parseSmartctlScanTargets([]byte(scanOpenPVENVMeOnly+scanOpenPVESATA), nil)
+func TestParseSmartctlScanTargetsRealScanOutput(t *testing.T) {
+ targets := parseSmartctlScanTargets([]byte(scanOpenPVENVMeOnly+scanSATA), nil)
if len(targets) != 3 {
t.Fatalf("expected 3 targets, got %#v", targets)
}
if targets[0].Path != "/dev/nvme0" || targets[0].DeviceType != "nvme" {
t.Errorf("unexpected first target: %#v", targets[0])
}
- if targets[2].Path != "/dev/sda" || targets[2].DeviceType != "sat" {
+ // Real `--scan` cannot open the device, so a libata disk arrives typed as
+ // a generic SCSI device. Probe selection is what recovers from that.
+ if targets[2].Path != "/dev/sda" || targets[2].DeviceType != "scsi" {
t.Errorf("unexpected SATA target: %#v", targets[2])
}
}
@@ -294,6 +307,9 @@ func TestCollectSMARTLocalEmitsIdentityOnlyEntryWhenSMARTUnavailable(t *testing.
map[string]string{
"/sys/block/sda/size": "1000215216\n", // 512110190592 bytes
"/sys/block/sda/device/model": "N900-512 \n",
+ // A real libata host exposes vendor ATA; without it the scan's
+ // generic "scsi" type would be the only evidence available.
+ "/sys/block/sda/device/vendor": "ATA \n",
},
)
@@ -307,7 +323,7 @@ func TestCollectSMARTLocalEmitsIdentityOnlyEntryWhenSMARTUnavailable(t *testing.
smartRunCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {
if len(args) == 1 && args[0] == "--scan" {
- return []byte(scanOpenPVESATA), nil
+ return []byte(scanSATA), nil
}
return []byte(smartctlNoDataJSON), nil
}
@@ -378,7 +394,7 @@ func TestCollectSMARTLocalSkipsIdentityOnlyEntries(t *testing.T) {
smartRunCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {
if len(args) == 1 && args[0] == "--scan" {
- return []byte(scanOpenPVESATA), nil
+ return []byte(scanSATA), nil
}
return []byte(smartctlNoDataJSON), nil
}