summaryrefslogtreecommitdiff
path: root/pkg/machine/qemu/machine.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2022-04-02 15:25:19 -0500
committerBrent Baude <bbaude@redhat.com>2022-04-25 13:05:35 -0500
commit833456e079c31111a15fedaa3ccd7f852e89e508 (patch)
tree4e06007f5bec3c1cdc763a6b879ecebca5d75a29 /pkg/machine/qemu/machine.go
parent6984a0f35704204fa15374aa2c133c4e6e0b366f (diff)
downloadpodman-833456e079c31111a15fedaa3ccd7f852e89e508.tar.gz
podman-833456e079c31111a15fedaa3ccd7f852e89e508.tar.bz2
podman-833456e079c31111a15fedaa3ccd7f852e89e508.zip
Add podman machine test suite
This PR introduces a test suite for podman machine. It can currently be run on developers' local machines and is not part of the official CI testing; however, the expectation is that any work on machine should come with an accompanying test. At present, the test must be run on Linux. It is untested on Darwin. There is no Makefile target for the test. It can be run like `ginkgo -v pkg/machine/test/.`. It should be run as a unprivileged user. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/machine/qemu/machine.go')
-rw-r--r--pkg/machine/qemu/machine.go42
1 files changed, 30 insertions, 12 deletions
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index c57fa32fb..69a986102 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -76,7 +76,6 @@ func (p *Provider) NewMachine(opts machine.InitOptions) (machine.VM, error) {
return nil, err
}
vm.IgnitionFilePath = *ignitionFile
-
imagePath, err := NewMachineFile(opts.ImagePath, nil)
if err != nil {
return nil, err
@@ -373,7 +372,6 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
if err := v.writeConfig(); err != nil {
return false, fmt.Errorf("writing JSON file: %w", err)
}
-
// User has provided ignition file so keygen
// will be skipped.
if len(opts.IgnitionPath) < 1 {
@@ -387,7 +385,6 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
if err := v.prepare(); err != nil {
return false, err
}
-
originalDiskSize, err := getDiskSize(v.getImageFile())
if err != nil {
return false, err
@@ -514,17 +511,28 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
time.Sleep(wait)
wait++
}
+ defer qemuSocketConn.Close()
if err != nil {
return err
}
-
fd, err := qemuSocketConn.(*net.UnixConn).File()
if err != nil {
return err
}
+ defer fd.Close()
+ dnr, err := os.OpenFile("/dev/null", os.O_RDONLY, 0755)
+ if err != nil {
+ return err
+ }
+ defer dnr.Close()
+ dnw, err := os.OpenFile("/dev/null", os.O_WRONLY, 0755)
+ if err != nil {
+ return err
+ }
+ defer dnw.Close()
attr := new(os.ProcAttr)
- files := []*os.File{os.Stdin, os.Stdout, os.Stderr, fd}
+ files := []*os.File{dnr, dnw, dnw, fd}
attr.Files = files
logrus.Debug(v.CmdLine)
cmd := v.CmdLine
@@ -552,7 +560,7 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
}
_, err = os.StartProcess(cmd[0], cmd, attr)
if err != nil {
- return err
+ return errors.Wrapf(err, "unable to execute %q", cmd)
}
}
fmt.Println("Waiting for VM ...")
@@ -575,11 +583,11 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
if err != nil {
return err
}
+ defer conn.Close()
_, err = bufio.NewReader(conn).ReadString('\n')
if err != nil {
return err
}
-
if len(v.Mounts) > 0 {
state, err := v.State()
if err != nil {
@@ -918,7 +926,7 @@ func (v *MachineVM) SSH(_ string, opts machine.SSHOptions) error {
sshDestination := username + "@localhost"
port := strconv.Itoa(v.Port)
- args := []string{"-i", v.IdentityPath, "-p", port, sshDestination, "-o", "UserKnownHostsFile /dev/null", "-o", "StrictHostKeyChecking no"}
+ args := []string{"-i", v.IdentityPath, "-p", port, sshDestination, "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no"}
if len(opts.Args) > 0 {
args = append(args, opts.Args...)
} else {
@@ -1085,9 +1093,19 @@ func (v *MachineVM) startHostNetworking() (string, apiForwardingState, error) {
}
attr := new(os.ProcAttr)
- // Pass on stdin, stdout, stderr
- files := []*os.File{os.Stdin, os.Stdout, os.Stderr}
- attr.Files = files
+ dnr, err := os.OpenFile("/dev/null", os.O_RDONLY, 0755)
+ if err != nil {
+ return "", noForwarding, err
+ }
+ dnw, err := os.OpenFile("/dev/null", os.O_WRONLY, 0755)
+ if err != nil {
+ return "", noForwarding, err
+ }
+
+ defer dnr.Close()
+ defer dnw.Close()
+
+ attr.Files = []*os.File{dnr, dnw, dnw}
cmd := []string{binary}
cmd = append(cmd, []string{"-listen-qemu", fmt.Sprintf("unix://%s", v.QMPMonitor.Address.GetPath()), "-pid-file", v.PidFilePath.GetPath()}...)
// Add the ssh port
@@ -1104,7 +1122,7 @@ func (v *MachineVM) startHostNetworking() (string, apiForwardingState, error) {
fmt.Println(cmd)
}
_, err = os.StartProcess(cmd[0], cmd, attr)
- return forwardSock, state, err
+ return forwardSock, state, errors.Wrapf(err, "unable to execute: %q", cmd)
}
func (v *MachineVM) setupAPIForwarding(cmd []string) ([]string, string, apiForwardingState) {