[tests] Use functions for starting and stopping lorax-composer

Cherry-picked from f978d4b01c

Related: rhbz#1769525
This commit is contained in:
Alexander Todorov 2019-11-06 14:22:39 +02:00 committed by Alexander Todorov
parent 71a666507b
commit e7f2706461
2 changed files with 65 additions and 22 deletions

View File

@ -1,7 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. /usr/share/beakerlib/beakerlib.sh
# Monkey-patch beakerlib to exit on first failure if COMPOSER_TEST_FAIL_FAST is # Monkey-patch beakerlib to exit on first failure if COMPOSER_TEST_FAIL_FAST is
# set. https://github.com/beakerlib/beakerlib/issues/42 # set. https://github.com/beakerlib/beakerlib/issues/42
COMPOSER_TEST_FAIL_FAST=${COMPOSER_TEST_FAIL_FAST:-0}
if [ "$COMPOSER_TEST_FAIL_FAST" == "1" ]; then if [ "$COMPOSER_TEST_FAIL_FAST" == "1" ]; then
eval "original$(declare -f __INTERNAL_LogAndJournalFail)" eval "original$(declare -f __INTERNAL_LogAndJournalFail)"
@ -37,6 +40,58 @@ boot_image() {
done; done;
} }
wait_for_composer() {
tries=0
until curl -m 15 --unix-socket /run/weldr/api.socket http://localhost:4000/api/status | grep 'db_supported.*true'; do
tries=$((tries + 1))
if [ $tries -gt 50 ]; then
exit 1
fi
sleep 5
echo "DEBUG: Waiting for backend API to become ready before testing ..."
done;
}
composer_start() {
local rc
local params="$@"
if [[ -z "$CLI" || "$CLI" == "./src/bin/composer-cli" ]]; then
./src/sbin/lorax-composer $params --sharedir $SHARE_DIR $BLUEPRINTS_DIR &
elif [ -n "$params" ]; then
/usr/sbin/lorax-composer $params /var/lib/lorax/composer/blueprints &
else
# socket stop/start seems to be necessary for a proper service restart
# after a previous direct manual run for it to work properly
systemctl start lorax-composer.socket
systemctl start lorax-composer
fi
rc=$?
# wait for the backend to become ready
if [ "$rc" -eq 0 ]; then
wait_for_composer
else
rlLogFail "Unable to start lorax-composer (exit code $rc)"
fi
return $rc
}
composer_stop() {
MANUAL=${MANUAL:-0}
# socket stop/start seems to be necessary for a proper service restart
# after a previous direct manual run for it to work properly
if systemctl list-units | grep -q lorax-composer.socket; then
systemctl stop lorax-composer.socket
fi
if [[ -z "$CLI" || "$CLI" == "./src/bin/composer-cli" || "$MANUAL" == "1" ]]; then
pkill -9 lorax-composer
rm -f /run/weldr/api.socket
else
systemctl stop lorax-composer
fi
}
# a generic helper function unifying the specific checks executed on a running # a generic helper function unifying the specific checks executed on a running
# image instance # image instance

View File

@ -3,6 +3,8 @@
set -eu set -eu
. $(dirname $0)/cli/lib/lib.sh
export BEAKERLIB_DIR=$(mktemp -d /tmp/composer-test.XXXXXX) export BEAKERLIB_DIR=$(mktemp -d /tmp/composer-test.XXXXXX)
CLI="${CLI:-}" CLI="${CLI:-}"
@ -58,38 +60,25 @@ if [ -z "$CLI" ]; then
export top_srcdir=`pwd` export top_srcdir=`pwd`
. ./tests/testenv.sh . ./tests/testenv.sh
BLUEPRINTS_DIR=`mktemp -d '/tmp/composer-blueprints.XXXXX'` export BLUEPRINTS_DIR=`mktemp -d '/tmp/composer-blueprints.XXXXX'`
export BLUEPRINTS_DIR
cp ./tests/pylorax/blueprints/*.toml $BLUEPRINTS_DIR cp ./tests/pylorax/blueprints/*.toml $BLUEPRINTS_DIR
SHARE_DIR=`mktemp -d '/tmp/composer-share.XXXXX'` export SHARE_DIR=`mktemp -d '/tmp/composer-share.XXXXX'`
cp -R ./share/* $SHARE_DIR cp -R ./share/* $SHARE_DIR
chmod a+rx -R $SHARE_DIR chmod a+rx -R $SHARE_DIR
setup_tests $SHARE_DIR $BLUEPRINTS_DIR setup_tests $SHARE_DIR $BLUEPRINTS_DIR
# start the lorax-composer daemon # start the lorax-composer daemon
./src/sbin/lorax-composer --sharedir $SHARE_DIR $BLUEPRINTS_DIR & composer_start
else else
export PACKAGE="composer-cli" export PACKAGE="composer-cli"
export BLUEPRINTS_DIR="/var/lib/lorax/composer/blueprints" export BLUEPRINTS_DIR="/var/lib/lorax/composer/blueprints"
systemctl stop lorax-composer composer_stop
setup_tests /usr/share/lorax /var/lib/lorax/composer/blueprints setup_tests /usr/share/lorax /var/lib/lorax/composer/blueprints
systemctl start lorax-composer composer_start
fi fi
# wait for the backend to become ready
tries=0
until curl -m 15 --unix-socket /run/weldr/api.socket http://localhost:4000/api/status | grep 'db_supported.*true'; do
tries=$((tries + 1))
if [ $tries -gt 50 ]; then
exit 1
fi
sleep 5
echo "DEBUG: Waiting for backend API to become ready before testing ..."
done;
export BEAKERLIB_JOURNAL=0 export BEAKERLIB_JOURNAL=0
export PATH="/usr/local/bin:$PATH" export PATH="/usr/local/bin:$PATH"
if [ -z "$*" ]; then if [ -z "$*" ]; then
@ -108,15 +97,14 @@ fi
if [ -z "$CLI" ]; then if [ -z "$CLI" ]; then
# stop lorax-composer and remove /run/weldr/api.socket # stop lorax-composer and remove /run/weldr/api.socket
# only if running against source # only if running against source
pkill -9 lorax-composer composer_stop
rm -f /run/weldr/api.socket
teardown_tests $SHARE_DIR $BLUEPRINTS_DIR teardown_tests $SHARE_DIR $BLUEPRINTS_DIR
else else
systemctl stop lorax-composer composer_stop
teardown_tests /usr/share/lorax /var/lib/lorax/composer/blueprints teardown_tests /usr/share/lorax /var/lib/lorax/composer/blueprints
# start lorax-composer again so we can continue with manual or other kinds # start lorax-composer again so we can continue with manual or other kinds
# of testing on the same system # of testing on the same system
systemctl start lorax-composer composer_start
fi fi
. $BEAKERLIB_DIR/TestResults . $BEAKERLIB_DIR/TestResults