lorax: Catch rootfs out of space failures

It isn't always obvious what happened when the rootfs runs out of space,
especially when using lorax via pungi. So this checks for the out of
space error string when building the runtime image and logs it to the
primary logfile and console as an error with the rootfs size.

eg.
2020-01-20 18:52:58,920: The rootfs ran out of space with size=1
This commit is contained in:
Brian C. Lane 2020-01-20 15:55:12 -08:00
parent 9dd160ba44
commit fe45fa3610
2 changed files with 26 additions and 2 deletions

View File

@ -23,6 +23,7 @@ logger = logging.getLogger("pylorax.treebuilder")
import os, re
from os.path import basename
from shutil import copytree, copy2
from subprocess import CalledProcessError
from pathlib import Path
import itertools
@ -228,8 +229,14 @@ class RuntimeBuilder(object):
workdir = joinpaths(os.path.dirname(outfile), "runtime-workdir")
os.makedirs(joinpaths(workdir, "LiveOS"))
imgutils.mkrootfsimg(self.vars.root, joinpaths(workdir, "LiveOS/rootfs.img"),
"Anaconda", size=size)
# Catch problems with the rootfs being too small and clearly log them
try:
imgutils.mkrootfsimg(self.vars.root, joinpaths(workdir, "LiveOS/rootfs.img"),
"Anaconda", size=size)
except CalledProcessError as e:
if e.stdout and "No space left on device" in e.stdout:
logger.error("The rootfs ran out of space with size=%d", size)
raise
# squash the live rootfs and clean up workdir
imgutils.mksquashfs(workdir, outfile, compression, compressargs)

View File

@ -17,6 +17,7 @@
import glob
import os
import parted
from subprocess import CalledProcessError
import tarfile
import tempfile
import unittest
@ -270,6 +271,22 @@ class ImgUtilsTest(unittest.TestCase):
file_details = get_file_magic(disk_img.name)
self.assertTrue("ext2 filesystem" in file_details, file_details)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def test_small_mkext4img(self):
"""Test mkext4img error handling"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
mkfakerootdir(work_dir)
# Add a 8MiB file
with open(joinpaths(work_dir, "large-file"), "w") as f:
for _ in range(5):
f.write("A" * 1024**2)
graft = {work_dir+"/etc/yum.repos.d/": "./tests/pylorax/repos/server-2.repo"}
try:
mkext4img(work_dir, disk_img.name, graft=graft, size=5*1024**2)
except CalledProcessError as e:
self.assertTrue(e.stdout and "No space left on device" in e.stdout)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def test_mkbtrfsimg(self):
"""Test mkbtrfsimg function (requires loop)"""