2020-05-19 18:00:00 +00:00
|
|
|
|
#!/usr/bin/env bash
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
set -eEuo pipefail
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
|
|
|
|
# DEBUG=1 enables set -x for this script so echos every command run
|
|
|
|
|
DEBUG=${DEBUG:-}
|
|
|
|
|
|
2020-05-19 18:00:00 +00:00
|
|
|
|
# ENVOY_VERSION to run each test against
|
2020-10-22 18:26:51 +00:00
|
|
|
|
ENVOY_VERSION=${ENVOY_VERSION:-"1.14.5"}
|
2020-05-19 18:00:00 +00:00
|
|
|
|
export ENVOY_VERSION
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
|
|
|
|
if [ ! -z "$DEBUG" ] ; then
|
|
|
|
|
set -x
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
source helpers.bash
|
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
function command_error {
|
2020-01-24 15:04:58 +00:00
|
|
|
|
echo "ERR: command exited with status $1" 1>&2
|
|
|
|
|
echo " command: $2" 1>&2
|
|
|
|
|
echo " line: $3" 1>&2
|
|
|
|
|
echo " function: $4" 1>&2
|
|
|
|
|
echo " called at: $5" 1>&2
|
2019-07-24 21:01:42 +00:00
|
|
|
|
# printf '%s\n' "${FUNCNAME[@]}"
|
|
|
|
|
# printf '%s\n' "${BASH_SOURCE[@]}"
|
|
|
|
|
# printf '%s\n' "${BASH_LINENO[@]}"
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 14:26:05 +00:00
|
|
|
|
trap 'command_error $? "${BASH_COMMAND}" "${LINENO}" "${FUNCNAME[0]:-main}" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}"' ERR
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
function init_workdir {
|
|
|
|
|
local DC="$1"
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
if test -z "$DC"
|
|
|
|
|
then
|
|
|
|
|
DC=primary
|
|
|
|
|
fi
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
# Note, we use explicit set of dirs so we don't delete .gitignore. Also,
|
|
|
|
|
# don't wipe logs between runs as they are already split and we need them to
|
|
|
|
|
# upload as artifacts later.
|
|
|
|
|
rm -rf workdir/${DC}
|
2020-01-24 15:04:58 +00:00
|
|
|
|
mkdir -p workdir/${DC}/{consul,envoy,bats,statsd,data}
|
2019-07-24 21:01:42 +00:00
|
|
|
|
|
|
|
|
|
# Reload consul config from defaults
|
|
|
|
|
cp consul-base-cfg/* workdir/${DC}/consul/
|
|
|
|
|
|
|
|
|
|
# Add any overrides if there are any (no op if not)
|
2019-08-02 03:03:34 +00:00
|
|
|
|
find ${CASE_DIR} -maxdepth 1 -name '*.hcl' -type f -exec cp -f {} workdir/${DC}/consul \;
|
2019-07-24 21:01:42 +00:00
|
|
|
|
|
|
|
|
|
# Copy all the test files
|
2019-08-02 03:03:34 +00:00
|
|
|
|
find ${CASE_DIR} -maxdepth 1 -name '*.bats' -type f -exec cp -f {} workdir/${DC}/bats \;
|
2019-07-24 21:01:42 +00:00
|
|
|
|
# Copy DC specific bats
|
|
|
|
|
cp helpers.bash workdir/${DC}/bats
|
|
|
|
|
|
|
|
|
|
# Add any DC overrides
|
|
|
|
|
if test -d "${CASE_DIR}/${DC}"
|
|
|
|
|
then
|
|
|
|
|
find ${CASE_DIR}/${DC} -type f -name '*.hcl' -exec cp -f {} workdir/${DC}/consul \;
|
|
|
|
|
find ${CASE_DIR}/${DC} -type f -name '*.bats' -exec cp -f {} workdir/${DC}/bats \;
|
|
|
|
|
fi
|
2020-11-11 23:31:40 +00:00
|
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
|
if test -d "${CASE_DIR}/data"
|
|
|
|
|
then
|
|
|
|
|
cp -r ${CASE_DIR}/data/* workdir/${DC}/data
|
|
|
|
|
fi
|
2020-11-11 23:31:40 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function start_consul {
|
|
|
|
|
local DC=${1:-primary}
|
|
|
|
|
|
|
|
|
|
# Start consul now as setup script needs it up
|
|
|
|
|
docker-compose rm -s -v -f consul-${DC} || true
|
|
|
|
|
docker-compose up -d consul-${DC}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function pre_service_setup {
|
|
|
|
|
local DC=${1:-primary}
|
|
|
|
|
|
|
|
|
|
# Run test case setup (e.g. generating Envoy bootstrap, starting containers)
|
2020-05-19 18:00:00 +00:00
|
|
|
|
if [ -f "${CASE_DIR}/${DC}/setup.sh" ]
|
2019-07-24 21:01:42 +00:00
|
|
|
|
then
|
2020-05-19 18:00:00 +00:00
|
|
|
|
source ${CASE_DIR}/${DC}/setup.sh
|
2019-07-24 21:01:42 +00:00
|
|
|
|
else
|
2020-05-19 18:00:00 +00:00
|
|
|
|
source ${CASE_DIR}/setup.sh
|
2019-07-24 21:01:42 +00:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function start_services {
|
|
|
|
|
# Push the state to the shared docker volume (note this is because CircleCI
|
|
|
|
|
# can't use shared volumes)
|
|
|
|
|
docker cp workdir/. envoy_workdir_1:/workdir
|
2020-01-24 15:04:58 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
# Start containers required
|
|
|
|
|
if [ ! -z "$REQUIRED_SERVICES" ] ; then
|
|
|
|
|
docker-compose rm -s -v -f $REQUIRED_SERVICES || true
|
|
|
|
|
docker-compose up --build -d $REQUIRED_SERVICES
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function verify {
|
|
|
|
|
local DC=$1
|
2020-05-19 18:00:00 +00:00
|
|
|
|
if test -z "$DC"; then
|
2019-07-24 21:01:42 +00:00
|
|
|
|
DC=primary
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Execute tests
|
|
|
|
|
res=0
|
|
|
|
|
|
|
|
|
|
# Nuke any previous case's verify container.
|
|
|
|
|
docker-compose rm -s -v -f verify-${DC} || true
|
|
|
|
|
|
|
|
|
|
if docker-compose up --abort-on-container-exit --exit-code-from verify-${DC} verify-${DC} ; then
|
|
|
|
|
echogreen "✓ PASS"
|
|
|
|
|
else
|
|
|
|
|
echored "⨯ FAIL"
|
|
|
|
|
res=1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return $res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function capture_logs {
|
2020-05-19 18:00:00 +00:00
|
|
|
|
echo "Capturing Logs"
|
2019-07-24 21:01:42 +00:00
|
|
|
|
mkdir -p "$LOG_DIR"
|
|
|
|
|
services="$REQUIRED_SERVICES consul-primary"
|
|
|
|
|
if is_set $REQUIRE_SECONDARY
|
|
|
|
|
then
|
|
|
|
|
services="$services consul-secondary"
|
|
|
|
|
fi
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2020-05-19 18:00:00 +00:00
|
|
|
|
if [ -f "${CASE_DIR}/capture.sh" ]
|
2019-07-24 21:01:42 +00:00
|
|
|
|
then
|
2020-05-19 18:00:00 +00:00
|
|
|
|
echo "Executing ${CASE_DIR}/capture.sh"
|
|
|
|
|
source ${CASE_DIR}/capture.sh || true
|
2019-07-24 21:01:42 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for cont in $services
|
|
|
|
|
do
|
|
|
|
|
echo "Capturing log for $cont"
|
|
|
|
|
docker-compose logs --no-color "$cont" 2>&1 > "${LOG_DIR}/${cont}.log"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function stop_services {
|
|
|
|
|
# Teardown
|
2020-05-19 18:00:00 +00:00
|
|
|
|
if [ -f "${CASE_DIR}/teardown.sh" ] ; then
|
|
|
|
|
source "${CASE_DIR}/teardown.sh"
|
2019-07-24 21:01:42 +00:00
|
|
|
|
fi
|
|
|
|
|
docker-compose rm -s -v -f $REQUIRED_SERVICES || true
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-19 18:00:00 +00:00
|
|
|
|
function init_vars {
|
2019-07-24 21:01:42 +00:00
|
|
|
|
source "defaults.sh"
|
2020-05-19 18:00:00 +00:00
|
|
|
|
if [ -f "${CASE_DIR}/vars.sh" ] ; then
|
|
|
|
|
source "${CASE_DIR}/vars.sh"
|
2019-07-24 21:01:42 +00:00
|
|
|
|
fi
|
|
|
|
|
}
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2020-03-09 20:59:02 +00:00
|
|
|
|
function global_setup {
|
2020-05-19 18:00:00 +00:00
|
|
|
|
if [ -f "${CASE_DIR}/global-setup.sh" ] ; then
|
|
|
|
|
source "${CASE_DIR}/global-setup.sh"
|
2020-03-09 20:59:02 +00:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-19 18:00:00 +00:00
|
|
|
|
function run_tests {
|
|
|
|
|
CASE_DIR="${CASE_DIR?CASE_DIR must be set to the path of the test case}"
|
|
|
|
|
CASE_NAME=$( basename $CASE_DIR | cut -c6- )
|
|
|
|
|
export CASE_NAME
|
|
|
|
|
|
|
|
|
|
export LOG_DIR="workdir/logs/${CASE_DIR}/${ENVOY_VERSION}"
|
|
|
|
|
|
|
|
|
|
init_vars
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
# Initialize the workdir
|
|
|
|
|
init_workdir primary
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
if is_set $REQUIRE_SECONDARY
|
|
|
|
|
then
|
|
|
|
|
init_workdir secondary
|
|
|
|
|
fi
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2020-03-09 20:59:02 +00:00
|
|
|
|
global_setup
|
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
# Wipe state
|
|
|
|
|
docker-compose up wipe-volumes
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
# Push the state to the shared docker volume (note this is because CircleCI
|
|
|
|
|
# can't use shared volumes)
|
|
|
|
|
docker cp workdir/. envoy_workdir_1:/workdir
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
start_consul primary
|
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
capture_logs
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2019-07-24 21:01:42 +00:00
|
|
|
|
if is_set $REQUIRE_SECONDARY
|
|
|
|
|
then
|
|
|
|
|
start_consul secondary
|
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
capture_logs
|
|
|
|
|
return 1
|
2019-04-29 16:27:57 +00:00
|
|
|
|
fi
|
2019-07-24 21:01:42 +00:00
|
|
|
|
fi
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
|
echo "Setting up the primary datacenter"
|
2019-07-24 21:01:42 +00:00
|
|
|
|
pre_service_setup primary
|
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
|
then
|
2020-01-24 15:04:58 +00:00
|
|
|
|
echo "Setting up the primary datacenter failed"
|
2019-07-24 21:01:42 +00:00
|
|
|
|
capture_logs
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if is_set $REQUIRE_SECONDARY
|
|
|
|
|
then
|
2020-01-24 15:04:58 +00:00
|
|
|
|
echo "Setting up the secondary datacenter"
|
2019-07-24 21:01:42 +00:00
|
|
|
|
pre_service_setup secondary
|
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
|
then
|
2020-01-24 15:04:58 +00:00
|
|
|
|
echo "Setting up the secondary datacenter failed"
|
2019-07-24 21:01:42 +00:00
|
|
|
|
capture_logs
|
|
|
|
|
return 1
|
2019-04-29 16:27:57 +00:00
|
|
|
|
fi
|
2019-07-24 21:01:42 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
|
echo "Starting services"
|
2019-07-24 21:01:42 +00:00
|
|
|
|
start_services
|
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
capture_logs
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Run the verify container and report on the output
|
|
|
|
|
verify primary
|
|
|
|
|
TESTRESULT=$?
|
|
|
|
|
|
|
|
|
|
if is_set $REQUIRE_SECONDARY && test "$TESTRESULT" -eq 0
|
|
|
|
|
then
|
|
|
|
|
verify secondary
|
|
|
|
|
SECONDARYRESULT=$?
|
|
|
|
|
|
|
|
|
|
if [ "$SECONDARYRESULT" -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
TESTRESULT=$SECONDARYRESULT
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "$TESTRESULT" -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
capture_logs
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
stop_services primary
|
|
|
|
|
|
|
|
|
|
if is_set $REQUIRE_SECONDARY
|
|
|
|
|
then
|
|
|
|
|
stop_services secondary
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $TESTRESULT
|
|
|
|
|
}
|
2019-05-02 11:53:06 +00:00
|
|
|
|
|
2020-05-19 18:00:00 +00:00
|
|
|
|
function suite_setup {
|
|
|
|
|
# Set a log dir to prevent docker-compose warning about unset var
|
|
|
|
|
export LOG_DIR="workdir/logs/"
|
|
|
|
|
# Cleanup from any previous unclean runs.
|
|
|
|
|
docker-compose down --volumes --timeout 0 --remove-orphans
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2020-05-19 18:00:00 +00:00
|
|
|
|
# Start the volume container
|
|
|
|
|
docker-compose up -d workdir
|
|
|
|
|
}
|
2019-07-24 21:01:42 +00:00
|
|
|
|
|
2020-05-19 18:00:00 +00:00
|
|
|
|
function suite_teardown {
|
|
|
|
|
# Set a log dir to prevent docker-compose warning about unset var
|
|
|
|
|
export LOG_DIR="workdir/logs/"
|
2019-07-24 21:01:42 +00:00
|
|
|
|
|
2020-05-19 18:00:00 +00:00
|
|
|
|
docker-compose down --volumes --timeout 0 --remove-orphans
|
|
|
|
|
}
|
2019-05-02 11:53:06 +00:00
|
|
|
|
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
2020-05-19 18:00:00 +00:00
|
|
|
|
case "${1-}" in
|
|
|
|
|
"")
|
|
|
|
|
echo "command required"
|
|
|
|
|
exit 1 ;;
|
|
|
|
|
*)
|
|
|
|
|
"$@" ;;
|
|
|
|
|
esac
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|