Files
llmgw/internal/control/facility/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

68 lines
2.1 KiB
Go

package facility
import (
"slices"
"testing"
)
func TestALocationIsReadFromTheWellKnownLabels(t *testing.T) {
loc := LocationOf(map[string]string{
"llmgw.io/site": "sto1", "llmgw.io/room": "hall-b", "llmgw.io/row": "12",
"llmgw.io/rack": "r12-07", "llmgw.io/pdu": "r12-07-a, r12-07-b,r12-07-a", "role": "gpu",
})
want := []Domain{"site:sto1", "room:hall-b", "row:12", "rack:r12-07", "pdu:r12-07-a", "pdu:r12-07-b"}
if got := loc.Domains(); !slices.Equal(got, want) {
t.Errorf("domains %v, want %v", got, want)
}
if loc.Short() != "r12-07 pdu r12-07-a,r12-07-b" {
t.Errorf("short %q", loc.Short())
}
if loc.At(Rack) != "rack:r12-07" || loc.At(PDU) != "pdu:r12-07-a" {
t.Errorf("at rack %q, at pdu %q", loc.At(Rack), loc.At(PDU))
}
}
func TestANodeWithoutLabelsIsNowhere(t *testing.T) {
loc := LocationOf(map[string]string{"role": "gpu"})
if !loc.Empty() || len(loc.Domains()) != 0 || loc.Short() != "" {
t.Errorf("an unlabelled node is somewhere: %+v", loc)
}
}
func TestADomainIsNamedAsLevelColonName(t *testing.T) {
d, err := ParseDomain(" Rack:r12-07 ")
if err != nil || d != "rack:r12-07" || d.Human() != "rack r12-07" {
t.Errorf("got %q, %v", d, err)
}
for _, bad := range []string{"r12-07", "rack:", "shelf:3"} {
if _, err := ParseDomain(bad); err == nil {
t.Errorf("%q was accepted as a domain", bad)
}
}
}
func TestTheLimitIsTheCapLessTheMargin(t *testing.T) {
p := Policy{Margin: 0.1, Budgets: map[Domain]Budget{"rack:r1": {CapWatts: 16000}}}
if got := p.Limit("rack:r1"); got != 14400 {
t.Errorf("limit %v, want 14400", got)
}
if p.Limit("rack:r2") != 0 {
t.Error("a domain with no budget has a limit")
}
}
func TestTheFirstHoldAmongANodesDomainsIsFound(t *testing.T) {
p := Policy{Holds: map[Domain]Hold{"pdu:p2": {Domain: "pdu:p2", Reason: "breaker"}}}
if h, ok := p.HeldIn([]Domain{"rack:r1", "pdu:p1", "pdu:p2"}); !ok || h.Reason != "breaker" {
t.Errorf("got %+v, %v", h, ok)
}
if _, ok := p.HeldIn([]Domain{"rack:r1"}); ok {
t.Error("an unheld rack is held")
}
c := p.Clone()
delete(c.Holds, "pdu:p2")
if _, ok := p.Holds["pdu:p2"]; !ok {
t.Error("changing a clone changed the original")
}
}