Files
ilkerandClaude Opus 5.5 772579648c hpcod: one binary installs, checks and tests the control plane
An installation used to be this one: the deploy scripts and the Ansible
defaults carried one site's domain, hypervisor and login, the Proxmox side
and the database were set up by hand, and deploying meant copying scripts
and a tree of roles beside the binary and keeping them in step with it.

The binary now carries the roles, the Terraform module, the schema and the
catalogue (embed.go), and installs itself:

- hpcod setup: a full-screen installer for administrators. It asks where
  clusters are built, signs in to Proxmox before asking anything else
  (root's password once, or tokens), offers nodes and datastores from what
  Proxmox has, checks every field as it is typed, runs every step with its
  output live, checks the result and offers a test cluster. -yes runs the
  same steps from a site file; make deploy uses that.
- hpcod verify: each fact checked by using it.
- hpcod selftest: the smallest real cluster, by the portal's own path, a
  job run on it, then taken down.
- Closed networks: hpcod serves HTTPS itself from a CA name-constrained to
  the site's domains, issuing and renewing its own certificate, and
  answers DNS for the portal and every cluster name.
- A simulated Proxmox: Proxmox VE in QEMU on the control plane host, on a
  private bridge with NAT, for trying it without one.

Every step reads back what it changed and is safe to run again. The
site's values live in one file; group_vars/all/site.yml is generated from
it, and the playbooks refuse to run without it. ci_user and -ssh-user no
longer default to a personal account. scripts/B10, B20 and C20 are gone:
their work is the setup steps.

Proven end to end on a simulated Proxmox (Proxmox VE 9 in a VM on a real
host): the install, the Proxmox step by the password path, the head
template, verify READY, and a test cluster that ran srun on its compute
node and was destroyed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 18:20:04 +01:00

85 lines
2.8 KiB
Go

package setup
import (
"strings"
"testing"
)
// Someone trying hpcod on a simulated Proxmox gives names and nothing
// else; every Proxmox and network value is filled in, and the site is whole.
func TestASimulatedSiteNeedsOnlyNames(t *testing.T) {
s := Defaults()
s["PVE_MODE"] = "sim"
s["PORTAL_DOMAIN"], s["CLUSTER_DOMAIN"] = "hpc.lab", "hpc.lab"
s["SERVE_MODE"], s["SERVE_DNS"], s["PUBLIC_IP"] = "direct", "true", "192.0.2.205"
s.ApplySim()
if errs := s.Validate(); len(errs) > 0 {
t.Fatalf("a simulated site is incomplete: %v", errs)
}
if s["PVE_ENDPOINT"] != "https://"+SimAddress+":8006" || s["MGMT_GATEWAY"] != SimGateway {
t.Errorf("not pointed at the simulation: %s via %s", s["PVE_ENDPOINT"], s["MGMT_GATEWAY"])
}
}
func TestApplySimLeavesARealSiteAlone(t *testing.T) {
s := goodSite()
before := s["PVE_ENDPOINT"]
s.ApplySim()
if s["PVE_ENDPOINT"] != before {
t.Error("a real site was rewritten")
}
}
func TestSimUnitRunsKVMOnItsOwnTap(t *testing.T) {
s := Defaults()
u := simUnit(s)
for _, want := range []string{"accel=kvm", "-cpu host", "-smp 8", "-m 24G",
"ifname=" + SimTap, "mac=" + simMAC, "Wants=" + SimNetUnit + ".service",
"ExecStop=" + BinPath + " pvesim powerdown", "monitor.sock"} {
if !strings.Contains(u, want) {
t.Errorf("unit lacks %q", want)
}
}
// Requires= would restart the VM whenever its network unit restarts:
// a power cut that once emptied a file the guest had just written.
if strings.Contains(u, "Requires=") {
t.Error("the VM's unit requires its network unit")
}
}
// The guest's network is matched by MAC, so the seed and the unit must
// name the same one.
func TestSimSeedMatchesTheUnitsMAC(t *testing.T) {
ud := simUserData("pw", "ssh-ed25519 AAAA x", "1.1.1.1")
if !strings.Contains(ud, simMAC) || !strings.Contains(ud, "proxmox-ve") {
t.Errorf("user-data does not install Proxmox on the NIC with %s", simMAC)
}
if strings.Contains(ud, "%!") {
t.Errorf("user-data carries a formatting error:\n%s", ud)
}
if !strings.Contains(ud, "PermitRootLogin yes") {
t.Error("root cannot sign in with its password, as setup's first install needs")
}
}
// Switching a simulated site to a real Proxmox must not offer the
// simulation's private address as the real one's; values the operator
// changed themselves stay.
func TestClearSimForgetsOnlyTheSimulation(t *testing.T) {
s := Defaults()
s["PVE_MODE"] = "sim"
s.ApplySim()
s["CI_USER"] = "ops"
s["PVE_MODE"] = "real"
s.ClearSim()
if s["PVE_ENDPOINT"] != "" || s["MGMT_GATEWAY"] != "" {
t.Errorf("simulation values survived: %q %q", s["PVE_ENDPOINT"], s["MGMT_GATEWAY"])
}
if s["PVE_DATASTORE"] != Defaults()["PVE_DATASTORE"] {
t.Errorf("datastore not reset to the default: %q", s["PVE_DATASTORE"])
}
if s["CI_USER"] != "ops" {
t.Error("an operator's own value was reset")
}
}