mirror of
https://github.com/containers/podman.git
synced 2025-11-11 16:45:02 +08:00
Create Qemu command wrapper
Creates a wrapper around the Qemu command line implementation to prevent the need to hard-code the different command line options in Init and Start. Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
This commit is contained in:
67
pkg/machine/qemu/qemu_command_test.go
Normal file
67
pkg/machine/qemu/qemu_command_test.go
Normal file
@@ -0,0 +1,67 @@
|
||||
//go:build (amd64 && !windows) || (arm64 && !windows)
|
||||
// +build amd64,!windows arm64,!windows
|
||||
|
||||
package qemu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/containers/podman/v4/pkg/machine"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestQemuCmd(t *testing.T) {
|
||||
ignFile, err := machine.NewMachineFile(t.TempDir()+"demo-ignition-file.ign", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
machineAddrFile, err := machine.NewMachineFile(t.TempDir()+"tmp.sock", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
readySocket, err := machine.NewMachineFile(t.TempDir()+"readySocket.sock", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
vmPidFile, err := machine.NewMachineFile(t.TempDir()+"vmpidfile.pid", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
monitor := Monitor{
|
||||
Address: *machineAddrFile,
|
||||
Network: "unix",
|
||||
Timeout: 3,
|
||||
}
|
||||
ignPath := ignFile.GetPath()
|
||||
addrFilePath := machineAddrFile.GetPath()
|
||||
readySocketPath := readySocket.GetPath()
|
||||
vmPidFilePath := vmPidFile.GetPath()
|
||||
bootableImagePath := t.TempDir() + "test-machine_fedora-coreos-38.20230918.2.0-qemu.x86_64.qcow2"
|
||||
|
||||
cmd := NewQemuBuilder("/usr/bin/qemu-system-x86_64", []string{})
|
||||
cmd.SetMemory(2048)
|
||||
cmd.SetCPUs(4)
|
||||
cmd.SetIgnitionFile(*ignFile)
|
||||
cmd.SetQmpMonitor(monitor)
|
||||
cmd.SetNetwork()
|
||||
cmd.SetSerialPort(*readySocket, *vmPidFile, "test-machine")
|
||||
cmd.SetVirtfsMount("/tmp/path", "vol10", "none", true)
|
||||
cmd.SetBootableImage(bootableImagePath)
|
||||
cmd.SetDisplay("none")
|
||||
|
||||
expected := []string{
|
||||
"/usr/bin/qemu-system-x86_64",
|
||||
"-m", "2048",
|
||||
"-smp", "4",
|
||||
"-fw_cfg", fmt.Sprintf("name=opt/com.coreos/config,file=%s", ignPath),
|
||||
"-qmp", fmt.Sprintf("unix:%s,server=on,wait=off", addrFilePath),
|
||||
"-netdev", "socket,id=vlan,fd=3",
|
||||
"-device", "virtio-net-pci,netdev=vlan,mac=5a:94:ef:e4:0c:ee",
|
||||
"-device", "virtio-serial",
|
||||
"-chardev", fmt.Sprintf("socket,path=%s,server=on,wait=off,id=atest-machine_ready", readySocketPath),
|
||||
"-device", "virtserialport,chardev=atest-machine_ready,name=org.fedoraproject.port.0",
|
||||
"-pidfile", vmPidFilePath,
|
||||
"-virtfs", "local,path=/tmp/path,mount_tag=vol10,security_model=none,readonly",
|
||||
"-drive", fmt.Sprintf("if=virtio,file=%s", bootableImagePath),
|
||||
"-display", "none"}
|
||||
|
||||
require.Equal(t, cmd.Build(), expected)
|
||||
}
|
||||
Reference in New Issue
Block a user