From 0282a7d5442d51accedf079a881e6ceef2fd9621 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Wed, 20 May 2015 22:34:39 -0400 Subject: [PATCH 1/3] Add tests for url/env commands when stopped w/virtualbox Refs #1168 Signed-off-by: Mike Fiedler --- test/integration/driver-virtualbox.bats | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/integration/driver-virtualbox.bats b/test/integration/driver-virtualbox.bats index bd23877718..234bf92b6b 100644 --- a/test/integration/driver-virtualbox.bats +++ b/test/integration/driver-virtualbox.bats @@ -124,6 +124,18 @@ buildMachineWithOldIsoCheckUpgrade() { [[ "$status" -eq 1 ]] } +@test "$DRIVER: url should show an error when machine is stopped" { + run machine url $NAME + [ "$status" -eq 1 ] + [[ ${output} == "host is not running" ]] +} + +@test "$DRIVER: env should show an error when machine is stopped" { + run machine env $NAME + [ "$status" -eq 1 ] + [[ ${output} == *"not running. Please start this with"* ]] +} + @test "$DRIVER: start" { run machine start $NAME [ "$status" -eq 0 ] From cd049cb4b984f02825af065f7ff8ec8d83788d84 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Wed, 20 May 2015 23:14:00 -0400 Subject: [PATCH 2/3] Convert vmwarefusion bats tests back to `machine` In #615, the helper function `machine()` was created and used within the vmwarefusion test suite (amongst others) to wrap a platform-specfic binary during the test suite. In #1034, it appears that this name was changed to the normal docker-machine binary, which can incoke the system-installed one, not the recently compiled one, potentially testing the incorrect binary. See: - https://github.com/docker/machine/pull/615#discussion_r25643553 - https://github.com/docker/machine/pull/1034/files#diff-62c88a2fede921556dbdeead731596b2R14 Signed-off-by: Mike Fiedler --- test/integration/driver-vmwarefusion.bats | 46 +++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/integration/driver-vmwarefusion.bats b/test/integration/driver-vmwarefusion.bats index 5e5f4e2092..1eab67ff65 100644 --- a/test/integration/driver-vmwarefusion.bats +++ b/test/integration/driver-vmwarefusion.bats @@ -11,94 +11,94 @@ function setup() { sleep 1 } -@test "$DRIVER: docker-machine should not exist" { - run docker-machine inspect $NAME +@test "$DRIVER: machine should not exist" { + run machine inspect $NAME [ "$status" -eq 1 ] } @test "$DRIVER: create" { - run docker-machine create -d $DRIVER $NAME + run machine create -d $DRIVER $NAME [ "$status" -eq 0 ] } @test "$DRIVER: ls" { - run docker-machine ls + run machine ls [ "$status" -eq 0 ] [[ ${lines[1]} == *"$NAME"* ]] } @test "$DRIVER: run busybox container" { - run docker $(docker-machine config $NAME) run busybox echo hello world + run docker $(machine config $NAME) run busybox echo hello world [ "$status" -eq 0 ] } @test "$DRIVER: url" { - run docker-machine url $NAME + run machine url $NAME [ "$status" -eq 0 ] } @test "$DRIVER: ip" { - run docker-machine ip $NAME + run machine ip $NAME [ "$status" -eq 0 ] } @test "$DRIVER: ssh" { - run docker-machine ssh $NAME -- ls -lah / + run machine ssh $NAME -- ls -lah / [ "$status" -eq 0 ] [[ ${lines[0]} =~ "total" ]] } @test "$DRIVER: stop" { - run docker-machine stop $NAME + run machine stop $NAME [ "$status" -eq 0 ] } -@test "$DRIVER: docker-machine should show stopped after stop" { - run docker-machine ls +@test "$DRIVER: machine should show stopped after stop" { + run machine ls [ "$status" -eq 0 ] [[ ${lines[1]} == *"Stopped"* ]] } @test "$DRIVER: start" { - run docker-machine start $NAME + run machine start $NAME [ "$status" -eq 0 ] } -@test "$DRIVER: docker-machine should show running after start" { - run docker-machine ls +@test "$DRIVER: machine should show running after start" { + run machine ls [ "$status" -eq 0 ] [[ ${lines[1]} == *"Running"* ]] } @test "$DRIVER: kill" { - run docker-machine kill $NAME + run machine kill $NAME [ "$status" -eq 0 ] } -@test "$DRIVER: docker-machine should show stopped after kill" { - run docker-machine ls +@test "$DRIVER: machine should show stopped after kill" { + run machine ls [ "$status" -eq 0 ] [[ ${lines[1]} == *"Stopped"* ]] } @test "$DRIVER: restart" { - run docker-machine restart $NAME + run machine restart $NAME [ "$status" -eq 0 ] } -@test "$DRIVER: docker-machine should show running after restart" { - run docker-machine ls +@test "$DRIVER: machine should show running after restart" { + run machine ls [ "$status" -eq 0 ] [[ ${lines[1]} == *"Running"* ]] } @test "$DRIVER: remove" { - run docker-machine rm -f $NAME + run machine rm -f $NAME [ "$status" -eq 0 ] } -@test "$DRIVER: docker-machine should not exist" { - run docker-machine inspect $NAME +@test "$DRIVER: machine should not exist" { + run machine inspect $NAME [ "$status" -eq 1 ] } From 67a501899949a251ac31981dea9e00fa6b87fcff Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Wed, 20 May 2015 23:30:11 -0400 Subject: [PATCH 3/3] Get machine state before looking up URL in vmwarefusion - Add a call to GetState() in GetIP() to bail if the machine is stopped, similar to how it is done in the virtualbox driver. - Add tests for `url` and `env` commands. Fixes #1168 Signed-off-by: Mike Fiedler --- drivers/vmwarefusion/fusion_darwin.go | 8 ++++++++ test/integration/driver-vmwarefusion.bats | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/vmwarefusion/fusion_darwin.go b/drivers/vmwarefusion/fusion_darwin.go index f485334e7b..6c6a6d896c 100644 --- a/drivers/vmwarefusion/fusion_darwin.go +++ b/drivers/vmwarefusion/fusion_darwin.go @@ -173,6 +173,14 @@ func (d *Driver) GetURL() (string, error) { } func (d *Driver) GetIP() (string, error) { + s, err := d.GetState() + if err != nil { + return "", err + } + if s != state.Running { + return "", drivers.ErrHostIsNotRunning + } + ip, err := d.getIPfromDHCPLease() if err != nil { return "", err diff --git a/test/integration/driver-vmwarefusion.bats b/test/integration/driver-vmwarefusion.bats index 1eab67ff65..8593031c9e 100644 --- a/test/integration/driver-vmwarefusion.bats +++ b/test/integration/driver-vmwarefusion.bats @@ -59,6 +59,18 @@ function setup() { [[ ${lines[1]} == *"Stopped"* ]] } +@test "$DRIVER: url should show an error when machine is stopped" { + run machine url $NAME + [ "$status" -eq 1 ] + [[ ${output} == "host is not running" ]] +} + +@test "$DRIVER: env should show an error when machine is stopped" { + run machine env $NAME + [ "$status" -eq 1 ] + [[ ${output} == *"not running. Please start this with"* ]] +} + @test "$DRIVER: start" { run machine start $NAME [ "$status" -eq 0 ]