Skip to content

Commit

Permalink
Merge pull request #341 from KKoukiou/fix-available-space-reclaim
Browse files Browse the repository at this point in the history
storage: fix available space in reclaim dialog when parent device is deleted
  • Loading branch information
KKoukiou authored Jul 8, 2024
2 parents ab5ae7e + 481b11a commit 4b5303d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/components/storage/ReclaimSpaceModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { HddIcon, TrashIcon, UndoIcon } from "@patternfly/react-icons";

import { removeDevice } from "../../apis/storage_partitioning_automatic_resizable.js";

import { getDeviceAncestors } from "../../helpers/storage.js";

import { ListingTable } from "cockpit-components-table.jsx";

import { StorageContext } from "../Common.jsx";
Expand Down Expand Up @@ -129,9 +131,15 @@ const ReclaimFooter = ({ isFormDisabled, onClose, onReclaim, unappliedActions })
const devices = useOriginalDevices();
const diskFreeSpace = useDiskFreeSpace({ devices, selectedDisks: diskSelection.selectedDisks });
const requiredSize = useRequiredSize();
const isDeviceRemoved = device => (
unappliedActions[device].includes("remove")
);
const isDeviceParentRemoved = device => (
getDeviceAncestors(devices, device).some(isDeviceRemoved)
);
const selectedSpaceToReclaim = (
Object.keys(unappliedActions)
.filter(device => unappliedActions[device].includes("remove"))
.filter(device => isDeviceRemoved(device) && !isDeviceParentRemoved(device))
.reduce((acc, device) => acc + devices[device].total.v - devices[device].free.v, 0)
);
const status = (diskFreeSpace + selectedSpaceToReclaim) < requiredSize ? "warning" : "success";
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
* @returns {Array}
*/
export const getDeviceAncestors = (deviceData, device) => {
// device ancestors including the device itself
const ancestors = [];
const deviceParents = deviceData[device]?.parents?.v || [];

ancestors.push(device);
deviceParents.forEach(parent => {
ancestors.push(parent);
ancestors.push(...getDeviceAncestors(deviceData, parent));
});

Expand Down
7 changes: 7 additions & 0 deletions test/check-storage-reclaim
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ class TestStorageUseFreeSpaceScenario(anacondalib.VirtInstallMachineCase, Storag
s.reclaim_check_action_present("vda4", "delete", True)
s.reclaim_check_available_space("9.66 GB")

# Check that deleting a parent disk which contains partitions marked for deletion
# correctly calculates the available space
s.reclaim_remove_device("vda (0x")
s.reclaim_check_available_space("16.1 GB")
s.reclaim_undo_action("vda (0x")
s.reclaim_check_available_space("9.66 GB")

s.reclaim_modal_submit()
s.check_encryption_selected(False)
i.reach(i.steps.REVIEW)
Expand Down

0 comments on commit 4b5303d

Please sign in to comment.