Test: unify test case implementation across c8s / c9s
Resolves: rhbz#2174847
This commit is contained in:
parent
09f8ff7118
commit
2d5873bf11
|
@ -4,6 +4,7 @@ prepare:
|
||||||
package:
|
package:
|
||||||
- git
|
- git
|
||||||
- make
|
- make
|
||||||
|
- osbuild
|
||||||
discover:
|
discover:
|
||||||
how: fmf
|
how: fmf
|
||||||
filter: tag:unit-test
|
filter: tag:unit-test
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
summary: Run osbuild unit tests from dist-git sources
|
summary: Run osbuild unit tests from dist-git sources
|
||||||
tag: unit-test
|
tag: unit-test
|
||||||
duration: 2h
|
duration: 2h
|
||||||
test: ./run-unit-tests.sh
|
test: ./prep-host-environment.sh; sudo chcon $(matchpathcon -n /usr/bin/osbuild) ./run-unit-tests.sh; ./run-unit-tests.sh
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
#!/usr/bin/bash
|
||||||
|
# Prepare the host environment for running the osbuild unit tests.
|
||||||
|
# This includes installing missing dependencies and tools.
|
||||||
|
|
||||||
|
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 \
|
||||||
|
rpm-ostree \
|
||||||
|
dosfstools \
|
||||||
|
gdisk
|
||||||
|
sudo dnf builddep -y osbuild.spec
|
||||||
|
|
||||||
|
# Install pytst from pip, because the version in some RHEL / CentOS releases is too old
|
||||||
|
sudo pip3 install pytest
|
||||||
|
|
||||||
|
# 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
|
|
@ -5,29 +5,15 @@ set -euxo pipefail
|
||||||
|
|
||||||
source /etc/os-release
|
source /etc/os-release
|
||||||
|
|
||||||
case "${ID}-${VERSION_ID}" in
|
case "${ID}" in
|
||||||
fedora-*)
|
fedora)
|
||||||
PKG_MAINT_TOOL="fedpkg"
|
PKG_MAINT_TOOL="fedpkg"
|
||||||
sudo dnf install -y "${PKG_MAINT_TOOL}"
|
|
||||||
;;
|
;;
|
||||||
rhel-8.*)
|
rhel)
|
||||||
PKG_MAINT_TOOL="rhpkg"
|
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.*)
|
centos)
|
||||||
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"
|
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}"
|
echo "Error: unsupported OS: ${ID}-${VERSION_ID}"
|
||||||
|
@ -42,36 +28,32 @@ cd "${TMT_TREE}"
|
||||||
# so we need to create it to make all *pkg tools happy
|
# so we need to create it to make all *pkg tools happy
|
||||||
git init
|
git init
|
||||||
|
|
||||||
# install all test dependencies
|
# deduct the release to pass to rpkg to prep the sources.
|
||||||
sudo dnf install -y \
|
# 1. use the DIST_GIT_RELEASE if set
|
||||||
"${PKG_MAINT_TOOL}" \
|
DIST_GIT_RELEASE="${DIST_GIT_RELEASE:-}"
|
||||||
rpmdevtools \
|
# 2. use the TARGET_BRANCH if set
|
||||||
python3-mako \
|
if [[ -z "${DIST_GIT_RELEASE}" ]]; then
|
||||||
python3-pip \
|
echo "DIST_GIT_RELEASE was not provided, trying to use TARGET_BRANCH"
|
||||||
dosfstools
|
DIST_GIT_RELEASE="${TARGET_BRANCH:-}"
|
||||||
sudo dnf builddep -y osbuild.spec
|
fi
|
||||||
|
# 3. use the host OS type and version
|
||||||
# Install pytst from pip, because the version in some RHEL / CentOS releases is too old
|
if [[ -z "${DIST_GIT_RELEASE}" ]]; then
|
||||||
sudo pip3 install pytest
|
echo "DIST_GIT_RELEASE nor TARGET_BRANCH were not provided, trying to use the host OS type and version"
|
||||||
|
case "${ID}" in
|
||||||
# Make sure that /usr/lib/systemd/boot/efi/linuxx64.efi.stub is available to enable pe32p tests
|
fedora)
|
||||||
case "${ID}-${VERSION_ID}" in
|
DIST_GIT_RELEASE="f${VERSION_ID}"
|
||||||
rhel-8.* | centos-8)
|
;;
|
||||||
sudo dnf install -y systemd-udev
|
rhel)
|
||||||
;;
|
DIST_GIT_RELEASE="rhel-${VERSION_ID}.0"
|
||||||
*)
|
;;
|
||||||
sudo dnf install -y systemd-boot-unsigned
|
centos)
|
||||||
;;
|
DIST_GIT_RELEASE="c${VERSION_ID}s"
|
||||||
esac
|
;;
|
||||||
|
esac
|
||||||
TARGET_BRANCH="${TARGET_BRANCH:-}"
|
|
||||||
PKG_MAINT_TOOL_EXTRA_ARGS=""
|
|
||||||
if [ -n "${TARGET_BRANCH}" ]; then
|
|
||||||
PKG_MAINT_TOOL_EXTRA_ARGS="--release ${TARGET_BRANCH}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
${PKG_MAINT_TOOL} ${PKG_MAINT_TOOL_EXTRA_ARGS} prep
|
${PKG_MAINT_TOOL} --release "${DIST_GIT_RELEASE}" prep
|
||||||
|
|
||||||
# Extract the Source0 basename without extension
|
# Extract the Source0 basename without extension
|
||||||
SRC_DIR=$(spectool --source 0 osbuild.spec | sed 's/.\+\(osbuild-[0-9]\+\)\.tar\.gz/\1/')
|
SRC_DIR=$(spectool --source 0 osbuild.spec | sed 's/.\+\(osbuild-[0-9]\+\)\.tar\.gz/\1/')
|
||||||
|
@ -83,6 +65,18 @@ git init .
|
||||||
git add *
|
git add *
|
||||||
git commit -m "Initial commit"
|
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
|
||||||
|
# 'install_exec_t' type.
|
||||||
|
|
||||||
|
ORIGINAL_TAR_CONTEXT="$(matchpathcon -n "$(which tar)")"
|
||||||
|
sudo chcon "system_u:object_r:install_exec_t:s0" "$(which tar)"
|
||||||
|
function restore_tar_context() {
|
||||||
|
sudo chcon "${ORIGINAL_TAR_CONTEXT}" "$(which tar)"
|
||||||
|
}
|
||||||
|
trap restore_tar_context EXIT
|
||||||
|
|
||||||
# Run the unit tests
|
# Run the unit tests
|
||||||
# Note:
|
# Note:
|
||||||
# - Ignore the boot test, because it requires qemu-system-x86_64 not available on all distributions.
|
# - Ignore the boot test, because it requires qemu-system-x86_64 not available on all distributions.
|
||||||
|
@ -94,10 +88,19 @@ if [ "${ID}" == "centos" ] || [ "${ID}" == "rhel" ]; then
|
||||||
UNSUPPORTED_FS="--unsupported-fs btrfs"
|
UNSUPPORTED_FS="--unsupported-fs btrfs"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
TEST_SELECTION_EXPR="not (TestBoot and boot)"
|
||||||
|
|
||||||
|
# disable some tests on RHEL-8
|
||||||
|
if ([ "${ID}" == "rhel" ] || [ "${ID}" == "centos" ]) && [ "${VERSION_ID%%.*}" == "8" ]; then
|
||||||
|
# qemu-img info in RHEL-8 produces "raw" as the image format for "vdi" images, which causes tests to fail. Skip it.
|
||||||
|
TEST_SELECTION_EXPR="${TEST_SELECTION_EXPR} and not (test_qemu[ext4-vdi] or test_qemu[xfs-vdi])"
|
||||||
|
TEST_SELECTION_EXPR="${TEST_SELECTION_EXPR} and not (TestStages and test_qemu)"
|
||||||
|
fi
|
||||||
|
|
||||||
sudo python3 -m pytest \
|
sudo python3 -m pytest \
|
||||||
--rootdir "$(pwd)" \
|
--rootdir "$(pwd)" \
|
||||||
--ignore "$(pwd)/test/src" \
|
--ignore "$(pwd)/test/src" \
|
||||||
${UNSUPPORTED_FS:-} \
|
${UNSUPPORTED_FS:-} \
|
||||||
-k "not test_boot" \
|
-k "${TEST_SELECTION_EXPR}" \
|
||||||
-v \
|
-v \
|
||||||
"$(pwd)/test/"
|
"$(pwd)/test/"
|
||||||
|
|
Loading…
Reference in New Issue