Skip to content
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

Report list of devices in the REST API #99

Merged
merged 10 commits into from
Feb 21, 2024
5 changes: 2 additions & 3 deletions cmd/vfkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/crc-org/vfkit/pkg/rest"
restvf "github.com/crc-org/vfkit/pkg/rest/vf"
"github.com/crc-org/vfkit/pkg/vf"
"github.com/docker/go-units"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -71,7 +70,7 @@ func newVMConfiguration(opts *cmdline.Options) (*config.VirtualMachine, error) {

vmConfig := config.NewVirtualMachine(
opts.Vcpus,
uint64(opts.MemoryMiB*units.MiB),
uint64(opts.MemoryMiB),
bootloader,
)
log.Info("virtual machine parameters:")
Expand Down Expand Up @@ -131,7 +130,7 @@ func runVFKit(vmConfig *config.VirtualMachine, opts *cmdline.Options) error {

// Do not enable the rests server if user sets scheme to None
if opts.RestfulURI != cmdline.DefaultRestfulURI {
restVM := restvf.NewVzVirtualMachine(vm, vzVMConfig)
restVM := restvf.NewVzVirtualMachine(vm, vzVMConfig, vmConfig)
srv, err := rest.NewServer(restVM, restVM, opts.RestfulURI)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.18
require (
github.com/Code-Hex/vz/v3 v3.1.0
github.com/cavaliergopher/grab/v3 v3.0.1
github.com/containers/common v0.57.1-0.20240210120841-91e0fac33e22
github.com/crc-org/crc/v2 v2.32.0
github.com/docker/go-units v0.5.0
github.com/gin-gonic/gin v1.9.1
github.com/prashantgupta24/mac-sleep-notifier v1.0.1
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -40,7 +40,7 @@ require (
github.com/h2non/filetype v1.1.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpV
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0=
github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/containers/common v0.57.1-0.20240210120841-91e0fac33e22 h1:HH3JAenyz6ysup3ADvVPuX0TqLcg6IleuoMi15B5MXM=
github.com/containers/common v0.57.1-0.20240210120841-91e0fac33e22/go.mod h1:Al9edwL72aYyVOfIE+DB635ltve3S98TrQgg/Tv5PLE=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/crc-org/crc/v2 v2.32.0 h1:I/62j5KrID8ua1vgAUPOVTtzhcsCsHWdqqiIRHySLfQ=
github.com/crc-org/crc/v2 v2.32.0/go.mod h1:Q2XJM3KkR/Gu+tBjeN77pk5P8DWYKdbxCSf+9l9MYcs=
Expand All @@ -31,8 +33,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
Expand Down Expand Up @@ -63,8 +63,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/bootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ type Bootloader interface {
// LinuxBootloader determines which kernel/initrd/kernel args to use when starting
// the virtual machine.
type LinuxBootloader struct {
VmlinuzPath string
KernelCmdLine string
InitrdPath string
VmlinuzPath string `json:"vmlinuzPath"`
KernelCmdLine string `json:"kernelCmdLine"`
InitrdPath string `json:"initrdPath"`
}

// EFIBootloader allows to set a few options related to EFI variable storage
type EFIBootloader struct {
EFIVariableStorePath string
EFIVariableStorePath string `json:"efiVariableStorePath"`
// TODO: virtualization framework allow both create and overwrite
CreateVariableStore bool
CreateVariableStore bool `json:"createVariableStore"`
}

// NewLinuxBootloader creates a new bootloader to start a VM with the file at
Expand Down
38 changes: 24 additions & 14 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ import (
"os/exec"
"strconv"
"strings"

"github.com/containers/common/pkg/strongunits"
)

// VirtualMachine is the top-level type. It describes the virtual machine
// configuration (bootloader, devices, ...).
type VirtualMachine struct {
Vcpus uint `json:"vcpus"`
MemoryBytes uint64 `json:"memoryBytes"`
Bootloader Bootloader `json:"bootloader"`
Devices []VirtioDevice `json:"devices,omitempty"`
Timesync *TimeSync `json:"timesync,omitempty"`
Vcpus uint `json:"vcpus"`
Memory strongunits.B `json:"memoryBytes"`
Bootloader Bootloader `json:"bootloader"`
Devices []VirtioDevice `json:"devices,omitempty"`
Timesync *TimeSync `json:"timesync,omitempty"`
}

// TimeSync enables synchronization of the host time to the linux guest after the host was suspended.
// This requires qemu-guest-agent to be running in the guest, and to be listening on a vsock socket
type TimeSync struct {
VsockPort uint
VsockPort uint `json:"vsockPort"`
}

// The VMComponent interface represents a VM element (device, bootloader, ...)
Expand All @@ -32,16 +34,24 @@ type VMComponent interface {
}

// NewVirtualMachine creates a new VirtualMachine instance. The virtual machine
// will use vcpus virtual CPUs and it will be allocated memoryBytes bytes of
// RAM. bootloader specifies which kernel/initrd/kernel args it will be using.
func NewVirtualMachine(vcpus uint, memoryBytes uint64, bootloader Bootloader) *VirtualMachine {
// will use vcpus virtual CPUs and it will be allocated memoryMiB mibibytes
// (1024*1024 bytes) of RAM. bootloader specifies how the virtual machine will
// be booted (UEFI or with the specified kernel/initrd/commandline)
func NewVirtualMachine(vcpus uint, memoryMiB uint64, bootloader Bootloader) *VirtualMachine {
return &VirtualMachine{
Vcpus: vcpus,
MemoryBytes: memoryBytes,
Bootloader: bootloader,
Vcpus: vcpus,
Memory: strongunits.MiB(memoryMiB).ToBytes(),
Bootloader: bootloader,
}
}

// round value up to the nearest mibibyte multiple
func roundToMiB(value strongunits.StorageUnits) strongunits.MiB {
mib := uint64(strongunits.MiB(1).ToBytes())
valueB := strongunits.B(uint64(value.ToBytes()) + mib - 1)
return strongunits.ToMib(valueB)
}

// ToCmdLine generates a list of arguments for use with the [os/exec] package.
// These arguments will start a virtual machine with the devices/bootloader/...
// described by vm If the virtual machine configuration described by vm is
Expand All @@ -53,8 +63,8 @@ func (vm *VirtualMachine) ToCmdLine() ([]string, error) {
if vm.Vcpus != 0 {
args = append(args, "--cpus", strconv.FormatUint(uint64(vm.Vcpus), 10))
}
if vm.MemoryBytes != 0 {
args = append(args, "--memory", strconv.FormatUint(vm.MemoryBytes, 10))
if uint64(vm.Memory.ToBytes()) != 0 {
args = append(args, "--memory", strconv.FormatUint(uint64(roundToMiB(vm.Memory)), 10))
}

if vm.Bootloader == nil {
Expand Down
42 changes: 35 additions & 7 deletions pkg/config/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"encoding/json"
"fmt"
"net"
)

// The technique for json (de)serialization was explained here:
Expand Down Expand Up @@ -88,6 +89,27 @@ func unmarshalDevices(rawMsg json.RawMessage) ([]VirtioDevice, error) {
return devices, nil
}

// VirtioNet needs a custom unmarshaller as net.HardwareAddress is not
// serialized/unserialized in its expected format, instead of
// '00:11:22:33:44:55', it's serialized as base64-encoded raw bytes such as
// 'ABEiM0RV'. This custom (un)marshalling code will use the desired format.
func unmarshalVirtioNet(rawMsg json.RawMessage) (*VirtioNet, error) {
var dev virtioNetForMarshalling

err := json.Unmarshal(rawMsg, &dev)
if err != nil {
return nil, err
}
if dev.MacAddress != "" {
macAddr, err := net.ParseMAC(dev.MacAddress)
if err != nil {
return nil, err
}
dev.VirtioNet.MacAddress = macAddr
}
return &dev.VirtioNet, nil
}

func unmarshalDevice(rawMsg json.RawMessage) (VirtioDevice, error) {
var (
kind jsonKind
Expand All @@ -99,9 +121,7 @@ func unmarshalDevice(rawMsg json.RawMessage) (VirtioDevice, error) {
}
switch kind.Kind {
case vfNet:
var newDevice VirtioNet
err = json.Unmarshal(rawMsg, &newDevice)
dev = &newDevice
dev, err = unmarshalVirtioNet(rawMsg)
case vfVsock:
var newDevice VirtioVsock
err = json.Unmarshal(rawMsg, &newDevice)
Expand Down Expand Up @@ -173,7 +193,7 @@ func (vm *VirtualMachine) UnmarshalJSON(b []byte) error {
case "vcpus":
err = json.Unmarshal(*rawMsg, &vm.Vcpus)
case "memoryBytes":
err = json.Unmarshal(*rawMsg, &vm.MemoryBytes)
err = json.Unmarshal(*rawMsg, &vm.Memory)
case "bootloader":
var bootloader Bootloader
bootloader, err = unmarshalBootloader(*rawMsg)
Expand Down Expand Up @@ -219,14 +239,22 @@ func (bootloader *LinuxBootloader) MarshalJSON() ([]byte, error) {
})
}

type virtioNetForMarshalling struct {
VirtioNet
MacAddress string `json:"macAddress,omitempty"`
}

func (dev *VirtioNet) MarshalJSON() ([]byte, error) {
type devWithKind struct {
jsonKind
VirtioNet
virtioNetForMarshalling
}
return json.Marshal(devWithKind{
jsonKind: kind(vfNet),
VirtioNet: *dev,
jsonKind: kind(vfNet),
virtioNetForMarshalling: virtioNetForMarshalling{
VirtioNet: *dev,
MacAddress: dev.MacAddress.String(),
},
})
}

Expand Down
31 changes: 15 additions & 16 deletions pkg/config/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ type jsonTest struct {
var jsonTests = map[string]jsonTest{
"TestLinuxVM": {
newVM: newLinuxVM,
expectedJSON: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"}}`,
expectedJSON: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"linuxBootloader","vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"}}`,
},
"TestUEFIVM": {
newVM: newUEFIVM,
expectedJSON: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"efiBootloader","EFIVariableStorePath":"/variable-store","CreateVariableStore":false}}`,
expectedJSON: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"efiBootloader","efiVariableStorePath":"/variable-store","createVariableStore":false}}`,
},
"TestTimeSync": {
newVM: func(t *testing.T) *VirtualMachine {
Expand All @@ -29,7 +29,7 @@ var jsonTests = map[string]jsonTest{
vm.Timesync = timesync.(*TimeSync)
return vm
},
expectedJSON: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"timesync":{"VsockPort":1234}}`,
expectedJSON: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"linuxBootloader","vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"},"timesync":{"vsockPort":1234}}`,
},
"TestVirtioRNG": {
newVM: func(t *testing.T) *VirtualMachine {
Expand All @@ -40,7 +40,7 @@ var jsonTests = map[string]jsonTest{
require.NoError(t, err)
return vm
},
expectedJSON: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"devices":[{"kind":"virtiorng"}]}`,
expectedJSON: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"linuxBootloader","vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"},"devices":[{"kind":"virtiorng"}]}`,
},
"TestMultipleVirtioBlk": {
newVM: func(t *testing.T) *VirtualMachine {
Expand All @@ -56,7 +56,7 @@ var jsonTests = map[string]jsonTest{
require.NoError(t, err)
return vm
},
expectedJSON: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"devices":[{"kind":"virtioblk","DevName":"virtio-blk","ImagePath":"/virtioblk1","ReadOnly":false,"DeviceIdentifier":""},{"kind":"virtioblk","DevName":"virtio-blk","ImagePath":"/virtioblk2","ReadOnly":false,"DeviceIdentifier":"virtio-blk2"}]}`,
expectedJSON: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"linuxBootloader","vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"},"devices":[{"kind":"virtioblk","devName":"virtio-blk","imagePath":"/virtioblk1"},{"kind":"virtioblk","devName":"virtio-blk","imagePath":"/virtioblk2","deviceIdentifier":"virtio-blk2"}]}`,
},
"TestAllVirtioDevices": {
newVM: func(t *testing.T) *VirtualMachine {
Expand Down Expand Up @@ -110,7 +110,7 @@ var jsonTests = map[string]jsonTest{

return vm
},
expectedJSON: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"devices":[{"kind":"virtioserial","LogFile":"/virtioserial","UsesStdio":false},{"kind":"virtioinput","inputType":"keyboard"},{"kind":"virtiogpu","usesGUI":false,"width":800,"height":600},{"kind":"virtionet","Nat":true,"MacAddress":"ABEiM0RV","Socket":null,"UnixSocketPath":""},{"kind":"virtiorng"},{"kind":"virtioblk","DevName":"virtio-blk","ImagePath":"/virtioblk","ReadOnly":false,"DeviceIdentifier":""},{"kind":"virtiosock","Port":1234,"SocketURL":"/virtiovsock","Listen":false},{"kind":"virtiofs","MountTag":"tag","SharedDir":"/virtiofs"},{"kind":"usbmassstorage","DevName":"usb-mass-storage","ImagePath":"/usbmassstorage","ReadOnly":false},{"kind":"rosetta","MountTag":"vz-rosetta","InstallRosetta":false}]}`,
expectedJSON: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"linuxBootloader","vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"},"devices":[{"kind":"virtioserial","logFile":"/virtioserial"},{"kind":"virtioinput","inputType":"keyboard"},{"kind":"virtiogpu","usesGUI":false,"width":800,"height":600},{"kind":"virtionet","nat":true,"macAddress":"00:11:22:33:44:55"},{"kind":"virtiorng"},{"kind":"virtioblk","devName":"virtio-blk","imagePath":"/virtioblk"},{"kind":"virtiosock","port":1234,"socketURL":"/virtiovsock"},{"kind":"virtiofs","mountTag":"tag","sharedDir":"/virtiofs"},{"kind":"usbmassstorage","devName":"usb-mass-storage","imagePath":"/usbmassstorage"},{"kind":"rosetta","mountTag":"vz-rosetta","installRosetta":false}]}`,
},
}

Expand All @@ -120,22 +120,22 @@ type invalidJSONTest struct {

var invalidJSONTests = map[string]invalidJSONTest{
"TestEmptyBootloaderKind": {
json: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"empty",VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"}}`,
json: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"empty",vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"}}`,
},
"TestInvalidBootloaderKind": {
json: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"invalid",VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"}}`,
json: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"invalid",vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"}}`,
},
"TestMissingBootloaderKind": {
json: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"}}`,
json: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"}}`,
},
"TestEmptyDeviceKind": {
json: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"devices":[{"kind":"","DevName":"virtio-blk","ImagePath":"/virtioblk1","ReadOnly":false,"DeviceIdentifier":""}]}`,
json: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"linuxBootloader","vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"},"devices":[{"kind":"","devName":"virtio-blk","imagePath":"/virtioblk1"}]}`,
},
"TestInvalidDeviceKind": {
json: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"devices":[{"kind":"invalid","DevName":"virtio-blk","ImagePath":"/virtioblk1","ReadOnly":false,"DeviceIdentifier":""}]}`,
json: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"linuxBootloader","vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"},"devices":[{"kind":"invalid","devName":"virtio-blk","imagePath":"/virtioblk1"}]}`,
},
"TestMissingDeviceKind": {
json: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"devices":[{"DevName":"virtio-blk","ImagePath":"/virtioblk1","ReadOnly":false,"DeviceIdentifier":""}]}`,
json: `{"vcpus":3,"memoryBytes":4194304000,"bootloader":{"kind":"linuxBootloader","vmlinuzPath":"/vmlinuz","initrdPath":"/initrd","kernelCmdLine":"console=hvc0"},"devices":[{"devName":"virtio-blk","imagePath":"/virtioblk1"}]}`,
},
}

Expand All @@ -153,7 +153,6 @@ func TestJSON(t *testing.T) {
testInvalidJSON(t, &test)
})
}

})
}

Expand All @@ -177,15 +176,15 @@ func testInvalidJSON(t *testing.T, test *invalidJSONTest) {
}

func newLinuxVM(*testing.T) *VirtualMachine {
bootloader := NewLinuxBootloader("/vmlinuz", "/initrd", "console=hvc0")
vm := NewVirtualMachine(3, 4_000_000_000, bootloader)
bootloader := NewLinuxBootloader("/vmlinuz", "console=hvc0", "/initrd")
vm := NewVirtualMachine(3, 4_000, bootloader)

return vm
}

func newUEFIVM(_ *testing.T) *VirtualMachine {
bootloader := NewEFIBootloader("/variable-store", false)
vm := NewVirtualMachine(3, 4_000_000_000, bootloader)
vm := NewVirtualMachine(3, 4_000, bootloader)

return vm
}
Loading
Loading