Merge pull request #7614 from radeksimko/f-qemu-go-version

builder/qemu: Replace dot-based parsing with hashicorp/go-version
This commit is contained in:
Megan Marsh 2019-05-06 16:47:19 -07:00 committed by GitHub
commit ad37e45006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 14 deletions

View File

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

2
go.mod
View File

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

2
go.sum
View File

@ -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=

View File

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

View File

@ -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.
//

2
vendor/modules.txt vendored
View File

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