Skip to content

Commit

Permalink
storage: add a new more generic API for mount point constraints
Browse files Browse the repository at this point in the history
Instead of adding GetRecommendedMountPoints to GetRequiredMountpoints
replace the both with a bit more generic GetMountPointConstraints
that would add recommended/required flag to the constraints.
  • Loading branch information
rvykydal committed Dec 11, 2023
1 parent 224d885 commit 910ebf6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pyanaconda/modules/common/structures/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ def __init__(self):
self._required_filesystem_type = ""
self._encryption_allowed = False
self._logical_volume_allowed = False
self._required = False
self._recommended = False

@property
def mount_point(self) -> Str:
Expand Down Expand Up @@ -506,3 +508,27 @@ def logical_volume_allowed(self) -> Bool:
@logical_volume_allowed.setter
def logical_volume_allowed(self, logical_volume_allowed: Bool):
self._logical_volume_allowed = logical_volume_allowed

@property
def required(self) -> Bool:
"""Whether this mount point is required
:return: bool
"""
return self._required

@required.setter
def required(self, required: Bool):
self._required = required

@property
def recommended(self) -> Bool:
"""Whether this mount point is recommended
:return: bool
"""
return self._recommended

@recommended.setter
def recommended(self, recommended: Bool):
self._recommended = recommended
48 changes: 48 additions & 0 deletions pyanaconda/modules/storage/devicetree/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,54 @@ def _get_os_data(self, root):
}
return data

def _get_mount_point_constraints_data(self, spec):
"""Get the mount point data.
:param spec: an instance of PartSpec
:return: an instance of MountPointConstraintsData
"""
data = MountPointConstraintsData()
data.mount_point = spec.mountpoint or ""
data.required_filesystem_type = spec.fstype or ""
data.encryption_allowed = spec.encrypted
data.logical_volume_allowed = spec.lv

return data

def get_mount_point_constraints(self):
"""Get list of constraints on mountpoints for the current platform
Also provides hints if the partition is required or recommended.
This includes mount points required to boot (e.g. /boot/efi, /boot)
and the / partition which is always considered to be required.
FIXME /boot can be required in some cases, depending on the filesystem
on the root partition (ie crypted root).
:return: a list of mount points with its constraints
"""

constraints = []

# Root partition is required
root_partition = PartSpec(mountpoint="/", lv=True, thin=True, encrypted=True)
root_constraint = self._get_mount_point_constraints_data(root_partition)
root_constraint.required = True
constraints.append(root_constraint)

# Platform partitions are required except for /boot partiotion which is recommended
for p in platform.partitions:
if p.mountpoint:
constraint = self._get_mount_point_constraints_data(p)
if p.mountpoint == "/boot":
constraint.recommended = True
else:
constraint.required = True
constraints.append(constraint)

return constraints

def _get_platform_mount_point_data(self, spec):
"""Get the mount point data.
Expand Down
14 changes: 14 additions & 0 deletions pyanaconda/modules/storage/devicetree/viewer_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ def GetExistingSystems(self) -> List[Structure]:
"""
return OSData.to_structure_list(self.implementation.get_existing_systems())

# FIXME: remove the replaced API
def GetMountPointConstraints(self) -> List[Structure]:
"""Get list of constraints on mountpoints for the current platform
Also provides hints if the partition is required or recommended.
This includes mount points required to boot (e.g. /boot/efi, /boot)
and the / partition which is always considered to be required.
:return: a list of mount points with its constraints
"""
return MountPointConstraintsData.to_structure_list(
self.implementation.get_mount_point_constraints())

def GetRequiredMountPoints(self) -> List[Structure]:
"""Get list of required mount points for the current platform
Expand Down

0 comments on commit 910ebf6

Please sign in to comment.