Network model, IPAM, interface layouts and the region/rack split (MAAS-style)
- fabrics, VLANs, subnets, IP ranges (dynamic/reserved/static), IPAM with adoption of addresses machines already have; rollcall fabric|vlan|subnet|range|ip - interface layouts (physical/bond/vlan, NICs by selector: boot, name, mac, fastest:N, ib:N) per machine or per tag; deployment allocates addresses and writes cloud-init network-config plus udev name rules (RHEL cloud images boot with net.ifnames=0); release frees them; rollcall layout, rollcall net show|set - region/rack: rollcall rack long-polls its desired state (per-MAC PXE files kept in the database, dnsmasq configuration and host files) and a BMC command queue, caches boot and OS images (kernels/initrds prefetched for TFTP), proxies the node API and tags requests with its name; the region runs an embedded rack controller; install-rack.sh, rollcall-rack.service - dnsmasq configuration generated per rack from the VLANs it serves (split pool for two racks); reload script restarts only on change and restores the last working config if dnsmasq does not come back (drilled in the lab) - web: Network page, per-machine network tab, layout action, tag layout; console: Network page, network section in the machine view, layout action - tests for candidates, plans (default, bond+VLAN, pinned, DHCP fallback), network-config, udev rules and dnsmasq rendering - lab: pve-vbmc address script finds the interface per BMC address Verified in the lab: embedded rack (10.213.77.0/24) and a remote rack controller on a second SDN segment (10.213.78.0/24): enlistment, commissioning, BMC through the rack's queue, image cache, deployment and phone-home through the rack; Debian 13, Ubuntu 24.04 and Rocky 9 with a static boot NIC and with an active-backup bond carrying VLAN 200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e3d9373201
commit
736a7e38a3
31 files changed
+4357
-176
No files matched your search
@@ -0,0 +1,165 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func labSubnet() Subnet {
|
||||
return Subnet{CIDR: "10.0.0.0/24", Gateway: "10.0.0.1", DNS: []string{"10.0.0.1"}, Domain: "lab.local", Fabric: "f0", MTU: 1500,
|
||||
DHCP: true, PrimaryRack: "r1", Purpose: "provisioning",
|
||||
Ranges: []IPRange{{Kind: "reserved", Start: "10.0.0.2", End: "10.0.0.20"}, {Kind: "dynamic", Start: "10.0.0.100", End: "10.0.0.200"}}}
|
||||
}
|
||||
|
||||
func TestFreeCandidates(t *testing.T) {
|
||||
sn := labSubnet()
|
||||
got := freeCandidates(sn, map[string]bool{"10.0.0.21": true}, []string{"10.0.0.22/24"}, 3)
|
||||
if strings.Join(got, " ") != "10.0.0.23 10.0.0.24 10.0.0.25" {
|
||||
t.Errorf("candidates: %v", got)
|
||||
}
|
||||
for _, ip := range freeCandidates(sn, nil, nil, 0) {
|
||||
if ip == "10.0.0.1" || ip == "10.0.0.0" || ip == "10.0.0.255" || (ipLess("10.0.0.99", ip) && ipLess(ip, "10.0.0.201")) {
|
||||
t.Fatalf("handed out %s", ip)
|
||||
}
|
||||
}
|
||||
sn.Ranges = append(sn.Ranges, IPRange{Kind: "static", Start: "10.0.0.50", End: "10.0.0.52"})
|
||||
if got := freeCandidates(sn, nil, nil, 0); strings.Join(got, " ") != "10.0.0.50 10.0.0.51 10.0.0.52" {
|
||||
t.Errorf("static range: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func allocFrom(next ...string) func(Subnet, string) (string, error) {
|
||||
return func(Subnet, string) (string, error) {
|
||||
ip := next[0]
|
||||
next = next[1:]
|
||||
return ip, nil
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultPlanAndNetworkConfig(t *testing.T) {
|
||||
nics := []invNIC{{Name: "eno1", MAC: "aa:bb:cc:00:00:01", Speed: 1000, Link: true, IPv4: []string{"10.0.0.150/24"}}}
|
||||
p := resolvePlan(nil, nics, &nics[0], []Subnet{labSubnet()}, nil, allocFrom("10.0.0.21"))
|
||||
if len(p.Warnings) > 0 || len(p.Ifaces) != 1 {
|
||||
t.Fatalf("plan: %+v", p)
|
||||
}
|
||||
if mgmt, _ := p.primaryIPs(); mgmt != "10.0.0.21" {
|
||||
t.Errorf("mgmt %q", mgmt)
|
||||
}
|
||||
b, _ := json.Marshal(networkConfig(p))
|
||||
s := string(b)
|
||||
for _, want := range []string{`"macaddress":"aa:bb:cc:00:00:01"`, `"set-name":"eno1"`, `"addresses":["10.0.0.21/24"]`,
|
||||
`"routes":[{"to":"0.0.0.0/0","via":"10.0.0.1"}]`, `"search":["lab.local"]`, `"dhcp4":false`} {
|
||||
if !strings.Contains(s, want) {
|
||||
t.Errorf("network-config lacks %s:\n%s", want, s)
|
||||
}
|
||||
}
|
||||
// a pinned address wins over allocation
|
||||
p = resolvePlan(nil, nics, &nics[0], []Subnet{labSubnet()}, []IPAddr{{IP: "10.0.0.60", Subnet: "10.0.0.0/24", Iface: "eno1", Kind: "static"}}, allocFrom("10.0.0.21"))
|
||||
if p.Ifaces[0].Links[0].IP != "10.0.0.60" || p.Ifaces[0].Links[0].Mode != "static" {
|
||||
t.Errorf("static pin ignored: %+v", p.Ifaces[0].Links[0])
|
||||
}
|
||||
// no subnet model for the boot network: DHCP, as before
|
||||
p = resolvePlan(nil, nics, &nics[0], nil, nil, nil)
|
||||
if p.Ifaces[0].Links[0].Mode != "dhcp" {
|
||||
t.Errorf("without subnets the default is dhcp, got %+v", p.Ifaces[0].Links)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBondVLANLayout(t *testing.T) {
|
||||
nics := []invNIC{
|
||||
{Name: "eno1", MAC: "aa:00:00:00:00:01", Speed: 1000, Link: true, IPv4: []string{"10.0.0.150/24"}},
|
||||
{Name: "ens1f0", MAC: "aa:00:00:00:00:02", Speed: 100000, Link: true},
|
||||
{Name: "ens1f1", MAC: "aa:00:00:00:00:03", Speed: 100000, Link: true},
|
||||
{Name: "ibp1s0", MAC: "80:00:00:00", IB: true, Link: true},
|
||||
}
|
||||
storage := Subnet{CIDR: "10.20.0.0/24", Fabric: "f0", VID: 200, MTU: 9000}
|
||||
ib := Subnet{CIDR: "10.30.0.0/24", Fabric: "ib0"}
|
||||
l := &NetLayout{Name: "gpu", Interfaces: []LayoutIface{
|
||||
{Type: "physical", Select: "boot", Links: []LayoutLink{{Subnet: "boot", Mode: "auto", Gateway: true}}},
|
||||
{Type: "bond", Name: "bond0", Members: []string{"fastest:2"}, Links: []LayoutLink{{Mode: "link_up"}}},
|
||||
{Type: "vlan", Parent: "bond0", VID: 200, Links: []LayoutLink{{Subnet: "10.20.0.0/24", Mode: "auto"}}},
|
||||
{Type: "physical", Select: "ib:0", Links: []LayoutLink{{Subnet: "10.30.0.0/24", Mode: "auto"}}},
|
||||
}}
|
||||
p := resolvePlan(l, nics, &nics[0], []Subnet{labSubnet(), storage, ib}, nil, allocFrom("10.0.0.21", "10.20.0.5", "10.30.0.5"))
|
||||
if len(p.Warnings) > 0 {
|
||||
t.Fatalf("warnings: %v", p.Warnings)
|
||||
}
|
||||
if got := p.Ifaces[1].Members; strings.Join(got, ",") != "ens1f0,ens1f1" {
|
||||
t.Errorf("bond members %v (the boot NIC must not be taken)", got)
|
||||
}
|
||||
if p.Ifaces[2].Name != "bond0.200" || p.Ifaces[2].MTU != 9000 {
|
||||
t.Errorf("vlan iface %+v", p.Ifaces[2])
|
||||
}
|
||||
if mgmt, ibip := p.primaryIPs(); mgmt != "10.0.0.21" || ibip != "10.30.0.5" {
|
||||
t.Errorf("primary %s ib %s", mgmt, ibip)
|
||||
}
|
||||
b, _ := json.Marshal(networkConfig(p))
|
||||
s := string(b)
|
||||
for _, want := range []string{`"bonds":{"bond0":`, `"interfaces":["ens1f0","ens1f1"]`, `"mode":"802.3ad"`, `"vlans":{"bond0.200":`,
|
||||
`"link":"bond0"`, `"id":200`, `"10.20.0.5/24"`, `"mtu":9000`, `"ibp1s0":{"addresses":["10.30.0.5/24"]`} {
|
||||
if !strings.Contains(s, want) {
|
||||
t.Errorf("network-config lacks %s:\n%s", want, s)
|
||||
}
|
||||
}
|
||||
if strings.Count(s, "0.0.0.0/0") != 1 {
|
||||
t.Errorf("want exactly one default route:\n%s", s)
|
||||
}
|
||||
rules := linkRules(p)
|
||||
for _, want := range []string{`ATTR{address}=="aa:00:00:00:00:01", NAME="eno1"`, `ATTR{address}=="aa:00:00:00:00:02", NAME="ens1f0"`, `ATTR{address}=="aa:00:00:00:00:03", NAME="ens1f1"`} {
|
||||
if !strings.Contains(rules, want) {
|
||||
t.Errorf("udev rules lack %s:\n%s", want, rules)
|
||||
}
|
||||
}
|
||||
if strings.Contains(rules, "ibp1s0") {
|
||||
t.Errorf("InfiniBand ports keep their names:\n%s", rules)
|
||||
}
|
||||
}
|
||||
|
||||
// NICs of one speed (VMs, a box of identical 25G ports): the bond must not count the boot NIC.
|
||||
func TestBondSkipsUsedNICs(t *testing.T) {
|
||||
nics := []invNIC{
|
||||
{Name: "ens18", MAC: "bc:00:00:00:00:01", Link: true, IPv4: []string{"10.0.0.150/24"}},
|
||||
{Name: "ens19", MAC: "bc:00:00:00:00:02", Link: true},
|
||||
{Name: "ens20", MAC: "bc:00:00:00:00:03", Link: true},
|
||||
}
|
||||
l := &NetLayout{Interfaces: []LayoutIface{
|
||||
{Type: "physical", Select: "boot", Links: []LayoutLink{{Subnet: "boot", Mode: "auto", Gateway: true}}},
|
||||
{Type: "bond", Name: "bond0", Members: []string{"fastest:2"}, BondMode: "active-backup", Links: []LayoutLink{{Mode: "link_up"}}},
|
||||
}}
|
||||
p := resolvePlan(l, nics, &nics[0], []Subnet{labSubnet()}, nil, allocFrom("10.0.0.21"))
|
||||
if got := strings.Join(p.Ifaces[1].Members, ","); got != "ens19,ens20" {
|
||||
t.Errorf("bond members %q, want ens19,ens20", got)
|
||||
}
|
||||
if lk := p.Ifaces[1].Links[0]; lk.Subnet != "" || lk.Mode != "link_up" {
|
||||
t.Errorf("a link_up link without a subnet stays without one: %+v", lk)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDnsmasqConfig(t *testing.T) {
|
||||
rc := RackController{Name: "r1", TFTPRoot: "/srv/tftp", Interfaces: []RackIface{{Name: "eth0", Addrs: []string{"192.168.1.5/24"}}, {Name: "eth1", Addrs: []string{"10.0.0.1/24"}}}}
|
||||
conf, ok := dnsmasqConfig(rc, []Subnet{labSubnet()}, "/var/lib/rollcall/dnsmasq")
|
||||
if !ok {
|
||||
t.Fatal("r1 serves 10.0.0.0/24")
|
||||
}
|
||||
for _, want := range []string{"interface=eth1\n", "dhcp-range=set:s0,10.0.0.100,10.0.0.200,255.255.255.0,12h", "dhcp-option=tag:s0,option:router,10.0.0.1",
|
||||
"dhcp-option=tag:s0,option:dns-server,10.0.0.1", "domain=lab.local,10.0.0.0/24", "dhcp-authoritative", "tftp-root=/srv/tftp"} {
|
||||
if !strings.Contains(conf, want) {
|
||||
t.Errorf("dnsmasq conf lacks %q:\n%s", want, conf)
|
||||
}
|
||||
}
|
||||
if strings.Contains(conf, "interface=eth0") {
|
||||
t.Errorf("must not serve the management interface:\n%s", conf)
|
||||
}
|
||||
// two racks: each takes half of the pool, nobody is authoritative
|
||||
sn := labSubnet()
|
||||
sn.SecondaryRack = "r2"
|
||||
c1, _ := dnsmasqConfig(rc, []Subnet{sn}, "/d")
|
||||
c2, _ := dnsmasqConfig(RackController{Name: "r2", Interfaces: []RackIface{{Name: "eth1", Addrs: []string{"10.0.0.2/24"}}}}, []Subnet{sn}, "/d")
|
||||
if !strings.Contains(c1, "10.0.0.100,10.0.0.150,") || !strings.Contains(c2, "10.0.0.151,10.0.0.200,") || strings.Contains(c1, "dhcp-authoritative") {
|
||||
t.Errorf("split pool:\n%s\n%s", c1, c2)
|
||||
}
|
||||
if _, ok := dnsmasqConfig(RackController{Name: "other"}, []Subnet{labSubnet()}, "/d"); ok {
|
||||
t.Errorf("a rack that serves nothing must not get a config")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user