Files
ilkerandClaude Opus 5.5 090719fc74
ci / derle (push) Successful in 30s
hpcod: clusters across the nodes of a Proxmox cluster
Discovery already saw every node of a Proxmox cluster and placement could
put a VM on any of them, but the template, the snippets and a simple SDN
zone only worked on PVE_NODE, so a cluster could land where it could not
be built.

- Setup asks which nodes clusters may use (PVE_NODES; a multi-select in
  the TUI when Proxmox has more than one). Discovery offers only those.
- Heads are placed on PVE_NODE only (head_node), where the template is, so
  no shared storage is needed; diskless compute nodes spread.
- PVE_SDN_ZONE_TYPE (auto|simple|vxlan): more than one node makes the zone
  vxlan, every node a peer, MTU 1450. A zone of the wrong type is remade
  only while no cluster has a vnet in it. Guest fabric NICs take the
  bridge MTU through virtio (mtu = 1).
- setup keeps nodes and head_node of its own site in sites.yaml, leaving
  the rest of the file as the operator wrote it.
- verify checks the nodes are online and the zone matches.

Run on the simulated Proxmox with the zone forced to vxlan: setup remade
the zone, a two-node selftest passed, both compute NICs came up at 1450,
and a DF ping of 1422 bytes passed between them while 1423 did not. Two
real Proxmox nodes have not been tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:51:35 +01:00

99 lines
3.0 KiB
Go

package setup
import (
"strings"
"testing"
"gopkg.in/yaml.v3"
"github.com/ilkermanap/hpcod/internal/inventory"
)
const twoSites = `# the operator's own comment
sites:
- id: hv01
name: "Lab"
kind: proxmox
settings:
endpoint: https://192.0.2.10:8006
token: env:HV01_TOKEN
nodes: "hv01"
- id: other
name: "Someone else's"
kind: proxmox
settings:
endpoint: https://192.0.2.20:8006
token: env:OTHER_TOKEN
`
func TestSyncSiteSettingsTouchesOnlyItsOwnSite(t *testing.T) {
out, changed, err := syncSiteSettings([]byte(twoSites), "hv01",
map[string]string{"nodes": "hv01,hv02", "head_node": "hv01"})
if err != nil || !changed {
t.Fatalf("changed=%v err=%v", changed, err)
}
var f inventory.Catalogue
if err := yaml.Unmarshal(out, &f); err != nil {
t.Fatal(err)
}
if got := f.Sites[0].Settings; got["nodes"] != "hv01,hv02" || got["head_node"] != "hv01" || got["token"] != "env:HV01_TOKEN" {
t.Errorf("hv01 settings = %v", got)
}
if got := f.Sites[1].Settings; got["nodes"] != "" || got["head_node"] != "" || len(got) != 2 {
t.Errorf("the other site was changed: %v", got)
}
if !strings.Contains(string(out), "# the operator's own comment") {
t.Error("the operator's comment was lost")
}
// A second run with the same answers changes nothing.
if _, again, err := syncSiteSettings(out, "hv01",
map[string]string{"nodes": "hv01,hv02", "head_node": "hv01"}); err != nil || again {
t.Errorf("second run: changed=%v err=%v", again, err)
}
}
func TestSyncSiteSettingsSaysWhenTheSiteIsGone(t *testing.T) {
if _, _, err := syncSiteSettings([]byte(twoSites), "renamed", map[string]string{"nodes": "x"}); err == nil {
t.Error("no error for a site that is not in the file")
}
}
func TestSiteNodesAndZoneType(t *testing.T) {
s := goodSite()
s["PVE_NODE"], s["PVE_NODES"], s["PVE_SDN_ZONE_TYPE"] = "pve1", "", "auto"
if got := strings.Join(s.Nodes(), ","); got != "pve1" || s.ZoneType() != "simple" {
t.Errorf("one node: nodes=%s zone=%s", got, s.ZoneType())
}
s["PVE_NODES"] = "pve2, pve1,pve3"
if got := strings.Join(s.Nodes(), ","); got != "pve1,pve2,pve3" || s.ZoneType() != "vxlan" {
t.Errorf("three nodes: nodes=%s zone=%s, want pve1 first and vxlan", got, s.ZoneType())
}
if errs := s.Validate(); len(errs) != 0 {
t.Errorf("valid site refused: %v", errs)
}
s["PVE_SDN_ZONE_TYPE"] = "simple"
if !hasErr(s.Validate(), "PVE_SDN_ZONE_TYPE") {
t.Error("a simple zone across three nodes was accepted")
}
s["PVE_SDN_ZONE_TYPE"], s["PVE_NODES"] = "auto", "pve2,pve3"
if !hasErr(s.Validate(), "PVE_NODES") {
t.Error("a node list without PVE_NODE was accepted")
}
// One node may still ask for vxlan, to be ready for more.
s["PVE_NODES"], s["PVE_SDN_ZONE_TYPE"] = "", "vxlan"
if s.ZoneType() != "vxlan" || len(s.Validate()) != 0 {
t.Errorf("one node with vxlan: zone=%s errs=%v", s.ZoneType(), s.Validate())
}
}
func hasErr(errs []error, key string) bool {
for _, e := range errs {
if strings.Contains(e.Error(), key) {
return true
}
}
return false
}