Skip to content

Commit 2d801e2

Browse files
committed
test(hostagent): stop the standby tests reading the runner's own disks
TestCollectDeviceSMARTStandby and its observability twin stub smartctl's execution but not the device-class probe, so collectDeviceSMART fell through to the *runner's* real /sys/block/sda/queue/rotational. smartctlArgs only sends the -n standby guard when the disk is not a confirmed SSD (#1516), and smartctlArgsUseStandbyExitStatus gates the standby reading of exit status 3 on that guard having been sent. On a Linux host whose own /dev/sda is non-rotational the guard is dropped, exit 3 stops meaning standby, and both tests fail deterministically: run smartctl for /dev/sda: exit status 3 They pass on macOS only because linuxNonRotationalBlockDevice returns false off Linux, and on Linux only where /dev/sda is absent or spinning. That makes the release-qualification suite unrunnable on an ordinary SSD-backed Linux worker. Pin the probed disk to rotational through the package's existing stubLinuxSysfs seam so the guard is always in play. Product behaviour is untouched; this only stops two unit tests depending on the hardware underneath them.
1 parent 44d53ed commit 2d801e2

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

internal/hostagent/collector_observability_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ func TestCollectDeviceSMART_LogsStructuredContextWhenDeviceInStandby(t *testing.
118118
execLookPath = origLook
119119
})
120120

121+
// Same host-sysfs leak as TestCollectDeviceSMARTStandby: the -n standby
122+
// guard, and therefore the standby meaning of exit status 3, depends on
123+
// the probed disk not being a confirmed SSD. Pin it to rotational instead
124+
// of reading the runner's own /sys/block/sda/queue/rotational.
125+
stubLinuxSysfs(t, []string{"sda"}, map[string]string{
126+
"/sys/block/sda/queue/rotational": "1\n",
127+
})
128+
121129
execLookPath = func(string) (string, error) { return "smartctl", nil }
122130
smartRunCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {
123131
return exec.CommandContext(ctx, "sh", "-c", "exit 3").Output()

internal/hostagent/smartctl_coverage_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,16 @@ func TestCollectDeviceSMARTStandby(t *testing.T) {
584584
timeNow = origNow
585585
})
586586

587+
// smartctlArgs only sends the -n standby guard for disks that are not
588+
// confirmed SSDs, and exit status 3 only means standby when that guard
589+
// was sent. Without a stubbed sysfs this reads the *runner's* real
590+
// /sys/block/sda/queue/rotational, so the case under test evaporates on
591+
// any Linux host whose own /dev/sda is an SSD. Pin the probed disk to
592+
// rotational so the guard is always in play.
593+
stubLinuxSysfs(t, []string{"sda"}, map[string]string{
594+
"/sys/block/sda/queue/rotational": "1\n",
595+
})
596+
587597
fixed := time.Date(2024, 2, 3, 4, 5, 6, 0, time.UTC)
588598
timeNow = func() time.Time { return fixed }
589599
execLookPath = func(string) (string, error) { return "smartctl", nil }

0 commit comments

Comments
 (0)