Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check fstab raid names #95

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pleskdistup/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .extensions import *
from .grub import *
from .mariadb import *
from .mounts import *
from .packages import *
from .plesk import *
from .spamassassin import *
Expand Down
24 changes: 1 addition & 23 deletions pleskdistup/actions/common_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import typing
from abc import abstractmethod

from pleskdistup.common import action, log, mounts, packages, php, plesk, version
from pleskdistup.common import action, log, packages, php, plesk, version


# This action should be considered as deprecated
Expand Down Expand Up @@ -677,25 +677,3 @@ def _do_check(self) -> bool:
return True

return False


class AssertFstabOrderingIsFine(action.CheckAction):
FSTAB_PATH: str = "/etc/fstab"

def __init__(self):
self.name = "checking if /etc/fstab is ordered properly"
self.description = """The /etc/fstab file entries is not ordered properly.
\t- {}"""

def _do_check(self) -> bool:
if not os.path.exists(self.FSTAB_PATH):
# Might be a problem, but it is not something we checking in scope of this check
return True

misorderings = mounts.get_fstab_configuration_misorderings(self.FSTAB_PATH)

if len(misorderings) == 0:
return True

self.description = self.description.format("\n\t- ".join([f"Mount point {mount_point} should be placed after {parent_dir}" for parent_dir, mount_point in misorderings]))
return False
64 changes: 64 additions & 0 deletions pleskdistup/actions/mounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2023-2024. WebPros International GmbH. All rights reserved.

import os

from pleskdistup.common import action, mounts

ukablan-wpc marked this conversation as resolved.
Show resolved Hide resolved

FSTAB_PATH: str = "/etc/fstab"


class AssertFstabOrderingIsFine(action.CheckAction):
def __init__(self):
self.name = "checking if /etc/fstab is ordered properly"
self.description = """The /etc/fstab file entries is not ordered properly.
\t- {}"""

def _do_check(self) -> bool:
if not os.path.exists(FSTAB_PATH):
# Might be a problem, but it is not something we checking in scope of this check
return True

misorderings = mounts.get_fstab_configuration_misorderings(FSTAB_PATH)

if len(misorderings) == 0:
return True

self.description = self.description.format("\n\t- ".join([f"Mount point {mount_point} should be placed after {parent_dir}" for parent_dir, mount_point in misorderings]))
return False


class AssertFstabHasDirectRaidDevices(action.CheckAction):
allow_raid_devices: bool

def __init__(self, allow_raid_devices: bool = False):
self.allow_raid_devices = allow_raid_devices
self.name = "checking if /etc/fstab has direct RAID devices"
self.description = """The /etc/fstab file has direct RAID devices entries.
A RAID device could be renamed after the conversion which will lead to unable to mount the device.
Potentially it could make the system unbootable.
To fix the issue, replace following direct RAID devices with the UUID:
\t- {}

Or you could skip the check by calling the tool with --allow-raid-devices option.
"""

def _do_check(self) -> bool:
if self.allow_raid_devices:
return True

if not os.path.exists(FSTAB_PATH):
# Might be a problem, but it is not something we checking in scope of this check
return True

raid_devices_in_fstab = []
with open(FSTAB_PATH, "r") as fstab_file:
for line in fstab_file.readlines():
if line.startswith("/dev/md"):
raid_devices_in_fstab.append(line.rstrip())

if len(raid_devices_in_fstab) == 0:
return True

self.description = self.description.format("\n\t- ".join(raid_devices_in_fstab))
return False
2 changes: 1 addition & 1 deletion pleskdistup/common/src/mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_fstab_configuration_misorderings(configpath: str) -> typing.List[typing.

misorderings: typing.List[typing.Tuple[str, str]] = []
for mount_point in mount_points_order.keys():
if mount_point == "/":
if mount_point == "/" or not mount_point.startswith("/"):
continue

parent_dir: str = mount_point
Expand Down
9 changes: 9 additions & 0 deletions pleskdistup/common/tests/mountstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,12 @@ def test_file_without_root(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), [("/home", "/home/test")])

def test_mount_point_is_swap(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 swap swap defaults 0 1\n")
f.write("/dev/sda4 /home ext4 defaults 0 1\n")

self.assertEqual(mounts.get_fstab_configuration_misorderings(self.test_file_path), [])
Loading