From 746e35d58a5d2febcaf057b56104cdd5b0e7ad1a Mon Sep 17 00:00:00 2001 From: Shreenidhi Shedi Date: Sun, 1 Dec 2024 02:43:16 +0530 Subject: [PATCH 1/5] Remove unused Dockerfile.photon-3.0 Signed-off-by: Shreenidhi Shedi --- ci/Dockerfile.photon-3.0 | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 ci/Dockerfile.photon-3.0 diff --git a/ci/Dockerfile.photon-3.0 b/ci/Dockerfile.photon-3.0 deleted file mode 100644 index cfa4e14c..00000000 --- a/ci/Dockerfile.photon-3.0 +++ /dev/null @@ -1,19 +0,0 @@ -FROM photon:3.0 - -RUN tdnf update -y -RUN tdnf remove -y toybox -RUN tdnf install -y --enablerepo=photon-debuginfo \ - build-essential cmake curl-devel rpm-build \ - libsolv-devel popt-devel sed createrepo_c glib expat-libs \ - findutils python3 python3-setuptools python3-devel \ - valgrind gpgme-devel glibc-debuginfo expat-devel \ - openssl-devel zlib-devel sqlite-devel python3-requests \ - python3-urllib3 python3-pyOpenSSL python3-pip \ - sudo shadow which e2fsprogs util-linux - -# TODO: we need to fix pytest in Ph3, after that this can be removed -RUN pip3 install pytest flake8 - -RUN mkdir -p /var/lib/tdnf - -CMD ["/bin/bash"] From 67f8cdb6e03afbd8b49e5a27ed1d3ece1de6dc9b Mon Sep 17 00:00:00 2001 From: Shreenidhi Shedi Date: Sun, 1 Dec 2024 02:44:01 +0530 Subject: [PATCH 2/5] Cleanups in docker entry point script Signed-off-by: Shreenidhi Shedi --- ci/docker-entrypoint.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ci/docker-entrypoint.sh b/ci/docker-entrypoint.sh index 132a8e03..34777f0e 100755 --- a/ci/docker-entrypoint.sh +++ b/ci/docker-entrypoint.sh @@ -1,14 +1,23 @@ #!/bin/bash + set -e rm -rf build mkdir -p build cd build || exit 1 -mkdir -p /usr/lib/sysimage/tdnf -cmake -DHISTORY_DB_DIR=/usr/lib/sysimage/tdnf .. && make -j32 && make python -j32 && make check -j32 || exit +JOBS=$(( ($(nproc)+1) / 2 )) +HIST_DB_DIR="/usr/lib/sysimage/tdnf" + +{ + mkdir -p ${HIST_DB_DIR} + cmake -DHISTORY_DB_DIR=${HIST_DB_DIR} .. + make -j${JOBS} + make python -j${JOBS} + make check -j${JOBS} +} || exit 1 if ! flake8 ../pytests ; then - echo "flake8 tests failed" + echo "ERROR: flake8 tests failed" >&2 exit 1 fi From dd3d0f8948011583d10c14c6931c1b001721304c Mon Sep 17 00:00:00 2001 From: Shreenidhi Shedi Date: Sun, 1 Dec 2024 02:45:10 +0530 Subject: [PATCH 3/5] Use a script to prep the container build image Signed-off-by: Shreenidhi Shedi --- ci/Dockerfile.fedora | 14 +++------- ci/Dockerfile.photon | 18 +++---------- ci/prep.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 26 deletions(-) create mode 100644 ci/prep.sh diff --git a/ci/Dockerfile.fedora b/ci/Dockerfile.fedora index 8fe6b129..09dc7475 100644 --- a/ci/Dockerfile.fedora +++ b/ci/Dockerfile.fedora @@ -1,15 +1,7 @@ FROM fedora:34 -RUN dnf -y upgrade -RUN dnf -y install gcc make cmake libcurl-devel rpm-devel rpm-build \ - libsolv-devel popt-devel sed createrepo_c glib2-devel expat \ - findutils python3-pytest python3-requests python3-urllib3 \ - python3-pyOpenSSL python3 python3-devel valgrind gpgme-devel \ - expat-devel openssl-devel sqlite-devel rpm-sign which python3-pip \ - shadow-utils sudo e2fsprogs util-linux - -RUN pip3 install flake8 - -RUN mkdir -p /var/lib/tdnf +COPY ci/prep.sh /prep.sh +RUN chmod +x /prep.sh +RUN /prep.sh CMD ["/bin/bash"] diff --git a/ci/Dockerfile.photon b/ci/Dockerfile.photon index b93955e2..d7919329 100644 --- a/ci/Dockerfile.photon +++ b/ci/Dockerfile.photon @@ -1,19 +1,7 @@ FROM photon:latest -RUN tdnf update -y -RUN tdnf remove -y toybox -RUN tdnf install -y --enablerepo=photon-debuginfo \ - build-essential cmake curl-devel rpm-build \ - libsolv-devel popt-devel sed createrepo_c glib expat-libs \ - findutils python3 python3-pip python3-setuptools \ - python3-devel valgrind gpgme-devel glibc-debuginfo \ - expat-devel openssl-devel zlib-devel sqlite-devel \ - python3-requests python3-urllib3 python3-pyOpenSSL \ - sudo shadow which e2fsprogs util-linux - -# this can to be removed once latest pytest gets published in photon -RUN pip3 install pytest flake8 - -RUN mkdir -p /var/lib/tdnf +COPY ci/prep.sh /prep.sh +RUN chmod +x /prep.sh +RUN /prep.sh CMD ["/bin/bash"] diff --git a/ci/prep.sh b/ci/prep.sh new file mode 100644 index 00000000..28d4ab22 --- /dev/null +++ b/ci/prep.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +set -ex + +rel_file="/etc/os-release" + +common_pkgs=( + cmake + createrepo_c + e2fsprogs + expat-devel + findutils + gpgme-devel + libsolv-devel + openssl-devel + popt-devel + python3-devel + python3-pip + python3-pyOpenSSL + python3-pytest + python3-requests + python3-urllib3 + rpm-build + sed + sqlite-devel + sudo + util-linux + valgrind + which +) + +if grep -qw "Fedora" ${rel_file}; then + fedora_packages=( + ${common_pkgs[@]} + gcc + glib2-devel + libcurl-devel + make + python3-flake8 + rpm-devel + rpm-sign + shadow-utils + ) + dnf -y upgrade --refresh + dnf -y install ${fedora_packages[@]} +elif grep -qw "Photon" ${rel_file}; then + photon_packages=( + ${common_pkgs[@]} + build-essential + curl-devel + glib + glibc-debuginfo + shadow + zlib-devel + ) + tdnf -y upgrade --refresh + tdnf remove -y toybox + tdnf -y install --enablerepo=photon-debuginfo ${photon_packages[@]} + pip3 install flake8 +fi + +mkdir -p /var/lib/tdnf From 96984812d7ef34c90d2e836028ecd793889df12e Mon Sep 17 00:00:00 2001 From: Shreenidhi Shedi Date: Sun, 1 Dec 2024 02:47:13 +0530 Subject: [PATCH 4/5] Use latest Fedora image and use RSA key type and curve for gpg key No need to use %_topdir in specs, it is implicitly done setup-repo.sh: No need to pass `-r' to rpmbuild command, it was a wrong usage for our usecase Signed-off-by: Shreenidhi Shedi --- ci/Dockerfile.fedora | 2 +- ci/prep.sh | 1 + pytests/repo/setup-repo.sh | 44 +++++++++---------- pytests/repo/tdnf-bad-pre.spec | 9 +--- pytests/repo/tdnf-conflict-file0.spec | 5 ++- pytests/repo/tdnf-conflict-file1.spec | 5 ++- pytests/repo/tdnf-missing-dep.spec | 4 +- pytests/repo/tdnf-multi1.spec | 4 +- pytests/repo/tdnf-multi2.spec | 4 +- pytests/repo/tdnf-multi3.spec | 4 +- pytests/repo/tdnf-multi4.spec | 4 +- pytests/repo/tdnf-repoquery-base.spec | 5 ++- pytests/repo/tdnf-repoquery-changelog.spec | 5 ++- pytests/repo/tdnf-repoquery-deps.spec.in | 5 ++- pytests/repo/tdnf-repoquery-queryformat.spec | 5 ++- pytests/repo/tdnf-test-cleanreq-leaf1.spec | 4 +- pytests/repo/tdnf-test-cleanreq-leaf2.spec | 4 +- pytests/repo/tdnf-test-cleanreq-required.spec | 4 +- pytests/repo/tdnf-test-noarch.spec | 4 +- pytests/repo/tdnf-test-one.spec | 4 +- pytests/repo/tdnf-test-toolarge.spec | 6 +-- pytests/repo/tdnf-verbose-scripts.spec | 6 +-- 22 files changed, 68 insertions(+), 70 deletions(-) diff --git a/ci/Dockerfile.fedora b/ci/Dockerfile.fedora index 09dc7475..b117ba17 100644 --- a/ci/Dockerfile.fedora +++ b/ci/Dockerfile.fedora @@ -1,4 +1,4 @@ -FROM fedora:34 +FROM fedora:latest COPY ci/prep.sh /prep.sh RUN chmod +x /prep.sh diff --git a/ci/prep.sh b/ci/prep.sh index 28d4ab22..ecbb3d32 100644 --- a/ci/prep.sh +++ b/ci/prep.sh @@ -19,6 +19,7 @@ common_pkgs=( python3-pyOpenSSL python3-pytest python3-requests + python3-setuptools python3-urllib3 rpm-build sed diff --git a/pytests/repo/setup-repo.sh b/pytests/repo/setup-repo.sh index f48f33bf..cd9ff893 100755 --- a/pytests/repo/setup-repo.sh +++ b/pytests/repo/setup-repo.sh @@ -8,22 +8,21 @@ # if [ $# -ne 2 ]; then - echo "Usage: $0 " + echo "Usage: $0 " >&2 exit 1 fi -function fix_dir_perms() -{ +function fix_dir_perms() { chmod 755 ${TEST_REPO_DIR} find ${TEST_REPO_DIR} -type d -exec chmod 0755 {} \; find ${TEST_REPO_DIR} -type f -exec chmod 0644 {} \; } ## used to check return code for each command. -function check_err { - rc=$? +function check_err() { + local rc=$? if [ $rc -ne 0 ]; then - echo $1 + echo "$1" >&2 exit $rc fi } @@ -37,7 +36,7 @@ fi REPO_SRC_DIR=$2 if [ ! -d ${REPO_SRC_DIR} ]; then - echo "specs dir does not exist" + echo "ERROR: specs dir does not exist" >&2 exit 1 fi @@ -58,21 +57,21 @@ mkdir -p -m 755 ${BUILD_PATH}/BUILD \ ${TEST_REPO_DIR}/yum.repos.d \ ${PUBLISH_PATH} \ ${PUBLISH_SRC_PATH} \ - ${PUBLISH_SHA512_PATH} \ + ${PUBLISH_SHA512_PATH} \ ${GNUPGHOME} #gpgkey data for unattended key generation cat << EOF > ${TEST_REPO_DIR}/gpgkeydata - %echo Generating a key for repogpgcheck signatures - %no-protection - Key-Type: default - Subkey-Type: default - Name-Real: tdnf test - Name-Comment: tdnf test key - Name-Email: tdnftest@tdnf.test - Expire-Date: 0 - %commit - %echo done +%echo Generating a key for repogpgcheck signatures +%no-protection +Key-Type: RSA +Subkey-Type: RSA +Name-Real: tdnf test +Name-Comment: tdnf test key +Name-Email: tdnftest@tdnf.test +Expire-Date: 0 +%commit +%echo done EOF #generate a key non interactively. this is used in testing @@ -90,12 +89,11 @@ for d in conflicts enhances obsoletes provides recommends requires suggests supp sed s/@@dep@@/$d/ < ${REPO_SRC_DIR}/tdnf-repoquery-deps.spec.in > ${BUILD_PATH}/SOURCES/tdnf-repoquery-$d.spec done -echo building packages +echo "Building packages" for spec in ${REPO_SRC_DIR}/*.spec ${BUILD_PATH}/SOURCES/*.spec ; do - echo "building ${spec}" - rpmbuild --define "_topdir ${BUILD_PATH}" \ - -r ${BUILD_PATH} -ba ${spec} 2>&1 - check_err "failed to build ${spec}" + echo "Building ${spec}" + rpmbuild -D "_topdir ${BUILD_PATH}" -ba ${spec} 2>&1 + check_err "ERROR: failed to build ${spec}" done rpmsign --addsign ${BUILD_PATH}/RPMS/*/*.rpm check_err "Failed to sign built packages." diff --git a/pytests/repo/tdnf-bad-pre.spec b/pytests/repo/tdnf-bad-pre.spec index 9cd4fc0f..15658323 100644 --- a/pytests/repo/tdnf-bad-pre.spec +++ b/pytests/repo/tdnf-bad-pre.spec @@ -19,19 +19,12 @@ Part of tdnf test spec. Test bad install scripts. %build %install -mkdir -p %_topdir/%buildroot/usr/bin -cat << EOF >> %_topdir/%buildroot/usr/bin/bad-pre.sh -#!/bin/sh -# dummy script. Return false because we are bad. -/bin/false -EOF %pre # fail intentionally -/bin/false +%{_bindir}/false %files -/usr/bin/bad-pre.sh %changelog * Fri Apr 2 2021 Oliver Kurth 1.0.0-1 diff --git a/pytests/repo/tdnf-conflict-file0.spec b/pytests/repo/tdnf-conflict-file0.spec index 57165db8..173d6633 100644 --- a/pytests/repo/tdnf-conflict-file0.spec +++ b/pytests/repo/tdnf-conflict-file0.spec @@ -16,9 +16,10 @@ Part of tdnf test spec. Two packages containing one identical file. %build %install -mkdir -p %_topdir/%buildroot/usr/lib/conflict +mkdir -p %{buildroot}/usr/lib/conflict # for a file conflict, cntents of the files need to differ -echo file0 > %_topdir/%buildroot/usr/lib/conflict/conflicting-file +echo file0 > %{buildroot}/usr/lib/conflict/conflicting-file + %files /usr/lib/conflict/conflicting-file diff --git a/pytests/repo/tdnf-conflict-file1.spec b/pytests/repo/tdnf-conflict-file1.spec index 55eda779..5ea7363e 100644 --- a/pytests/repo/tdnf-conflict-file1.spec +++ b/pytests/repo/tdnf-conflict-file1.spec @@ -16,8 +16,9 @@ Part of tdnf test spec. Two packages containing one identical file. %build %install -mkdir -p %_topdir/%buildroot/usr/lib/conflict -echo file > %_topdir/%buildroot/usr/lib/conflict/conflicting-file +mkdir -p %{buildroot}/usr/lib/conflict +echo file > %{buildroot}/usr/lib/conflict/conflicting-file + %files /usr/lib/conflict/conflicting-file diff --git a/pytests/repo/tdnf-missing-dep.spec b/pytests/repo/tdnf-missing-dep.spec index b624405d..75b65464 100644 --- a/pytests/repo/tdnf-missing-dep.spec +++ b/pytests/repo/tdnf-missing-dep.spec @@ -22,8 +22,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test %build %install -mkdir -p %_topdir/%buildroot/lib/systemd/system/ -cat << EOF >> %_topdir/%buildroot/lib/systemd/system/%name.service +mkdir -p %{buildroot}/lib/systemd/system/ +cat << EOF >> %{buildroot}/lib/systemd/system/%name.service [Unit] Description=%name.service for whatprovides test. diff --git a/pytests/repo/tdnf-multi1.spec b/pytests/repo/tdnf-multi1.spec index ff8ceab8..a690d7cc 100644 --- a/pytests/repo/tdnf-multi1.spec +++ b/pytests/repo/tdnf-multi1.spec @@ -20,8 +20,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test # files should not conflict %install -mkdir -p %_topdir/%buildroot/usr/share/multiinstall -touch %_topdir/%buildroot/usr/share/multiinstall-%{release} +mkdir -p %{buildroot}/usr/share/multiinstall +touch %{buildroot}/usr/share/multiinstall-%{release} %files /usr/share/multiinstall-%{release} diff --git a/pytests/repo/tdnf-multi2.spec b/pytests/repo/tdnf-multi2.spec index fba78695..84e1d3ba 100644 --- a/pytests/repo/tdnf-multi2.spec +++ b/pytests/repo/tdnf-multi2.spec @@ -20,8 +20,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test # files should not conflict %install -mkdir -p %_topdir/%buildroot/usr/share/multiinstall -touch %_topdir/%buildroot/usr/share/multiinstall-%{release} +mkdir -p %{buildroot}/usr/share/multiinstall +touch %{buildroot}/usr/share/multiinstall-%{release} %files /usr/share/multiinstall-%{release} diff --git a/pytests/repo/tdnf-multi3.spec b/pytests/repo/tdnf-multi3.spec index c0519c83..e2ce20af 100644 --- a/pytests/repo/tdnf-multi3.spec +++ b/pytests/repo/tdnf-multi3.spec @@ -20,8 +20,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test # files should not conflict %install -mkdir -p %_topdir/%buildroot/usr/share/multiinstall -touch %_topdir/%buildroot/usr/share/multiinstall-%{release} +mkdir -p %{buildroot}/usr/share/multiinstall +touch %{buildroot}/usr/share/multiinstall-%{release} %files /usr/share/multiinstall-%{release} diff --git a/pytests/repo/tdnf-multi4.spec b/pytests/repo/tdnf-multi4.spec index 9bcb0b42..6f61356c 100644 --- a/pytests/repo/tdnf-multi4.spec +++ b/pytests/repo/tdnf-multi4.spec @@ -20,8 +20,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test # files should not conflict %install -mkdir -p %_topdir/%buildroot/usr/share/multiinstall -touch %_topdir/%buildroot/usr/share/multiinstall-%{release} +mkdir -p %{buildroot}/usr/share/multiinstall +touch %{buildroot}/usr/share/multiinstall-%{release} %files /usr/share/multiinstall-%{release} diff --git a/pytests/repo/tdnf-repoquery-base.spec b/pytests/repo/tdnf-repoquery-base.spec index 3f552665..d6cc10d1 100644 --- a/pytests/repo/tdnf-repoquery-base.spec +++ b/pytests/repo/tdnf-repoquery-base.spec @@ -17,8 +17,9 @@ depend on this in some way. %build %install -mkdir -p %_topdir/%buildroot/usr/lib/repoquery -touch %_topdir/%buildroot/usr/lib/repoquery/%name +mkdir -p %{buildroot}/usr/lib/repoquery +touch %{buildroot}/usr/lib/repoquery/%name + %files /usr/lib/repoquery/%name diff --git a/pytests/repo/tdnf-repoquery-changelog.spec b/pytests/repo/tdnf-repoquery-changelog.spec index 5d1419c7..b5a769ec 100644 --- a/pytests/repo/tdnf-repoquery-changelog.spec +++ b/pytests/repo/tdnf-repoquery-changelog.spec @@ -17,8 +17,9 @@ depend on this in some way. %build %install -mkdir -p %_topdir/%buildroot/usr/lib/repoquery -touch %_topdir/%buildroot/usr/lib/repoquery/%name +mkdir -p %{buildroot}/usr/lib/repoquery +touch %{buildroot}/usr/lib/repoquery/%name + %files /usr/lib/repoquery/%name diff --git a/pytests/repo/tdnf-repoquery-deps.spec.in b/pytests/repo/tdnf-repoquery-deps.spec.in index b90360de..5ca5892d 100644 --- a/pytests/repo/tdnf-repoquery-deps.spec.in +++ b/pytests/repo/tdnf-repoquery-deps.spec.in @@ -19,8 +19,9 @@ depend on tdnf-repoquery-base (or provide, ...) %build %install -mkdir -p %_topdir/%buildroot/usr/lib/repoquery -touch %_topdir/%buildroot/usr/lib/repoquery/%name +mkdir -p %{buildroot}/usr/lib/repoquery +touch %{buildroot}/usr/lib/repoquery/%name + %files /usr/lib/repoquery/%name diff --git a/pytests/repo/tdnf-repoquery-queryformat.spec b/pytests/repo/tdnf-repoquery-queryformat.spec index d7766633..0534b383 100644 --- a/pytests/repo/tdnf-repoquery-queryformat.spec +++ b/pytests/repo/tdnf-repoquery-queryformat.spec @@ -21,8 +21,9 @@ depend on this in some way. %build %install -mkdir -p %_topdir/%buildroot/usr/lib/repoquery -touch %_topdir/%buildroot/usr/lib/repoquery/%name +mkdir -p %{buildroot}/usr/lib/repoquery +touch %{buildroot}/usr/lib/repoquery/%name + %files /usr/lib/repoquery/%name diff --git a/pytests/repo/tdnf-test-cleanreq-leaf1.spec b/pytests/repo/tdnf-test-cleanreq-leaf1.spec index 62c97108..7bfa37bd 100644 --- a/pytests/repo/tdnf-test-cleanreq-leaf1.spec +++ b/pytests/repo/tdnf-test-cleanreq-leaf1.spec @@ -20,8 +20,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test %build %install -mkdir -p %_topdir/%buildroot/lib/cleanreq/ -touch %_topdir/%buildroot/lib/cleanreq/%name +mkdir -p %{buildroot}/lib/cleanreq/ +touch %{buildroot}/lib/cleanreq/%name %files /lib/cleanreq/%name diff --git a/pytests/repo/tdnf-test-cleanreq-leaf2.spec b/pytests/repo/tdnf-test-cleanreq-leaf2.spec index e22ab0f1..690379c4 100644 --- a/pytests/repo/tdnf-test-cleanreq-leaf2.spec +++ b/pytests/repo/tdnf-test-cleanreq-leaf2.spec @@ -20,8 +20,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test %build %install -mkdir -p %_topdir/%buildroot/lib/cleanreq/ -touch %_topdir/%buildroot/lib/cleanreq/%name +mkdir -p %{buildroot}/lib/cleanreq/ +touch %{buildroot}/lib/cleanreq/%name %files /lib/cleanreq/%name diff --git a/pytests/repo/tdnf-test-cleanreq-required.spec b/pytests/repo/tdnf-test-cleanreq-required.spec index 1678c782..fbdcb648 100644 --- a/pytests/repo/tdnf-test-cleanreq-required.spec +++ b/pytests/repo/tdnf-test-cleanreq-required.spec @@ -19,8 +19,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test %build %install -mkdir -p %_topdir/%buildroot/lib/cleanreq/ -touch %_topdir/%buildroot/lib/cleanreq/required +mkdir -p %{buildroot}/lib/cleanreq/ +touch %{buildroot}/lib/cleanreq/required %files /lib/cleanreq/required diff --git a/pytests/repo/tdnf-test-noarch.spec b/pytests/repo/tdnf-test-noarch.spec index 748fb773..a68a0ec7 100644 --- a/pytests/repo/tdnf-test-noarch.spec +++ b/pytests/repo/tdnf-test-noarch.spec @@ -20,8 +20,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test %build %install -mkdir -p %_topdir/%buildroot/lib/systemd/system/ -cat << EOF >> %_topdir/%buildroot/lib/systemd/system/%{name}.service +mkdir -p %{buildroot}/lib/systemd/system/ +cat << EOF >> %{buildroot}/lib/systemd/system/%{name}.service [Unit] Description=%{name} for arch related tests diff --git a/pytests/repo/tdnf-test-one.spec b/pytests/repo/tdnf-test-one.spec index a8021938..2cf39d21 100644 --- a/pytests/repo/tdnf-test-one.spec +++ b/pytests/repo/tdnf-test-one.spec @@ -19,8 +19,8 @@ Part of tdnf test spec. Basic install/remove/upgrade test %build %install -mkdir -p %_topdir/%buildroot/lib/systemd/system/ -cat << EOF >> %_topdir/%buildroot/lib/systemd/system/tdnf-test-one.service +mkdir -p %{buildroot}/lib/systemd/system/ +cat << EOF >> %{buildroot}/lib/systemd/system/tdnf-test-one.service [Unit] Description=tdnf-test-one.service for whatprovides test. diff --git a/pytests/repo/tdnf-test-toolarge.spec b/pytests/repo/tdnf-test-toolarge.spec index 5d4958e7..760b5425 100644 --- a/pytests/repo/tdnf-test-toolarge.spec +++ b/pytests/repo/tdnf-test-toolarge.spec @@ -20,9 +20,9 @@ out of disk space error. %build %install -mkdir -p %_topdir/%buildroot/lib/toolarge/ -touch %_topdir/%buildroot/lib/toolarge/largedata.txt -dd if=/dev/urandom of=%_topdir/%buildroot/lib/toolarge/largedata.txt bs=1M count=1 +mkdir -p %{buildroot}/lib/toolarge/ +touch %{buildroot}/lib/toolarge/largedata.txt +dd if=/dev/urandom of=%{buildroot}/lib/toolarge/largedata.txt bs=1M count=1 %files /lib/toolarge/largedata.txt diff --git a/pytests/repo/tdnf-verbose-scripts.spec b/pytests/repo/tdnf-verbose-scripts.spec index 4b1e2c71..28f04479 100644 --- a/pytests/repo/tdnf-verbose-scripts.spec +++ b/pytests/repo/tdnf-verbose-scripts.spec @@ -19,9 +19,9 @@ Part of tdnf test spec. Basic install/remove/upgrade test %build %install -mkdir -p %_topdir/%buildroot/lib/systemd/system/ -echo %_topdir/%buildroot/lib/systemd/system/%{name}.service -cat << EOF >> %_topdir/%buildroot/lib/systemd/system/%{name}.service +mkdir -p %{buildroot}/lib/systemd/system/ +echo %{buildroot}/lib/systemd/system/%{name}.service +cat << EOF >> %{buildroot}/lib/systemd/system/%{name}.service [Unit] Description=%{name}.service for rpm script test. From d7c743aac360a06b46ed0cd6ea5ed235b98b9792 Mon Sep 17 00:00:00 2001 From: Shreenidhi Shedi Date: Mon, 2 Dec 2024 13:56:50 +0530 Subject: [PATCH 5/5] Start test containers in privileged mode to avoid skipping cache dir out of space checks Fix small cache test Signed-off-by: Shreenidhi Shedi --- .github/workflows/ci.yml | 4 +-- pytests/conftest.py | 8 ++++++ pytests/mount-small-cache.in | 52 +++++++++++++++++++----------------- pytests/tests/test_cache.py | 17 ++++++------ 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eba38ec3..536bf0fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - name: run container with tests working-directory: ${{ github.workspace }} run: | - docker run --security-opt seccomp:unconfined --rm -e DIST -v$(pwd):/build -w/build ${DIST}/tdnf-build ./ci/docker-entrypoint.sh + docker run --privileged --security-opt seccomp:unconfined --rm -e DIST -v$(pwd):/build -w/build ${DIST}/tdnf-build ./ci/docker-entrypoint.sh fedora: env: DIST: fedora @@ -30,5 +30,5 @@ jobs: - name: run container with tests working-directory: ${{ github.workspace }} run: | - docker run --security-opt seccomp:unconfined --rm -e DIST -v$(pwd):/build -w/build ${DIST}/tdnf-build ./ci/docker-entrypoint.sh + docker run --privileged --security-opt seccomp:unconfined --rm -e DIST -v$(pwd):/build -w/build ${DIST}/tdnf-build ./ci/docker-entrypoint.sh diff --git a/pytests/conftest.py b/pytests/conftest.py index e57ddb8c..4afe158f 100644 --- a/pytests/conftest.py +++ b/pytests/conftest.py @@ -193,6 +193,14 @@ def assert_file_exists(self, file_path): raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), file_path) + def clear_directory(self, dir_path): + for item in os.listdir(dir_path): + item_path = os.path.join(dir_path, item) + if os.path.isfile(item_path) or os.path.islink(item_path): + os.unlink(item_path) + elif os.path.isdir(item_path): + shutil.rmtree(item_path) + def check_package(self, package, version=None): ''' Check if a package exists ''' ret = self.run(["tdnf", "--disablerepo=*", "list", "-j", "--installed", package]) diff --git a/pytests/mount-small-cache.in b/pytests/mount-small-cache.in index f0739cb9..a4a33bd9 100755 --- a/pytests/mount-small-cache.in +++ b/pytests/mount-small-cache.in @@ -1,8 +1,7 @@ -#!/usr/bin/env bash +#!/bin/bash ## file: mount-small-cache.sh ## brief: mounts an intentionally small directory for out-of-diskspace tests. -## author: Preston Narchetti if [ ${EUID} -ne 0 ]; then echo "Script must be run as root." 1>&2 @@ -13,29 +12,34 @@ fi small_cache_path="@CMAKE_CURRENT_BINARY_DIR@/small_cache/" quota_size="1M" -## used to check return code for each command. -function check_err { - rc=$? +check_err() { + local rc=$? if [ $rc -ne 0 ]; then - echo $1 - exit $rc + echo "$1" 1>&2 + exit $rc fi } -echo "Creating mount point." -rm -rf ./virtual_disks -mkdir -p ./virtual_disks -rm -rf ${small_cache_path} -mkdir -p ${small_cache_path} -check_err "Failed to mkdir ${small_cache_path}." - -echo "Creating tmpfs." -touch ./virtual_disks/fs.ext4 -dd if=/dev/zero of=./virtual_disks/fs.ext4 bs=${quota_size} count=1 -check_err "Failed to make exf4 tmpfs: dd" -mkfs.ext4 ./virtual_disks/fs.ext4 -check_err "Failed to make exf4 tmpfs: mkfs.ext4" - -echo "Mounting tmpfs at ${small_cache_path}." -mount -o loop,rw,usrquota,grpquota ./virtual_disks/fs.ext4 ${small_cache_path} -check_err "Failed to mount exf4 tmpfs." +vdisk="virtual_disks" +ext4_fn="${vdisk}/fs.ext4" + +echo "Creating mount point ..." +if mountpoint ${small_cache_path} &> /dev/null; then + umount ${small_cache_path} + check_err "ERROR: umount ${small_cache_path}" + sync +fi +rm -rf ${vdisk} ${small_cache_path} +mkdir -p ${vdisk} ${small_cache_path} +check_err "ERROR: failed to mkdir ${vdisk} ${small_cache_path}" + +echo "Creating tmpfs ..." +dd if=/dev/zero of=${ext4_fn} bs=${quota_size} count=1 +check_err "ERROR: dd failed" + +mkfs.ext4 ${ext4_fn} +check_err "ERROR: mkfs.ext4 failed" + +echo "Mounting tmpfs at ${small_cache_path} ..." +mount -o loop,rw,usrquota,grpquota ${ext4_fn} ${small_cache_path} +check_err "ERROR: failed to mount exf4 tmpfs" diff --git a/pytests/tests/test_cache.py b/pytests/tests/test_cache.py index 6545bed3..4755d36a 100644 --- a/pytests/tests/test_cache.py +++ b/pytests/tests/test_cache.py @@ -52,10 +52,6 @@ def switch_cache_path(utils, new_path): utils.edit_config({'cachedir': new_path}) -def clean_small_cache(utils): - utils.run(['rm', '-rf', utils.config['small_cache_path']]) - - def try_mount_small_cache(): import subprocess mount_script = subprocess.Popen( @@ -218,15 +214,19 @@ def test_download_vs_cache_size_multiple_packages(utils): assert utils.floats_approx_equal(down_bytes, cached_rpm_bytes) -@pytest.mark.skipif(try_mount_small_cache() != 0, reason="Failed to mount small cache directory.") def test_cache_directory_out_of_disk_space(utils): + if try_mount_small_cache(): + print("Failed to mount small cache directory") + return + small_cache_path = utils.config['small_cache_path'] orig_cache_path = utils.tdnf_config.get('main', 'cachedir') switch_cache_path(utils, small_cache_path) enable_cache(utils) - clean_small_cache(utils) + # can't rm the dir because it's a mount point + utils.clear_directory(small_cache_path) - run_args = ['tdnf', 'install', '-y', '--nogpgcheck'] + run_args = 'tdnf install -y --nogpgcheck'.split() pkg_list = [utils.config["toolarge_pkgname"]] for pkgname in pkg_list: utils.erase_package(pkgname) @@ -235,7 +235,8 @@ def test_cache_directory_out_of_disk_space(utils): switch_cache_path(utils, orig_cache_path) clean_cache(utils) - clean_small_cache(utils) + utils.clear_directory(small_cache_path) + utils.run(f"umount {small_cache_path}".split()) assert ret['retval'] == 1036