From 3ab1933d0451171c47cfa60032154805f7d6e78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Thu, 30 May 2024 14:36:46 +0200 Subject: [PATCH] Don't rely on rhpkg and centpkg tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since [1], TMT finally applies downstream patches when extracting sources for testing. Fixing this took eternity, and in the meantime, we moved to using rhpkg / centpkg to prepare the sources for testing. This is however now causing a lot of pain in c10s / el10, because these tools are not yet build for the new distro versions. Let's move back to relying on TMT to extract sources and apply downstream, patches. [1] https://github.com/teemtee/tmt/pull/2641 Signed-off-by: Tomáš Hozza --- plans/unit-tests.fmf | 1 + tests/unit-tests/prep-host-environment.sh | 35 ----------- tests/unit-tests/run-unit-tests.sh | 71 +++-------------------- 3 files changed, 10 insertions(+), 97 deletions(-) diff --git a/plans/unit-tests.fmf b/plans/unit-tests.fmf index 85b550b..90a58a9 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 4a5351d..a304384 100755 --- a/tests/unit-tests/prep-host-environment.sh +++ b/tests/unit-tests/prep-host-environment.sh @@ -6,47 +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 - - # CRB repos are available for CentOS Stream 10 - if [ "${VERSION_ID}" == "10" ]; 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 d9f3f8d..968079c 100755 --- a/tests/unit-tests/run-unit-tests.sh +++ b/tests/unit-tests/run-unit-tests.sh @@ -5,68 +5,6 @@ set -euxo pipefail source /etc/os-release -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 's/.\+\(osbuild-[0-9]\+\)\.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 @@ -99,6 +37,15 @@ if ([ "${ID}" == "rhel" ] || [ "${ID}" == "centos" ]) && [ "${VERSION_ID%%.*}" = TEST_SELECTION_EXPR="${TEST_SELECTION_EXPR} and not (TestStages and test_qemu)" 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 's/.\+\(osbuild-[0-9]\+\)\.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" \