功能:完善云管助手与GPU故障恢复核对

This commit is contained in:
songyiming committed 2026-11-13 19:08:40 +08:00
1 parent b6026f9759
commit 9f7b01e4db
42 files changed
+3576 -120

No files matched your search

@@ -0,0 +1,50 @@
package server
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestGPUAgentHealthIsAuthenticatedAndVisibleInInventory(t *testing.T) {
f := newFixture(t)
f.server.Config.GPUAgentToken = "agent-token"
fakeGPUPVE(t, f, "normal")
status, out := f.request("POST", "/gpu-agent/health", "", map[string]any{
"node": "node-a",
"samples": []map[string]any{{
"address": "0000:01:00.0", "temperatureC": 61.5, "utilizationPercent": 42.0,
"memoryUsedBytes": 1024, "memoryTotalBytes": 4096, "driver": "nvidia", "driverBinding": "bound",
}},
}, "")
// f.request cannot attach the collector header, so the route must reject it.
expect(t, 401, status, out)
body, _ := json.Marshal(map[string]any{
"node": "node-a", "samples": []map[string]any{{"address": "0000:01:00.0", "temperatureC": 61.5, "driver": "nvidia", "driverBinding": "bound"}},
})
r := httptest.NewRequest(http.MethodPost, "/api/v1/gpu-agent/health", bytes.NewReader(body))
r.Header.Set("Content-Type", "application/json")
r.Header.Set("X-GPU-Agent-Token", "agent-token")
w := httptest.NewRecorder()
f.server.Router.ServeHTTP(w, r)
expect(t, 202, w.Code, w.Body.String())
status, out = f.request("GET", "/resources/gpus?node=node-a", f.login("admin"), nil, "")
expect(t, 200, status, out)
items := out["items"].([]any)
var found bool
for _, raw := range items {
item := raw.(map[string]any)
if item["address"] == "0000:01:00.0" {
health := item["health"].(map[string]any)
found = health["status"] == "collected" && health["driverBinding"] == "bound" && health["temperatureC"] == 61.5 && health["driver"] == "nvidia"
}
}
if !found {
t.Fatal("ingested GPU health was not visible in inventory", out)
}
}