Skip to content

Commit

Permalink
Webui: Port deprecated components in Patternfly 5 to new implementati…
Browse files Browse the repository at this point in the history
…on - Wizard

Get list of required mount points for mount point assignment from backend
  • Loading branch information
vojtechtrefny authored and adamkankovsky committed Sep 25, 2023
2 parents 2a0c987 + d481ba2 commit 1b1413f
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 246 deletions.
60 changes: 60 additions & 0 deletions pyanaconda/modules/common/structures/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,63 @@ def get_root_device(self):
:return: a device name or None
"""
return self.mount_points.get("/")


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

def __init__(self):
self._mount_point = ""
self._required_filesystem_type = ""
self._encryption_allowed = False
self._logical_volume_allowed = False

@property
def mount_point(self) -> Str:
"""Mount point value, e.g. /boot/efi
:return: a string with mount point
"""
return self._mount_point

@mount_point.setter
def mount_point(self, mount_point: Str):
self._mount_point = mount_point

@property
def required_filesystem_type(self) -> Str:
"""Filesystem type required for mount point
:return: a string with filesystem type required for this mount point
"""
return self._required_filesystem_type

@required_filesystem_type.setter
def required_filesystem_type(self, required_filesystem_type: Str):
self._required_filesystem_type = required_filesystem_type

@property
def encryption_allowed(self) -> Bool:
"""Whether this mount point can be encrypted or not
:return: bool
"""
return self._encryption_allowed

@encryption_allowed.setter
def encryption_allowed(self, encryption_allowed: Bool):
self._encryption_allowed = encryption_allowed

@property
def logical_volume_allowed(self) -> Bool:
"""Whether this mount point can be a LVM logical volume or not
:return: bool
"""
return self._logical_volume_allowed

@logical_volume_allowed.setter
def logical_volume_allowed(self, logical_volume_allowed: Bool):
self._logical_volume_allowed = logical_volume_allowed
31 changes: 30 additions & 1 deletion pyanaconda/modules/storage/devicetree/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
from pyanaconda.core.i18n import _
from pyanaconda.modules.common.errors.storage import UnknownDeviceError
from pyanaconda.modules.common.structures.storage import DeviceData, DeviceActionData, \
DeviceFormatData, OSData
DeviceFormatData, OSData, RequiredMountPointData
from pyanaconda.modules.storage.devicetree.utils import get_required_device_size, \
get_supported_filesystems
from pyanaconda.modules.storage.platform import platform
from pyanaconda.modules.storage.partitioning.specification import PartSpec

log = get_module_logger(__name__)

Expand Down Expand Up @@ -467,3 +469,30 @@ def _get_os_data(self, root):
path: device.name for path, device in root.mounts.items()
}
return data

def _get_platform_mount_point_data(self, spec):
"""Get the mount point data.
:param spec: an instance of PartSpec
:return: an instance of RequiredMountPointData
"""
data = RequiredMountPointData()
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_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)
and the / partition which is always considered to be required.
:return: a list of mount points
"""
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] + [root_partition]))
return ret
13 changes: 12 additions & 1 deletion 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
DeviceFormatData, OSData, RequiredMountPointData

__all__ = ["DeviceTreeViewerInterface"]

Expand Down Expand Up @@ -192,3 +192,14 @@ def GetExistingSystems(self) -> List[Structure]:
:return: a list of data about found installations
"""
return OSData.to_structure_list(self.implementation.get_existing_systems())

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)
and the / partition which is always considered to be required.
:return: a list of mount points
"""
return RequiredMountPointData.to_structure_list(
self.implementation.get_required_mount_points())
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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
from pyanaconda.modules.common.structures.storage import DeviceFormatData, RequiredMountPointData
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 @@ -849,6 +849,25 @@ def test_set_device_mount_options(self):
self.interface.SetDeviceMountOptions("dev1", "")
assert dev1.format.options == "defaults"

def test_get_required_mount_points(self):
"""Test GetRequiredMountPoints."""
result = self.interface.GetRequiredMountPoints()
assert isinstance(result, list)
assert len(result) != 0

result = RequiredMountPointData.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

# we are always adding / so it's a good candidate for testing
root = next(r for r in result if r.mount_point == "/")
assert root is not None
assert root.encryption_allowed is True
assert root.logical_volume_allowed is True
assert root.mount_point == "/"
assert root.required_filesystem_type == ""


class DeviceTreeTasksTestCase(unittest.TestCase):
"""Test the storage tasks."""
Expand Down
12 changes: 12 additions & 0 deletions ui/webui/src/apis/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ export const getRequiredDeviceSize = ({ requiredSpace }) => {
.then(res => res[0]);
};

/**
* @returns {Promise} List of all mount points required on the platform
*/
export const getRequiredMountPoints = () => {
return new StorageClient().client.call(
"/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree",
"org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Viewer",
"GetRequiredMountPoints", []
)
.then(res => res[0]);
};

/**
* @param {Array[string]} diskNames A list of disk names
*
Expand Down
Loading

0 comments on commit 1b1413f

Please sign in to comment.