2017-08-18 08:52:31 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
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)
|
|
|
|
# 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:-}
|
|
|
|
|
2017-08-18 08:52:31 -05:00
|
|
|
function log_section {
|
|
|
|
set +x
|
|
|
|
echo 1>&2
|
|
|
|
echo 1>&2
|
|
|
|
echo === $* === 1>&2
|
|
|
|
set -x
|
|
|
|
}
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
2017-12-12 19:56:15 +00:00
|
|
|
function cleanup {
|
|
|
|
sudo docker stop $POSTGRES_ID
|
|
|
|
if [ -n "$DECKHAND_ID" ]; then
|
|
|
|
sudo docker stop $DECKHAND_ID
|
|
|
|
fi
|
|
|
|
rm -rf $CONF_DIR
|
2018-01-09 05:44:36 +00:00
|
|
|
|
|
|
|
if [ -z "$DECKHAND_IMAGE" ]; then
|
|
|
|
# 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)
|
|
|
|
setsid kill -- -$PGID
|
|
|
|
fi
|
2017-12-12 19:56:15 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 05:44:36 +00:00
|
|
|
|
2017-12-12 19:56:15 +00:00
|
|
|
trap cleanup EXIT
|
|
|
|
|
2017-08-18 08:52:31 -05:00
|
|
|
|
|
|
|
POSTGRES_ID=$(
|
|
|
|
sudo docker run \
|
|
|
|
--detach \
|
|
|
|
--publish :5432 \
|
|
|
|
-e POSTGRES_DB=deckhand \
|
|
|
|
-e POSTGRES_USER=deckhand \
|
|
|
|
-e POSTGRES_PASSWORD=password \
|
2017-10-02 17:25:35 +01:00
|
|
|
postgres:9.5
|
2017-08-18 08:52:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
POSTGRES_IP=$(
|
|
|
|
sudo docker inspect \
|
|
|
|
--format='{{ .NetworkSettings.Networks.bridge.IPAddress }}' \
|
|
|
|
$POSTGRES_ID
|
|
|
|
)
|
|
|
|
|
2017-12-12 19:56:15 +00:00
|
|
|
|
|
|
|
CONF_DIR=$(mktemp -d -p $(pwd))
|
|
|
|
sudo chmod 777 -R $CONF_DIR
|
2017-08-18 08:52:31 -05:00
|
|
|
|
2017-09-21 18:22:03 +01:00
|
|
|
function gen_config {
|
|
|
|
log_section Creating config file
|
2017-08-18 08:52:31 -05:00
|
|
|
|
2017-09-21 18:22:03 +01:00
|
|
|
export DECKHAND_TEST_URL=http://localhost:9000
|
|
|
|
export DATABASE_URL=postgresql+psycopg2://deckhand:password@$POSTGRES_IP:5432/deckhand
|
|
|
|
# Used by Deckhand's initialization script to search for config files.
|
|
|
|
export OS_DECKHAND_CONFIG_DIR=$CONF_DIR
|
|
|
|
|
|
|
|
cp etc/deckhand/logging.conf.sample $CONF_DIR/logging.conf
|
2017-08-18 08:52:31 -05:00
|
|
|
|
2018-01-09 03:16:35 +00:00
|
|
|
# Create a logging config file to dump everything to stdout/stderr.
|
|
|
|
cat <<EOCONF > $CONF_DIR/logging.conf
|
|
|
|
[loggers]
|
|
|
|
keys = root, deckhand
|
|
|
|
|
|
|
|
[handlers]
|
|
|
|
keys = null, stderr, stdout
|
|
|
|
|
|
|
|
[formatters]
|
|
|
|
keys = simple, context
|
|
|
|
|
|
|
|
[logger_deckhand]
|
|
|
|
level = DEBUG
|
|
|
|
handlers = stdout
|
|
|
|
qualname = deckhand
|
|
|
|
|
|
|
|
[logger_root]
|
|
|
|
level = WARNING
|
|
|
|
handlers = null
|
|
|
|
|
|
|
|
[handler_stderr]
|
|
|
|
class = StreamHandler
|
|
|
|
args = (sys.stderr,)
|
|
|
|
formatter = context
|
|
|
|
|
|
|
|
[handler_stdout]
|
|
|
|
class = StreamHandler
|
|
|
|
args = (sys.stdout,)
|
|
|
|
formatter = context
|
|
|
|
|
|
|
|
[handler_null]
|
|
|
|
class = logging.NullHandler
|
|
|
|
formatter = context
|
|
|
|
args = ()
|
|
|
|
|
|
|
|
[formatter_context]
|
|
|
|
class = oslo_log.formatters.ContextFormatter
|
|
|
|
|
|
|
|
[formatter_simple]
|
|
|
|
format=%(asctime)s.%(msecs)03d %(process)d %(levelname)s: %(message)s
|
|
|
|
EOCONF
|
|
|
|
|
|
|
|
# Create a Deckhand config file with bare minimum options.
|
2017-08-18 08:52:31 -05:00
|
|
|
cat <<EOCONF > $CONF_DIR/deckhand.conf
|
|
|
|
[DEFAULT]
|
|
|
|
debug = true
|
2018-01-09 03:16:35 +00:00
|
|
|
# NOTE: Use the location of this file inside the mounted volume in the
|
|
|
|
# container.
|
|
|
|
log_config_append = /etc/deckhand/logging.conf
|
|
|
|
publish_errors = true
|
2017-08-18 08:52:31 -05:00
|
|
|
use_stderr = true
|
2018-01-09 03:16:35 +00:00
|
|
|
# NOTE: allow_anonymous_access allows these functional tests to get around
|
|
|
|
# Keystone authentication, but the context that is provided has zero privileges
|
|
|
|
# so we must also override the policy file for authorization to pass.
|
2017-10-11 19:50:11 -04:00
|
|
|
allow_anonymous_access = true
|
2017-08-18 08:52:31 -05:00
|
|
|
|
2017-09-21 18:22:03 +01:00
|
|
|
[oslo_policy]
|
|
|
|
policy_file = policy.yaml
|
|
|
|
|
2017-09-19 19:30:12 +01:00
|
|
|
[barbican]
|
2017-08-18 08:52:31 -05:00
|
|
|
|
|
|
|
[database]
|
2017-09-18 20:11:32 +01:00
|
|
|
connection = $DATABASE_URL
|
2017-08-18 08:52:31 -05:00
|
|
|
|
|
|
|
[keystone_authtoken]
|
2017-10-11 19:50:11 -04:00
|
|
|
# Populate keystone_authtoken with values like the following should Keystone
|
|
|
|
# integration be needed here.
|
|
|
|
# project_domain_name = Default
|
|
|
|
# project_name = admin
|
|
|
|
# user_domain_name = Default
|
|
|
|
# password = devstack
|
|
|
|
# username = admin
|
|
|
|
# auth_url = http://127.0.0.1/identity
|
|
|
|
# auth_type = password
|
2017-08-18 08:52:31 -05:00
|
|
|
EOCONF
|
|
|
|
|
2017-09-21 18:22:03 +01:00
|
|
|
echo $CONF_DIR/deckhand.conf 1>&2
|
|
|
|
cat $CONF_DIR/deckhand.conf 1>&2
|
|
|
|
|
2018-01-09 03:16:35 +00:00
|
|
|
echo $CONF_DIR/logging.conf 1>&2
|
|
|
|
cat $CONF_DIR/logging.conf 1>&2
|
|
|
|
|
2017-09-21 18:22:03 +01:00
|
|
|
log_section Starting server
|
|
|
|
}
|
|
|
|
|
2017-10-11 19:50:11 -04:00
|
|
|
function gen_paste {
|
|
|
|
log_section Creating paste config without [filter:authtoken]
|
|
|
|
# NOTE(fmontei): Since this script does not currently support Keystone
|
|
|
|
# integration, we remove ``filter:authtoken`` from the ``deckhand_api``
|
|
|
|
# pipeline to avoid any kind of auth issues.
|
|
|
|
sed 's/authtoken api/api/' etc/deckhand/deckhand-paste.ini &> $CONF_DIR/deckhand-paste.ini
|
|
|
|
}
|
|
|
|
|
2017-09-21 18:22:03 +01:00
|
|
|
function gen_policy {
|
|
|
|
log_section Creating policy file with liberal permissions
|
|
|
|
|
|
|
|
policy_file='etc/deckhand/policy.yaml.sample'
|
|
|
|
policy_pattern="deckhand\:"
|
2017-08-18 08:52:31 -05:00
|
|
|
|
2017-09-21 18:22:03 +01:00
|
|
|
touch $CONF_DIR/policy.yaml
|
|
|
|
|
|
|
|
sed -n "/$policy_pattern/p" "$policy_file" \
|
|
|
|
| sed 's/^../\"/' \
|
|
|
|
| sed 's/rule\:[A-Za-z\_\-]*/@/' > $CONF_DIR/policy.yaml
|
|
|
|
|
|
|
|
echo $CONF_DIR/'policy.yaml' 1>&2
|
|
|
|
cat $CONF_DIR/'policy.yaml' 1>&2
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_config
|
2017-10-11 19:50:11 -04:00
|
|
|
gen_paste
|
2017-09-21 18:22:03 +01:00
|
|
|
gen_policy
|
2017-08-18 08:52:31 -05:00
|
|
|
|
2017-12-12 19:56:15 +00:00
|
|
|
log_section Starting Deckhand image
|
|
|
|
|
|
|
|
if [ -z "$DECKHAND_IMAGE" ]; then
|
|
|
|
echo "Running Deckhand via uwsgi"
|
2018-01-09 05:44:36 +00:00
|
|
|
|
|
|
|
# Set --workers 2, so that concurrency is always tested.
|
2017-12-12 19:56:15 +00:00
|
|
|
uwsgi \
|
2017-08-18 08:52:31 -05:00
|
|
|
--http :9000 \
|
|
|
|
-w deckhand.cmd \
|
|
|
|
--callable deckhand_callable \
|
|
|
|
--enable-threads \
|
2018-01-09 05:44:36 +00:00
|
|
|
--workers 2 \
|
|
|
|
--threads 1 \
|
2017-08-18 08:52:31 -05:00
|
|
|
-L \
|
2018-01-09 03:16:35 +00:00
|
|
|
--pyargv "--config-file $CONF_DIR/deckhand.conf" &> $STDOUT &
|
2017-12-12 19:56:15 +00:00
|
|
|
else
|
|
|
|
echo "Running Deckhand via Docker"
|
|
|
|
sudo docker run \
|
|
|
|
--rm \
|
|
|
|
--net=host \
|
|
|
|
-p 9000:9000 \
|
|
|
|
-v $CONF_DIR:/etc/deckhand \
|
|
|
|
$DECKHAND_IMAGE &> $STDOUT &
|
|
|
|
fi
|
2017-08-18 08:52:31 -05:00
|
|
|
|
2017-12-12 19:56:15 +00:00
|
|
|
# Give the server a chance to come up. Better to poll a health check.
|
2017-08-18 08:52:31 -05:00
|
|
|
sleep 5
|
|
|
|
|
2017-12-12 19:56:15 +00:00
|
|
|
DECKHAND_ID=$(sudo docker ps | grep deckhand | awk '{print $1}')
|
|
|
|
echo $DECKHAND_ID
|
|
|
|
|
2017-08-18 08:52:31 -05:00
|
|
|
log_section Running tests
|
|
|
|
|
2017-10-25 23:12:13 +01:00
|
|
|
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
2017-10-26 21:33:44 +01:00
|
|
|
# Create folder for saving HTML test results.
|
|
|
|
if [ ! -d $ROOTDIR/results ]; then
|
|
|
|
mkdir $ROOTDIR/results
|
|
|
|
fi
|
|
|
|
|
2017-08-18 08:52:31 -05:00
|
|
|
set +e
|
2017-09-21 18:22:03 +01:00
|
|
|
posargs=$@
|
|
|
|
if [ ${#posargs} -ge 1 ]; then
|
2017-10-25 23:12:13 +01:00
|
|
|
py.test -k $1 -svx $( dirname $ROOTDIR )/deckhand/tests/functional/test_gabbi.py --html=results/index.html
|
2017-09-21 18:22:03 +01:00
|
|
|
else
|
2017-10-25 23:12:13 +01:00
|
|
|
py.test -svx $( dirname $ROOTDIR )/deckhand/tests/functional/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
|