Provision and destroy test VMs in the background.
This should help speed-up the build by provisioning test VMs while we run unit tests, and destroying them while we generate coverage reports.
This commit is contained in:
1 parent
67dbdd377c
commit
dd935b7e9e
7 files changed
+141
-48
No files matched your search
@@ -369,14 +369,10 @@ integration-tests: all testrunner
|
|||||||
# PLAYBOOK="<filename>" \
|
# PLAYBOOK="<filename>" \
|
||||||
# RUNNER_ARGS="<...>" \
|
# RUNNER_ARGS="<...>" \
|
||||||
# TESTS="<...>" \ # Can be set to only run one or a few tests instead of the full test suite.
|
# TESTS="<...>" \ # Can be set to only run one or a few tests instead of the full test suite.
|
||||||
# SKIP_CREATE=1 \ # Skip the provisioning phase before running tests.
|
|
||||||
# SKIP_CONFIG=1 \ # Skip the configuration phase before running tests.
|
|
||||||
# SKIP_DESTROY=1 \ # Skip the destroy phase after running tests.
|
|
||||||
# ONLY_DESTROY=1 \ # Destroy the test cluster (and do not do anything else, like starting the test cluster, configuring it, or running tests).
|
|
||||||
# DOCKER_VERSION=<...> \
|
# DOCKER_VERSION=<...> \
|
||||||
# KUBERNETES_VERSION=<...> \
|
# KUBERNETES_VERSION=<...> \
|
||||||
# KUBERNETES_CNI_VERSION=<...> \
|
# KUBERNETES_CNI_VERSION=<...> \
|
||||||
# <...> # See also run-integration-test.sh for all variables.
|
# <...> # See also run-integration-test.sh for all variables and individual functions.
|
||||||
# integration-tests
|
# integration-tests
|
||||||
#
|
#
|
||||||
RUNNER_ARGS="-parallel" ./test/run-integration-tests.sh
|
RUNNER_ARGS="-parallel" ./test/run-integration-tests.sh
|
||||||
+17
-2
@@ -3,7 +3,22 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
source "$STATE"
|
source "$STATE"
|
||||||
|
source "$(dirname "$0")/wait_for.sh"
|
||||||
|
|
||||||
if [ -n "$TEST_AND_PUBLISH" ] ; then
|
if [ -n "$TEST_AND_PUBLISH" ]; then
|
||||||
cd $SRCDIR/test
|
[ -n "$SECRET_KEY" ] || {
|
||||||
|
echo "Cannot run smoke tests: no secret key"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Provisioning from image typically take 90 seconds,
|
||||||
|
# but if we are creating a GCP image, it can take more than 10 minutes:
|
||||||
|
wait_for 900 "$TEST_VMS_PROV_AND_CONF_LOCK_FILE"
|
||||||
|
|
||||||
|
# Upload built binaries to testing VMs:
|
||||||
|
rm -f "$TEST_VMS_READY_LOCK_FILE"
|
||||||
|
cd "$SRCDIR/test" # Ensures we generate Terraform state files in the right folder, for later use by integration tests.
|
||||||
|
./run-integration-tests.sh setup >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1
|
||||||
|
touch "$TEST_VMS_READY_LOCK_FILE"
|
||||||
|
echo "Test VMs now ready. $(date)." >>"$TEST_VMS_SETUP_OUTPUT_FILE"
|
||||||
fi
|
fi
|
||||||
+7
-13
@@ -3,27 +3,21 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
source "$STATE"
|
source "$STATE"
|
||||||
|
source "$(dirname "$0")/wait_for.sh"
|
||||||
|
|
||||||
if [ -n "$TEST_AND_PUBLISH" ]; then
|
if [ -n "$TEST_AND_PUBLISH" ]; then
|
||||||
[ -n "$SECRET_KEY" ] || {
|
[ -n "$SECRET_KEY" ] || {
|
||||||
echo "Cannot run smoke tests: no secret key"
|
echo "Cannot run smoke tests: no secret key"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
# Install Terraform and Ansible:
|
|
||||||
curl -fsS https://releases.hashicorp.com/terraform/0.8.5/terraform_0.8.5_linux_amd64.zip | gunzip >terraform && chmod +x terraform && sudo mv terraform /usr/bin
|
# Provisioning from image typically take 90 seconds,
|
||||||
sudo apt-get update || true
|
# but if we are creating a GCP image, it can take more than 10 minutes:
|
||||||
sudo apt-get install -qq -y python-pip python-dev libffi-dev libssl-dev && pip install --user -U cffi && pip install --user ansible
|
wait_for 900 "$TEST_VMS_READY_LOCK_FILE"
|
||||||
export PATH="$PATH:$HOME/.local/bin"
|
|
||||||
|
|
||||||
# Run integration tests:
|
# Run integration tests:
|
||||||
export COVERAGE=true
|
export COVERAGE=true
|
||||||
export WEAVE_NET_SANITY_CHECKS_FILES="$CIRCLE_ARTIFACTS/weave_net_sanity_check_*.log"
|
export WEAVE_NET_SANITY_CHECKS_FILES="$CIRCLE_ARTIFACTS/weave_net_sanity_check_*.log"
|
||||||
export NAME="test-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX"
|
cd "$SRCDIR/test" # Ensures we generate code coverage files in the right folder, and use the Terraform state of previously provisionned VMs.
|
||||||
export DISK_NAME_PREFIX="test-$CIRCLE_BUILD_NUM-0"
|
./run-integration-tests.sh test
|
||||||
export USE_IMAGE=1
|
|
||||||
# Only attempt to create GCP image in first container, wait for it to be created otherwise:
|
|
||||||
[ "$CIRCLE_NODE_INDEX" == "0" ] && export CREATE_IMAGE=1
|
|
||||||
|
|
||||||
cd "$SRCDIR/test" # Ensures we generate code coverage files in the right folder.
|
|
||||||
./run-integration-tests.sh
|
|
||||||
fi
|
fi
|
||||||
Executable
+35
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
source "$STATE"
|
||||||
|
|
||||||
|
function install_terraform() {
|
||||||
|
curl -fsS https://releases.hashicorp.com/terraform/0.8.5/terraform_0.8.5_linux_amd64.zip | gunzip >terraform && chmod +x terraform && sudo mv terraform /usr/bin
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_ansible() {
|
||||||
|
sudo apt-get update || true
|
||||||
|
sudo apt-get install -qq -y python-pip python-dev libffi-dev libssl-dev && pip install --user -U cffi && pip install --user ansible
|
||||||
|
export PATH="$PATH:$HOME/.local/bin"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -n "$TEST_AND_PUBLISH" ]; then
|
||||||
|
[ -n "$SECRET_KEY" ] || {
|
||||||
|
echo "Cannot run smoke tests: no secret key"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
install_terraform >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1
|
||||||
|
install_ansible >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1
|
||||||
|
|
||||||
|
# Only attempt to create GCP image in first container, wait for it to be created otherwise:
|
||||||
|
[ "$CIRCLE_NODE_INDEX" == "0" ] && export CREATE_IMAGE=1
|
||||||
|
|
||||||
|
# Provision and configure testing VMs:
|
||||||
|
rm -f "$TEST_VMS_PROV_AND_CONF_LOCK_FILE"
|
||||||
|
cd "$SRCDIR/test" # Ensures we generate Terraform state files in the right folder, for later use by integration tests.
|
||||||
|
./run-integration-tests.sh configure >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1
|
||||||
|
touch "$TEST_VMS_PROV_AND_CONF_LOCK_FILE"
|
||||||
|
echo "Test VMs now provisioned and configured. $(date)." >>"$TEST_VMS_SETUP_OUTPUT_FILE"
|
||||||
|
fi
|
||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
wait_for() {
|
||||||
|
local timeout=$1
|
||||||
|
local lock_file=$2
|
||||||
|
for i in $(seq 1 "$timeout"); do
|
||||||
|
[ -f "$lock_file" ] && echo "[$i seconds]: $lock_file found." && return
|
||||||
|
if ! ((i % 10)); then echo "[$i seconds]: Waiting for $lock_file to be created..."; fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo "Timed out waiting for test VMs to be ready. See details in: $TEST_VMS_SETUP_OUTPUT_FILE" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
+17
@@ -14,17 +14,30 @@ machine:
|
|||||||
PATH: $PATH:$HOME/.local/bin
|
PATH: $PATH:$HOME/.local/bin
|
||||||
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
|
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
|
||||||
STATE: /home/ubuntu/state.env
|
STATE: /home/ubuntu/state.env
|
||||||
|
# Base name of VMs for integration tests:
|
||||||
|
NAME: test-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX
|
||||||
|
TEST_VMS_SETUP_OUTPUT_FILE: $CIRCLE_ARTIFACTS/test_vms_setup_output.txt
|
||||||
|
TEST_VMS_PROV_AND_CONF_LOCK_FILE: $CIRCLE_ARTIFACTS/test_vms_provisioned_and_configured.txt
|
||||||
|
TEST_VMS_READY_LOCK_FILE: $CIRCLE_ARTIFACTS/test_vms_ready.txt
|
||||||
|
# Google Cloud Platorm images for integration tests:
|
||||||
|
USE_IMAGE: 1
|
||||||
|
DISK_NAME_PREFIX: test-$CIRCLE_BUILD_NUM-0
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
cache_directories:
|
cache_directories:
|
||||||
- "~/docker"
|
- "~/docker"
|
||||||
post:
|
post:
|
||||||
|
# Provision & configure testing VMs:
|
||||||
|
- "while [ ! -d $SRCDIR ]; do sleep 1; done; $SRCDIR/bin/provision_test_vms.sh":
|
||||||
|
parallel: true
|
||||||
|
background: true
|
||||||
- bin/circle-dependencies-post
|
- bin/circle-dependencies-post
|
||||||
|
|
||||||
test:
|
test:
|
||||||
pre:
|
pre:
|
||||||
- "$SRCDIR/bin/circle-test-pre":
|
- "$SRCDIR/bin/circle-test-pre":
|
||||||
parallel: true
|
parallel: true
|
||||||
|
background: true
|
||||||
override:
|
override:
|
||||||
- "$SRCDIR/bin/circle-test-unit":
|
- "$SRCDIR/bin/circle-test-unit":
|
||||||
parallel: true
|
parallel: true
|
||||||
@@ -37,6 +50,10 @@ test:
|
|||||||
|
|
||||||
teardown:
|
teardown:
|
||||||
pre:
|
pre:
|
||||||
|
# Destroy testing VMs:
|
||||||
|
- "cd $SRCDIR/test && ./run-integration-tests.sh destroy":
|
||||||
|
parallel: true
|
||||||
|
background: true
|
||||||
- "$SRCDIR/bin/circle-teardown-pre":
|
- "$SRCDIR/bin/circle-teardown-pre":
|
||||||
parallel: true
|
parallel: true
|
||||||
|
|
||||||
|
|||||||
@@ -194,6 +194,11 @@ function update_remote_etc_hosts() {
|
|||||||
for pid in $pids; do wait "$pid"; done
|
for pid in $pids; do wait "$pid"; done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2155
|
||||||
|
function set_hosts() {
|
||||||
|
export HOSTS="$(echo "$ssh_hosts" | tr '\n' ' ')"
|
||||||
|
}
|
||||||
|
|
||||||
function provision_remotely() {
|
function provision_remotely() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
on)
|
on)
|
||||||
@@ -241,7 +246,7 @@ function provision() {
|
|||||||
;;
|
;;
|
||||||
'gcp')
|
'gcp')
|
||||||
gcp_on
|
gcp_on
|
||||||
[[ "$USE_IMAGE" == 1 ]] && use_or_create_image
|
[[ "$1" == "on" ]] && [[ "$USE_IMAGE" == 1 ]] && use_or_create_image
|
||||||
provision_remotely "$1" "$2"
|
provision_remotely "$1" "$2"
|
||||||
;;
|
;;
|
||||||
'vagrant')
|
'vagrant')
|
||||||
@@ -252,7 +257,7 @@ function provision() {
|
|||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
[ "$1" == "on" ] && set_hosts
|
||||||
echo
|
echo
|
||||||
greenly echo "> Provisioning took $(date -u -d @$(($(date +%s) - begin_prov)) +"%T")."
|
greenly echo "> Provisioning took $(date -u -d @$(($(date +%s) - begin_prov)) +"%T")."
|
||||||
}
|
}
|
||||||
@@ -289,9 +294,6 @@ function configure() {
|
|||||||
|
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
function run_tests() {
|
function run_tests() {
|
||||||
export HOSTS="$(echo "$3" | tr '\n' ' ')"
|
|
||||||
shift 3 # Drop the first 3 arguments, the remainder being, optionally, the list of tests to run.
|
|
||||||
"$DIR/setup.sh"
|
|
||||||
echo
|
echo
|
||||||
greenly echo "> Running tests..."
|
greenly echo "> Running tests..."
|
||||||
local begin_tests=$(date +%s)
|
local begin_tests=$(date +%s)
|
||||||
@@ -303,36 +305,57 @@ function run_tests() {
|
|||||||
return $status
|
return $status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function end() {
|
||||||
|
echo
|
||||||
|
echo "> Build took $(date -u -d @$(($(date +%s) - begin)) +"%T")."
|
||||||
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
begin=$(date +%s)
|
begin=$(date +%s)
|
||||||
|
trap end EXIT
|
||||||
|
|
||||||
print_vars
|
print_vars
|
||||||
verify_dependencies
|
verify_dependencies
|
||||||
|
|
||||||
if [ -z "$ONLY_DESTROY" ]; then
|
case "$1" in
|
||||||
provision on "$PROVIDER"
|
"") # Provision, configure, run tests, and destroy test environment:
|
||||||
if [ $? -ne 0 ]; then
|
provision on "$PROVIDER"
|
||||||
echo >&2 "> Failed to provision test host(s)."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$SKIP_CONFIG" ]; then
|
|
||||||
configure "$ssh_user" "$ssh_hosts" "${ssh_port:-22}" "$ssh_id_file"
|
configure "$ssh_user" "$ssh_hosts" "${ssh_port:-22}" "$ssh_id_file"
|
||||||
if [ $? -ne 0 ]; then
|
"$DIR/setup.sh"
|
||||||
echo >&2 "Failed to configure test host(s)."
|
run_tests "$TESTS"
|
||||||
exit 1
|
status=$?
|
||||||
fi
|
provision off "$PROVIDER"
|
||||||
fi
|
exit $status
|
||||||
|
;;
|
||||||
|
|
||||||
run_tests "$ssh_user" "$ssh_id_file" "$ssh_hosts" "$TESTS"
|
provision)
|
||||||
status=$?
|
provision on "$PROVIDER"
|
||||||
fi
|
;;
|
||||||
if [ -z "$SKIP_DESTROY" ]; then
|
|
||||||
provision off "$PROVIDER"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
configure)
|
||||||
greenly echo "> Build took $(date -u -d @$(($(date +%s) - begin)) +"%T")."
|
provision on "$PROVIDER" # Vagrant and Terraform do not provision twice if VMs are already provisioned, so we just set environment variables.
|
||||||
exit $status
|
configure "$ssh_user" "$ssh_hosts" "${ssh_port:-22}" "$ssh_id_file"
|
||||||
|
;;
|
||||||
|
|
||||||
|
setup)
|
||||||
|
provision on "$PROVIDER" # Vagrant and Terraform do not provision twice if VMs are already provisioned, so we just set environment variables.
|
||||||
|
"$DIR/setup.sh"
|
||||||
|
;;
|
||||||
|
|
||||||
|
test)
|
||||||
|
provision on "$PROVIDER" # Vagrant and Terraform do not provision twice if VMs are already provisioned, so we just set environment variables.
|
||||||
|
run_tests "$TESTS"
|
||||||
|
;;
|
||||||
|
|
||||||
|
destroy)
|
||||||
|
provision off "$PROVIDER"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Unknown command: $1" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
main "$@"
|
||||||
Reference in new issue
Block a user