Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Qemu to fingerprint and test properly on both windows and linux #352

Merged
merged 3 commits into from
Oct 29, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 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,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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a small comment here around why we are switching commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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
}
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