From dcc77f88910f92ea26cd73c9e9c8d36fb71429c8 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 6 Jan 2016 12:22:25 +0100 Subject: [PATCH] FIX #2756 Disable support for VBox <= 4.2 Signed-off-by: David Gageot --- docs/drivers/virtualbox.md | 2 +- drivers/virtualbox/vbm.go | 26 ++++++++++++++++++++++++-- drivers/virtualbox/vbm_test.go | 13 ++++++++----- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/docs/drivers/virtualbox.md b/docs/drivers/virtualbox.md index d0aa87ab3c..b31d406cb2 100644 --- a/docs/drivers/virtualbox.md +++ b/docs/drivers/virtualbox.md @@ -12,7 +12,7 @@ parent="smn_machine_drivers" Create machines locally using [VirtualBox](https://www.virtualbox.org/). This driver requires VirtualBox 5+ to be installed on your host. -Using VirtualBox 4+ should work but will give you a warning. Older versions +Using VirtualBox 4.3+ should work but will give you a warning. Older versions will refuse to work. $ docker-machine create --driver=virtualbox vbox-test diff --git a/drivers/virtualbox/vbm.go b/drivers/virtualbox/vbm.go index 09c1e78f96..c2b5180acd 100644 --- a/drivers/virtualbox/vbm.go +++ b/drivers/virtualbox/vbm.go @@ -9,6 +9,8 @@ import ( "regexp" "strings" + "strconv" + "github.com/docker/machine/libmachine/log" ) @@ -78,17 +80,37 @@ func (v *VBoxCmdManager) vbmOutErr(args ...string) (string, string, error) { } func checkVBoxManageVersion(version string) error { - if !strings.HasPrefix(version, "5.") && !strings.HasPrefix(version, "4.") { + major, minor, err := parseVersion(version) + if (err != nil) || (major < 4) || (major == 4 && minor <= 2) { return fmt.Errorf("We support Virtualbox starting with version 5. Your VirtualBox install is %q. Please upgrade at https://www.virtualbox.org", version) } - if !strings.HasPrefix(version, "5.") { + if major < 5 { log.Warnf("You are using version %s of VirtualBox. If you encouter issues, you might want to upgrade to version 5 at https://www.virtualbox.org", version) } return nil } +func parseVersion(version string) (int, int, error) { + parts := strings.Split(version, ".") + if len(parts) < 2 { + return 0, 0, fmt.Errorf("Invalid version: %q", version) + } + + major, err := strconv.Atoi(parts[0]) + if err != nil { + return 0, 0, fmt.Errorf("Invalid version: %q", version) + } + + minor, err := strconv.Atoi(parts[1]) + if err != nil { + return 0, 0, fmt.Errorf("Invalid version: %q", version) + } + + return major, minor, err +} + func parseKeyValues(stdOut string, regexp *regexp.Regexp, callback func(key, val string) error) error { r := strings.NewReader(stdOut) s := bufio.NewScanner(r) diff --git a/drivers/virtualbox/vbm_test.go b/drivers/virtualbox/vbm_test.go index ddfd078ad5..8b6caf2ebe 100644 --- a/drivers/virtualbox/vbm_test.go +++ b/drivers/virtualbox/vbm_test.go @@ -6,15 +6,14 @@ import ( "github.com/stretchr/testify/assert" ) -func TestCheckVBoxManageVersionValid(t *testing.T) { +func TestValidCheckVBoxManageVersion(t *testing.T) { var tests = []struct { version string }{ + {"5.1"}, {"5.0.8r103449"}, {"5.0"}, - {"5.1"}, - {"4.1"}, - {"4.2.0"}, + {"4.10"}, {"4.3.1"}, } @@ -25,12 +24,16 @@ func TestCheckVBoxManageVersionValid(t *testing.T) { } } -func TestCheckVBoxManageVersionInvalid(t *testing.T) { +func TestInvalidCheckVBoxManageVersion(t *testing.T) { var tests = []struct { version string expectedError string }{ {"3.9", `We support Virtualbox starting with version 5. Your VirtualBox install is "3.9". Please upgrade at https://www.virtualbox.org`}, + {"4.0", `We support Virtualbox starting with version 5. Your VirtualBox install is "4.0". Please upgrade at https://www.virtualbox.org`}, + {"4.1.1", `We support Virtualbox starting with version 5. Your VirtualBox install is "4.1.1". Please upgrade at https://www.virtualbox.org`}, + {"4.2.36-104064", `We support Virtualbox starting with version 5. Your VirtualBox install is "4.2.36-104064". Please upgrade at https://www.virtualbox.org`}, + {"X.Y", `We support Virtualbox starting with version 5. Your VirtualBox install is "X.Y". Please upgrade at https://www.virtualbox.org`}, {"", `We support Virtualbox starting with version 5. Your VirtualBox install is "". Please upgrade at https://www.virtualbox.org`}, }