Files
llmgw/internal/agent/selfdescribe_test.go
T
Ilker ManapandClaude Opus 5.5 20deb22dfa
CI / test (push) Successful in 1m47s
Let a node describe itself instead of being described by hand
Every agent file on the cluster named its own node, its own address, the
path to llama-server and two weight directories — different on every node,
kept true by hand, and not true: node05 carried "ram: 32g" beside a measured
31 GB, looked for weights in an empty directory while fetching them into
another, and the other four never looked in theirs at all, so four nodes
reported no disk. Growing a node's RAM would have gone unnoticed, because
memory was read once, at registration.

The agent now finds these out. Its id is the hostname, which is also the
certificate's common name. Its address is the one on the route to the
control plane, which the kernel picks for a UDP dial without sending
anything. llama-server is looked for on PATH and then where release archives
are unpacked. A missing nvidia-smi is a node without NVIDIA cards rather
than a failed discovery — which also cut discovery short before InfiniBand
on every CPU node not told to skip GPUs. Fetched weights land in
/var/lib/llmgw-weights by default, and wherever they land is always looked
in.

Memory is read on every heartbeat, and installed engines are probed again
each minute and sent when they change, so a VM given more RAM or a node
given vLLM becomes a candidate without anyone restarting its agent. The
control plane logs both changes, since "the node now qualifies" is the
answer to why a model placed an hour after it was asked for.

What is written still wins. The agent file shrinks to the control plane's
addresses and the TLS files, the same on every node; onboarding writes only
the overrides it was given. What cannot be found stays configuration: which
fabric an adapter is on, because OpenSM's default prefix is the same on all
of them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 10:13:42 +02:00

81 lines
2.5 KiB
Go

package agent
import (
"os"
"slices"
"testing"
llmgwv1 "gitea.mynodes.xyz/ilker/llmgw/api/gen/llmgw/v1"
)
func TestAnAgentConfigNeedsOnlyWhereTheControlPlaneIs(t *testing.T) {
// Every node carried its own name, its own address and the same two
// directories written out by hand, so no two agent files were alike and a
// copy taken from one node registered the next as the first.
cfg := Config{Server: "127.0.0.1:7443"}
if err := cfg.normalize(); err != nil {
t.Fatal(err)
}
host, _ := os.Hostname()
if cfg.NodeID != host || cfg.Hostname != host {
t.Errorf("node_id %q, hostname %q; expected the machine's name %q",
cfg.NodeID, cfg.Hostname, host)
}
if cfg.MgmtAddr != "127.0.0.1" {
t.Errorf("mgmt_addr %q, expected the address on the route to the control plane",
cfg.MgmtAddr)
}
if cfg.WeightsCache != DefaultWeightsCache {
t.Errorf("weights land in %q", cfg.WeightsCache)
}
if !slices.Contains(cfg.ModelDirs, cfg.WeightsCache) {
t.Errorf("the download directory %q is not looked in: %v",
cfg.WeightsCache, cfg.ModelDirs)
}
}
func TestWhatIsWrittenStillWins(t *testing.T) {
cfg := Config{
Server: "127.0.0.1:7443", NodeID: "gpu-a-01", MgmtAddr: "10.9.9.9",
ModelDirs: []string{"/lustre/models"}, WeightsCache: "/scratch/w",
}
if err := cfg.normalize(); err != nil {
t.Fatal(err)
}
if cfg.NodeID != "gpu-a-01" || cfg.MgmtAddr != "10.9.9.9" {
t.Errorf("configured identity overridden: %q %q", cfg.NodeID, cfg.MgmtAddr)
}
if !slices.Equal(cfg.ModelDirs, []string{"/lustre/models", "/scratch/w"}) {
t.Errorf("model dirs %v", cfg.ModelDirs)
}
}
func TestAHeartbeatSaysWhenTheEnginesChanged(t *testing.T) {
cfg := Config{Server: "127.0.0.1:7443", NodeID: "n1", WeightsCache: t.TempDir()}
cfg.Superv.WorkDir = t.TempDir()
a, err := New(cfg, nil, nil)
if err != nil {
t.Fatal(err)
}
engines := func(m *llmgwv1.AgentMessage) *llmgwv1.Heartbeat { return m.GetHeartbeat() }
a.mu.Lock()
a.engineVers = map[string]string{"llamacpp": "unknown"}
a.enginesSent = enginesFingerprint(a.engineVers)
a.mu.Unlock()
if hb := engines(a.heartbeat()); hb.GetEnginesChanged() {
t.Errorf("unchanged engines were resent")
}
a.mu.Lock()
a.engineVers = map[string]string{"llamacpp": "unknown", "vllm": "unknown"}
a.mu.Unlock()
hb := engines(a.heartbeat())
if !hb.GetEnginesChanged() || len(hb.GetEngineVersions()) != 2 {
t.Errorf("an installed engine was not reported: %v", hb.GetEngineVersions())
}
if engines(a.heartbeat()).GetEnginesChanged() {
t.Errorf("reported again on the next heartbeat")
}
}