Skip to content

Commit

Permalink
webui: Get the required mountpoints from the backend
Browse files Browse the repository at this point in the history
We now have a backend function to get list of mount points
required for mount point assignment.
  • Loading branch information
vojtechtrefny committed Sep 4, 2023
1 parent 90fb4cd commit debe428
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
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
13 changes: 12 additions & 1 deletion ui/webui/src/components/AnacondaWizard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { usePageLocation } from "hooks";
import {
applyStorage,
resetPartitioning,
getRequiredMountPoints,
} from "../apis/storage.js";

const _ = cockpit.gettext;
Expand All @@ -60,11 +61,21 @@ export const AnacondaWizard = ({ dispatch, isBootIso, osRelease, storageData, lo
const [storageEncryption, setStorageEncryption] = useState(getStorageEncryptionState());
const [storageScenarioId, setStorageScenarioId] = useState(window.sessionStorage.getItem("storage-scenario-id") || getDefaultScenario().id);
const [reusePartitioning, setReusePartitioning] = useState(false);
const [requiredMountPoints, setRequiredMountPoints] = useState();

const availableDevices = useMemo(() => {
return Object.keys(storageData.devices);
}, [storageData.devices]);

useEffect(() => {
const updateRequiredMountPoints = async () => {
const requiredMountPoints = await getRequiredMountPoints().catch(console.error);

setRequiredMountPoints(requiredMountPoints);
};
updateRequiredMountPoints();
}, []);

useEffect(() => {
/*
* When disk selection changes or the user re-scans the devices we need to re-create the partitioning.
Expand Down Expand Up @@ -103,7 +114,7 @@ export const AnacondaWizard = ({ dispatch, isBootIso, osRelease, storageData, lo
label: _("Disk configuration"),
steps: [{
component: MountPointMapping,
data: { deviceData: storageData.devices, diskSelection: storageData.diskSelection, partitioningData: storageData.partitioning, dispatch, reusePartitioning, setReusePartitioning },
data: { deviceData: storageData.devices, diskSelection: storageData.diskSelection, partitioningData: storageData.partitioning, requiredMountPoints, dispatch, reusePartitioning, setReusePartitioning },
id: "mount-point-mapping",
label: _("Manual disk configuration"),
isHidden: storageScenarioId !== "mount-point-mapping"
Expand Down
23 changes: 6 additions & 17 deletions ui/webui/src/components/storage/MountPointMapping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ const getInitialRequests = (usablePartitioningRequests, requiredMountPoints) =>
const bootEfiOriginalRequest = usablePartitioningRequests.find(r => r["mount-point"] === "/boot/efi");

const requests = requiredMountPoints.map((mountPoint, idx) => {
const request = ({ "mount-point": mountPoint.value, reformat: mountPoint.name === "root" });
const request = ({ "mount-point": mountPoint.value.v, reformat: mountPoint.value.v === "/" });

if (mountPoint.name === "boot" && bootOriginalRequest) {
if (mountPoint.value.v === "/boot" && bootOriginalRequest) {
return { ...bootOriginalRequest, ...request };
}

if (mountPoint.name === "root" && rootOriginalRequest) {
if (mountPoint.value.v === "/" && rootOriginalRequest) {
return { ...rootOriginalRequest, ...request };
}

if (mountPoint.name === "boot-efi" && bootEfiOriginalRequest) {
if (mountPoint.value.v === "/boot/efi" && bootEfiOriginalRequest) {
return { ...bootEfiOriginalRequest, ...request };
}

Expand Down Expand Up @@ -358,7 +358,7 @@ const RequestsTable = ({
}) => {
const columnClassName = idPrefix + "__column";
const getRequestRow = (request) => {
const isRequiredMountPoint = !!requiredMountPoints.find(val => val.value === request["mount-point"]);
const isRequiredMountPoint = !!requiredMountPoints.find(val => val.value.v === request["mount-point"]);
const duplicatedMountPoint = isDuplicateRequestField(requests, "mount-point", request["mount-point"]);
const rowId = idPrefix + "-row-" + request["request-id"];

Expand Down Expand Up @@ -570,19 +570,8 @@ const MountPointMappingContent = ({ deviceData, partitioningData, usablePartitio
}
};

export const MountPointMapping = ({ deviceData, diskSelection, partitioningData, dispatch, idPrefix, setIsFormValid, onAddErrorNotification, reusePartitioning, setReusePartitioning, stepNotification }) => {
export const MountPointMapping = ({ deviceData, diskSelection, partitioningData, requiredMountPoints, dispatch, idPrefix, setIsFormValid, onAddErrorNotification, reusePartitioning, setReusePartitioning, stepNotification }) => {
const [usedPartitioning, setUsedPartitioning] = useState(partitioningData?.path);
const requiredMountPoints = useMemo(() => {
const mounts = [
{ value: "/boot", name: "boot" },
{ value: "/", name: "root" },
];

cockpit.spawn(["ls", "/sys/firmware/efi"], { err: "ignore" })
.then(() => { mounts.push({ value: "/boot/efi", name: "boot-efi" }) });

return mounts;
}, []);

const isUsableDevice = (devSpec, deviceData) => {
const device = deviceData[devSpec];
Expand Down
22 changes: 11 additions & 11 deletions ui/webui/test/check-storage
Original file line number Diff line number Diff line change
Expand Up @@ -955,23 +955,23 @@ class TestStorageMountPointsEFI(anacondalib.VirtInstallMachineCase, TestUtils):

# verify gathered requests
# root partition is not auto-mapped
self.check_row_mountpoint(b, 1, "/boot")
self.check_row_mountpoint(b, 1, "/boot/efi")
self.check_row_device(b, 1, "Select a device")
self.check_reformat(b, 1, False)
self.select_row_device(b, 1, f"{dev}2")
self.check_format_type(b, 1, "ext4")
self.select_row_device(b, 1, f"{dev}1")
self.check_format_type(b, 1, "EFI System Partition")

self.check_row_mountpoint(b, 2, "/")
self.check_row_mountpoint(b, 2, "/boot")
self.check_row_device(b, 2, "Select a device")
self.check_reformat(b, 2, True)
self.select_row_device(b, 2, f"{dev}3")
self.check_format_type(b, 2, "xfs")
self.check_reformat(b, 2, False)
self.select_row_device(b, 2, f"{dev}2")
self.check_format_type(b, 2, "ext4")

self.check_row_mountpoint(b, 3, "/boot/efi")
self.check_row_mountpoint(b, 3, "/")
self.check_row_device(b, 3, "Select a device")
self.check_reformat(b, 3, False)
self.select_row_device(b, 3, f"{dev}1")
self.check_format_type(b, 3, "EFI System Partition")
self.check_reformat(b, 3, True)
self.select_row_device(b, 3, f"{dev}3")
self.check_format_type(b, 3, "xfs")

i.next()

Expand Down

0 comments on commit debe428

Please sign in to comment.