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