Skip to content

Commit

Permalink
test: make diskusage data available even after successful runs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvo5 committed Jan 11, 2025
1 parent d61eaaa commit 5b6e319
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ jobs:
run: |
df -h
sudo du -sh * /var/tmp /tmp /var/lib/containers | sort -sh
find /mnt/var/tmp/bib-tests -name du.log"|xargs cat
23 changes: 13 additions & 10 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5b6e319

Please sign in to comment.