From a5a1e45f4b5e7be1fe993275a5f970e682fa6c97 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 27 Oct 2015 15:27:11 -0700 Subject: [PATCH 1/3] Get Qemu to fingerprint and test properly on both windows and linux --- client/driver/qemu.go | 13 +++++-------- client/testutil/driver_compatible.go | 5 +---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 90b9aa19f..147c074ea 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,11 @@ 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" { + 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 df1d27d11..a9d1cdc42 100644 --- a/client/testutil/driver_compatible.go +++ b/client/testutil/driver_compatible.go @@ -14,10 +14,7 @@ func ExecCompatible(t *testing.T) { } func QemuCompatible(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Must be on non-windows environments to run test") - } - // else see if qemu exists + // Check if qemu exists _, err := exec.Command("qemu-system-x86_64", "-version").CombinedOutput() if err != nil { t.Skip("Must have Qemu installed for Qemu specific tests to run") From 9f7dcc4ceddd83d78baefabcba7b88e6800b351c Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 28 Oct 2015 10:28:53 -0700 Subject: [PATCH 2/3] Use same binary as Fingerprint in the QemuCompatible function --- client/testutil/driver_compatible.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/testutil/driver_compatible.go b/client/testutil/driver_compatible.go index a9d1cdc42..d73d62f33 100644 --- a/client/testutil/driver_compatible.go +++ b/client/testutil/driver_compatible.go @@ -15,7 +15,11 @@ func ExecCompatible(t *testing.T) { func QemuCompatible(t *testing.T) { // Check if qemu exists - _, err := exec.Command("qemu-system-x86_64", "-version").CombinedOutput() + bin := "qemu-system-x86_64" + if runtime.GOOS == "windows" { + bin = "qemu-img" + } + _, err := exec.Command(bin, "--version").CombinedOutput() if err != nil { t.Skip("Must have Qemu installed for Qemu specific tests to run") } From 01e0be4cc663dd7dc8d99026194e625574b8ed33 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 29 Oct 2015 16:57:02 -0700 Subject: [PATCH 3/3] Add comment explaining the qemu-img command on windows --- client/driver/qemu.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 147c074ea..abf6d4dfa 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -57,6 +57,8 @@ func NewQemuDriver(ctx *DriverContext) Driver { func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { 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(bin, "--version").Output()