Skip to content

Commit

Permalink
Merge pull request #5078 from KKoukiou/webui-rescan-no-unselect
Browse files Browse the repository at this point in the history
webui: When re-scanning don't reset disk selection
  • Loading branch information
KKoukiou committed Sep 4, 2023
2 parents bdaed22 + 19dc11f commit 70c7b06
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
13 changes: 6 additions & 7 deletions ui/webui/src/components/storage/InstallationMethod.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ const N_ = cockpit.noop;
/**
* Select default disks for the partitioning.
*
* If there are some disks already selected, do nothing.
* If there are some usable disks already selected, show these.
* In the automatic installation, select all disks. In
* the interactive installation, select a disk if there
* is only one available.
* @return: the list of selected disks
*/
const selectDefaultDisks = ({ ignoredDisks, selectedDisks, usableDisks }) => {
if (selectedDisks.length) {
// Do nothing if there are some disks selected
if (selectedDisks.length && selectedDisks.some(disk => usableDisks.includes(disk))) {
// Filter the selection by checking the usable disks if there are some disks selected
console.log("Selecting disks selected in backend:", selectedDisks.join(","));
return selectedDisks;
return selectedDisks.filter(disk => usableDisks.includes(disk));
} else {
const availableDisks = usableDisks.filter(disk => !ignoredDisks.includes(disk));
console.log("Selecting one or less disks by default:", availableDisks.join(","));
Expand Down Expand Up @@ -307,7 +307,6 @@ const InstallationDestination = ({ deviceData, diskSelection, dispatch, idPrefix
if (refUsableDisks.current !== undefined) {
return;
}
refUsableDisks.current = diskSelection.usableDisks;

const defaultDisks = selectDefaultDisks({
ignoredDisks: diskSelection.ignoredDisks,
Expand Down Expand Up @@ -343,7 +342,7 @@ const InstallationDestination = ({ deviceData, diskSelection, dispatch, idPrefix
icon={<SyncAltIcon />}
onClick={() => {
setIsRescanningDisks(true);
setSelectedDisks({ drives: [] });
refUsableDisks.current = undefined;
scanDevicesWithTask()
.then(res => {
return runStorageTask({
Expand Down Expand Up @@ -374,7 +373,7 @@ const InstallationDestination = ({ deviceData, diskSelection, dispatch, idPrefix
/>
);

const equalDisks = refUsableDisks.current && containEqualDisks(refUsableDisks.current, diskSelection.usableDisks);
const equalDisks = !refUsableDisks.current || containEqualDisks(refUsableDisks.current, diskSelection.usableDisks);
const headingLevel = isBootIso ? "h2" : "h3";

return (
Expand Down
19 changes: 11 additions & 8 deletions ui/webui/test/check-storage
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):
s.rescan_disks()

# Check that the disk selection persists when moving next and back
s.select_disk("vda", True)
s.check_disk_selected("vda", True)
i.next()
i.back()
s.check_disk_selected("vda", True)
Expand Down Expand Up @@ -287,24 +287,26 @@ class TestStorageExtraDisks(anacondalib.VirtInstallMachineCase, StorageHelpers):
s.check_single_disk_destination("vda")

s.rescan_disks()

s.check_disk_visible("vda")
s.check_disk_visible(dev)

s.wait_no_disks_detected_not_present()

s.check_disk_selected("vda", False)
s.check_disk_selected("vda", True)
s.check_disk_selected(dev, False)

s.rescan_disks()
s.wait_no_disks_detected()

s.check_disk_selected("vda", True)
s.check_disk_selected(dev, False)

s.select_disk(dev)

# Check that disk selection is kept on Next and Back
disks = ["vda"]
for disk in disks:
s.select_disk(disk)
i.next()
i.back()
for disk in disks:
for disk in ["vda", dev]:
s.check_disk_selected(disk)

class TestUtils():
Expand All @@ -324,7 +326,7 @@ class TestUtils():
b.wait(lambda : self.disks_loaded(s, disks))

for disk in disks:
current_selection = s.get_disk_selected(disk)
current_selection = s.get_disk_selected(disk[0])
if current_selection != disk[1]:
s.select_disk(disk[0], disk[1], len(disks) == 1)

Expand Down Expand Up @@ -556,6 +558,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, TestUtils):
# Select first only vdb disk and verify that the partitioning request is correct
i.open()
i.next()

s.rescan_disks()

self.select_mountpoint(b, i, s, [(dev1, False), (dev2, True)])
Expand Down
8 changes: 6 additions & 2 deletions ui/webui/test/helpers/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def check_disk_selected(self, disk, selected=True):
self.browser.wait_not_present(f"#{id_prefix}-selector-form li.pf-v5-c-chip-group__list-item:contains({disk})")

def get_disk_selected(self, disk):
return self.browser.is_present(f"#{id_prefix}-selector-form li.pf-v5-c-chip-group__list-item:contains({disk})")
return (
self.browser.is_present(f"#{id_prefix}-selector-form li.pf-v5-c-chip-group__list-item:contains({disk})") or
(self.browser.is_present(f"#{id_prefix}-target-disk") and
disk in self.browser.text(f"#{id_prefix}-target-disk"))
)

@log_step()
def wait_no_disks(self):
Expand Down Expand Up @@ -169,6 +173,7 @@ def dbus_set_initialization_mode(self, value):
@log_step(snapshots=True)
def rescan_disks(self):
self.browser.click(f"#{self._step}-rescan-disks")
self.browser.wait_not_present(f"#{self._step}-rescan-disks.pf-m-disabled")

@log_step(snapshot_before=True)
def check_disk_visible(self, disk, visible=True):
Expand Down Expand Up @@ -281,7 +286,6 @@ def add_basic_partitioning(self, target="vda", size="1GiB"):
# Add a partition for "Use free space" scenario to be present
self.machine.execute(f"sgdisk --new=0:0:+{size} /dev/{target}")
self.rescan_disks()
self.select_disk(target, True, True)

# partitions_params expected structure: [("size", "file system" {, "other mkfs.fs flags"})]
def partition_disk(self, disk, partitions_params):
Expand Down

0 comments on commit 70c7b06

Please sign in to comment.