Harden IPMI power probe timeout
This commit is contained in:
@@ -1601,7 +1601,10 @@ func maxInt(a, b int) int {
|
|||||||
// queryIPMIServerPowerW reads the current server power draw via ipmitool dcmi.
|
// queryIPMIServerPowerW reads the current server power draw via ipmitool dcmi.
|
||||||
// Returns 0 and an error if IPMI is unavailable or the output cannot be parsed.
|
// Returns 0 and an error if IPMI is unavailable or the output cannot be parsed.
|
||||||
func queryIPMIServerPowerW() (float64, error) {
|
func queryIPMIServerPowerW() (float64, error) {
|
||||||
out, err := satExecCommand("ipmitool", "dcmi", "power", "reading").Output()
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
cmd := exec.CommandContext(ctx, "ipmitool", "dcmi", "power", "reading")
|
||||||
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("ipmitool dcmi power reading: %w", err)
|
return 0, fmt.Errorf("ipmitool dcmi power reading: %w", err)
|
||||||
}
|
}
|
||||||
@@ -1620,6 +1623,7 @@ func sampleIPMIPowerSeries(ctx context.Context, durationSec int) (meanW float64,
|
|||||||
}
|
}
|
||||||
deadline := time.Now().Add(time.Duration(durationSec) * time.Second)
|
deadline := time.Now().Add(time.Duration(durationSec) * time.Second)
|
||||||
var samples []float64
|
var samples []float64
|
||||||
|
loop:
|
||||||
for {
|
for {
|
||||||
if w, err := queryIPMIServerPowerW(); err == nil {
|
if w, err := queryIPMIServerPowerW(); err == nil {
|
||||||
samples = append(samples, w)
|
samples = append(samples, w)
|
||||||
@@ -1629,7 +1633,7 @@ func sampleIPMIPowerSeries(ctx context.Context, durationSec int) (meanW float64,
|
|||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
break
|
break loop
|
||||||
case <-time.After(2 * time.Second):
|
case <-time.After(2 * time.Second):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user