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

108 lines
3.4 KiB
Go

package dnsserver
import (
"context"
"net"
"testing"
"github.com/miekg/dns"
)
func start(t *testing.T, cfg Config) string {
t.Helper()
l, err := net.ListenPacket("udp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
addr := l.LocalAddr().String()
l.Close()
cfg.Listen = addr
s, err := New(cfg)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
if err := s.Run(ctx); err != nil {
t.Fatal(err)
}
return addr
}
func ask(t *testing.T, server, name string, qtype uint16, proto string) *dns.Msg {
t.Helper()
m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(name), qtype)
c := &dns.Client{Net: proto}
in, _, err := c.Exchange(m, server)
if err != nil {
t.Fatalf("%s %s: %v", proto, name, err)
}
return in
}
func aRecord(in *dns.Msg) string {
for _, rr := range in.Answer {
if a, ok := rr.(*dns.A); ok {
return a.A.String()
}
}
return ""
}
func TestAnswersForThePortalAndEveryCluster(t *testing.T) {
srv := start(t, Config{Address: net.ParseIP("10.0.0.205"), Portal: "hpc.lab", Clusters: "hpc.lab"})
for _, n := range []string{"hpc.lab", "c001.hpc.lab", "C042.HPC.lab"} {
for _, proto := range []string{"udp", "tcp"} {
in := ask(t, srv, n, dns.TypeA, proto)
if got := aRecord(in); got != "10.0.0.205" || !in.Authoritative {
t.Errorf("%s over %s: %q authoritative=%v", n, proto, got, in.Authoritative)
}
}
}
// A name that exists with no AAAA: no data, not "no such name" - which
// a browser would cache as the name not existing at all.
if in := ask(t, srv, "c001.hpc.lab", dns.TypeAAAA, "udp"); in.Rcode != dns.RcodeSuccess || len(in.Answer) != 0 {
t.Errorf("AAAA: rcode %d, %d answers", in.Rcode, len(in.Answer))
}
}
func TestSeparatePortalAndClusterDomains(t *testing.T) {
srv := start(t, Config{Address: net.ParseIP("10.0.0.205"), Portal: "portal.example.lab", Clusters: "hpc.example.lab"})
if got := aRecord(ask(t, srv, "portal.example.lab", dns.TypeA, "udp")); got != "10.0.0.205" {
t.Errorf("portal: %q", got)
}
if got := aRecord(ask(t, srv, "c003.hpc.example.lab", dns.TypeA, "udp")); got != "10.0.0.205" {
t.Errorf("cluster: %q", got)
}
// Not ours and nobody to forward to: refused, never an open resolver.
if in := ask(t, srv, "example.com", dns.TypeA, "udp"); in.Rcode != dns.RcodeRefused {
t.Errorf("outside the zones without forwarders: rcode %d", in.Rcode)
}
// Inside a zone but not one of our names.
if in := ask(t, srv, "other.portal.example.lab", dns.TypeA, "udp"); in.Rcode != dns.RcodeNameError {
t.Errorf("unknown name in zone: rcode %d", in.Rcode)
}
}
func TestForwardsWhatIsNotOurs(t *testing.T) {
// The upstream is another of these, so the test needs no network.
up := start(t, Config{Address: net.ParseIP("192.0.2.7"), Portal: "elsewhere.test", Clusters: "elsewhere.test"})
srv := start(t, Config{Address: net.ParseIP("10.0.0.205"), Portal: "hpc.lab", Clusters: "hpc.lab", Forwarders: []string{up}})
if got := aRecord(ask(t, srv, "elsewhere.test", dns.TypeA, "udp")); got != "192.0.2.7" {
t.Errorf("forwarded answer: %q", got)
}
}
func TestAPortInUseFailsAtStart(t *testing.T) {
l, err := net.ListenPacket("udp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer l.Close()
s, _ := New(Config{Listen: l.LocalAddr().String(), Address: net.ParseIP("10.0.0.1"), Portal: "a.lab", Clusters: "a.lab"})
if err := s.Run(context.Background()); err == nil {
t.Fatal("started on a port another process holds")
}
}