2017-08-18 08:52:31 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-01-12 03:28:49 +00:00
|
|
|
# Script intended for running Deckhand functional tests via gabbi. Requires
|
|
|
|
# Docker CE (at least) to run.
|
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
set -xe
|
|
|
|
|
2017-12-12 19:56:15 +00:00
|
|
|
# Meant for capturing output of Deckhand image. This requires that logging
|
|
|
|
# in the image be set up to pipe everything out to stdout/stderr.
|
|
|
|
STDOUT=$(mktemp)
|
2018-04-14 17:09:23 -04:00
|
|
|
|
2017-12-12 19:56:15 +00:00
|
|
|
# NOTE(fmontei): `DECKHAND_IMAGE` should only be specified if the desire is to
|
|
|
|
# run Deckhand functional tests against a specific Deckhand image, which is
|
|
|
|
# useful for CICD (as validating the image is vital). However, if the
|
|
|
|
# `DECKHAND_IMAGE` is not specified, then this implies that the most current
|
|
|
|
# version of the code should be used, which is in the repo itself.
|
|
|
|
DECKHAND_IMAGE=${DECKHAND_IMAGE:-}
|
2018-04-14 17:09:23 -04:00
|
|
|
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2017-12-12 19:56:15 +00:00
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
source $ROOTDIR/common-tests.sh
|
2017-08-18 08:52:31 -05:00
|
|
|
|
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
function cleanup_deckhand {
|
|
|
|
set +e
|
|
|
|
|
|
|
|
if [ -n "$POSTGRES_ID" ]; then
|
|
|
|
sudo docker stop $POSTGRES_ID
|
|
|
|
fi
|
2018-04-18 19:48:00 -04:00
|
|
|
|
2017-12-12 19:56:15 +00:00
|
|
|
if [ -n "$DECKHAND_ID" ]; then
|
|
|
|
sudo docker stop $DECKHAND_ID
|
|
|
|
fi
|
2018-04-18 19:48:00 -04:00
|
|
|
|
|
|
|
rm -rf $CONF_DIR
|
2018-01-09 05:44:36 +00:00
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
# Kill all processes and child processes (for example, if workers > 1)
|
|
|
|
# if using uwsgi only.
|
|
|
|
PGID=$(ps -o comm -o pgid | grep uwsgi | grep -o [0-9]* | head -n 1)
|
|
|
|
if [ -n "$PGID" ]; then
|
2018-01-09 05:44:36 +00:00
|
|
|
setsid kill -- -$PGID
|
|
|
|
fi
|
2017-12-12 19:56:15 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 05:44:36 +00:00
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
trap cleanup_deckhand EXIT
|
2018-01-09 03:16:35 +00:00
|
|
|
|
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
function deploy_deckhand {
|
|
|
|
gen_config "http://localhost:9000"
|
|
|
|
gen_paste true
|
|
|
|
gen_policy
|
2017-08-18 08:52:31 -05:00
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
if [ -z "$DECKHAND_IMAGE" ]; then
|
2018-04-07 14:53:48 -04:00
|
|
|
log_section "Running Deckhand via uwsgi."
|
2018-04-14 17:09:23 -04:00
|
|
|
|
|
|
|
alembic upgrade head
|
|
|
|
# NOTE(fmontei): Deckhand's database is not configured to work with
|
|
|
|
# multiprocessing. Currently there is a data race on acquiring shared
|
|
|
|
# SQLAlchemy engine pooled connection strings when workers > 1. As a
|
|
|
|
# workaround, we use multiple threads but only 1 worker. For more
|
|
|
|
# information, see: https://github.com/att-comdev/deckhand/issues/20
|
|
|
|
export DECKHAND_API_WORKERS=1
|
|
|
|
export DECKHAND_API_THREADS=4
|
|
|
|
source $ROOTDIR/../entrypoint.sh server &
|
|
|
|
else
|
2018-04-07 14:53:48 -04:00
|
|
|
log_section "Running Deckhand via Docker."
|
2018-04-14 17:09:23 -04:00
|
|
|
sudo docker run \
|
|
|
|
--rm \
|
|
|
|
--net=host \
|
|
|
|
-v $CONF_DIR:/etc/deckhand \
|
|
|
|
$DECKHAND_IMAGE alembic upgrade head &> $STDOUT &
|
|
|
|
sudo docker run \
|
|
|
|
--rm \
|
|
|
|
--net=host \
|
|
|
|
-p 9000:9000 \
|
|
|
|
-v $CONF_DIR:/etc/deckhand \
|
|
|
|
$DECKHAND_IMAGE server &> $STDOUT &
|
|
|
|
fi
|
2017-09-21 18:22:03 +01:00
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
# Give the server a chance to come up. Better to poll a health check.
|
|
|
|
sleep 5
|
2017-09-21 18:22:03 +01:00
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
DECKHAND_ID=$(sudo docker ps | grep deckhand | awk '{print $1}')
|
|
|
|
echo $DECKHAND_ID
|
2017-09-21 18:22:03 +01:00
|
|
|
}
|
|
|
|
|
2017-08-18 08:52:31 -05:00
|
|
|
|
2018-04-14 17:09:23 -04:00
|
|
|
# Deploy Deckhand and PostgreSQL and run tests.
|
|
|
|
deploy_postgre
|
|
|
|
deploy_deckhand
|
2017-12-12 19:56:15 +00:00
|
|
|
|
2017-08-18 08:52:31 -05:00
|
|
|
log_section Running tests
|
|
|
|
|
2017-10-26 21:33:44 +01:00
|
|
|
# Create folder for saving HTML test results.
|
2018-04-18 19:48:00 -04:00
|
|
|
mkdir -p $ROOTDIR/results
|
|
|
|
|
|
|
|
export DECKHAND_TESTS_DIR=${ROOTDIR}/../deckhand/tests/functional/gabbits
|
2017-10-26 21:33:44 +01:00
|
|
|
|
2017-08-18 08:52:31 -05:00
|
|
|
set +e
|
2017-09-21 18:22:03 +01:00
|
|
|
posargs=$@
|
|
|
|
if [ ${#posargs} -ge 1 ]; then
|
2018-04-18 19:48:00 -04:00
|
|
|
py.test -k $1 -svx $( dirname $ROOTDIR )/deckhand/tests/common/test_gabbi.py --html=results/index.html
|
2017-09-21 18:22:03 +01:00
|
|
|
else
|
2018-04-18 19:48:00 -04:00
|
|
|
py.test -svx $( dirname $ROOTDIR )/deckhand/tests/common/test_gabbi.py --html=results/index.html
|
2017-09-21 18:22:03 +01:00
|
|
|
fi
|
2017-08-18 08:52:31 -05:00
|
|
|
TEST_STATUS=$?
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ "x$TEST_STATUS" = "x0" ]; then
|
|
|
|
log_section Done SUCCESS
|
|
|
|
else
|
|
|
|
log_section Deckhand Server Log
|
2017-12-12 19:56:15 +00:00
|
|
|
cat $STDOUT
|
2017-08-18 08:52:31 -05:00
|
|
|
log_section Done FAILURE
|
|
|
|
exit $TEST_STATUS
|
|
|
|
fi
|