Files
rollcall/cmd/rollcall/grub_test.go
T
Ilker ManapandClaude Opus 5.5 c494c7b226
CI / go (push) Successful in 45s
CI / agent (push) Successful in 4s
CI / site (push) Successful in 2s
GRUB local boot chainloads the disk's signed loader; image sums
On the Secure Boot lab VM, GRUB's "exit" back to the firmware did not
reach the disk: OVMF went on to its other network boot options and
stopped in its own boot menu. The local-disk entry now finds the
installed OS's signed loader on the EFI partition (shimx64.efi under
EFI/debian, ubuntu, rocky, almalinux, redhat, centos; shim.efi for
SUSE; else EFI/BOOT/BOOTX64.EFI) and chainloads it, as MAAS does.

build-image.sh writes SHA256SUMS next to the image (the old one was
stale after a rebuild; bootstrap.sh --image-url checks it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 11:28:56 +01:00

41 lines
1.6 KiB
Go

package main
import (
"fmt"
"strings"
"testing"
)
func TestPxelinuxToGrub(t *testing.T) {
commissioned := fmt.Sprintf(commissionedTmpl, "now", "m-1", "QEMU", "PC", "S1", "m-1", "QEMU", "PC", "S1",
"boot=live components fetch=http://10.213.77.1/rollcall/filesystem.squashfs rollcall.server=http://10.213.77.1 rollcall.token=abc")
g := pxelinuxToGrub(commissioned)
for _, want := range []string{
"set default=0\nset timeout=15\n",
"menuentry 'Commissioned: power off (default in 15s)' {\n halt\n}",
"menuentry 'Re-run commissioning' {\n linux /rollcall/vmlinuz boot=live components fetch=http://10.213.77.1/rollcall/filesystem.squashfs",
" initrd /rollcall/initrd.img\n",
"menuentry 'Boot from local disk' {\n insmod part_gpt\n",
"chainloader $f",
} {
if !strings.Contains(g, want) {
t.Errorf("missing %q in\n%s", want, g)
}
}
deployed := fmt.Sprintf(deployedTmpl, "now", "m-1", "debian-13", "1", "node01", "debian-13", "m-1", "debian-13", "boot=live")
if g := pxelinuxToGrub(deployed); !strings.Contains(g, "set default=0\n") || !strings.Contains(g, "/EFI/debian/shimx64.efi") {
t.Errorf("deployed:\n%s", g)
}
// nothing from a cmdline can break out of the menu entry
g = pxelinuxToGrub("LABEL x\n MENU DEFAULT\n KERNEL k\n APPEND a=$(x) b;reboot c='q'\n")
if !strings.Contains(g, `'a=$(x)' 'b;reboot' 'c='\''q'\'''`) {
t.Errorf("quoting:\n%s", g)
}
if n := grubName("01-bc-24-11-f7-53-6b"); n != "grub.cfg-bc:24:11:f7:53:6b" {
t.Errorf("name %q", n)
}
if grubName("01-../x") != "" || grubName("default") != "" {
t.Error("a non-MAC file name became a GRUB file")
}
}