From 763bddf57408fb720a87fc80074262a635ee1771 Mon Sep 17 00:00:00 2001 From: Shreenidhi Shedi Date: Mon, 2 Dec 2024 13:56:50 +0530 Subject: [PATCH] Start test containers in privieged 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/mount-small-cache.in | 52 +++++++++++++++++++----------------- pytests/tests/test_cache.py | 16 +++++------ 3 files changed, 38 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/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..eb0792ad 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,18 @@ 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) + utils.run(f"rm -rf {small_cache_path}/*".split()) - 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 +234,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.run(f"rm -rf {small_cache_path}/*".split()) + utils.run(f"umount {small_cache_path}".split()) assert ret['retval'] == 1036