Stop using kernel IP autoconfig for runtime VMs
Avoid the Alpine boot stall caused by kernel ip= autoconfig running before virtio_net is available. Split runtime and image-build boot args so managed VMs boot without kernel network autoconfig, inject a static guest network config plus bootstrap script into the runtime overlay, and keep image builds on the old path for compatibility with existing base images. Preserve executable bits when patching guest files into ext4 images and add coverage for the new boot-arg split and guest network config generation. Validated with go test ./..., a rebuilt Alpine image, and a fresh alp-fast create/ssh check that brought vm.start down to about 2.7s.
This commit is contained in:
parent
092d848620
commit
14d8563f3c
7 changed files with 186 additions and 28 deletions
|
|
@ -167,16 +167,26 @@ func TestReadNormalizedLines(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuildBootArgsIncludesHostnameInIPField(t *testing.T) {
|
||||
func TestBuildBootArgsOmitsKernelIPAutoconfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got := BuildBootArgs("devbox", "172.16.0.2", "172.16.0.1", "1.1.1.1")
|
||||
want := "console=ttyS0 reboot=k panic=1 pci=off root=/dev/vda rootfstype=ext4 rw ip=172.16.0.2::172.16.0.1:255.255.255.0:devbox:eth0:off:1.1.1.1 hostname=devbox systemd.mask=home.mount systemd.mask=var.mount"
|
||||
got := BuildBootArgs("devbox")
|
||||
want := "console=ttyS0 reboot=k panic=1 pci=off root=/dev/vda rootfstype=ext4 rw hostname=devbox systemd.mask=home.mount systemd.mask=var.mount"
|
||||
if got != want {
|
||||
t.Fatalf("BuildBootArgs() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildBootArgsWithKernelIPIncludesHostnameInIPField(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got := BuildBootArgsWithKernelIP("devbox", "172.16.0.2", "172.16.0.1", "1.1.1.1")
|
||||
want := "console=ttyS0 reboot=k panic=1 pci=off root=/dev/vda rootfstype=ext4 rw ip=172.16.0.2::172.16.0.1:255.255.255.0:devbox:eth0:off:1.1.1.1 hostname=devbox systemd.mask=home.mount systemd.mask=var.mount"
|
||||
if got != want {
|
||||
t.Fatalf("BuildBootArgsWithKernelIP() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteExt4FileRemovesTempFileAndReturnsCopyError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
@ -212,6 +222,46 @@ func TestWriteExt4FileRemovesTempFileAndReturnsCopyError(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestWriteExt4FileModeUsesRequestedPermissions(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
debugfsCalled := false
|
||||
runner := funcRunner{
|
||||
runSudo: func(ctx context.Context, args ...string) ([]byte, error) {
|
||||
switch args[0] {
|
||||
case "e2rm":
|
||||
return nil, nil
|
||||
case "e2cp":
|
||||
info, err := os.Stat(args[1])
|
||||
if err != nil {
|
||||
t.Fatalf("Stat(temp file): %v", err)
|
||||
}
|
||||
if got := info.Mode().Perm(); got != 0o755 {
|
||||
t.Fatalf("temp file mode = %o, want 755", got)
|
||||
}
|
||||
return nil, nil
|
||||
case "debugfs":
|
||||
debugfsCalled = true
|
||||
want := []string{"debugfs", "-w", "-R", "sif /usr/local/libexec/banger-network-bootstrap mode 0100755", "/tmp/root.ext4"}
|
||||
if !reflect.DeepEqual(args, want) {
|
||||
t.Fatalf("debugfs args = %v, want %v", args, want)
|
||||
}
|
||||
return nil, nil
|
||||
default:
|
||||
t.Fatalf("unexpected sudo call: %v", args)
|
||||
return nil, nil
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
if err := WriteExt4FileMode(context.Background(), runner, "/tmp/root.ext4", "/usr/local/libexec/banger-network-bootstrap", 0o755, []byte("#!/bin/sh\n")); err != nil {
|
||||
t.Fatalf("WriteExt4FileMode() error = %v", err)
|
||||
}
|
||||
if !debugfsCalled {
|
||||
t.Fatal("expected debugfs mode fixup to run")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMountTempDirUsesLoopForRegularFilesAndCleanupUsesBackgroundContext(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue