cockpit/test/verify/check-storage-format

205 lines
7.8 KiB
Python
Executable File

#!/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 <http://www.gnu.org/licenses/>.
from storagelib import StorageCase
from testlib import test_main
class TestStorageFormat(StorageCase):
def testFormatTooSmall(self):
m = self.machine
b = self.browser
self.login_and_go("/storage")
# Try to format a disk that is too small for XFS.
m.add_disk("5M", serial="DISK1")
b.wait_in_text("#drives", "DISK1")
b.click('#drives .sidepanel-row:contains("DISK1")')
b.wait_visible('#storage-detail')
self.content_row_action(1, "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")
m.add_disk("320M", serial="DISK1") # xfs minimum size is ~300MB.
b.wait_in_text("#drives", "DISK1")
b.click('#drives .sidepanel-row:contains("DISK1")')
b.wait_visible('#storage-detail')
def check_type(type, label_limit, head_action=False):
if head_action:
self.content_row_action(1, "Format")
else:
self.content_dropdown_action(1, "Format")
self.dialog_wait_open()
self.dialog_set_val("type", type)
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()
self.content_row_wait_in_col(1, 2, type + " filesystem")
def check_unsupported_type(type):
self.content_dropdown_action(1, "Format")
self.dialog_wait_open()
b.wait_not_present(f'#dialog li[value={type}]')
self.dialog_cancel()
self.dialog_wait_close()
check_type("xfs", 12, head_action=True)
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.content_dropdown_action(1, "Format")
self.dialog_wait_open()
self.dialog_apply_secondary()
self.dialog_wait_close()
# Verify button text is 'Format' when no filesystem is selected
self.content_dropdown_action(1, "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")
b.wait_in_text("#drives", "VirtIO")
# 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")
b.click("#others .sidepanel-row:contains('/dev/mapper/superslow')")
b.wait_visible('#storage-detail')
# 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.content_row_action(1, "Format")
self.dialog_wait_open()
self.dialog_set_val("erase.on", 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")
info = m.add_disk("50M", serial="DISK1")
dev = "/dev/" + info['dev']
b.wait_in_text("#drives", "DISK1")
b.click('#drives .sidepanel-row:contains("DISK1")')
b.wait_visible('#storage-detail')
def format(expected_at_boot, at_boot, keep, row_action=False):
if row_action:
self.content_row_action(1, "Format")
else:
self.content_dropdown_action(1, "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("nofail", "local", False, True)
self.assertNotIn("noauto", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
format("local", "nofail", True)
self.content_tab_wait_in_info(1, 1, "Mount point", "ignore failure")
self.assertIn("nofail", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(dev, "crypttab", "options", "nofail")
format("nofail", "netdev", True)
self.content_tab_wait_in_info(1, 1, "Mount point", "after network")
self.assertIn("_netdev", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(dev, "crypttab", "options", "_netdev")
format("netdev", "never", True)
self.content_tab_wait_in_info(1, 1, "Mount point", "never mount")
self.assertIn("x-cockpit-never-auto", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(dev, "crypttab", "options", "noauto")
format("never", "nofail", False)
self.content_tab_wait_in_info(1, 1, "Mount point", "ignore failure")
self.assertIn("nofail", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(dev, "crypttab", "options", "nofail")
format("nofail", "netdev", False)
self.content_tab_wait_in_info(1, 1, "Mount point", "after network")
self.assertIn("_netdev", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(dev, "crypttab", "options", "_netdev")
format("netdev", "never", False)
self.content_tab_wait_in_info(1, 1, "Mount point", "never mount")
self.assertIn("x-cockpit-never-auto", m.execute("findmnt --fstab -n -o OPTIONS /foo"))
self.assert_in_configuration(dev, "crypttab", "options", "noauto")
if __name__ == '__main__':
test_main()