package slurmsvc import ( "context" "errors" "slices" "testing" "gitea.mynodes.xyz/ilker/llmgw/internal/config" ) func TestSharedFilesFromTheController(t *testing.T) { r := newRig() r.set.Shared = config.SharedStorage{Path: "/shared", Server: "node06"} r.tick() ctl, node := r.agents.last("node06").GetShared(), r.agents.last("cuda01").GetShared() if !ctl.GetServe() || !slices.Equal(ctl.GetClients(), []string{"10.0.0.147"}) || ctl.GetPath() != "/shared" { t.Fatalf("server told %v", ctl) } if node.GetServe() || node.GetNfs() != "10.0.0.146:/shared" { t.Fatalf("client told %v", node) } // The site's own export: every machine mounts it. r.set.Shared = config.SharedStorage{Path: "/shared", NFS: "filer:/hpc"} r.tick() if r.agents.last("node06").GetShared().GetNfs() != "filer:/hpc" || r.agents.last("cuda01").GetShared().GetServe() { t.Fatal("the site's export not sent") } } func TestSharedServerNotKnownTellsNothing(t *testing.T) { r := newRig() r.set.Shared = config.SharedStorage{Path: "/shared", Server: "node06"} delete(r.inv.nodes, "node06") r.svc.known.ControllerAddr, r.svc.known.Controller = "10.0.0.146", "node06" r.tick() if r.agents.last("cuda01").GetShared().GetNfs() != "10.0.0.146:/shared" { t.Fatalf("the kept address not used: %v", r.agents.last("cuda01")) } r2 := newRig() r2.set.Nodes = []string{"cuda01", "site2"} r2.agents.conn = append(r2.agents.conn, "site2") r2.set.Shared = config.SharedStorage{Path: "/shared", Server: "site2"} r2.tick() if r2.agents.last("cuda01") != nil { t.Fatal("told with no address for the server: its mount would go") } } func TestUsersSentOnceRead(t *testing.T) { r := newRig() r.set.Users = config.UsersLlmgw r.set.Shared = config.SharedStorage{Path: "/shared", Server: "node06"} fail := true r.svc.SetUsers(func(context.Context) ([]User, error) { if fail { return nil, errors.New("store down") } return []User{{Login: "ayse", UID: 200000, Name: "Ayşe", SSHKeys: []string{"ssh-ed25519 AAAA"}}}, nil }) r.tick() if len(r.agents.got["cuda01"]) != 0 { t.Fatal("told before the users were read: every user would go") } fail = false r.svc.UsersChanged() r.tick() ctl, node := r.agents.last("node06"), r.agents.last("cuda01") if !ctl.GetManageUsers() || !ctl.GetMakeHomes() || node.GetMakeHomes() || len(node.GetUsers()) != 1 { t.Fatalf("controller %v\nnode %v", ctl, node) } if u := node.GetUsers()[0]; u.GetHome() != "/shared/home/ayse" || u.GetUid() != 200000 || len(u.GetSshKeys()) != 1 { t.Fatalf("user %v", u) } // The store down later: the last users are kept. fail = true r.svc.UsersChanged() r.tick() if len(r.agents.last("cuda01").GetUsers()) != 1 { t.Fatal("users lost when the store could not be read") } if st := r.svc.Status(); st.UserCount != 1 || st.Shared.Server != "node06" { t.Fatalf("status %+v", st) } }