-
Notifications
You must be signed in to change notification settings - Fork 23
Add Windows hypervisor primitives #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4ab69ee
Add Windows hypervisor primitives
sjmiller609 a5f3c40
Make UEFI profile test architecture-aware
sjmiller609 54fab7a
Support Debian Secure Boot firmware paths
sjmiller609 1ae68d6
Allow loaded hosts to start Windows devices
sjmiller609 9a4cafa
Isolate the Windows hypervisor CI gate
sjmiller609 53c6be8
Retry the isolated Windows config gate
sjmiller609 32eb71a
Address Windows hypervisor review feedback
sjmiller609 6b63aca
Rewrite Windows state paths for QEMU forks
sjmiller609 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package hypervisor | ||
|
|
||
| import "fmt" | ||
|
|
||
| // ValidateBootConfig validates boot and disk fields shared by hypervisor backends. | ||
| func ValidateBootConfig(cfg VMConfig) error { | ||
| switch cfg.EffectiveBootMode() { | ||
| case BootModeDirect: | ||
| if cfg.Firmware != nil { | ||
| return fmt.Errorf("direct boot cannot specify firmware") | ||
| } | ||
| if cfg.TPM != nil { | ||
| return fmt.Errorf("direct boot cannot specify a TPM") | ||
| } | ||
| case BootModeUEFI: | ||
| if cfg.Firmware == nil { | ||
| return fmt.Errorf("UEFI boot requires firmware") | ||
| } | ||
| if cfg.Firmware.CodePath == "" || cfg.Firmware.VarsPath == "" { | ||
| return fmt.Errorf("UEFI boot requires firmware code and variable storage paths") | ||
| } | ||
| if cfg.KernelPath != "" || cfg.InitrdPath != "" || cfg.KernelArgs != "" { | ||
| return fmt.Errorf("UEFI boot cannot specify a direct kernel, initrd, or kernel arguments") | ||
| } | ||
| if cfg.TPM != nil && (cfg.TPM.SocketPath == "" || cfg.TPM.StateDir == "") { | ||
| return fmt.Errorf("TPM requires socket and state directory paths") | ||
| } | ||
| default: | ||
| return fmt.Errorf("unsupported boot mode %q", cfg.BootMode) | ||
| } | ||
|
|
||
| for i, disk := range cfg.Disks { | ||
| switch disk.EffectiveFormat() { | ||
| case DiskFormatRaw, DiskFormatQCOW2: | ||
| default: | ||
| return fmt.Errorf("disk %d has unsupported format %q", i, disk.Format) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // ValidateDirectRawConfig preserves the Linux-only contract of backends that | ||
| // do not implement firmware boot or qcow2 disks. | ||
| func ValidateDirectRawConfig(backend string, cfg VMConfig) error { | ||
| if err := ValidateBootConfig(cfg); err != nil { | ||
| return err | ||
| } | ||
| if cfg.EffectiveBootMode() != BootModeDirect { | ||
| return fmt.Errorf("%s does not support %s boot", backend, cfg.EffectiveBootMode()) | ||
| } | ||
| for i, disk := range cfg.Disks { | ||
| if disk.EffectiveFormat() != DiskFormatRaw { | ||
| return fmt.Errorf("%s does not support disk %d format %q", backend, i, disk.EffectiveFormat()) | ||
| } | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package hypervisor | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestValidateBootConfigPreservesDirectRawDefaults(t *testing.T) { | ||
| cfg := VMConfig{ | ||
| KernelPath: "/kernel", | ||
| Disks: []DiskConfig{{Path: "/rootfs"}}, | ||
| } | ||
| require.NoError(t, ValidateBootConfig(cfg)) | ||
| assert.Equal(t, BootModeDirect, cfg.EffectiveBootMode()) | ||
| assert.Equal(t, DiskFormatRaw, cfg.Disks[0].EffectiveFormat()) | ||
| } | ||
|
|
||
| func TestValidateBootConfigUEFI(t *testing.T) { | ||
| valid := VMConfig{ | ||
| BootMode: BootModeUEFI, | ||
| Firmware: &FirmwareConfig{CodePath: "/ovmf/code", VarsPath: "/instance/vars"}, | ||
| TPM: &TPMConfig{SocketPath: "/instance/swtpm.sock", StateDir: "/instance/tpm"}, | ||
| Disks: []DiskConfig{{Path: "/instance/disk", Format: DiskFormatQCOW2}}, | ||
| } | ||
| require.NoError(t, ValidateBootConfig(valid)) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| cfg VMConfig | ||
| }{ | ||
| {name: "missing firmware", cfg: VMConfig{BootMode: BootModeUEFI}}, | ||
| {name: "direct kernel", cfg: VMConfig{BootMode: BootModeUEFI, Firmware: valid.Firmware, KernelPath: "/kernel"}}, | ||
| {name: "incomplete TPM", cfg: VMConfig{BootMode: BootModeUEFI, Firmware: valid.Firmware, TPM: &TPMConfig{StateDir: "/state"}}}, | ||
| {name: "unknown disk", cfg: VMConfig{Disks: []DiskConfig{{Path: "/disk", Format: "vhdx"}}}}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| assert.Error(t, ValidateBootConfig(tt.cfg)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestValidateDirectRawConfigRejectsFirmwareAndQCOW2(t *testing.T) { | ||
| uefi := VMConfig{BootMode: BootModeUEFI, Firmware: &FirmwareConfig{CodePath: "/code", VarsPath: "/vars"}} | ||
| assert.ErrorContains(t, ValidateDirectRawConfig("backend", uefi), "does not support uefi boot") | ||
|
|
||
| qcow := VMConfig{Disks: []DiskConfig{{Path: "/disk", Format: DiskFormatQCOW2}}} | ||
| assert.ErrorContains(t, ValidateDirectRawConfig("backend", qcow), "does not support disk 0 format") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.