From 17b1e571f2feff8385411fc235115862bb1ce5f6 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 7 Dec 2015 15:42:33 +0100 Subject: [PATCH 1/5] Group engine options test Signed-off-by: David Gageot --- .../core/arbitrary-engine-envs.bats | 19 --------- .../core/arbitrary-engine-options.bats | 18 --------- test/integration/core/engine-options.bats | 40 +++++++++++++++++++ .../core/supported-engine-options.bats | 23 ----------- 4 files changed, 40 insertions(+), 60 deletions(-) delete mode 100644 test/integration/core/arbitrary-engine-envs.bats delete mode 100644 test/integration/core/arbitrary-engine-options.bats create mode 100644 test/integration/core/engine-options.bats delete mode 100644 test/integration/core/supported-engine-options.bats diff --git a/test/integration/core/arbitrary-engine-envs.bats b/test/integration/core/arbitrary-engine-envs.bats deleted file mode 100644 index 6e1accd20c..0000000000 --- a/test/integration/core/arbitrary-engine-envs.bats +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -@test "$DRIVER: create with arbitrary engine envs" { - run machine create -d $DRIVER \ - --engine-env=TEST=VALUE \ - $NAME - echo ${output} - [ $status -eq 0 ] -} - -@test "$DRIVER: test docker process envs" { - # get pid of docker process, check process envs for set Environment Variable from above test - run machine ssh $NAME 'sudo cat /proc/$(pgrep -f "docker [d]aemon")/environ' - echo ${output} - [ $status -eq 0 ] - [[ "${output}" =~ "TEST=VALUE" ]] -} diff --git a/test/integration/core/arbitrary-engine-options.bats b/test/integration/core/arbitrary-engine-options.bats deleted file mode 100644 index 0f11da9b3d..0000000000 --- a/test/integration/core/arbitrary-engine-options.bats +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -@test "$DRIVER: create with arbitrary engine option" { - run machine create -d $DRIVER \ - --engine-opt log-driver=none \ - $NAME - echo ${output} - [ $status -eq 0 ] -} - -@test "$DRIVER: check created engine option (log driver)" { - docker $(machine config $NAME) run --name nolog busybox echo this should not be logged - run docker $(machine config $NAME) inspect -f '{{.HostConfig.LogConfig.Type}}' nolog - echo ${output} - [ ${output} == "none" ] -} diff --git a/test/integration/core/engine-options.bats b/test/integration/core/engine-options.bats new file mode 100644 index 0000000000..8f74098533 --- /dev/null +++ b/test/integration/core/engine-options.bats @@ -0,0 +1,40 @@ +#!/usr/bin/env bats + +load ${BASE_TEST_DIR}/helpers.bash + +@test "$DRIVER: create with supported engine options" { + run machine create -d $DRIVER \ + --engine-label spam=eggs \ + --engine-storage-driver overlay \ + --engine-insecure-registry registry.myco.com \ + --engine-env=TEST=VALUE \ + --engine-opt log-driver=none \ + $NAME + echo "$output" + [ $status -eq 0 ] +} + +@test "$DRIVER: check for engine label" { + spamlabel=$(docker $(machine config $NAME) info | grep spam) + [[ $spamlabel =~ "spam=eggs" ]] +} + +@test "$DRIVER: check for engine storage driver" { + storage_driver_info=$(docker $(machine config $NAME) info | grep "Storage Driver") + [[ $storage_driver_info =~ "overlay" ]] +} + +@test "$DRIVER: test docker process envs" { + # get pid of docker process, check process envs for set Environment Variable from above test + run machine ssh $NAME 'sudo cat /proc/$(pgrep -f "docker [d]aemon")/environ' + echo ${output} + [ $status -eq 0 ] + [[ "${output}" =~ "TEST=VALUE" ]] +} + +@test "$DRIVER: check created engine option (log driver)" { + docker $(machine config $NAME) run --name nolog busybox echo this should not be logged + run docker $(machine config $NAME) inspect -f '{{.HostConfig.LogConfig.Type}}' nolog + echo ${output} + [ ${output} == "none" ] +} diff --git a/test/integration/core/supported-engine-options.bats b/test/integration/core/supported-engine-options.bats deleted file mode 100644 index afa56678f9..0000000000 --- a/test/integration/core/supported-engine-options.bats +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -@test "$DRIVER: create with supported engine options" { - run machine create -d $DRIVER \ - --engine-label spam=eggs \ - --engine-storage-driver overlay \ - --engine-insecure-registry registry.myco.com \ - $NAME - echo "$output" - [ $status -eq 0 ] -} - -@test "$DRIVER: check for engine label" { - spamlabel=$(docker $(machine config $NAME) info | grep spam) - [[ $spamlabel =~ "spam=eggs" ]] -} - -@test "$DRIVER: check for engine storage driver" { - storage_driver_info=$(docker $(machine config $NAME) info | grep "Storage Driver") - [[ $storage_driver_info =~ "overlay" ]] -} From a708bf7e6c156555b85be5fcdd12df5f80199f56 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 7 Dec 2015 15:43:16 +0100 Subject: [PATCH 2/5] Cleanup machines only at the end Signed-off-by: David Gageot --- test/integration/core/certs-extra-san.bats | 3 +++ test/integration/core/core-commands.bats | 14 ++++++------- test/integration/core/engine-options.bats | 4 ++++ test/integration/core/env_shell.bats | 7 +++---- test/integration/core/inspect_format.bats | 7 +++---- test/integration/core/regenerate-certs.bats | 6 +++--- test/integration/core/scp.bats | 10 ++++----- test/integration/core/ssh-backends.bats | 9 +++----- test/integration/helpers.bash | 21 ++++++++++++++----- test/integration/run-bats.sh | 19 +++++++++-------- .../virtualbox/bad-create-iso.bats | 4 ++++ .../virtualbox/certs-checksum.bats | 6 +++--- .../virtualbox/custom-mem-disk.bats | 4 ++++ test/integration/virtualbox/dns.bats | 4 ++++ .../virtualbox/pause-save-start.bats | 7 +++---- test/integration/virtualbox/upgrade.bats | 4 ++++ 16 files changed, 77 insertions(+), 52 deletions(-) diff --git a/test/integration/core/certs-extra-san.bats b/test/integration/core/certs-extra-san.bats index 4973fb5259..8e32080c04 100644 --- a/test/integration/core/certs-extra-san.bats +++ b/test/integration/core/certs-extra-san.bats @@ -2,6 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi @test "$DRIVER: create" { run machine create --tls-san foo.bar.tld --tls-san 10.42.42.42 -d $DRIVER $NAME diff --git a/test/integration/core/core-commands.bats b/test/integration/core/core-commands.bats index 7615ad1274..43e8bd246c 100644 --- a/test/integration/core/core-commands.bats +++ b/test/integration/core/core-commands.bats @@ -2,17 +2,15 @@ load ${BASE_TEST_DIR}/helpers.bash +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi + @test "$DRIVER: machine should not exist" { - run machine inspect $NAME + run machine inspect UNKNOWN echo ${output} [ "$status" -eq 1 ] - [[ ${lines[0]} =~ "Host does not exist: \"$NAME\"" ]] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - echo ${output} - [ "$status" -eq 0 ] + [[ ${lines[0]} =~ "Host does not exist: \"UNKNOWN\"" ]] } @test "$DRIVER: appears with ls" { diff --git a/test/integration/core/engine-options.bats b/test/integration/core/engine-options.bats index 8f74098533..c338dc0755 100644 --- a/test/integration/core/engine-options.bats +++ b/test/integration/core/engine-options.bats @@ -2,6 +2,10 @@ load ${BASE_TEST_DIR}/helpers.bash +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + @test "$DRIVER: create with supported engine options" { run machine create -d $DRIVER \ --engine-label spam=eggs \ diff --git a/test/integration/core/env_shell.bats b/test/integration/core/env_shell.bats index e290997e4e..1d4dd577f1 100644 --- a/test/integration/core/env_shell.bats +++ b/test/integration/core/env_shell.bats @@ -2,10 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: test basic bash / zsh notation" { run machine env $NAME diff --git a/test/integration/core/inspect_format.bats b/test/integration/core/inspect_format.bats index e5267f25e5..b7705fc185 100644 --- a/test/integration/core/inspect_format.bats +++ b/test/integration/core/inspect_format.bats @@ -2,10 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: inspect format template" { run machine inspect -f '{{.DriverName}}' $NAME diff --git a/test/integration/core/regenerate-certs.bats b/test/integration/core/regenerate-certs.bats index e7ca5dde84..0bd189f3c7 100644 --- a/test/integration/core/regenerate-certs.bats +++ b/test/integration/core/regenerate-certs.bats @@ -2,9 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: regenerate the certs" { run machine regenerate-certs -f $NAME diff --git a/test/integration/core/scp.bats b/test/integration/core/scp.bats index 0f1f8968c9..8e36430029 100644 --- a/test/integration/core/scp.bats +++ b/test/integration/core/scp.bats @@ -2,12 +2,10 @@ load ${BASE_TEST_DIR}/helpers.bash -export SECOND_MACHINE="$NAME-2" - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [[ ${status} -eq 0 ]] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" + export SECOND_MACHINE="$NAME-2" +fi @test "$DRIVER: test machine scp command from remote to host" { machine ssh $NAME 'echo A file created remotely! >/tmp/foo.txt' diff --git a/test/integration/core/ssh-backends.bats b/test/integration/core/ssh-backends.bats index 7fc1fba0d9..b4399b3f4d 100644 --- a/test/integration/core/ssh-backends.bats +++ b/test/integration/core/ssh-backends.bats @@ -2,12 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash -# Basic smoke test for SSH backends - -@test "$DRIVER: create SSH test box" { - run machine create -d $DRIVER $NAME - [[ "$status" -eq 0 ]] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: test external ssh backend" { run machine ssh $NAME df -h diff --git a/test/integration/helpers.bash b/test/integration/helpers.bash index f97528fa60..1276c70e33 100644 --- a/test/integration/helpers.bash +++ b/test/integration/helpers.bash @@ -1,6 +1,6 @@ #!/bin/bash -echo_to_log() { +function echo_to_log { echo "$BATS_TEST_NAME ---------- $output @@ -9,27 +9,38 @@ $output " >> ${BATS_LOG} } -teardown() { +function teardown { echo_to_log } -function errecho () { +function errecho { >&2 echo "$@" } -function only_if_env () { +function only_if_env { if [[ ${!1} != "$2" ]]; then errecho "This test requires the $1 environment variable to be set to $2. Skipping..." skip fi } -function require_env () { +function require_env { if [[ -z ${!1} ]]; then errecho "This test requires the $1 environment variable to be set in order to run." exit 1 fi } +function unique_machine_name { + echo "bats-$DRIVER-test-$(date +%s)" +} + +function shared_machine_name { + if [[ $(machine ls -q --filter name=$SHARED_NAME | wc -l) -eq 0 ]]; then + machine create -d $DRIVER $SHARED_NAME &>/dev/null + fi + echo "$SHARED_NAME" +} + # Make sure these aren't set while tests run (can cause confusing behavior) unset DOCKER_HOST DOCKER_TLS_VERIFY DOCKER_CERT_DIR diff --git a/test/integration/run-bats.sh b/test/integration/run-bats.sh index f3390f3ce5..97ce41cd20 100755 --- a/test/integration/run-bats.sh +++ b/test/integration/run-bats.sh @@ -14,9 +14,11 @@ function quiet_run () { } function cleanup_machines() { - if [[ $(machine ls -q | wc -l) -ne 0 ]]; then - quiet_run machine rm -f $(machine ls -q) - fi + for MACHINE_NAME in $(machine ls -q); do + if [[ "$MACHINE_NAME" != "$SHARED_NAME" ]] || [[ "$1" == "ALL" ]]; then + quiet_run machine rm -f $MACHINE_NAME + fi + done } function cleanup_store() { @@ -26,18 +28,15 @@ function cleanup_store() { } function machine() { - export PATH="$MACHINE_ROOT"/bin:$PATH "$MACHINE_ROOT"/bin/"$MACHINE_BIN_NAME" "$@" } function run_bats() { for bats_file in $(find "$1" -name \*.bats); do - export NAME="bats-$DRIVER-test-$(date +%s)" - - # BATS returns non-zero to indicate the tests have failed, we shouldn't - # neccesarily bail in this case, so that's the reason for the e toggle. echo "=> $bats_file" + # BATS returns non-zero to indicate the tests have failed, we shouldn't + # necessarily bail in this case, so that's the reason for the e toggle. set +e bats "$bats_file" if [[ $? -ne 0 ]]; then @@ -88,13 +87,14 @@ export MACHINE_STORAGE_PATH="/tmp/machine-bats-test-$DRIVER" export MACHINE_BIN_NAME=docker-machine export BATS_LOG="$MACHINE_ROOT/bats.log" export B2D_LOCATION=~/.docker/machine/cache/boot2docker.iso +export SHARED_NAME="bats-$DRIVER-test-shared-$(date +%s)" # This function gets used in the integration tests, so export it. export -f machine > "$BATS_LOG" -cleanup_machines +cleanup_machines "ALL" cleanup_store if [[ -f "$B2D_LOCATION" ]]; then @@ -108,6 +108,7 @@ fi run_bats "$BATS_FILE" +cleanup_machines "ALL" cleanup_store exit ${EXIT_STATUS} diff --git a/test/integration/virtualbox/bad-create-iso.bats b/test/integration/virtualbox/bad-create-iso.bats index f10d530ef3..ab633cc6da 100644 --- a/test/integration/virtualbox/bad-create-iso.bats +++ b/test/integration/virtualbox/bad-create-iso.bats @@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + export BAD_URL="http://dev.null:9111/bad.iso" @test "$DRIVER: Should not allow machine creation with bad ISO" { diff --git a/test/integration/virtualbox/certs-checksum.bats b/test/integration/virtualbox/certs-checksum.bats index e2e48e7f3f..a9a8a6531f 100644 --- a/test/integration/virtualbox/certs-checksum.bats +++ b/test/integration/virtualbox/certs-checksum.bats @@ -4,9 +4,9 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: verify that server cert checksum matches local checksum" { # TODO: This test is tightly coupled to VirtualBox right now, but should be diff --git a/test/integration/virtualbox/custom-mem-disk.bats b/test/integration/virtualbox/custom-mem-disk.bats index a7c1a6560c..eb973a3aed 100644 --- a/test/integration/virtualbox/custom-mem-disk.bats +++ b/test/integration/virtualbox/custom-mem-disk.bats @@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + # Default memsize is 1024MB and disksize is 20000MB # These values are defined in drivers/virtualbox/virtualbox.go export DEFAULT_MEMSIZE=1024 diff --git a/test/integration/virtualbox/dns.bats b/test/integration/virtualbox/dns.bats index 802548baf0..69107c80e2 100644 --- a/test/integration/virtualbox/dns.bats +++ b/test/integration/virtualbox/dns.bats @@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + @test "$DRIVER: Create a vm with a dns proxy set" { run machine create -d $DRIVER --virtualbox-dns-proxy=true $NAME [[ ${status} -eq 0 ]] diff --git a/test/integration/virtualbox/pause-save-start.bats b/test/integration/virtualbox/pause-save-start.bats index cdab7621e9..0f865c27e8 100644 --- a/test/integration/virtualbox/pause-save-start.bats +++ b/test/integration/virtualbox/pause-save-start.bats @@ -4,10 +4,9 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: VBoxManage pause" { run VBoxManage controlvm $NAME pause diff --git a/test/integration/virtualbox/upgrade.bats b/test/integration/virtualbox/upgrade.bats index 893fea4e0a..5233b79bc5 100644 --- a/test/integration/virtualbox/upgrade.bats +++ b/test/integration/virtualbox/upgrade.bats @@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + export OLD_ISO_URL="https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso" @test "$DRIVER: create for upgrade" { From 57085d89e580e8ed58acdb5a29a8de7cf61ba77f Mon Sep 17 00:00:00 2001 From: David Gageot Date: Tue, 8 Dec 2015 12:28:02 +0100 Subject: [PATCH 3/5] Fix test Signed-off-by: David Gageot --- test/integration/core/inspect_format.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/core/inspect_format.bats b/test/integration/core/inspect_format.bats index b7705fc185..0e34183ef8 100644 --- a/test/integration/core/inspect_format.bats +++ b/test/integration/core/inspect_format.bats @@ -23,7 +23,7 @@ fi @test "$DRIVER: check .Driver output is not flawed" { only_if_env DRIVER virtualbox - run docker-machine inspect -f '{{.Driver.SSHUser}}' $NAME + run machine inspect -f '{{.Driver.SSHUser}}' $NAME [ "$status" -eq 0 ] [[ ${output} == "docker" ]] } From 3071da0673c53f2f3b730a5efd262e969b6df5ca Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 7 Dec 2015 17:13:13 +0100 Subject: [PATCH 4/5] FIX #2490 - Reuse machines in ITs Signed-off-by: David Gageot --- test/integration/core/certs-extra-san.bats | 4 +--- test/integration/core/core-commands.bats | 4 +--- test/integration/core/engine-options.bats | 4 +--- test/integration/core/env_shell.bats | 4 +--- test/integration/core/inspect_format.bats | 4 +--- test/integration/core/regenerate-certs.bats | 4 +--- test/integration/core/scp.bats | 6 ++---- test/integration/core/ssh-backends.bats | 4 +--- test/integration/helpers.bash | 16 ++++++++++------ test/integration/run-bats.sh | 7 ++++++- test/integration/virtualbox/bad-create-iso.bats | 4 +--- test/integration/virtualbox/certs-checksum.bats | 4 +--- test/integration/virtualbox/custom-mem-disk.bats | 4 +--- test/integration/virtualbox/dns.bats | 4 +--- .../integration/virtualbox/pause-save-start.bats | 4 +--- test/integration/virtualbox/upgrade.bats | 4 +--- 16 files changed, 31 insertions(+), 50 deletions(-) diff --git a/test/integration/core/certs-extra-san.bats b/test/integration/core/certs-extra-san.bats index 8e32080c04..0e91d78423 100644 --- a/test/integration/core/certs-extra-san.bats +++ b/test/integration/core/certs-extra-san.bats @@ -2,9 +2,7 @@ load ${BASE_TEST_DIR}/helpers.bash -if [[ -z "$NAME" ]]; then - export NAME="$(unique_machine_name)" -fi +use_disposable_machine @test "$DRIVER: create" { run machine create --tls-san foo.bar.tld --tls-san 10.42.42.42 -d $DRIVER $NAME diff --git a/test/integration/core/core-commands.bats b/test/integration/core/core-commands.bats index 43e8bd246c..2362db7f4e 100644 --- a/test/integration/core/core-commands.bats +++ b/test/integration/core/core-commands.bats @@ -2,9 +2,7 @@ load ${BASE_TEST_DIR}/helpers.bash -if [[ -z "$NAME" ]]; then - export NAME="$(shared_machine_name)" -fi +use_shared_machine @test "$DRIVER: machine should not exist" { run machine inspect UNKNOWN diff --git a/test/integration/core/engine-options.bats b/test/integration/core/engine-options.bats index c338dc0755..73153becb4 100644 --- a/test/integration/core/engine-options.bats +++ b/test/integration/core/engine-options.bats @@ -2,9 +2,7 @@ load ${BASE_TEST_DIR}/helpers.bash -if [[ -z "$NAME" ]]; then - export NAME="$(unique_machine_name)" -fi +use_disposable_machine @test "$DRIVER: create with supported engine options" { run machine create -d $DRIVER \ diff --git a/test/integration/core/env_shell.bats b/test/integration/core/env_shell.bats index 1d4dd577f1..b18a4d97de 100644 --- a/test/integration/core/env_shell.bats +++ b/test/integration/core/env_shell.bats @@ -2,9 +2,7 @@ load ${BASE_TEST_DIR}/helpers.bash -if [[ -z "$NAME" ]]; then - export NAME="$(shared_machine_name)" -fi +use_shared_machine @test "$DRIVER: test basic bash / zsh notation" { run machine env $NAME diff --git a/test/integration/core/inspect_format.bats b/test/integration/core/inspect_format.bats index 0e34183ef8..41996de7a3 100644 --- a/test/integration/core/inspect_format.bats +++ b/test/integration/core/inspect_format.bats @@ -2,9 +2,7 @@ load ${BASE_TEST_DIR}/helpers.bash -if [[ -z "$NAME" ]]; then - export NAME="$(shared_machine_name)" -fi +use_shared_machine @test "$DRIVER: inspect format template" { run machine inspect -f '{{.DriverName}}' $NAME diff --git a/test/integration/core/regenerate-certs.bats b/test/integration/core/regenerate-certs.bats index 0bd189f3c7..121bdec325 100644 --- a/test/integration/core/regenerate-certs.bats +++ b/test/integration/core/regenerate-certs.bats @@ -2,9 +2,7 @@ load ${BASE_TEST_DIR}/helpers.bash -if [[ -z "$NAME" ]]; then - export NAME="$(shared_machine_name)" -fi +use_shared_machine @test "$DRIVER: regenerate the certs" { run machine regenerate-certs -f $NAME diff --git a/test/integration/core/scp.bats b/test/integration/core/scp.bats index 8e36430029..6e00c51651 100644 --- a/test/integration/core/scp.bats +++ b/test/integration/core/scp.bats @@ -2,10 +2,8 @@ load ${BASE_TEST_DIR}/helpers.bash -if [[ -z "$NAME" ]]; then - export NAME="$(shared_machine_name)" - export SECOND_MACHINE="$NAME-2" -fi +use_shared_machine +export SECOND_MACHINE="$NAME-2" @test "$DRIVER: test machine scp command from remote to host" { machine ssh $NAME 'echo A file created remotely! >/tmp/foo.txt' diff --git a/test/integration/core/ssh-backends.bats b/test/integration/core/ssh-backends.bats index b4399b3f4d..b1b5f59e8e 100644 --- a/test/integration/core/ssh-backends.bats +++ b/test/integration/core/ssh-backends.bats @@ -2,9 +2,7 @@ load ${BASE_TEST_DIR}/helpers.bash -if [[ -z "$NAME" ]]; then - export NAME="$(shared_machine_name)" -fi +use_shared_machine @test "$DRIVER: test external ssh backend" { run machine ssh $NAME df -h diff --git a/test/integration/helpers.bash b/test/integration/helpers.bash index 1276c70e33..7138ed741f 100644 --- a/test/integration/helpers.bash +++ b/test/integration/helpers.bash @@ -31,15 +31,19 @@ function require_env { fi } -function unique_machine_name { - echo "bats-$DRIVER-test-$(date +%s)" +function use_disposable_machine { + if [[ -z "$NAME" ]]; then + export NAME="bats-$DRIVER-test-$(date +%s)" + fi } -function shared_machine_name { - if [[ $(machine ls -q --filter name=$SHARED_NAME | wc -l) -eq 0 ]]; then - machine create -d $DRIVER $SHARED_NAME &>/dev/null +function use_shared_machine { + if [[ -z "$NAME" ]]; then + export NAME="$SHARED_NAME" + if [[ $(machine ls -q --filter name=$NAME | wc -l) -eq 0 ]]; then + machine create -d $DRIVER $NAME &>/dev/null + fi fi - echo "$SHARED_NAME" } # Make sure these aren't set while tests run (can cause confusing behavior) diff --git a/test/integration/run-bats.sh b/test/integration/run-bats.sh index 97ce41cd20..7496a74240 100755 --- a/test/integration/run-bats.sh +++ b/test/integration/run-bats.sh @@ -45,7 +45,12 @@ function run_bats() { set -e echo - cleanup_machines + + if [[ "$NO_SHARE_MACHINES" == "1" ]]; then + cleanup_machines "ALL" + else + cleanup_machines "NON-SHARED" + fi done } diff --git a/test/integration/virtualbox/bad-create-iso.bats b/test/integration/virtualbox/bad-create-iso.bats index ab633cc6da..4abeacbeb8 100644 --- a/test/integration/virtualbox/bad-create-iso.bats +++ b/test/integration/virtualbox/bad-create-iso.bats @@ -4,9 +4,7 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -if [[ -z "$NAME" ]]; then - export NAME="$(unique_machine_name)" -fi +use_disposable_machine export BAD_URL="http://dev.null:9111/bad.iso" diff --git a/test/integration/virtualbox/certs-checksum.bats b/test/integration/virtualbox/certs-checksum.bats index a9a8a6531f..4e35c4aa87 100644 --- a/test/integration/virtualbox/certs-checksum.bats +++ b/test/integration/virtualbox/certs-checksum.bats @@ -4,9 +4,7 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -if [[ -z "$NAME" ]]; then - export NAME="$(shared_machine_name)" -fi +use_shared_machine @test "$DRIVER: verify that server cert checksum matches local checksum" { # TODO: This test is tightly coupled to VirtualBox right now, but should be diff --git a/test/integration/virtualbox/custom-mem-disk.bats b/test/integration/virtualbox/custom-mem-disk.bats index eb973a3aed..5828b4fc3f 100644 --- a/test/integration/virtualbox/custom-mem-disk.bats +++ b/test/integration/virtualbox/custom-mem-disk.bats @@ -4,9 +4,7 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -if [[ -z "$NAME" ]]; then - export NAME="$(unique_machine_name)" -fi +use_disposable_machine # Default memsize is 1024MB and disksize is 20000MB # These values are defined in drivers/virtualbox/virtualbox.go diff --git a/test/integration/virtualbox/dns.bats b/test/integration/virtualbox/dns.bats index 69107c80e2..7b7afca0f8 100644 --- a/test/integration/virtualbox/dns.bats +++ b/test/integration/virtualbox/dns.bats @@ -4,9 +4,7 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -if [[ -z "$NAME" ]]; then - export NAME="$(unique_machine_name)" -fi +use_disposable_machine @test "$DRIVER: Create a vm with a dns proxy set" { run machine create -d $DRIVER --virtualbox-dns-proxy=true $NAME diff --git a/test/integration/virtualbox/pause-save-start.bats b/test/integration/virtualbox/pause-save-start.bats index 0f865c27e8..2102aefc38 100644 --- a/test/integration/virtualbox/pause-save-start.bats +++ b/test/integration/virtualbox/pause-save-start.bats @@ -4,9 +4,7 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -if [[ -z "$NAME" ]]; then - export NAME="$(shared_machine_name)" -fi +use_shared_machine @test "$DRIVER: VBoxManage pause" { run VBoxManage controlvm $NAME pause diff --git a/test/integration/virtualbox/upgrade.bats b/test/integration/virtualbox/upgrade.bats index 5233b79bc5..dc906b77fe 100644 --- a/test/integration/virtualbox/upgrade.bats +++ b/test/integration/virtualbox/upgrade.bats @@ -4,9 +4,7 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -if [[ -z "$NAME" ]]; then - export NAME="$(unique_machine_name)" -fi +use_disposable_machine export OLD_ISO_URL="https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso" From fd0f002065b9865ec9de1cea34238094a5cddea1 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 9 Dec 2015 15:54:08 +0100 Subject: [PATCH 5/5] Fix test Signed-off-by: David Gageot --- test/integration/core/swarm-options.bats | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/integration/core/swarm-options.bats b/test/integration/core/swarm-options.bats index a87f7f3c4c..03cb0185b7 100644 --- a/test/integration/core/swarm-options.bats +++ b/test/integration/core/swarm-options.bats @@ -1,7 +1,8 @@ #!/usr/bin/env bats load ${BASE_TEST_DIR}/helpers.bash -export TOKEN=$(curl -sS -X POST "https://discovery-stage.hub.docker.com/v1/clusters") + +export TOKEN=$(curl -sS -X POST "https://discovery.hub.docker.com/v1/clusters") @test "create swarm master" { run machine create -d $DRIVER --swarm --swarm-master --swarm-discovery "token://$TOKEN" --swarm-strategy binpack --swarm-opt heartbeat=5s queenbee @@ -21,7 +22,7 @@ export TOKEN=$(curl -sS -X POST "https://discovery-stage.hub.docker.com/v1/clust } @test "ensure heartbeat" { - heartbeat_arg=$(docker $(machine config queenbee) inspect -f '{{index .Args 9}}' swarm-agent-master) + heartbeat_arg=$(docker $(machine config queenbee) inspect -f '{{index .Args}}' swarm-agent-master) echo ${heartbeat_arg} - [[ "$heartbeat_arg" == "--heartbeat=5s" ]] + [[ "$heartbeat_arg" =~ "--heartbeat=5s" ]] }