Cleanup machines only at the end

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot 2015-12-07 15:43:16 +01:00
parent 17b1e571f2
commit a708bf7e6c
16 changed files with 77 additions and 52 deletions

View File

@ -2,6 +2,9 @@
load ${BASE_TEST_DIR}/helpers.bash load ${BASE_TEST_DIR}/helpers.bash
if [[ -z "$NAME" ]]; then
export NAME="$(unique_machine_name)"
fi
@test "$DRIVER: create" { @test "$DRIVER: create" {
run machine create --tls-san foo.bar.tld --tls-san 10.42.42.42 -d $DRIVER $NAME run machine create --tls-san foo.bar.tld --tls-san 10.42.42.42 -d $DRIVER $NAME

View File

@ -2,17 +2,15 @@
load ${BASE_TEST_DIR}/helpers.bash load ${BASE_TEST_DIR}/helpers.bash
if [[ -z "$NAME" ]]; then
export NAME="$(shared_machine_name)"
fi
@test "$DRIVER: machine should not exist" { @test "$DRIVER: machine should not exist" {
run machine inspect $NAME run machine inspect UNKNOWN
echo ${output} echo ${output}
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[[ ${lines[0]} =~ "Host does not exist: \"$NAME\"" ]] [[ ${lines[0]} =~ "Host does not exist: \"UNKNOWN\"" ]]
}
@test "$DRIVER: create" {
run machine create -d $DRIVER $NAME
echo ${output}
[ "$status" -eq 0 ]
} }
@test "$DRIVER: appears with ls" { @test "$DRIVER: appears with ls" {

View File

@ -2,6 +2,10 @@
load ${BASE_TEST_DIR}/helpers.bash load ${BASE_TEST_DIR}/helpers.bash
if [[ -z "$NAME" ]]; then
export NAME="$(unique_machine_name)"
fi
@test "$DRIVER: create with supported engine options" { @test "$DRIVER: create with supported engine options" {
run machine create -d $DRIVER \ run machine create -d $DRIVER \
--engine-label spam=eggs \ --engine-label spam=eggs \

View File

@ -2,10 +2,9 @@
load ${BASE_TEST_DIR}/helpers.bash load ${BASE_TEST_DIR}/helpers.bash
@test "$DRIVER: create" { if [[ -z "$NAME" ]]; then
run machine create -d $DRIVER $NAME export NAME="$(shared_machine_name)"
[ "$status" -eq 0 ] fi
}
@test "$DRIVER: test basic bash / zsh notation" { @test "$DRIVER: test basic bash / zsh notation" {
run machine env $NAME run machine env $NAME

View File

@ -2,10 +2,9 @@
load ${BASE_TEST_DIR}/helpers.bash load ${BASE_TEST_DIR}/helpers.bash
@test "$DRIVER: create" { if [[ -z "$NAME" ]]; then
run machine create -d $DRIVER $NAME export NAME="$(shared_machine_name)"
[ "$status" -eq 0 ] fi
}
@test "$DRIVER: inspect format template" { @test "$DRIVER: inspect format template" {
run machine inspect -f '{{.DriverName}}' $NAME run machine inspect -f '{{.DriverName}}' $NAME

View File

@ -2,9 +2,9 @@
load ${BASE_TEST_DIR}/helpers.bash load ${BASE_TEST_DIR}/helpers.bash
@test "$DRIVER: create" { if [[ -z "$NAME" ]]; then
run machine create -d $DRIVER $NAME export NAME="$(shared_machine_name)"
} fi
@test "$DRIVER: regenerate the certs" { @test "$DRIVER: regenerate the certs" {
run machine regenerate-certs -f $NAME run machine regenerate-certs -f $NAME

View File

@ -2,12 +2,10 @@
load ${BASE_TEST_DIR}/helpers.bash load ${BASE_TEST_DIR}/helpers.bash
if [[ -z "$NAME" ]]; then
export NAME="$(shared_machine_name)"
export SECOND_MACHINE="$NAME-2" export SECOND_MACHINE="$NAME-2"
fi
@test "$DRIVER: create" {
run machine create -d $DRIVER $NAME
[[ ${status} -eq 0 ]]
}
@test "$DRIVER: test machine scp command from remote to host" { @test "$DRIVER: test machine scp command from remote to host" {
machine ssh $NAME 'echo A file created remotely! >/tmp/foo.txt' machine ssh $NAME 'echo A file created remotely! >/tmp/foo.txt'

View File

@ -2,12 +2,9 @@
load ${BASE_TEST_DIR}/helpers.bash load ${BASE_TEST_DIR}/helpers.bash
# Basic smoke test for SSH backends if [[ -z "$NAME" ]]; then
export NAME="$(shared_machine_name)"
@test "$DRIVER: create SSH test box" { fi
run machine create -d $DRIVER $NAME
[[ "$status" -eq 0 ]]
}
@test "$DRIVER: test external ssh backend" { @test "$DRIVER: test external ssh backend" {
run machine ssh $NAME df -h run machine ssh $NAME df -h

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
echo_to_log() { function echo_to_log {
echo "$BATS_TEST_NAME echo "$BATS_TEST_NAME
---------- ----------
$output $output
@ -9,27 +9,38 @@ $output
" >> ${BATS_LOG} " >> ${BATS_LOG}
} }
teardown() { function teardown {
echo_to_log echo_to_log
} }
function errecho () { function errecho {
>&2 echo "$@" >&2 echo "$@"
} }
function only_if_env () { function only_if_env {
if [[ ${!1} != "$2" ]]; then if [[ ${!1} != "$2" ]]; then
errecho "This test requires the $1 environment variable to be set to $2. Skipping..." errecho "This test requires the $1 environment variable to be set to $2. Skipping..."
skip skip
fi fi
} }
function require_env () { function require_env {
if [[ -z ${!1} ]]; then if [[ -z ${!1} ]]; then
errecho "This test requires the $1 environment variable to be set in order to run." errecho "This test requires the $1 environment variable to be set in order to run."
exit 1 exit 1
fi 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) # Make sure these aren't set while tests run (can cause confusing behavior)
unset DOCKER_HOST DOCKER_TLS_VERIFY DOCKER_CERT_DIR unset DOCKER_HOST DOCKER_TLS_VERIFY DOCKER_CERT_DIR

View File

@ -14,9 +14,11 @@ function quiet_run () {
} }
function cleanup_machines() { function cleanup_machines() {
if [[ $(machine ls -q | wc -l) -ne 0 ]]; then for MACHINE_NAME in $(machine ls -q); do
quiet_run machine rm -f $(machine ls -q) if [[ "$MACHINE_NAME" != "$SHARED_NAME" ]] || [[ "$1" == "ALL" ]]; then
quiet_run machine rm -f $MACHINE_NAME
fi fi
done
} }
function cleanup_store() { function cleanup_store() {
@ -26,18 +28,15 @@ function cleanup_store() {
} }
function machine() { function machine() {
export PATH="$MACHINE_ROOT"/bin:$PATH
"$MACHINE_ROOT"/bin/"$MACHINE_BIN_NAME" "$@" "$MACHINE_ROOT"/bin/"$MACHINE_BIN_NAME" "$@"
} }
function run_bats() { function run_bats() {
for bats_file in $(find "$1" -name \*.bats); do 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" 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 set +e
bats "$bats_file" bats "$bats_file"
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
@ -88,13 +87,14 @@ export MACHINE_STORAGE_PATH="/tmp/machine-bats-test-$DRIVER"
export MACHINE_BIN_NAME=docker-machine export MACHINE_BIN_NAME=docker-machine
export BATS_LOG="$MACHINE_ROOT/bats.log" export BATS_LOG="$MACHINE_ROOT/bats.log"
export B2D_LOCATION=~/.docker/machine/cache/boot2docker.iso 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. # This function gets used in the integration tests, so export it.
export -f machine export -f machine
> "$BATS_LOG" > "$BATS_LOG"
cleanup_machines cleanup_machines "ALL"
cleanup_store cleanup_store
if [[ -f "$B2D_LOCATION" ]]; then if [[ -f "$B2D_LOCATION" ]]; then
@ -108,6 +108,7 @@ fi
run_bats "$BATS_FILE" run_bats "$BATS_FILE"
cleanup_machines "ALL"
cleanup_store cleanup_store
exit ${EXIT_STATUS} exit ${EXIT_STATUS}

View File

@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash
only_if_env DRIVER virtualbox only_if_env DRIVER virtualbox
if [[ -z "$NAME" ]]; then
export NAME="$(unique_machine_name)"
fi
export BAD_URL="http://dev.null:9111/bad.iso" export BAD_URL="http://dev.null:9111/bad.iso"
@test "$DRIVER: Should not allow machine creation with bad ISO" { @test "$DRIVER: Should not allow machine creation with bad ISO" {

View File

@ -4,9 +4,9 @@ load ${BASE_TEST_DIR}/helpers.bash
only_if_env DRIVER virtualbox only_if_env DRIVER virtualbox
@test "$DRIVER: create" { if [[ -z "$NAME" ]]; then
run machine create -d $DRIVER $NAME export NAME="$(shared_machine_name)"
} fi
@test "$DRIVER: verify that server cert checksum matches local checksum" { @test "$DRIVER: verify that server cert checksum matches local checksum" {
# TODO: This test is tightly coupled to VirtualBox right now, but should be # TODO: This test is tightly coupled to VirtualBox right now, but should be

View File

@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash
only_if_env DRIVER virtualbox only_if_env DRIVER virtualbox
if [[ -z "$NAME" ]]; then
export NAME="$(unique_machine_name)"
fi
# Default memsize is 1024MB and disksize is 20000MB # Default memsize is 1024MB and disksize is 20000MB
# These values are defined in drivers/virtualbox/virtualbox.go # These values are defined in drivers/virtualbox/virtualbox.go
export DEFAULT_MEMSIZE=1024 export DEFAULT_MEMSIZE=1024

View File

@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash
only_if_env DRIVER virtualbox 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" { @test "$DRIVER: Create a vm with a dns proxy set" {
run machine create -d $DRIVER --virtualbox-dns-proxy=true $NAME run machine create -d $DRIVER --virtualbox-dns-proxy=true $NAME
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]

View File

@ -4,10 +4,9 @@ load ${BASE_TEST_DIR}/helpers.bash
only_if_env DRIVER virtualbox only_if_env DRIVER virtualbox
@test "$DRIVER: create" { if [[ -z "$NAME" ]]; then
run machine create -d $DRIVER $NAME export NAME="$(shared_machine_name)"
[ "$status" -eq 0 ] fi
}
@test "$DRIVER: VBoxManage pause" { @test "$DRIVER: VBoxManage pause" {
run VBoxManage controlvm $NAME pause run VBoxManage controlvm $NAME pause

View File

@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash
only_if_env DRIVER virtualbox 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" export OLD_ISO_URL="https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso"
@test "$DRIVER: create for upgrade" { @test "$DRIVER: create for upgrade" {