diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index abb64f039..3631b9bda 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -5,9 +5,9 @@ import ( "fmt" "log" "path/filepath" - "strconv" "strings" + "github.com/hashicorp/go-version" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/template/interpolate" @@ -85,16 +85,14 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0") } - qemuVersion, err := driver.Version() + rawVersion, err := driver.Version() if err != nil { return nil, err } - parts := strings.Split(qemuVersion, ".") - qemuMajor, err := strconv.Atoi(parts[0]) - if err != nil { - return nil, err - } - if qemuMajor >= 2 { + qemuVersion, err := version.NewVersion(rawVersion) + v2 := version.Must(version.NewVersion("1.2")) + + if qemuVersion.GreaterThanOrEqual(v2) { if config.DiskInterface == "virtio-scsi" { deviceArgs = append(deviceArgs, "virtio-scsi-pci,id=scsi0", "scsi-hd,bus=scsi0.0,drive=drive0") driveArgumentString := fmt.Sprintf("if=none,file=%s,id=drive0,cache=%s,discard=%s,format=%s", imgPath, config.DiskCache, config.DiskDiscard, config.Format) @@ -133,7 +131,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error "to inspect the progress of the build.") } } else { - if qemuMajor >= 2 { + if qemuVersion.GreaterThanOrEqual(v2) { if !config.UseDefaultDisplay { defaultArgs["-display"] = "sdl" } diff --git a/go.mod b/go.mod index b09691cab..a2bb25ae3 100644 --- a/go.mod +++ b/go.mod @@ -47,7 +47,7 @@ require ( github.com/hashicorp/go-retryablehttp v0.5.2 // indirect github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 // indirect github.com/hashicorp/go-uuid v1.0.1 - github.com/hashicorp/go-version v1.1.0 + github.com/hashicorp/go-version v1.2.0 github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/serf v0.8.2 // indirect github.com/hashicorp/vault v1.1.0 diff --git a/go.sum b/go.sum index d800c2cfc..79d921747 100644 --- a/go.sum +++ b/go.sum @@ -187,6 +187,8 @@ github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1 github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= +github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= diff --git a/vendor/github.com/hashicorp/go-version/.travis.yml b/vendor/github.com/hashicorp/go-version/.travis.yml index 542ca8b7f..01c5dc219 100644 --- a/vendor/github.com/hashicorp/go-version/.travis.yml +++ b/vendor/github.com/hashicorp/go-version/.travis.yml @@ -1,13 +1,13 @@ language: go go: - - 1.0 - - 1.1 - 1.2 - 1.3 - 1.4 - 1.9 - "1.10" + - 1.11 + - 1.12 script: - go test diff --git a/vendor/github.com/hashicorp/go-version/version.go b/vendor/github.com/hashicorp/go-version/version.go index 186fd7cc1..1032c5606 100644 --- a/vendor/github.com/hashicorp/go-version/version.go +++ b/vendor/github.com/hashicorp/go-version/version.go @@ -112,7 +112,7 @@ func Must(v *Version, err error) *Version { // or larger than the other version, respectively. // // If you want boolean results, use the LessThan, Equal, -// or GreaterThan methods. +// GreaterThan, GreaterThanOrEqual or LessThanOrEqual methods. func (v *Version) Compare(other *Version) int { // A quick, efficient equality check if v.String() == other.String() { @@ -288,11 +288,21 @@ func (v *Version) GreaterThan(o *Version) bool { return v.Compare(o) > 0 } +// GreaterThanOrEqualTo tests if this version is greater than or equal to another version. +func (v *Version) GreaterThanOrEqual(o *Version) bool { + return v.Compare(o) >= 0 +} + // LessThan tests if this version is less than another version. func (v *Version) LessThan(o *Version) bool { return v.Compare(o) < 0 } +// LessThanOrEqualTo tests if this version is less than or equal to another version. +func (v *Version) LessThanOrEqual(o *Version) bool { + return v.Compare(o) <= 0 +} + // Metadata returns any metadata that was part of the version // string. // diff --git a/vendor/modules.txt b/vendor/modules.txt index 8b707c5c1..3c73bce8b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -253,7 +253,7 @@ github.com/hashicorp/go-safetemp github.com/hashicorp/go-sockaddr # github.com/hashicorp/go-uuid v1.0.1 github.com/hashicorp/go-uuid -# github.com/hashicorp/go-version v1.1.0 +# github.com/hashicorp/go-version v1.2.0 github.com/hashicorp/go-version # github.com/hashicorp/golang-lru v0.5.0 github.com/hashicorp/golang-lru/simplelru