v0.55.0: raw-device discovery + registry-sourced drive tracking (Impl-2a)
GET /disks/candidates enumerates host disks the Impl-1 unclaimed filter proves free (init/attach split). RegistryKnownTargets sources the watchdog's known-drive set from the intent registry + Felhom .mount units (not Observe/PVE storages) — decouples drive health from PVE storage (closes the registry-only false-detach class); Observe kept for real PVE storages + a deduped /disks union. Idempotent existing-drive migration at start. Tests + red-proof (Observe misses a registry-only drive; registry provider tracks it). go build/vet/test clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package localapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-agent/internal/storage"
|
||||
)
|
||||
|
||||
// handleDiskCandidates splits discovery into initialize (all unclaimed) + attach (mountable-FS subset).
|
||||
func TestDiskCandidates_Split(t *testing.T) {
|
||||
d := &fakeDiskOps{candidates: []storage.CandidateDisk{
|
||||
{Device: "/dev/sdd", SizeBytes: 64 << 30, DataBearing: false}, // blank → initialize only
|
||||
{Device: "/dev/sde", FSType: "ext4", DataBearing: true, Mountable: true, MountSource: "/dev/sde1"}, // FS → init + attach
|
||||
{Device: "/dev/sdf", FSType: "ntfs", DataBearing: true, Mountable: false}, // ntfs → initialize only
|
||||
}}
|
||||
h := newDiskServer(t, d, &fakeGate{}, nil, nil)
|
||||
|
||||
w := do(t, h, "GET", "/disks/candidates", "A", "")
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("candidates: got %d want 200 (%s)", w.Code, w.Body.String())
|
||||
}
|
||||
var env struct {
|
||||
Data struct {
|
||||
Initialize []storage.CandidateDisk `json:"initialize"`
|
||||
Attach []storage.CandidateDisk `json:"attach"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &env); err != nil {
|
||||
t.Fatalf("parse: %v", err)
|
||||
}
|
||||
resp := env.Data
|
||||
if len(resp.Initialize) != 3 {
|
||||
t.Fatalf("initialize must list all 3 unclaimed disks, got %d", len(resp.Initialize))
|
||||
}
|
||||
if len(resp.Attach) != 1 || resp.Attach[0].Device != "/dev/sde" {
|
||||
t.Fatalf("attach must list only the mountable-FS disk, got %+v", resp.Attach)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user