From 953f87870ab8f60cc3b98875f4c38870268434a2 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Tue, 26 Nov 2024 10:11:39 +0200 Subject: [PATCH] fixup! fixup! fixup! Add a preliminary checker to ensure the mount points in /etc/fstab are in the correct order --- pleskdistup/common/src/mounts.py | 2 +- pleskdistup/common/tests/mountstests.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pleskdistup/common/src/mounts.py b/pleskdistup/common/src/mounts.py index 3a0c213..73e22ae 100644 --- a/pleskdistup/common/src/mounts.py +++ b/pleskdistup/common/src/mounts.py @@ -35,7 +35,7 @@ def get_fstab_configuration_misorderings(configpath: str) -> typing.List[typing. if mount_point == "/": continue - if mount_points_order["/"] > mount_points_order[mount_point]: + if "/" in mount_points_order and mount_points_order["/"] > mount_points_order[mount_point]: misorderings.append(("/", mount_point)) parant_dir = os.path.dirname(mount_point) diff --git a/pleskdistup/common/tests/mountstests.py b/pleskdistup/common/tests/mountstests.py index c9d075e..ea6aabc 100644 --- a/pleskdistup/common/tests/mountstests.py +++ b/pleskdistup/common/tests/mountstests.py @@ -70,3 +70,14 @@ def test_several_different_misorderings(self): f.write("devpts /dev/pts devpts gid=5,mode=620 0 0\n") f.write("tmpfs /dev/shm tmpfs defaults 0 0\n") self.assertEqual(mounts.get_fstab_configuration_misorderings(self.test_file_path), [("/", "/var"), ("/home", "/home/test")]) + + def test_file_without_root(self): + with open(self.test_file_path, "w") as f: + f.write("# comment\n") + f.write("/dev/sda2 /var ext4 defaults 0 1\n") + f.write("/dev/sda5 /home/test ext4 defaults 0 1\n") + f.write("/dev/sda4 /home ext4 defaults 0 1\n") + f.write("proc /proc proc defaults 0 0\n") + f.write("devpts /dev/pts devpts gid=5,mode=620 0 0\n") + f.write("tmpfs /dev/shm tmpfs defaults 0 0\n") + self.assertEqual(mounts.get_fstab_configuration_misorderings(self.test_file_path), [("/home", "/home/test")])