From 288b280073ee1cf2c4dac20ce75404fa0146dc88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Wed, 5 Apr 2023 15:59:50 +0200 Subject: [PATCH] Test: rework execution of unit-tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have been running just a subset of osbuild unit tests and also not as a root, so some of them would be skipped. In addition, the downstream patches were never applied on sources which were used for unit-testing. Thus if any issue with test was just backported as a patch, this had no effect on the test result. Rework how tests are executed by using a dedicated script which will take care of the installation of test dependencies, preparation of sources including application of downstream patches and execute all unit tests. Rework also the FMF test metadata and test discovery. Related: rhbz#2174847 Signed-off-by: Tomáš Hozza --- plans/unit-tests.fmf | 11 ++-- tests/unit-tests/main.fmf | 4 ++ tests/unit-tests/run-unit-tests.sh | 101 +++++++++++++++++++++++++++++ tests/unit.fmf | 2 - 4 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 tests/unit-tests/main.fmf create mode 100755 tests/unit-tests/run-unit-tests.sh delete mode 100644 tests/unit.fmf diff --git a/plans/unit-tests.fmf b/plans/unit-tests.fmf index 0a6450c..f54785c 100644 --- a/plans/unit-tests.fmf +++ b/plans/unit-tests.fmf @@ -1,14 +1,11 @@ -summary: Run osbuild unit tests from source +summary: Run osbuild unit tests from dist-git sources prepare: how: install package: - - git - - make - - python3-mako - - python3-pytest - - osbuild + - git + - make discover: how: fmf - dist-git-source: true + filter: tag:unit-test execute: how: tmt diff --git a/tests/unit-tests/main.fmf b/tests/unit-tests/main.fmf new file mode 100644 index 0000000..37d5c6a --- /dev/null +++ b/tests/unit-tests/main.fmf @@ -0,0 +1,4 @@ +summary: Run osbuild unit tests from dist-git sources +tag: unit-test +duration: 2h +test: ./run-unit-tests.sh diff --git a/tests/unit-tests/run-unit-tests.sh b/tests/unit-tests/run-unit-tests.sh new file mode 100755 index 0000000..34860b2 --- /dev/null +++ b/tests/unit-tests/run-unit-tests.sh @@ -0,0 +1,101 @@ +#!/usr/bin/bash +# Execute osbuild unit tests from a checked out dist-git repo + +set -euxo pipefail + +source /etc/os-release + +case "${ID}-${VERSION_ID}" in + fedora-*) + PKG_MAINT_TOOL="fedpkg" + sudo dnf install -y "${PKG_MAINT_TOOL}" + ;; + rhel-8.*) + PKG_MAINT_TOOL="rhpkg" + # rhpkg is not available in the default repos + sudo curl -L -o /etc/yum.repos.d/rcm-tools-rhel-8-baseos.repo http://download.devel.redhat.com/rel-eng/internal/rcm-tools-rhel-8-baseos.repo + ;; + rhel-9.*) + PKG_MAINT_TOOL="rhpkg" + # rhpkg is not available in the default repos + sudo curl -L -o /etc/yum.repos.d/rcm-tools-rhel-9-baseos.repo http://download.devel.redhat.com/rel-eng/internal/rcm-tools-rhel-9-baseos.repo + ;; + centos-*) + PKG_MAINT_TOOL="centpkg" + # centpkg is not available in the default repos + sudo dnf install -y epel-release + # CRB repos are available only for CentOS Stream 9 + if [ "${VERSION_ID}" == "9" ]; then + dnf config-manager --set-enabled crb + fi + ;; + *) + echo "Error: unsupported OS: ${ID}-${VERSION_ID}" + exit 1 + ;; +esac + +# Move to the checked out git repo with the test plans +# this should be the root of the dist-git repo +cd "${TMT_TREE}" +# the content of the directory is copy of the dist-git repo, but the .git directory is missing +# so we need to create it to make all *pkg tools happy +git init + +# install all test dependencies +sudo dnf install -y \ + "${PKG_MAINT_TOOL}" \ + rpmdevtools \ + python3-mako \ + python3-pytest \ + dosfstools +sudo dnf builddep -y osbuild.spec + +# Make sure that /usr/lib/systemd/boot/efi/linuxx64.efi.stub is available to enable pe32p tests +case "${ID}-${VERSION_ID}" in + rhel-8.* | centos-8) + sudo dnf install -y systemd-udev + ;; + *) + sudo dnf install -y systemd-boot-unsigned + ;; +esac + +TARGET_BRANCH="${TARGET_BRANCH:-}" +PKG_MAINT_TOOL_EXTRA_ARGS="" +if [ -n "${TARGET_BRANCH}" ]; then + PKG_MAINT_TOOL_EXTRA_ARGS="--release ${TARGET_BRANCH}" +fi + +# shellcheck disable=SC2086 +${PKG_MAINT_TOOL} ${PKG_MAINT_TOOL_EXTRA_ARGS} prep + +# Extract the Source0 basename without extension +SRC_DIR=$(rpmdev-spectool --source 0 osbuild.spec | awk '{print $2}' | sed 's/.tar.gz//') +SRC_DIR="${SRC_DIR##*/}" + +cd "${SRC_DIR}" + +# Some unit tests depend on the fact that the source code is in a git repo +git init . +git add * +git commit -m "Initial commit" + +# Run the unit tests +# Note: +# - Ignore the boot test, because it requires qemu-system-x86_64 not available on all distributions. +# - Ignore source code tests, which run linters, since we can't ensure that all linters are available +# and of the same version as in upstream. +# - Explicitly mark btrfs as unsupported on CentOS / RHEL + +if [ "${ID}" == "centos" ] || [ "${ID}" == "rhel" ]; then + UNSUPPORTED_FS="--unsupported-fs btrfs" +fi + +sudo python3 -m pytest \ + --rootdir "$(pwd)" \ + --ignore "$(pwd)/test/src" \ + ${UNSUPPORTED_FS:-} \ + -k "not test_boot" \ + -v \ + "$(pwd)/test/" diff --git a/tests/unit.fmf b/tests/unit.fmf deleted file mode 100644 index 28a6b69..0000000 --- a/tests/unit.fmf +++ /dev/null @@ -1,2 +0,0 @@ -summary: Run unit tests using upstream source -test: cd ../osbuild-*/ && python3 -m pytest test/mod