From d8c1ebee0cabee24bab4e239e1fa77194c3e06bf Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 11 Jan 2025 09:39:21 +0100 Subject: [PATCH] test: make diskusage data available even after successful runs Pytest eats the output for successful tests so in order to know how often cached images need to get removed we need a trick like this. --- .github/workflows/tests.yml | 1 + test/test_build.py | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a253e66aa..d0db16449 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -136,3 +136,4 @@ jobs: run: | df -h sudo du -sh * /var/tmp /tmp /var/lib/containers | sort -sh + sudo find /mnt/var/tmp/bib-tests -name du.log|sudo xargs cat diff --git a/test/test_build.py b/test/test_build.py index c8ab91516..2576f28da 100644 --- a/test/test_build.py +++ b/test/test_build.py @@ -484,16 +484,19 @@ def del_ami(): # Try to cache as much as possible for image_type in image_types: img = artifact[image_type] - print(f"Checking disk usage for {img}") - if os.path.exists(img): - # might already be removed if we're deleting 'raw' and 'ami' - disk_usage = shutil.disk_usage(img) - print(f"NOTE: disk usage after {img}: {disk_usage.free / 1_000_000} / {disk_usage.total / 1_000_000}") - if disk_usage.free < 1_000_000_000: - print(f"WARNING: running low on disk space, removing {img}") - img.unlink() - else: - print("does not exist") + # XXX: make parallizable via flock + with open(shared_tmpdir / "du.log", "a") as fp: + fp.write(f"Checking disk usage for {img}\n") + if os.path.exists(img): + # might already be removed if we're deleting 'raw' and 'ami' + disk_usage = shutil.disk_usage(img) + fp.write(f"NOTE: disk usage after {img}: {disk_usage.free / 1_000_000} / {disk_usage.total / 1_000_000}\n") + if disk_usage.free < 1_000_000_000: + fp.write(f"WARNING: running low on disk space, removing {img}\n") + img.unlink() + else: + fp.write("does not exist\n") + fp.write("---\n") subprocess.run(["podman", "rmi", container_ref], check=False) return