diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 90b9aa19fc6..abf6d4dfa29 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -15,7 +15,6 @@ import ( "runtime" "strconv" "strings" - "syscall" "time" "github.com/hashicorp/go-getter" @@ -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 @@ -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 } diff --git a/client/testutil/driver_compatible.go b/client/testutil/driver_compatible.go index df1d27d1157..d73d62f33df 100644 --- a/client/testutil/driver_compatible.go +++ b/client/testutil/driver_compatible.go @@ -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") }