Merge pull request #352 from hashicorp/f-qemu-windows

Get Qemu to fingerprint and test properly on both windows and linux
This commit is contained in:
Alex Dadgar 2015-10-29 16:57:29 -07:00
commit 93e1b49278
2 changed files with 11 additions and 11 deletions

View file

@ -15,7 +15,6 @@ import (
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"github.com/hashicorp/go-getter" "github.com/hashicorp/go-getter"
@ -25,7 +24,7 @@ import (
) )
var ( var (
reQemuVersion = regexp.MustCompile("QEMU emulator version ([\\d\\.]+).+") reQemuVersion = regexp.MustCompile(`version (\d[\.\d+]+)`)
) )
// QemuDriver is a driver for running images via Qemu // 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) { func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
// Only enable if we are root when running on non-windows systems. bin := "qemu-system-x86_64"
if runtime.GOOS != "windows" && syscall.Geteuid() != 0 { if runtime.GOOS == "windows" {
d.logger.Printf("[DEBUG] driver.qemu: must run as root user, disabling") // On windows, the "qemu-system-x86_64" command does not respond to the
return false, nil // version flag.
bin = "qemu-img"
} }
outBytes, err := exec.Command(bin, "--version").Output()
outBytes, err := exec.Command("qemu-system-x86_64", "-version").Output()
if err != nil { if err != nil {
return false, nil return false, nil
} }

View file

@ -14,11 +14,12 @@ func ExecCompatible(t *testing.T) {
} }
func QemuCompatible(t *testing.T) { func QemuCompatible(t *testing.T) {
// Check if qemu exists
bin := "qemu-system-x86_64"
if runtime.GOOS == "windows" { 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(bin, "--version").CombinedOutput()
_, err := exec.Command("qemu-system-x86_64", "-version").CombinedOutput()
if err != nil { if err != nil {
t.Skip("Must have Qemu installed for Qemu specific tests to run") t.Skip("Must have Qemu installed for Qemu specific tests to run")
} }