[tests] Use functions for starting and stopping lorax-composer
This commit is contained in:
parent
4643afa58d
commit
f978d4b01c
@ -1,7 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
. /usr/share/beakerlib/beakerlib.sh
|
||||
|
||||
# Monkey-patch beakerlib to exit on first failure if COMPOSER_TEST_FAIL_FAST is
|
||||
# set. https://github.com/beakerlib/beakerlib/issues/42
|
||||
COMPOSER_TEST_FAIL_FAST=${COMPOSER_TEST_FAIL_FAST:-0}
|
||||
if [ "$COMPOSER_TEST_FAIL_FAST" == "1" ]; then
|
||||
eval "original$(declare -f __INTERNAL_LogAndJournalFail)"
|
||||
|
||||
@ -39,6 +42,58 @@ boot_image() {
|
||||
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
|
||||
# image instance
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
set -eu
|
||||
|
||||
. $(dirname $0)/cli/lib/lib.sh
|
||||
|
||||
export BEAKERLIB_DIR=$(mktemp -d /tmp/composer-test.XXXXXX)
|
||||
CLI="${CLI:-}"
|
||||
|
||||
@ -58,37 +60,25 @@ if [ -z "$CLI" ]; then
|
||||
export top_srcdir=`pwd`
|
||||
. ./tests/testenv.sh
|
||||
|
||||
BLUEPRINTS_DIR=`mktemp -d '/tmp/composer-blueprints.XXXXX'`
|
||||
export BLUEPRINTS_DIR
|
||||
export BLUEPRINTS_DIR=`mktemp -d '/tmp/composer-blueprints.XXXXX'`
|
||||
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
|
||||
chmod a+rx -R $SHARE_DIR
|
||||
|
||||
setup_tests $SHARE_DIR $BLUEPRINTS_DIR
|
||||
# start the lorax-composer daemon
|
||||
./src/sbin/lorax-composer --sharedir $SHARE_DIR $BLUEPRINTS_DIR &
|
||||
composer_start
|
||||
else
|
||||
export PACKAGE="composer-cli"
|
||||
export BLUEPRINTS_DIR="/var/lib/lorax/composer/blueprints"
|
||||
systemctl stop lorax-composer
|
||||
composer_stop
|
||||
setup_tests /usr/share/lorax /var/lib/lorax/composer/blueprints
|
||||
systemctl start lorax-composer
|
||||
composer_start
|
||||
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
|
||||
if [ -z "$*" ]; then
|
||||
# invoke cli/ tests which can be executed without special preparation
|
||||
@ -106,15 +96,14 @@ fi
|
||||
if [ -z "$CLI" ]; then
|
||||
# stop lorax-composer and remove /run/weldr/api.socket
|
||||
# only if running against source
|
||||
pkill -9 lorax-composer
|
||||
rm -f /run/weldr/api.socket
|
||||
composer_stop
|
||||
teardown_tests $SHARE_DIR $BLUEPRINTS_DIR
|
||||
else
|
||||
systemctl stop lorax-composer
|
||||
composer_stop
|
||||
teardown_tests /usr/share/lorax /var/lib/lorax/composer/blueprints
|
||||
# start lorax-composer again so we can continue with manual or other kinds
|
||||
# of testing on the same system
|
||||
systemctl start lorax-composer
|
||||
composer_start
|
||||
fi
|
||||
|
||||
. $BEAKERLIB_DIR/TestResults
|
||||
|
Loading…
Reference in New Issue
Block a user