1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)
# This file is part of Cockpit.
#
# Copyright (C) 2015 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <https://www.gnu.org/licenses/>.
import storagelib
import testlib
@testlib.nondestructive
class TestStorageFormat(storagelib.StorageCase):
def testFormatTooSmall(self):
b = self.browser
self.login_and_go("/storage")
# Try to format a disk that is too small for XFS.
disk = self.add_ram_disk(size=5)
self.click_card_row("Storage", name=disk)
self.click_card_dropdown("Unformatted data", "Format")
self.dialog_wait_open()
self.dialog_set_val("type", "xfs")
self.dialog_set_val("mount_point", "/foo")
self.dialog_apply_secondary()
b.wait_in_text("#dialog", "Error creating")
b.wait_in_text("#dialog", "too small")
def testFormatTypes(self):
m = self.machine
b = self.browser
self.login_and_go("/storage")
disk = self.add_ram_disk(size=320) # xfs minimum size is ~300MB
self.click_card_row("Storage", name=disk)
def check_type(fstype, label_limit):
self.click_card_dropdown("Unformatted data", "Format")
self.dialog_wait_open()
self.dialog_set_val("type", fstype)
self.dialog_set_val("mount_point", "/foo")
self.dialog_set_val("name", "X" * (label_limit + 1))
self.dialog_apply_secondary()
self.dialog_wait_error("name", "Name cannot be longer than %d characters" % label_limit)
self.dialog_set_val("name", "X" * label_limit)
self.dialog_apply_secondary()
self.dialog_wait_close()
b.wait_visible(self.card(fstype + " filesystem"))
self.click_card_dropdown(fstype + " filesystem", "Format")
self.dialog({"type": "empty"})
b.wait_visible(self.card("Unformatted data"))
def check_unsupported_type(fstype):
self.click_card_dropdown("Unformatted data", "Format")
self.dialog_wait_open()
b.wait_not_present(f'#dialog li[value={fstype}]')
self.dialog_cancel()
self.dialog_wait_close()
check_type("xfs", 12)
check_type("ext4", 16)
check_type("vfat", 11)
if m.image.startswith("rhel") or m.image.startswith("centos"):
check_unsupported_type("ntfs")
else:
check_type("ntfs", 128)
# Format without mount point
self.click_card_dropdown("Unformatted data", "Format")
self.dialog_wait_open()
self.dialog_set_val("type", "xfs")
self.dialog_apply_secondary()
self.dialog_wait_close()
# Verify button text is 'Format' when no filesystem is selected
self.click_card_dropdown("xfs filesystem", "Format")
self.dialog_wait_open()
self.dialog_set_val("type", "empty")
b.wait_text("#dialog .apply", "Format")
def testFormatCancel(self):
m = self.machine
b = self.browser
self.login_and_go("/storage")
# Make a super slow block device so that we have enough
# chances to cancel the operation
disk = self.add_ram_disk()
blocks = int(m.execute(f"blockdev --getsz {disk}"))
m.execute(f"echo '0 {blocks} delay {disk} 0 500' | dmsetup create superslow")
self.click_card_row("Storage", name="/dev/mapper/superslow")
# Put a signature near the end
sigoff = (blocks - 1) * 512
m.execute(f"echo hello | dd if=/dev/stdin of=/dev/mapper/superslow bs=1 count=5 seek={sigoff}")
self.click_card_dropdown("Unformatted data", "Format")
self.dialog_wait_open()
self.dialog_set_val("erase.on", val=True)
self.dialog_set_val("mount_point", "/foo")
self.dialog_apply()
with b.wait_timeout(60):
b.wait_in_text("footer", "Erasing /dev/mapper/superslow")
self.dialog_cancel()
self.dialog_wait_close()
# The signature should still be there
sig = m.execute(f"dd if=/dev/mapper/superslow of=/dev/stdout bs=1 count=5 skip={sigoff}")
self.assertEqual(sig, 'hello')
def testAtBoot(self):
m = self.machine
b = self.browser
self.login_and_go("/storage")
disk = self.add_ram_disk()
self.click_card_row("Storage", name=disk)
def format_partition(expected_at_boot, at_boot, keep, first=False):
self.click_card_dropdown("Unformatted data" if first else "ext4 filesystem", "Format")
self.dialog_wait_open()
self.dialog_wait_val("at_boot", expected_at_boot)
self.dialog_set_val("type", "ext4")
self.dialog_set_val("mount_point", "/foo")
self.dialog_set_val("at_boot", at_boot)
if keep:
self.dialog_set_val("crypto", " keep")
else:
self.dialog_set_val("crypto", "luks1")
self.dialog_set_val("passphrase", "foobarfoo")
self.dialog_set_val("passphrase2", "foobarfoo")
self.dialog_apply()
self.dialog_wait_close()
format_partition("nofail", "local", keep=False, first=True)
b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "stop boot on failure")
self.assertNotIn("noauto", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
format_partition("local", "nofail", keep=True)
b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "ignore failure")
self.assertIn("nofail", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(disk, "crypttab", "options", "nofail")
format_partition("nofail", "netdev", keep=True)
b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "after network")
self.assertIn("_netdev", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(disk, "crypttab", "options", "_netdev")
format_partition("netdev", "never", keep=True)
b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "never mount")
self.assertIn("x-cockpit-never-auto", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(disk, "crypttab", "options", "noauto")
format_partition("never", "nofail", keep=False)
b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "ignore failure")
self.assertIn("nofail", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(disk, "crypttab", "options", "nofail")
format_partition("nofail", "netdev", keep=False)
b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "after network")
self.assertIn("_netdev", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(disk, "crypttab", "options", "_netdev")
format_partition("netdev", "never", keep=False)
b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "never mount")
self.assertIn("x-cockpit-never-auto", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(disk, "crypttab", "options", "noauto")
if __name__ == '__main__':
testlib.test_main()
|