tests: Use BACKEND env variable instead of hard-coded values

- default BACKEND to lorax-composer
- pass BACKEND everywhere we need to
This commit is contained in:
Alexander Todorov 2019-11-27 13:43:14 +02:00 committed by Brian C. Lane
parent f1c15c67e0
commit 14a3c8d5a7
6 changed files with 31 additions and 17 deletions

View File

@ -5,6 +5,7 @@ mandir ?= $(PREFIX)/share/man
DOCKER ?= podman
DOCS_VERSION ?= next
RUN_TESTS ?= ci
BACKEND ?= lorax-composer
PKGNAME = lorax
VERSION = $(shell awk '/Version:/ { print $$2 }' $(PKGNAME).spec)
@ -173,10 +174,10 @@ vm-local-repos: vm
$(TEST_OS)
bots/image-customize -v \
--upload $(REPOS_DIR):/etc/yum.repos.d \
--run-command "yum -y remove composer-cli lorax-composer" \
--run-command "yum -y remove composer-cli $(BACKEND)" \
--run-command "yum -y update" \
--run-command "yum -y install composer-cli lorax-composer" \
--run-command "systemctl enable lorax-composer" \
--run-command "yum -y install composer-cli $(BACKEND)" \
--run-command "systemctl enable $(BACKEND).socket" \
$(TEST_OS)
vm-reset:

View File

@ -127,7 +127,7 @@ class ComposerTestCase(VirtMachineTestCase):
# Upload the contents of the ./tests/ directory to the machine (it must have beakerlib already installed)
self.machine.upload(["../tests"], "/")
print("Waiting for lorax-composer to become ready...")
print("Waiting for backend to become ready...")
curl_command = ["curl", "--max-time", "360",
"--silent",
"--unix-socket", "/run/weldr/api.socket",
@ -149,7 +149,7 @@ class ComposerTestCase(VirtMachineTestCase):
return local_dir
def runCliTest(self, script):
extra_env = []
extra_env = ["BACKEND=%s" % os.getenv('BACKEND', 'lorax-composer')]
if self.sit:
extra_env.append("COMPOSER_TEST_FAIL_FAST=1")

View File

@ -2,6 +2,8 @@
# This is the expected entry point for Cockpit CI; will be called without
# arguments but with an appropriate $TEST_OS, and optionally $TEST_SCENARIO
export BACKEND="${BACKEND:-lorax-composer}"
make vm
if [ -n "$TEST_SCENARIO" ]; then

View File

@ -1,10 +1,11 @@
#!/bin/sh -eux
BACKEND="${BACKEND:-lorax-composer}"
SRPM="$1"
# always remove older versions of these RPMs if they exist
# to ensure newly built packages have been installed
yum -y remove lorax lorax-composer composer-cli
yum -y remove lorax $BACKEND composer-cli
if ! rpm -q beakerlib; then
if [ $(. /etc/os-release && echo $ID) = "rhel" ]; then
@ -41,9 +42,12 @@ rm -rf build-results
su builder -c "/usr/bin/mock --verbose --no-clean --resultdir build-results --rebuild $SRPM"
packages=$(find build-results -name '*.rpm' -not -name '*.src.rpm')
yum install -y $packages
if [ "$BACKEND" == "osbuild-composer" ]; then
packages=$(find build-results -name '*.rpm' -not -name '*.src.rpm' -not -name '*lorax-composer*')
fi
yum install -y $packages $BACKEND
systemctl enable lorax-composer.socket
systemctl enable $BACKEND.socket
if [ -f /usr/bin/docker ]; then
yum remove -y $(rpm -qf /usr/bin/docker)

View File

@ -2,6 +2,9 @@
. /usr/share/beakerlib/beakerlib.sh
BACKEND="${BACKEND:-lorax-composer}"
export BACKEND
# 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}
@ -97,8 +100,8 @@ composer_start() {
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
systemctl start $BACKEND.socket
systemctl start $BACKEND
fi
rc=$?
@ -106,7 +109,7 @@ composer_start() {
if [ "$rc" -eq 0 ]; then
wait_for_composer
else
rlLogFail "Unable to start lorax-composer (exit code $rc)"
rlLogFail "Unable to start $BACKEND (exit code $rc)"
fi
return $rc
}
@ -115,15 +118,15 @@ 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
if systemctl list-units | grep -q $BACKEND.socket; then
systemctl stop $BACKEND.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
systemctl stop $BACKEND
fi
}

View File

@ -10,6 +10,8 @@ set -eu
CLI="${CLI:-}"
function setup_tests {
[ "$BACKEND" == "osbuild-composer" ] && return 0
local share_dir=$1
local blueprints_dir=$2
@ -56,6 +58,8 @@ __EOF__
}
function teardown_tests {
[ "$BACKEND" == "osbuild-composer" ] && return 0
local share_dir=$1
local blueprints_dir=$2
@ -91,7 +95,7 @@ if [ -z "$CLI" ]; then
chmod a+rx -R $SHARE_DIR
setup_tests $SHARE_DIR $BLUEPRINTS_DIR
# start the lorax-composer daemon
# start the backend daemon
composer_start
else
export PACKAGE="composer-cli"
@ -111,14 +115,14 @@ setup_beakerlib_env
run_beakerlib_tests "$@"
if [ -z "$CLI" ]; then
# stop lorax-composer and remove /run/weldr/api.socket
# stop backend and remove /run/weldr/api.socket
# only if running against source
composer_stop
teardown_tests $SHARE_DIR $BLUEPRINTS_DIR
else
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
# start backend again so we can continue with manual or other kinds
# of testing on the same system
composer_start
fi