mirror of https://github.com/docker/docs.git
				
				
				
			Merge pull request #2760 from dgageot/disable-old-vbox
Disable support for VBox <= 4.2
This commit is contained in:
		
						commit
						04160e392b
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -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`}, | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue