Skip to content

Commit

Permalink
storage: provide list of required mount points
Browse files Browse the repository at this point in the history
Add GetRecommendedMountPoints.
  • Loading branch information
rvykydal committed Dec 11, 2023
1 parent deb5e07 commit 1f8f2a3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 17 deletions.
6 changes: 2 additions & 4 deletions pyanaconda/modules/common/structures/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,8 @@ def get_root_device(self):
return self.mount_points.get("/")


class RequiredMountPointData(DBusData):
"""Constrains (filesystem and device types allowed) for mount points required
for the installed system
"""
class MountPointConstraintsData(DBusData):
"""Constrains (filesystem and device types allowed) for mount points"""

def __init__(self):
self._mount_point = ""
Expand Down
31 changes: 24 additions & 7 deletions pyanaconda/modules/storage/devicetree/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pyanaconda.core.i18n import _
from pyanaconda.modules.common.errors.storage import UnknownDeviceError
from pyanaconda.modules.common.structures.storage import DeviceData, DeviceActionData, \
DeviceFormatData, OSData, RequiredMountPointData
DeviceFormatData, OSData, MountPointConstraintsData
from pyanaconda.modules.storage.devicetree.utils import get_required_device_size, \
get_supported_filesystems
from pyanaconda.modules.storage.platform import platform
Expand Down Expand Up @@ -466,9 +466,9 @@ def _get_platform_mount_point_data(self, spec):
"""Get the mount point data.
:param spec: an instance of PartSpec
:return: an instance of RequiredMountPointData
:return: an instance of MountPointConstraintsData
"""
data = RequiredMountPointData()
data = MountPointConstraintsData()
data.mount_point = spec.mountpoint or ""
data.required_filesystem_type = spec.fstype or ""
data.encryption_allowed = spec.encrypted
Expand All @@ -479,16 +479,33 @@ def _get_platform_mount_point_data(self, spec):
def get_required_mount_points(self):
"""Get list of required mount points for the current platform
This includes mount points required to boot (e.g. /boot and /boot/efi)
This includes mount points required to boot (e.g. /boot/efi)
and the / partition which is always considered to be required.
:return: a list of mount points
FIXME in general /boot is not required, just recommended. Depending on
the filesystem on the root partition it may be required (ie crypted
root).
:return: a list of mount points with its constraints
"""
root_partition = PartSpec(mountpoint="/", lv=True, thin=True, encrypted=True)
ret = list(map(self._get_platform_mount_point_data,
[p for p in platform.partitions if p.mountpoint and p.mountpoint != "/boot"]
+ [root_partition]))
return ret

def get_recommended_mount_points(self):
"""Get list of recommended mount points for the current platform
Currently it contains only /boot partition if it is default the for
platform.
:return: a list of mount points with its constraints
"""
# FIXME in general /boot is not required, just recommended. Depending
# on the filesystem on the root partition it may be required (ie
# crypted root).
recommended = ["/boot"]
ret = list(map(self._get_platform_mount_point_data,
[p for p in platform.partitions if p.mountpoint and p.mountpoint != "/boot"]
+ [root_partition]))
[p for p in platform.partitions if p.mountpoint in recommended]))
return ret
23 changes: 19 additions & 4 deletions pyanaconda/modules/storage/devicetree/viewer_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from dasbus.typing import * # pylint: disable=wildcard-import
from pyanaconda.modules.common.constants.interfaces import DEVICE_TREE_VIEWER
from pyanaconda.modules.common.structures.storage import DeviceData, DeviceActionData, \
DeviceFormatData, OSData, RequiredMountPointData
DeviceFormatData, OSData, MountPointConstraintsData

__all__ = ["DeviceTreeViewerInterface"]

Expand Down Expand Up @@ -196,10 +196,25 @@ def GetExistingSystems(self) -> List[Structure]:
def GetRequiredMountPoints(self) -> List[Structure]:
"""Get list of required mount points for the current platform
This includes mount points required to boot (e.g. /boot and /boot/efi)
This includes mount points required to boot (e.g. /boot/efi)
and the / partition which is always considered to be required.
:return: a list of mount points
FIXME in general /boot is not required, just recommended. Depending on
the filesystem on the root partition it may be required (ie crypted
root).
:return: a list of mount points with its constraints
"""
return RequiredMountPointData.to_structure_list(
return MountPointConstraintsData.to_structure_list(
self.implementation.get_required_mount_points())

def GetRecommendedMountPoints(self) -> List[Structure]:
"""Get list of recommended mount points for the current platform
Currently it contains only /boot partition if it is default the for
platform.
:return: a list of mount points with its constraints
"""
return MountPointConstraintsData.to_structure_list(
self.implementation.get_recommended_mount_points())
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from dasbus.typing import * # pylint: disable=wildcard-import
from pyanaconda.core.kernel import KernelArguments
from pyanaconda.modules.common.errors.storage import UnknownDeviceError, MountFilesystemError
from pyanaconda.modules.common.structures.storage import DeviceFormatData, RequiredMountPointData
from pyanaconda.modules.common.structures.storage import DeviceFormatData, \
MountPointConstraintsData
from pyanaconda.modules.storage.devicetree import DeviceTreeModule, create_storage, utils
from pyanaconda.modules.storage.devicetree.devicetree_interface import DeviceTreeInterface
from pyanaconda.modules.storage.devicetree.populate import FindDevicesTask
Expand Down Expand Up @@ -835,7 +836,9 @@ def test_get_required_mount_points(self):
assert isinstance(result, list)
assert len(result) != 0

result = RequiredMountPointData.from_structure_list(self.interface.GetRequiredMountPoints())
result = MountPointConstraintsData.from_structure_list(
self.interface.GetRequiredMountPoints()
)
for mp in result:
assert mp.mount_point is not None
assert mp.required_filesystem_type is not None
Expand All @@ -848,6 +851,19 @@ def test_get_required_mount_points(self):
assert root.mount_point == "/"
assert root.required_filesystem_type == ""

def test_get_recommended_mount_points(self):
"""Test GetRecommendedMountPoints."""
result = self.interface.GetRecommendedMountPoints()
assert isinstance(result, list)
assert len(result) == 1

result = MountPointConstraintsData.from_structure_list(self.interface.GetRecommendedMountPoints())
boot = result[0]
assert boot is not None
assert boot.encryption_allowed is False
assert boot.logical_volume_allowed is False
assert boot.mount_point == "/boot"
assert boot.required_filesystem_type == ""

class DeviceTreeTasksTestCase(unittest.TestCase):
"""Test the storage tasks."""
Expand Down

0 comments on commit 1f8f2a3

Please sign in to comment.