refactor: modularize audit and harden build validation
This commit is contained in:
+28
-36
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"bee/audit/internal/collector"
|
||||
@@ -96,14 +95,38 @@ type installer interface {
|
||||
type GPUPresenceResult struct {
|
||||
Nvidia bool
|
||||
AMD bool
|
||||
// NvidiaInitializing / AMDInitializing report a PCI device of that vendor
|
||||
// when DetectGPUVendor did not report the vendor as operational.
|
||||
NvidiaInitializing bool
|
||||
AMDInitializing bool
|
||||
}
|
||||
|
||||
// DetectGPUPresence combines the existing operational vendor detection with a
|
||||
// PCI display-class scan. The latter distinguishes absent hardware from a
|
||||
// detected PCI function whose runtime is not operational yet.
|
||||
func (a *App) DetectGPUPresence() GPUPresenceResult {
|
||||
vendor := a.sat.DetectGPUVendor()
|
||||
return GPUPresenceResult{
|
||||
res := GPUPresenceResult{
|
||||
Nvidia: vendor == "nvidia",
|
||||
AMD: vendor == "amd",
|
||||
}
|
||||
physNvidia, physAMD := a.sat.PhysicalGPUVendors()
|
||||
res.NvidiaInitializing = physNvidia && !res.Nvidia
|
||||
res.AMDInitializing = physAMD && !res.AMD
|
||||
return res
|
||||
}
|
||||
|
||||
// RuntimeHealthNow collects a fresh runtime-health snapshot (driver / CUDA
|
||||
// readiness, GSP state). Unlike ReadRuntimeHealth it does not read the
|
||||
// boot-time JSON; callers that poll for the GPU stack to come up need
|
||||
// current data.
|
||||
func (a *App) RuntimeHealthNow() (schema.RuntimeHealth, error) {
|
||||
return a.runtime.CollectRuntimeHealth(DefaultExportDir)
|
||||
}
|
||||
|
||||
// TPMPresent reports whether this host has a TPM the checks can talk to.
|
||||
func (a *App) TPMPresent() bool {
|
||||
return a.sat.TPMPresent()
|
||||
}
|
||||
|
||||
func (a *App) IsLiveMediaInRAM() bool {
|
||||
@@ -132,13 +155,14 @@ type satRunner interface {
|
||||
RunNvidiaOfficialComputePack(ctx context.Context, baseDir string, durationSec int, gpuIndices []int, staggerSec int, logFunc func(string)) (string, error)
|
||||
RunNvidiaTargetedPowerPack(ctx context.Context, baseDir string, durationSec int, gpuIndices []int, logFunc func(string)) (string, error)
|
||||
RunNvidiaPulseTestPack(ctx context.Context, baseDir string, durationSec int, gpuIndices []int, logFunc func(string)) (string, error)
|
||||
RunNvidiaBandwidthPack(ctx context.Context, baseDir string, gpuIndices []int, logFunc func(string)) (string, error)
|
||||
RunNvidiaBandwidthPack(ctx context.Context, baseDir string, gpuIndices []int, fullMatrix bool, logFunc func(string)) (string, error)
|
||||
RunNvidiaStressPack(ctx context.Context, baseDir string, opts platform.NvidiaStressOptions, logFunc func(string)) (string, error)
|
||||
ListNvidiaGPUStatuses() ([]platform.NvidiaGPUStatus, error)
|
||||
ResetNvidiaGPU(index int) (string, error)
|
||||
RunMemoryAcceptancePack(ctx context.Context, baseDir string, sizeMB, passes int, logFunc func(string)) (string, error)
|
||||
RunStorageAcceptancePack(ctx context.Context, baseDir string, extended bool, logFunc func(string)) (string, error)
|
||||
RunTPMValidationPack(ctx context.Context, baseDir string, logFunc func(string)) (string, error)
|
||||
TPMPresent() bool
|
||||
RunNvidiaConfigCheckPack(ctx context.Context, baseDir string, logFunc func(string)) (string, error)
|
||||
RunPCIeLinkCheckPack(ctx context.Context, baseDir string, logFunc func(string)) (string, error)
|
||||
RunNvidiaPCIeBandwidthPack(ctx context.Context, baseDir string, gpuIndices []int, logFunc func(string)) (string, error)
|
||||
@@ -151,6 +175,7 @@ type satRunner interface {
|
||||
SetNvidiaGPUPowerLimit(index int, watts float64) (string, error)
|
||||
ResetNvidiaGPUDefaults() (string, error)
|
||||
DetectGPUVendor() string
|
||||
PhysicalGPUVendors() (nvidia bool, amd bool)
|
||||
ListAMDGPUs() ([]platform.AMDGPUInfo, error)
|
||||
RunAMDAcceptancePack(ctx context.Context, baseDir string, logFunc func(string)) (string, error)
|
||||
RunAMDMemIntegrityPack(ctx context.Context, baseDir string, logFunc func(string)) (string, error)
|
||||
@@ -279,15 +304,6 @@ func (a *App) RunRuntimePreflight(output string) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) RunRuntimePreflightResult() (ActionResult, error) {
|
||||
path, err := a.RunRuntimePreflight("file:" + DefaultRuntimeJSONPath)
|
||||
body := "Runtime preflight completed."
|
||||
if path != "" {
|
||||
body = "Runtime health written to " + path
|
||||
}
|
||||
return ActionResult{Title: "Run self-check", Body: body}, err
|
||||
}
|
||||
|
||||
func (a *App) RuntimeHealthResult() ActionResult {
|
||||
health, err := ReadRuntimeHealth(DefaultRuntimeJSONPath)
|
||||
if err != nil {
|
||||
@@ -326,10 +342,6 @@ func (a *App) RunAuditNow(runtimeMode runtimeenv.Mode) (ActionResult, error) {
|
||||
return ActionResult{Title: "Run audit", Body: body}, err
|
||||
}
|
||||
|
||||
func (a *App) RunAuditToDefaultFile(runtimeMode runtimeenv.Mode) (string, error) {
|
||||
return a.RunAudit(runtimeMode, "file:"+DefaultAuditJSONPath)
|
||||
}
|
||||
|
||||
func (a *App) HealthSummaryResult() ActionResult {
|
||||
raw, err := os.ReadFile(DefaultAuditJSONPath)
|
||||
if err != nil {
|
||||
@@ -399,26 +411,6 @@ func (a *App) MainBanner() string {
|
||||
return strings.TrimSpace(strings.Join(lines, "\n"))
|
||||
}
|
||||
|
||||
func (a *App) FormatToolStatuses(statuses []platform.ToolStatus) string {
|
||||
var body strings.Builder
|
||||
for _, tool := range statuses {
|
||||
status := "MISSING"
|
||||
if tool.OK {
|
||||
status = "OK (" + tool.Path + ")"
|
||||
}
|
||||
fmt.Fprintf(&body, "- %s: %s\n", tool.Name, status)
|
||||
}
|
||||
return strings.TrimSpace(body.String())
|
||||
}
|
||||
|
||||
func (a *App) ParsePrefix(raw string, fallback int) int {
|
||||
value, err := strconv.Atoi(strings.TrimSpace(raw))
|
||||
if err != nil || value <= 0 {
|
||||
return fallback
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// writePSUStatusesToDB records PSU statuses collected during audit into the
|
||||
// component-status DB so they are visible in the Hardware Summary card.
|
||||
// PSU status is sourced from IPMI (ipmitool fru + sdr) during audit.
|
||||
|
||||
Reference in New Issue
Block a user