Skip to content

Commit dcc77f8

Browse files
committed
FIX docker-archive-public#2756 Disable support for VBox <= 4.2
Signed-off-by: David Gageot <david@gageot.net>
1 parent 7442ccc commit dcc77f8

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

docs/drivers/virtualbox.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ parent="smn_machine_drivers"
1212

1313
Create machines locally using [VirtualBox](https://www.virtualbox.org/).
1414
This driver requires VirtualBox 5+ to be installed on your host.
15-
Using VirtualBox 4+ should work but will give you a warning. Older versions
15+
Using VirtualBox 4.3+ should work but will give you a warning. Older versions
1616
will refuse to work.
1717

1818
$ docker-machine create --driver=virtualbox vbox-test

drivers/virtualbox/vbm.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"regexp"
1010
"strings"
1111

12+
"strconv"
13+
1214
"github.com/docker/machine/libmachine/log"
1315
)
1416

@@ -78,17 +80,37 @@ func (v *VBoxCmdManager) vbmOutErr(args ...string) (string, string, error) {
7880
}
7981

8082
func checkVBoxManageVersion(version string) error {
81-
if !strings.HasPrefix(version, "5.") && !strings.HasPrefix(version, "4.") {
83+
major, minor, err := parseVersion(version)
84+
if (err != nil) || (major < 4) || (major == 4 && minor <= 2) {
8285
return fmt.Errorf("We support Virtualbox starting with version 5. Your VirtualBox install is %q. Please upgrade at https://www.virtualbox.org", version)
8386
}
8487

85-
if !strings.HasPrefix(version, "5.") {
88+
if major < 5 {
8689
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)
8790
}
8891

8992
return nil
9093
}
9194

95+
func parseVersion(version string) (int, int, error) {
96+
parts := strings.Split(version, ".")
97+
if len(parts) < 2 {
98+
return 0, 0, fmt.Errorf("Invalid version: %q", version)
99+
}
100+
101+
major, err := strconv.Atoi(parts[0])
102+
if err != nil {
103+
return 0, 0, fmt.Errorf("Invalid version: %q", version)
104+
}
105+
106+
minor, err := strconv.Atoi(parts[1])
107+
if err != nil {
108+
return 0, 0, fmt.Errorf("Invalid version: %q", version)
109+
}
110+
111+
return major, minor, err
112+
}
113+
92114
func parseKeyValues(stdOut string, regexp *regexp.Regexp, callback func(key, val string) error) error {
93115
r := strings.NewReader(stdOut)
94116
s := bufio.NewScanner(r)

drivers/virtualbox/vbm_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import (
66
"github.com/stretchr/testify/assert"
77
)
88

9-
func TestCheckVBoxManageVersionValid(t *testing.T) {
9+
func TestValidCheckVBoxManageVersion(t *testing.T) {
1010
var tests = []struct {
1111
version string
1212
}{
13+
{"5.1"},
1314
{"5.0.8r103449"},
1415
{"5.0"},
15-
{"5.1"},
16-
{"4.1"},
17-
{"4.2.0"},
16+
{"4.10"},
1817
{"4.3.1"},
1918
}
2019

@@ -25,12 +24,16 @@ func TestCheckVBoxManageVersionValid(t *testing.T) {
2524
}
2625
}
2726

28-
func TestCheckVBoxManageVersionInvalid(t *testing.T) {
27+
func TestInvalidCheckVBoxManageVersion(t *testing.T) {
2928
var tests = []struct {
3029
version string
3130
expectedError string
3231
}{
3332
{"3.9", `We support Virtualbox starting with version 5. Your VirtualBox install is "3.9". Please upgrade at https://www.virtualbox.org`},
33+
{"4.0", `We support Virtualbox starting with version 5. Your VirtualBox install is "4.0". Please upgrade at https://www.virtualbox.org`},
34+
{"4.1.1", `We support Virtualbox starting with version 5. Your VirtualBox install is "4.1.1". Please upgrade at https://www.virtualbox.org`},
35+
{"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`},
36+
{"X.Y", `We support Virtualbox starting with version 5. Your VirtualBox install is "X.Y". Please upgrade at https://www.virtualbox.org`},
3437
{"", `We support Virtualbox starting with version 5. Your VirtualBox install is "". Please upgrade at https://www.virtualbox.org`},
3538
}
3639

0 commit comments

Comments
 (0)