Skip to content

Commit 4fff45f

Browse files
mvollmermartinpitt
authored andcommitted
storage: Always round dialog size slider input
Otherwise we will very likely pass a non-integer number to the D-Bus call, which will fail. This affects the size slider for new partitions, and without this fix, setting a size for a new partition with the slider will cause a unhelpful error message. Closes cockpit-project#10968
1 parent f509d06 commit 4fff45f

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

pkg/storaged/dialog.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@ class SizeSliderElement extends React.Component {
807807
value = round(value);
808808
else
809809
value = Math.round(value / round) * round;
810+
} else {
811+
// Only produce integers by default
812+
value = Math.round(value);
810813
}
811814

812815
onChange(Math.max(min, value));

test/verify/check-storage-partitions

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,45 @@ class TestStorage(StorageCase):
6161
self.confirm()
6262
self.content_row_wait_in_col(1, 1, "Free Space")
6363

64+
def testSizeSlider(self):
65+
m = self.machine
66+
b = self.browser
67+
68+
self.login_and_go("/storage")
69+
b.wait_in_text("#drives", "VirtIO")
70+
71+
m.add_disk("50M", serial="DISK1")
72+
b.wait_in_text("#drives", "DISK1")
73+
b.click('#drives tr:contains("DISK1")')
74+
b.wait_present('#storage-detail')
75+
76+
b.wait_visible('button:contains(Create partition table)')
77+
b.click('button:contains(Create partition table)')
78+
self.dialog({"type": "gpt"})
79+
self.content_row_wait_in_col(1, 1, "Free Space")
80+
81+
self.content_row_action(1, "Create Partition")
82+
self.dialog_wait_open()
83+
self.dialog_set_val("type", "empty")
84+
85+
slider = self.dialog_field("size") + " .slider"
86+
87+
# Move the slider one pixel past the middle, this should give a fractional size.
88+
# See https://github.com/cockpit-project/cockpit/pull/10968 for more about this.
89+
width = b.call_js_func('(function (sel) { return ph_find(sel).offsetWidth; })', slider)
90+
about_half_way = width / 2 + 1
91+
92+
b.mouse(slider, "mousedown", about_half_way, 0)
93+
b.mouse(slider, "mouseup", about_half_way, 0)
94+
self.dialog_wait_val("size", 25.1)
95+
96+
self.dialog_apply()
97+
self.dialog_wait_close()
98+
99+
# With old Udisks2 versions, the partition will end up being
100+
# 25.1M while newer versions give us 26M.
101+
wait(lambda: m.execute("lsblk -no SIZE /dev/sda1").strip() in ["25.1M", "26M"])
102+
64103

65104
if __name__ == '__main__':
66105
test_main()

0 commit comments

Comments
 (0)