Merge pull request #2954 from jeanlaurent/engine-url

Fix #2029 - local drivers dont run with engine-install-url
This commit is contained in:
David Gageot 2016-01-28 18:26:01 +01:00
commit b6be1b79bc
9 changed files with 56 additions and 7 deletions

View File

@ -45,7 +45,7 @@ var (
cli.StringFlag{
Name: "engine-install-url",
Usage: "Custom URL to use for engine installation",
Value: "https://get.docker.com",
Value: drivers.DefaultEngineInstallURL,
EnvVar: "MACHINE_DOCKER_INSTALL_URL",
},
cli.StringSliceFlag{

View File

@ -6,6 +6,8 @@ import (
"os"
"time"
"errors"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnflag"
@ -78,6 +80,9 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
}
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
if drivers.EngineInstallURLFlagSet(flags) {
return errors.New("--engine-install-url cannot be used with the hyperv driver, use --hyperv-boot2docker-url instead")
}
d.Boot2DockerURL = flags.String("hyperv-boot2docker-url")
d.VSwitch = flags.String("hyperv-virtual-switch")
d.DiskSize = flags.Int("hyperv-disk-size")

View File

@ -190,6 +190,9 @@ func (d *Driver) GetURL() (string, error) {
}
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
if drivers.EngineInstallURLFlagSet(flags) {
return errors.New("--engine-install-url cannot be used with the virtualbox driver, use --virtualbox-boot2docker-url instead")
}
d.CPU = flags.Int("virtualbox-cpu-count")
d.Memory = flags.Int("virtualbox-memory")
d.DiskSize = flags.Int("virtualbox-disk-size")

View File

@ -18,6 +18,8 @@ import (
"text/template"
"time"
"errors"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnflag"
@ -144,6 +146,9 @@ func (d *Driver) DriverName() string {
}
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
if drivers.EngineInstallURLFlagSet(flags) {
return errors.New("--engine-install-url cannot be used with the vmwarefusion driver, use --vmwarefusion-boot2docker-url instead")
}
d.Memory = flags.Int("vmwarefusion-memory-size")
d.CPU = flags.Int("vmwarefusion-cpu-count")
d.DiskSize = flags.Int("vmwarefusion-disk-size")

View File

@ -21,6 +21,8 @@ import (
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"errors"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/guest"
@ -177,6 +179,9 @@ func (d *Driver) DriverName() string {
}
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
if drivers.EngineInstallURLFlagSet(flags) {
return errors.New("--engine-install-url cannot be used with the vmwarevsphere driver, use --vmwarevsphere-boot2docker-url instead")
}
d.SSHUser = "docker"
d.SSHPort = 22
d.CPU = flags.Int("vmwarevsphere-cpu-count")

View File

@ -6,8 +6,9 @@ import (
)
const (
DefaultSSHUser = "root"
DefaultSSHPort = 22
DefaultSSHUser = "root"
DefaultSSHPort = 22
DefaultEngineInstallURL = "https://get.docker.com"
)
// BaseDriver - Embed this struct into drivers to provide the common set
@ -83,3 +84,8 @@ func (d *BaseDriver) SetSwarmConfigFromFlags(flags DriverOptions) {
d.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery")
}
func EngineInstallURLFlagSet(flags DriverOptions) bool {
engineInstallURLFlag := flags.String("engine-install-url")
return engineInstallURLFlag != DefaultEngineInstallURL && engineInstallURLFlag != ""
}

View File

@ -4,6 +4,7 @@ import (
"errors"
"testing"
"github.com/docker/machine/libmachine/mcnflag"
"github.com/stretchr/testify/assert"
)
@ -26,3 +27,24 @@ func TestIP(t *testing.T) {
assert.Equal(t, c.expectedErr, err)
}
}
func TestEngineInstallUrlFlagEmpty(t *testing.T) {
assert.False(t, EngineInstallURLFlagSet(&CheckDriverOptions{}))
}
func createDriverOptionWithEngineInstall(url string) *CheckDriverOptions {
return &CheckDriverOptions{
FlagsValues: map[string]interface{}{"engine-install-url": url},
CreateFlags: []mcnflag.Flag{mcnflag.StringFlag{Name: "engine-install-url", Value: ""}},
}
}
func TestEngineInstallUrlFlagDefault(t *testing.T) {
options := createDriverOptionWithEngineInstall(DefaultEngineInstallURL)
assert.False(t, EngineInstallURLFlagSet(options))
}
func TestEngineInstallUrlFlagSet(t *testing.T) {
options := createDriverOptionWithEngineInstall("https://test.docker.com")
assert.True(t, EngineInstallURLFlagSet(options))
}

View File

@ -75,7 +75,7 @@ func (api *Client) NewHost(driverName string, rawDriver []byte) (*host.Host, err
ServerKeyPath: filepath.Join(api.GetMachinesDir(), "server-key.pem"),
},
EngineOptions: &engine.Options{
InstallURL: "https://get.docker.com",
InstallURL: drivers.DefaultEngineInstallURL,
StorageDriver: "aufs",
TLSVerify: true,
},

View File

@ -6,9 +6,12 @@ only_if_env DRIVER virtualbox
use_disposable_machine
export BAD_URL="http://dev.null:9111/bad.iso"
@test "$DRIVER: Should not allow machine creation with bad ISO" {
run machine create -d virtualbox --virtualbox-boot2docker-url $BAD_URL $NAME
run machine create -d virtualbox --virtualbox-boot2docker-url http://dev.null:9111/bad.iso $NAME
[[ ${status} -eq 1 ]]
}
@test "$DRIVER: Should not allow machine creation with engine-install-url" {
run machine create --engine-install-url https://test.docker.com -d virtualbox $NAME
[[ ${output} == *"--engine-install-url cannot be used"* ]]
}