Skip to content

Commit

Permalink
Start test containers in privileged mode to avoid
Browse files Browse the repository at this point in the history
skipping cache dir out of space checks

Fix small cache test

Signed-off-by: Shreenidhi Shedi <[email protected]>
  • Loading branch information
sshedi committed Dec 4, 2024
1 parent 42f855e commit 0f3aaf6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 8 additions & 0 deletions pytests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
52 changes: 28 additions & 24 deletions pytests/mount-small-cache.in
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

if [ ${EUID} -ne 0 ]; then
echo "Script must be run as root." 1>&2
Expand All @@ -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"
17 changes: 9 additions & 8 deletions pytests/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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


Expand Down

0 comments on commit 0f3aaf6

Please sign in to comment.