| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2015 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
import storagelib |
| 9 |
import testlib |
| 10 |
|
| 11 |
|
| 12 |
@testlib.nondestructive |
| 13 |
class TestStoragePartitions(storagelib.StorageCase): |
| 14 |
|
| 15 |
def testPartitions(self): |
| 16 |
b = self.browser |
| 17 |
|
| 18 |
self.login_and_go("/storage") |
| 19 |
|
| 20 |
# A loopback device ends with a digit and partitions have |
| 21 |
# names like "/dev/loop0p1". Check that the storage stack has |
| 22 |
# no difficulties with that. |
| 23 |
# |
| 24 |
# We are especially careful to use a device name that doesn't |
| 25 |
# end in all zeros, because that would be too easy and |
| 26 |
# wouldn't trigger this bug: |
| 27 |
# |
| 28 |
# https://github.com/storaged-project/storaged/issues/97 |
| 29 |
|
| 30 |
dev = self.add_loopback_disk(10, "loop12") |
| 31 |
self.click_card_row("Storage", name=dev) |
| 32 |
|
| 33 |
self.click_card_dropdown("Block device", "Create partition table") |
| 34 |
self.dialog({"type": "gpt"}) |
| 35 |
b.wait_text(self.card_row_col("GPT partitions", 1, 1), "Free space") |
| 36 |
|
| 37 |
self.click_dropdown(self.card_row("GPT partitions", 1), "Create partition") |
| 38 |
self.dialog({"type": "ext4", |
| 39 |
"mount_point": f"{self.mnt_dir}/foo"}) |
| 40 |
b.wait_text(self.card_row_col("GPT partitions", 1, 3), f"{self.mnt_dir}/foo") |
| 41 |
|
| 42 |
self.click_card_row("GPT partitions", 1) |
| 43 |
self.click_card_dropdown("Partition", "Delete") |
| 44 |
self.confirm() |
| 45 |
b.wait_text(self.card_row_col("GPT partitions", 1, 1), "Free space") |
| 46 |
|
| 47 |
def testSizeSlider(self): |
| 48 |
m = self.machine |
| 49 |
b = self.browser |
| 50 |
|
| 51 |
self.login_and_go("/storage") |
| 52 |
|
| 53 |
disk = self.add_ram_disk() |
| 54 |
self.click_card_row("Storage", name=disk) |
| 55 |
|
| 56 |
self.click_card_dropdown("Solid State Drive", "Create partition table") |
| 57 |
self.dialog({"type": "gpt"}) |
| 58 |
b.wait_text(self.card_row_col("GPT partitions", 1, 1), "Free space") |
| 59 |
|
| 60 |
self.click_dropdown(self.card_row("GPT partitions", 1), "Create partition") |
| 61 |
self.dialog_wait_open() |
| 62 |
self.dialog_set_val("type", "empty") |
| 63 |
|
| 64 |
slider = self.dialog_field("size") + " .pf-v6-c-slider .pf-v6-c-slider__rail" |
| 65 |
|
| 66 |
# Move the slider one pixel past the middle, this should give a fractional size. |
| 67 |
# See https://github.com/cockpit-project/cockpit/pull/10968 for more about this. |
| 68 |
width = b.call_js_func('(function (sel) { return ph_find(sel).offsetWidth; })', slider) |
| 69 |
about_half_way = width / 2 + 1 |
| 70 |
|
| 71 |
b.mouse(slider, "click", about_half_way, 0) |
| 72 |
self.dialog_wait_val("size", 27.3) |
| 73 |
b.focus(slider + " + .pf-v6-c-slider__thumb") |
| 74 |
b.key("ArrowLeft", 5) |
| 75 |
self.dialog_wait_val("size", 26.2) |
| 76 |
|
| 77 |
# Check that changing units doesn't affect the text input |
| 78 |
unit = "1000000000" |
| 79 |
b.select_from_dropdown(".size-unit > select", unit) |
| 80 |
self.dialog_wait_val("size", 26.2, unit) |
| 81 |
|
| 82 |
# Switch the dialog into the mode where it stores separate text and unit |
| 83 |
# instead of a numeric value. |
| 84 |
b.set_input_text(".size-text > input", "26.200001") |
| 85 |
b.select_from_dropdown(".size-unit > select", "1000000000") # GB |
| 86 |
|
| 87 |
# Apply the dialog. This will convert from text+unit back to a |
| 88 |
# correctly rounded numeric value (which is too large). |
| 89 |
|
| 90 |
self.dialog_apply() |
| 91 |
self.dialog_wait_error("size", "Size is too large") |
| 92 |
|
| 93 |
# The text in the input field must not have changed |
| 94 |
b.wait_val(".size-text > input", "26.200001") |
| 95 |
|
| 96 |
# Change unit back to MB. (This must round again, which it |
| 97 |
# didn't always do.) |
| 98 |
b.select_from_dropdown(".size-unit > select", "1000000") # MB |
| 99 |
|
| 100 |
self.dialog_apply() |
| 101 |
self.dialog_wait_close() |
| 102 |
|
| 103 |
testlib.wait(lambda: m.execute(f"lsblk -no SIZE {disk}1").strip() == "25M") |
| 104 |
|
| 105 |
def testResize(self): |
| 106 |
m = self.machine |
| 107 |
b = self.browser |
| 108 |
|
| 109 |
self.login_and_go("/storage") |
| 110 |
|
| 111 |
disk = self.add_ram_disk(100) |
| 112 |
self.click_card_row("Storage", name=disk) |
| 113 |
|
| 114 |
self.click_card_dropdown("Solid State Drive", "Create partition table") |
| 115 |
self.dialog({"type": "gpt"}) |
| 116 |
b.wait_text(self.card_row_col("GPT partitions", 1, 1), "Free space") |
| 117 |
|
| 118 |
# Make two partitions that cover the whole disk. |
| 119 |
|
| 120 |
self.click_dropdown(self.card_row("GPT partitions", 1), "Create partition") |
| 121 |
self.dialog({"type": "ext4", |
| 122 |
"mount_point": f"{self.mnt_dir}/foo1", |
| 123 |
"size": 80}, |
| 124 |
secondary=True) |
| 125 |
self.click_dropdown(self.card_row("GPT partitions", 2), "Create partition") |
| 126 |
self.dialog({"type": "ext4", |
| 127 |
"mount_point": f"{self.mnt_dir}/foo2", |
| 128 |
"size": 23}, |
| 129 |
secondary=True) |
| 130 |
|
| 131 |
b.wait_text(self.card_row_col("GPT partitions", 1, 4), "79.7 MB") |
| 132 |
b.wait_text(self.card_row_col("GPT partitions", 2, 4), "23.1 MB") |
| 133 |
|
| 134 |
# Shrink the first |
| 135 |
self.click_card_row("GPT partitions", 1) |
| 136 |
b.click(self.card_button("Partition", "Shrink")) |
| 137 |
self.dialog({"size": 50}) |
| 138 |
b.wait_in_text(self.card_desc("Partition", "Size"), "50.3 MB") |
| 139 |
|
| 140 |
# Grow it back externally, Cockpit should complain. Shrink it |
| 141 |
# again with Cockpit. |
| 142 |
m.execute(f"parted -s {disk} resizepart 1 80.7MB") |
| 143 |
b.click(self.card_button("Partition", "Shrink partition")) |
| 144 |
b.wait_in_text(self.card_desc("Partition", "Size"), "50.3 MB") |
| 145 |
|
| 146 |
# Grow it back externally again. Grow the filesystem with |
| 147 |
# Cockpit. |
| 148 |
m.execute(f"parted -s {disk} resizepart 1 80.7MB") |
| 149 |
b.click(self.card_button("Partition", "Grow content")) |
| 150 |
b.wait_in_text(self.card_desc("Partition", "Size"), "79.7 MB") |
| 151 |
b.wait_visible(self.card_button("Partition", "Grow") + ":disabled") |
| 152 |
|
| 153 |
# Delete second partition and grow the first to take all the |
| 154 |
# space. |
| 155 |
b.click(self.card_parent_link()) |
| 156 |
self.click_card_row("GPT partitions", 2) |
| 157 |
self.click_card_dropdown("Partition", "Delete") |
| 158 |
self.confirm() |
| 159 |
self.click_card_row("GPT partitions", location=f"{self.mnt_dir}/foo1 (not mounted)") |
| 160 |
b.click(self.card_button("Partition", "Grow")) |
| 161 |
self.dialog({"size": 103}) |
| 162 |
b.wait_visible(self.card_button("Partition", "Grow") + ":disabled") |
| 163 |
b.wait_in_text(self.card_desc("Partition", "Size"), "103 MB") |
| 164 |
|
| 165 |
def testType(self): |
| 166 |
b = self.browser |
| 167 |
|
| 168 |
self.login_and_go("/storage") |
| 169 |
|
| 170 |
disk = self.add_ram_disk(100) |
| 171 |
self.click_card_row("Storage", name=disk) |
| 172 |
|
| 173 |
# GPT |
| 174 |
|
| 175 |
self.click_card_dropdown("Solid State Drive", "Create partition table") |
| 176 |
self.dialog({"type": "gpt"}) |
| 177 |
b.wait_text(self.card_row_col("GPT partitions", 1, 1), "Free space") |
| 178 |
|
| 179 |
self.click_dropdown(self.card_row("GPT partitions", 1), "Create partition") |
| 180 |
self.dialog({"type": "empty"}) |
| 181 |
|
| 182 |
self.click_card_row("GPT partitions", 1) |
| 183 |
b.wait_text(self.card_desc("Partition", "Type"), "Linux filesystem data") |
| 184 |
b.click(self.card_desc_action("Partition", "Type")) |
| 185 |
self.dialog({"type": "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"}) |
| 186 |
b.wait_text(self.card_desc("Partition", "Type"), "EFI system partition") |
| 187 |
b.click(self.card_desc_action("Partition", "Type")) |
| 188 |
self.dialog_wait_open() |
| 189 |
self.dialog_set_val("type", "custom") |
| 190 |
self.dialog_set_val("custom", "bla bla") |
| 191 |
self.dialog_apply() |
| 192 |
self.dialog_wait_error("custom", "Type can only contain the characters 0 to 9, A to F, and \"-\".") |
| 193 |
self.dialog_set_val("custom", "7D0359A3-02B3-4F0A865C-654403E70625") |
| 194 |
self.dialog_apply() |
| 195 |
self.dialog_wait_error("custom", "Type must be of the form NNNNNNNN-NNNN-NNNN-NNNN-NNNNNNNNNNNN.") |
| 196 |
self.dialog_set_val("custom", "7D0359A3-02B3-4F0A-865C-654403E70625") |
| 197 |
self.dialog_apply() |
| 198 |
self.dialog_wait_close() |
| 199 |
b.wait_text(self.card_desc("Partition", "Type"), "7d0359a3-02b3-4f0a-865c-654403e70625") |
| 200 |
|
| 201 |
# DOS |
| 202 |
|
| 203 |
b.click(self.card_parent_link()) |
| 204 |
self.click_card_dropdown("Solid State Drive", "Create partition table") |
| 205 |
self.dialog({"type": "dos"}) |
| 206 |
b.wait_text(self.card_row_col("DOS partitions", 1, 1), "Free space") |
| 207 |
|
| 208 |
self.click_dropdown(self.card_row("DOS partitions", 1), "Create partition") |
| 209 |
self.dialog({"size": 100, "type": "empty"}) |
| 210 |
|
| 211 |
self.click_card_row("DOS partitions", 1) |
| 212 |
b.wait_text(self.card_desc("Partition", "Type"), "Linux filesystem data") |
| 213 |
b.click(self.card_desc_action("Partition", "Type")) |
| 214 |
self.dialog({"type": "ef"}) |
| 215 |
b.wait_text(self.card_desc("Partition", "Type"), "EFI system partition") |
| 216 |
b.click(self.card_desc_action("Partition", "Type")) |
| 217 |
self.dialog_wait_open() |
| 218 |
self.dialog_set_val("type", "custom") |
| 219 |
self.dialog_set_val("custom", "bla bla") |
| 220 |
self.dialog_apply() |
| 221 |
self.dialog_wait_error("custom", "Type must contain exactly two hexadecimal characters (0 to 9, A to F).") |
| 222 |
self.dialog_set_val("custom", "C7") |
| 223 |
self.dialog_apply() |
| 224 |
self.dialog_wait_close() |
| 225 |
b.wait_text(self.card_desc("Partition", "Type"), "c7") |
| 226 |
|
| 227 |
|
| 228 |
if __name__ == '__main__': |
| 229 |
testlib.test_main() |