Files
llmgw/internal/config/slurm_test.go
T
Ilker ManapandClaude Opus 5.5 d8ce573bdb
CI / test (push) Failing after 7m1s
Slurm's shared files and users: one path everywhere, accounts as Linux users
slurm.shared mounts the site's NFS export, has an llmgw node export the path
over NFS to the Slurm machines alone (2049 in the firewall), or looks for a
file system the site mounts. slurm.users "llmgw" makes each active account a
Linux user on every Slurm machine: login from its e-mail, a UID from 200000
kept in slurm_users and never reused, its home on the shared path, its SSH
keys from the portal's Profile (or ctl slurm users keys) read by sshd from
/etc/llmgw/ssh-keys. server init --slurm chooses /shared from the first
machine and llmgw's users; --slurm-shared and --slurm-users change that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 21:34:34 +01:00

97 lines
3.1 KiB
Go

package config
import (
"strings"
"testing"
)
func TestSlurmCheck(t *testing.T) {
ok := SlurmSettings{Enabled: true, Controller: "node06", Nodes: []string{"cuda01", "site2"}, Lent: []string{"cuda01"}}
if err := ok.Check(); err != nil {
t.Fatal(err)
}
if !ok.IsLent("cuda01") || ok.IsLent("site2") || ok.IsLent("node06") {
t.Error("IsLent is wrong")
}
if ok.Cluster() != "llmgw" || ok.PartitionName() != "gpu" {
t.Error("defaults are wrong")
}
if (SlurmSettings{Lent: []string{"x"}}).Check() != nil {
t.Error("settings that are off were checked")
}
for want, s := range map[string]SlurmSettings{
"controller is empty": {Enabled: true},
"not a name": {Enabled: true, Controller: "bad name"},
"twice": {Enabled: true, Controller: "c", Nodes: []string{"a", "a"}},
"not in slurm.nodes": {Enabled: true, Controller: "c", Nodes: []string{"a"}, Lent: []string{"b"}},
"slurm.partition": {Enabled: true, Controller: "c", Partition: "a b"},
} {
if err := s.Check(); err == nil || !strings.Contains(err.Error(), want) {
t.Errorf("%+v: got %v, want %q", s, err, want)
}
}
if (SlurmSettings{Enabled: false, Lent: []string{"a"}}).IsLent("a") {
t.Error("a node is lent with Slurm off")
}
}
func TestSlurmShared(t *testing.T) {
base := SlurmSettings{Enabled: true, Controller: "c", Nodes: []string{"a"}}
for _, sh := range []SharedStorage{{}, {Path: "/shared"}, {Path: "/shared", NFS: "filer.site:/export/hpc"},
{Path: "/data/hpc", Server: "c"}, {Path: "/shared", Server: "a"}} {
s := base
s.Shared = sh
if err := s.Check(); err != nil {
t.Errorf("%+v refused: %v", sh, err)
}
}
for want, sh := range map[string]SharedStorage{
"path is empty": {NFS: "f:/x"},
"plain names": {Path: "shared"},
"system's own": {Path: "/home"},
"one of them": {Path: "/shared", NFS: "f:/x", Server: "c"},
"not host:/path": {Path: "/shared", NFS: "f/x"},
"neither": {Path: "/shared", Server: "z"},
} {
s := base
s.Shared = sh
if err := s.Check(); err == nil || !strings.Contains(err.Error(), want) {
t.Errorf("%+v: got %v, want %q", sh, err, want)
}
}
s := base
s.Shared = SharedStorage{Path: "/a/../etc"}
if s.Check() == nil {
t.Error("a path with .. taken")
}
s.Shared, s.Users = SharedStorage{}, "ldap"
if s.Check() == nil {
t.Error("slurm.users ldap taken")
}
s.Users, s.Shared = UsersLlmgw, SharedStorage{Path: "/shared"}
if s.Check() != nil || s.HomeDir("ayse") != "/shared/home/ayse" {
t.Errorf("home %s", s.HomeDir("ayse"))
}
s.Shared = SharedStorage{}
if s.HomeDir("ayse") != "/home/ayse" {
t.Errorf("home %s", s.HomeDir("ayse"))
}
}
func TestSlurmAllNodes(t *testing.T) {
s := SlurmSettings{Enabled: true, Controller: "c", AllNodes: true, Lent: []string{"joined"}}
if err := s.Check(); err != nil {
t.Fatalf("a node lent with all_nodes refused: %v", err)
}
if !s.IsLent("joined") {
t.Fatal("not lent with all_nodes")
}
if got := s.WithNodes([]string{"a", "joined"}).Nodes; len(got) != 2 {
t.Fatalf("nodes %v", got)
}
s.AllNodes = false
if s.Check() == nil || len(s.WithNodes([]string{"a"}).Nodes) != 0 {
t.Fatal("all_nodes off still takes the inventory's nodes")
}
}