diff --git a/plans/unit-tests.fmf b/plans/unit-tests.fmf index 6b6e36e..be96033 100644 --- a/plans/unit-tests.fmf +++ b/plans/unit-tests.fmf @@ -7,6 +7,7 @@ prepare: - osbuild discover: how: fmf + dist-git-source: true filter: tag:unit-test execute: how: tmt diff --git a/tests/unit-tests/prep-host-environment.sh b/tests/unit-tests/prep-host-environment.sh index eb19934..7435e04 100755 --- a/tests/unit-tests/prep-host-environment.sh +++ b/tests/unit-tests/prep-host-environment.sh @@ -6,42 +6,12 @@ set -euxo pipefail source /etc/os-release -case "${ID}" in - fedora) - PKG_MAINT_TOOL="fedpkg" - sudo dnf install -y "${PKG_MAINT_TOOL}" - ;; - rhel) - PKG_MAINT_TOOL="rhpkg" - # rhpkg is not available in the default repos - sudo curl -L -o "/etc/yum.repos.d/rcm-tools-rhel-${VERSION_ID%.*}-baseos.repo" "http://download.devel.redhat.com/rel-eng/internal/rcm-tools-rhel-${VERSION_ID%.*}-baseos.repo" - # install the RH IT CA certificate used by the repo above - sudo curl -L -o /etc/pki/ca-trust/source/anchors/2015-IT-Root-CA.pem http://certs.corp.redhat.com/certs/2015-IT-Root-CA.pem - sudo curl -L -o /etc/pki/ca-trust/source/anchors/2022-IT-Root-CA.pem http://certs.corp.redhat.com/certs/2022-IT-Root-CA.pem - sudo update-ca-trust - ;; - 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}" # install all test dependencies sudo dnf install -y \ - "${PKG_MAINT_TOOL}" \ rpmdevtools \ python3-mako \ python3-pip \ diff --git a/tests/unit-tests/run-unit-tests.sh b/tests/unit-tests/run-unit-tests.sh index c04d7d6..3181add 100755 --- a/tests/unit-tests/run-unit-tests.sh +++ b/tests/unit-tests/run-unit-tests.sh @@ -13,68 +13,6 @@ if [ "$(uname -m)" != "x86_64" ]; then exit 0 fi -case "${ID}" in - fedora) - PKG_MAINT_TOOL="fedpkg" - ;; - rhel) - PKG_MAINT_TOOL="rhpkg" - ;; - centos) - PKG_MAINT_TOOL="centpkg" - ;; - *) - 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 - -# deduct the release to pass to rpkg to prep the sources. -# 1. use the DIST_GIT_RELEASE if set -DIST_GIT_RELEASE="${DIST_GIT_RELEASE:-}" -# 2. use the TARGET_BRANCH if set -if [[ -z "${DIST_GIT_RELEASE}" ]]; then - echo "DIST_GIT_RELEASE was not provided, trying to use TARGET_BRANCH" - DIST_GIT_RELEASE="${TARGET_BRANCH:-}" -fi -# 3. use the host OS type and version -if [[ -z "${DIST_GIT_RELEASE}" ]]; then - echo "DIST_GIT_RELEASE nor TARGET_BRANCH were not provided, trying to use the host OS type and version" - case "${ID}" in - fedora) - DIST_GIT_RELEASE="f${VERSION_ID}" - ;; - rhel) - DIST_GIT_RELEASE="rhel-${VERSION_ID}.0" - ;; - centos) - DIST_GIT_RELEASE="c${VERSION_ID}s" - ;; - esac -fi - -# The namespace and name must be passed explicitly to rhpkg, because it can't determine them on its own. -# Passing these options to centpkg and fedpkg is harmless, so we can use them for all tools. -# shellcheck disable=SC2086 -${PKG_MAINT_TOOL} -v --namespace rpms --name osbuild --release "${DIST_GIT_RELEASE}" prep - -# Extract the Source0 basename without extension -SRC_DIR=$(spectool --source 0 osbuild.spec | sed -E 's|.*/([^/]*)\.tar\.gz$|\1|') - -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" - # The 'test/run/test_assemblers.py::test_tar' test case uses system tar to extract the built tar archive. # However, files in the tar archive can have SELinux context not present in the system policy. Therefore, # in order for the system tar to be able to set it when extracting the archive, it must be labeled with @@ -112,6 +50,15 @@ if ([ "${ID}" == "rhel" ] || [ "${ID}" == "centos" ]) && [ "${VERSION_ID%%.*}" = TEST_SELECTION_EXPR="${TEST_SELECTION_EXPR} and not (test_write_read)" fi +# Move to the directory with sources +cd "${TMT_SOURCE_DIR}" + +# Extract the Source0 basename without extension +SRC_DIR=$(spectool --source 0 osbuild.spec | sed -E 's|.*/([^/]*)\.tar\.gz$|\1|') + +# Move to the extracted sources directory (patches are applied by default) +cd "${SRC_DIR}" + sudo python3 -m pytest \ --rootdir "$(pwd)" \ --ignore "$(pwd)/test/src" \