Skip to content

Commit 3b30b07

Browse files
authored
Merge pull request #96 from desultory/dev
Make filesystem testing more thorough
2 parents 83745ce + fc8a617 commit 3b30b07

File tree

7 files changed

+80
-28
lines changed

7 files changed

+80
-28
lines changed

readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ The following root filesystems have been tested:
8080
* BTRFS
8181
* EXT4
8282
* XFS
83-
* FAT32
8483
* NILFS2
8584

85+
Additionally, the following filesystems have been tested for non-root mounts:
86+
87+
* FAT32
88+
8689
If the required kernel module is not built into the kernel, and the filesystem is not listed above, the kernel module may need to be included in `kmod_init`.
8790

8891
> The example config has `kmod_autodetect_lsmod` enabled which should automatically pull in the required modules, unless the active kernel differs from the build kernel.

src/ugrd/fs/test_image.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
__version__ = "0.7.1"
1+
__version__ = "0.8.0"
22

33
from zenlib.util import contains
44

55

6-
@contains('test_flag', 'A test flag must be set to create a test image', raise_exception=True)
6+
@contains("test_flag", "A test flag must be set to create a test image", raise_exception=True)
77
def init_banner(self):
8-
""" Initialize the test image banner, set a random flag if not set. """
9-
self['banner'] = f"echo {self['test_flag']}"
8+
"""Initialize the test image banner, set a random flag if not set."""
9+
self["banner"] = f"echo {self['test_flag']}"
1010

1111

1212
def _allocate_image(self, image_path):
13-
""" Allocate the test image size """
13+
"""Allocate the test image size"""
1414
if image_path.exists():
1515
if self.clean:
1616
self.logger.warning("Removing existing filesystem image file: %s" % image_path)
@@ -20,27 +20,38 @@ def _allocate_image(self, image_path):
2020

2121
with open(image_path, "wb") as f:
2222
self.logger.info("Allocating test image file: %s" % f.name)
23-
f.write(b"\0" * self.test_image_size * 2 ** 20)
23+
f.write(b"\0" * self.test_image_size * 2**20)
2424

2525

2626
def make_test_image(self):
27-
""" Creates a test image from the build dir """
28-
build_dir = self._get_build_path('/').resolve()
27+
"""Creates a test image from the build dir"""
28+
build_dir = self._get_build_path("/").resolve()
2929
self.logger.info("Creating test image from: %s" % build_dir)
3030

31-
rootfs_uuid = self['mounts']['root']['uuid']
32-
rootfs_type = self['mounts']['root']['type']
31+
rootfs_uuid = self["mounts"]["root"]["uuid"]
32+
rootfs_type = self["mounts"]["root"]["type"]
3333

34-
image_path = self._get_out_path(self['out_file'])
35-
if rootfs_type == 'ext4':
34+
image_path = self._get_out_path(self["out_file"])
35+
if rootfs_type == "ext4":
3636
# Create the test image file, flll with 0s
3737
_allocate_image(self, image_path)
38-
self._run(['mkfs', '-t', rootfs_type, '-d', build_dir, '-U', rootfs_uuid, '-F', image_path])
39-
elif rootfs_type == 'btrfs':
40-
if self['clean'] and image_path.exists():
38+
self._run(["mkfs", "-t", rootfs_type, "-d", build_dir, "-U", rootfs_uuid, "-F", image_path])
39+
elif rootfs_type == "btrfs":
40+
if self["clean"] and image_path.exists():
4141
self.logger.warning("Removing existing test image file: %s" % image_path)
4242
image_path.unlink()
43-
self._run(['mkfs', '-t', rootfs_type, '-f', '--rootdir', build_dir, '-U', rootfs_uuid, image_path])
43+
self._run(["mkfs", "-t", rootfs_type, "-f", "--rootdir", build_dir, "-U", rootfs_uuid, image_path])
44+
elif rootfs_type == "xfs":
45+
_allocate_image(self, image_path)
46+
self._run(["mkfs", "-t", rootfs_type, "-m", "uuid=%s" % rootfs_uuid, image_path])
47+
try: # XFS doesn't support importing a directory as a filesystem, it must be mounted
48+
from tempfile import TemporaryDirectory
49+
50+
with TemporaryDirectory() as tmp_dir:
51+
self._run(["mount", image_path, tmp_dir])
52+
self._run(["cp", "-a", f"{build_dir}/.", tmp_dir])
53+
self._run(["umount", tmp_dir])
54+
except RuntimeError as e:
55+
raise RuntimeError("Could not mount the XFS test image: %s", e)
4456
else:
45-
raise Exception("Unsupported test rootfs type: %s" % rootfs_type)
46-
57+
raise NotImplementedError("Unsupported test rootfs type: %s" % rootfs_type)

tests/fs/btrfs.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# BTRFS test
2+
modules = [ "ugrd.base.test" ]
3+
4+
out_dir = "initramfs_test"
5+
6+
cpio_compression = false
7+
hostonly = false
8+
9+
[mounts.root]
10+
uuid = "aaaabbbb-cccc-dddd-eeee-ffff00000000"
11+
type = "btrfs"

tests/ext4.toml renamed to tests/fs/ext4.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
# EXT4 test
22
modules = [ "ugrd.base.test" ]
33

4-
# The initramfs will be built in /tmp/initramfs if "build_dir" is not specified not specified
54
out_dir = "initramfs_test"
6-
75
cpio_compression = false
8-
9-
autodetect_root = false
10-
116
hostonly = false
127

138
[mounts.root]

tests/fs/xfs.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# XFS test
2+
modules = [ "ugrd.base.test" ]
3+
4+
out_dir = "initramfs_test"
5+
6+
cpio_compression = false
7+
hostonly = false
8+
9+
test_image_size = 300 # XFS requires at least 300MB
10+
11+
[mounts.root]
12+
uuid = "aaaabbbb-cccc-dddd-eeee-ffff00000000"
13+
type = "xfs"

tests/test_filesystems.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from unittest import TestCase, main
2+
3+
from ugrd.initramfs_generator import InitramfsGenerator
4+
from zenlib.logging import loggify
5+
6+
7+
@loggify
8+
class TestCpio(TestCase):
9+
def test_ext4(self):
10+
generator = InitramfsGenerator(logger=self.logger, config="tests/fs/ext4.toml")
11+
generator.build()
12+
13+
def test_btrfs(self):
14+
generator = InitramfsGenerator(logger=self.logger, config="tests/fs/btrfs.toml")
15+
generator.build()
16+
17+
def test_xfs(self):
18+
generator = InitramfsGenerator(logger=self.logger, config="tests/fs/xfs.toml")
19+
generator.build()
20+
21+
22+
if __name__ == "__main__":
23+
main()

tests/test_ugrd.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ def test_fullauto(self):
1111
generator = InitramfsGenerator(logger=self.logger, config='tests/fullauto.toml')
1212
generator.build()
1313

14-
def test_ext4(self):
15-
generator = InitramfsGenerator(logger=self.logger, config='tests/ext4.toml')
16-
generator.build()
17-
1814
def test_xz(self):
1915
generator = InitramfsGenerator(logger=self.logger, config='tests/fullauto.toml', cpio_compression='xz')
2016
generator.build()

0 commit comments

Comments
 (0)