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:
commit
93e1b49278
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue