From 3071da0673c53f2f3b730a5efd262e969b6df5ca Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 7 Dec 2015 17:13:13 +0100 Subject: [PATCH] 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 8e32080c..0e91d784 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 43e8bd24..2362db7f 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 c338dc07..73153bec 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 1d4dd577..b18a4d97 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 0e34183e..41996de7 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 0bd189f3..121bdec3 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 8e364300..6e00c516 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 b4399b3f..b1b5f59e 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 1276c70e..7138ed74 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 97ce41cd..7496a742 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 ab633cc6..4abeacbe 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 a9a8a653..4e35c4aa 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 eb973a3a..5828b4fc 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 69107c80..7b7afca0 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 0f865c27..2102aefc 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 5233b79b..dc906b77 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"