Files
llmgw/internal/store/facility_test.go
Ilker ManapandClaude Opus 5.5 0d3eb82b9b Facility-aware placement: racks, PDUs, holds and power caps
Nodes say where they are with llmgw.io/site, room, row, rack and pdu labels,
from agent.yaml or `llmgw ctl label` (kept in the store, over the agent's).
Placement spreads a model's replicas across racks and PDUs, keeps a
multi-node replica within one domain when its profile says keep_within,
places nothing in a domain held with `llmgw ctl facility hold` (optionally
draining it), and refuses a shard that would take a domain past its power
cap from facility.budgets, counting declared, derived and measured draw.
Explain-placement names the domain, and keeps the rejections of a placed
replica; `ctl nodes` gains LOCATION and --domain; `ctl facility` lists the
domains; the console's Nodes view shows and sets location and holds.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 01:17:49 +02:00

53 lines
1.6 KiB
Go

package store
import (
"testing"
"time"
)
func TestAHeldDomainIsKeptUntilReleasedAndHoldingAgainChangesTheReason(t *testing.T) {
db := capacityStore(t)
ctx := t.Context()
at := time.UnixMilli(1_700_000_000_000)
if err := db.SetFacilityHold(ctx, FacilityHold{Domain: "rack:r1", Reason: "PDU swap", At: at, By: "ilker"}); err != nil {
t.Fatal(err)
}
if err := db.SetFacilityHold(ctx, FacilityHold{Domain: "rack:r1", Reason: "cooling", Drain: true, At: at, By: "ilker"}); err != nil {
t.Fatal(err)
}
got, err := db.FacilityHolds(ctx)
if err != nil || len(got) != 1 {
t.Fatalf("got %v, %v; one hold per domain", got, err)
}
if h := got[0]; h.Reason != "cooling" || !h.Drain || !h.At.Equal(at) || h.By != "ilker" {
t.Errorf("the second hold did not replace the first: %+v", h)
}
if err := db.DeleteFacilityHold(ctx, "rack:r1"); err != nil {
t.Fatal(err)
}
if got, _ := db.FacilityHolds(ctx); len(got) != 0 {
t.Errorf("released, still %v", got)
}
}
func TestANodeLabelSetThroughTheControlPlaneIsKeptAndCanBeRemoved(t *testing.T) {
db := capacityStore(t)
ctx := t.Context()
if err := db.SetNodeLabel(ctx, "gpu07", "llmgw.io/rack", "r12-07", "ilker"); err != nil {
t.Fatal(err)
}
if err := db.SetNodeLabel(ctx, "gpu07", "llmgw.io/rack", "r12-08", "ilker"); err != nil {
t.Fatal(err)
}
got, err := db.NodeLabels(ctx)
if err != nil || got["gpu07"]["llmgw.io/rack"] != "r12-08" {
t.Fatalf("got %v, %v", got, err)
}
if err := db.SetNodeLabel(ctx, "gpu07", "llmgw.io/rack", "", "ilker"); err != nil {
t.Fatal(err)
}
if got, _ := db.NodeLabels(ctx); len(got["gpu07"]) != 0 {
t.Errorf("removed, still %v", got)
}
}