From 9193384bb82c8c9e56c95c900b52a75d6b288da9 Mon Sep 17 00:00:00 2001 From: Alexander Todorov Date: Wed, 27 Nov 2019 13:43:14 +0200 Subject: [PATCH] tests: Use BACKEND env variable instead of hard-coded values - default BACKEND to lorax-composer - pass BACKEND everywhere we need to Cherry-picked from 14a3c8d5a7fda9f334a70c7b0efbc0d3ab9da0fe Related: rhbz#1825190 --- Makefile | 7 ++++--- test/composertest.py | 4 ++-- test/run | 2 ++ test/vm.install | 10 +++++++--- tests/cli/lib/lib.sh | 15 +++++++++------ tests/test_cli.sh | 10 +++++++--- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 3e25a386..5620f405 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ PYTHON ?= /usr/bin/python3 DESTDIR ?= / DOCKER ?= docker +BACKEND ?= lorax-composer PKGNAME = lorax VERSION = $(shell awk '/Version:/ { print $$2 }' $(PKGNAME).spec) @@ -144,10 +145,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: diff --git a/test/composertest.py b/test/composertest.py index 9e5ac64f..09675a25 100644 --- a/test/composertest.py +++ b/test/composertest.py @@ -85,7 +85,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", @@ -107,7 +107,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") diff --git a/test/run b/test/run index 9addef0d..f66bdf2c 100755 --- a/test/run +++ b/test/run @@ -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 diff --git a/test/vm.install b/test/vm.install index c83bf7f7..8c1237ce 100755 --- a/test/vm.install +++ b/test/vm.install @@ -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 @@ -37,9 +38,12 @@ rm -rf build-results su builder -c "/usr/bin/mock --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) diff --git a/tests/cli/lib/lib.sh b/tests/cli/lib/lib.sh index e628f7f8..474cde61 100755 --- a/tests/cli/lib/lib.sh +++ b/tests/cli/lib/lib.sh @@ -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 } diff --git a/tests/test_cli.sh b/tests/test_cli.sh index e75de4fb..bee776cc 100755 --- a/tests/test_cli.sh +++ b/tests/test_cli.sh @@ -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