Skip to content

Commit

Permalink
Merge pull request #352 from hashicorp/f-qemu-windows
Browse files Browse the repository at this point in the history
Get Qemu to fingerprint and test properly on both windows and linux
  • Loading branch information
dadgar committed Oct 29, 2015
2 parents 56f5e53 + 1d06f44 commit f9497a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 7 additions & 8 deletions client/driver/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"runtime"
"strconv"
"strings"
"syscall"
"time"

"github.com/hashicorp/go-getter"
Expand All @@ -25,7 +24,7 @@ import (
)

var (
reQemuVersion = regexp.MustCompile("QEMU emulator version ([\\d\\.]+).+")
reQemuVersion = regexp.MustCompile(`version (\d[\.\d+]+)`)
)

// QemuDriver is a driver for running images via Qemu
Expand Down Expand Up @@ -56,13 +55,13 @@ func NewQemuDriver(ctx *DriverContext) Driver {
}

func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
// Only enable if we are root when running on non-windows systems.
if runtime.GOOS != "windows" && syscall.Geteuid() != 0 {
d.logger.Printf("[DEBUG] driver.qemu: must run as root user, disabling")
return false, nil
bin := "qemu-system-x86_64"
if runtime.GOOS == "windows" {
// On windows, the "qemu-system-x86_64" command does not respond to the
// version flag.
bin = "qemu-img"
}

outBytes, err := exec.Command("qemu-system-x86_64", "-version").Output()
outBytes, err := exec.Command(bin, "--version").Output()
if err != nil {
return false, nil
}
Expand Down
7 changes: 4 additions & 3 deletions client/testutil/driver_compatible.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ func ExecCompatible(t *testing.T) {
}

func QemuCompatible(t *testing.T) {
// Check if qemu exists
bin := "qemu-system-x86_64"
if runtime.GOOS == "windows" {
t.Skip("Must be on non-windows environments to run test")
bin = "qemu-img"
}
// else see if qemu exists
_, err := exec.Command("qemu-system-x86_64", "-version").CombinedOutput()
_, err := exec.Command(bin, "--version").CombinedOutput()
if err != nil {
t.Skip("Must have Qemu installed for Qemu specific tests to run")
}
Expand Down

0 comments on commit f9497a5

Please sign in to comment.