def test_parents_selection(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device), ("free", self._get_free_device()), ("free", self._get_free_device())],
                               self.supported_filesystems, [])

        # partition -- only one parent, shouldn't be allowed to deselect it
        add_dialog.devices_combo.set_active_id("partition")
        add_dialog.on_cell_toggled(None, 0)
        self.assertTrue(add_dialog.parents_store[0][2])
        self.assertTrue(add_dialog.parents_store[0][3])

        # lvm -- allow secting other parents
        add_dialog.devices_combo.set_active_id("lvm")
        # it is not possible to the emmit toggle programmatically, we need to call the signal handler manually and
        # set the value in the TreeStore to True
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True

        self.assertTrue(add_dialog.parents_store[1][3])

        # deselect second parent
        add_dialog.parents_store[1][2] = False
        add_dialog.on_cell_toggled(None, 1)

        self.assertFalse(add_dialog.parents_store[1][3])
    def test_lvm_selection(self):
        parent_device1 = self._get_parent_device()
        parent_device2 = self._get_parent_device()
        free_device1 = self._get_free_device(parent=parent_device1)
        free_device2 = self._get_free_device(parent=parent_device2)

        add_dialog = AddDialog(
            self.parent_window, parent_device1, free_device1, [("free", free_device1), ("free", free_device2)], [], True
        )

        name = "name"
        size1 = Size("4 GiB")
        size2 = Size("6 GiB")

        add_dialog.devices_combo.set_active_id("lvm")

        # select second free space
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True

        add_dialog.size_area.main_chooser.selected_size = size1 + size2

        add_dialog.name_entry.set_text(name)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "lvm")
        self.assertEqual(selection.size, size1 + size2)
        self.assertEqual(selection.filesystem, None)
        self.assertEqual(selection.name, name)
        self.assertTrue(selection.label in (None, ""))
        self.assertTrue(selection.mountpoint in (None, ""))
        self.assertFalse(selection.encrypt)
        self.assertTrue(selection.passphrase in (None, ""))
        self.assertIsNone(selection.raid_level)
    def test_btrfs_selection(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(
            parent=parent_device, size=Size("8 GiB"), is_free_region=False, is_empty_disk=True
        )

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], [])

        add_dialog.devices_combo.set_active_id("btrfs volume")

        name = "name"

        add_dialog.name_entry.set_text(name)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "btrfs volume")
        self.assertEqual(selection.size, free_device.size)
        self.assertTrue(selection.filesystem in (None, ""))
        self.assertEqual(selection.name, name)
        self.assertTrue(selection.label in (None, ""))
        self.assertTrue(selection.mountpoint in (None, ""))
        self.assertFalse(selection.encrypt)
        self.assertTrue(selection.passphrase in (None, ""))
        self.assertEqual(selection.parents, [(parent_device, free_device.size)])
        self.assertTrue(selection.raid_level in (None, ""))
    def test_raid_type(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device, size=Size("8 GiB"))

        add_dialog = AddDialog(
            self.parent_window,
            parent_device,
            free_device,
            [("free", free_device), ("free", self._get_free_device(size=Size("4 GiB")))],
            [],
        )

        add_dialog.devices_combo.set_active_id("mdraid")

        self.assertEqual(len(add_dialog.parents_store), 2)
        # select second parent --> raid combo should be visible
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True
        self.assertTrue(add_dialog.raid_combo.get_visible())
        self.assertEqual(add_dialog.raid_combo.get_active_id(), "linear")  # linear is default value for mdraid

        # only 2 parents --> only "linear", "raid1" and "raid0" should be available; "raid5" needs at least 3 parents
        # set_active_id returns True or False based on success --> it should return False for "raid5" and True otherwise
        self.assertTrue(add_dialog.raid_combo.set_active_id("raid0"))
        self.assertTrue(add_dialog.raid_combo.set_active_id("raid1"))
        self.assertFalse(add_dialog.raid_combo.set_active_id("raid5"))

        # raid1 type is selected --> we should have 2 size areas, both with max size 4 GiB (smaller free space size)
        self.assertEqual(add_dialog.size_area.max_size, Size("4 GiB"))
    def test_partition_selection(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], [], True)

        fstype = next((fs.type for fs in supported_filesystems()), None)
        if fstype is None:
            self.skipTest("No supported filesystems found.")

        label = "label"
        size = Size("1 GiB")
        mountpoint = "/home"
        password = "******"

        add_dialog.devices_combo.set_active_id("partition")
        add_dialog.filesystems_combo.set_active_id(fstype)
        add_dialog.size_area.main_chooser.selected_size = size
        add_dialog.label_entry.set_text(label)
        add_dialog.mountpoint_entry.set_text(mountpoint)
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text(password)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "partition")
        self.assertEqual(selection.size, size)
        self.assertEqual(selection.filesystem, fstype)
        self.assertTrue(selection.name in (None, ""))
        self.assertEqual(selection.label, label)
        self.assertEqual(selection.mountpoint, mountpoint)
        self.assertTrue(selection.encrypt)
        self.assertEqual(selection.passphrase, password)
        self.assertEqual(selection.parents, [(parent_device, size)])
        self.assertIsNone(selection.raid_level)
Exemple #6
0
    def test_btrfs_selection(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device, size=Size("8 GiB"), is_free_region=False,
                                            is_empty_disk=True)

        add_dialog = AddDialog(self.parent_window, "disk", parent_device, free_device, [],
                               [free_device], self.supported_raids, self.supported_fs, [])

        add_dialog.devices_combo.set_active_id("btrfs volume")

        name = "name"

        add_dialog.name_entry.set_text(name)

        # select free space type to "disks"
        add_dialog.free_type_chooser[1].set_active(True)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "btrfs volume")
        self.assertEqual(selection.size, free_device.size)
        self.assertTrue(selection.filesystem in (None, ""))
        self.assertEqual(selection.name, name)
        self.assertTrue(selection.label in (None, ""))
        self.assertTrue(selection.mountpoint in (None, ""))
        self.assertFalse(selection.encrypt)
        self.assertTrue(selection.passphrase in (None, ""))
        self.assertEqual(selection.parents, [[parent_device, free_device.size]])
        self.assertEqual(selection.btrfs_type, "disks")
        self.assertTrue(selection.raid_level in (None, ""))
Exemple #7
0
    def test_partition_selection(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, "disk", parent_device, free_device, [],
                               [free_device], self.supported_raids, self.supported_fs, [], True)

        fstype = "xfs"
        label = "label"
        size = Size("1 GiB")
        mountpoint = "/home"
        password = "******"

        add_dialog.devices_combo.set_active_id("partition")
        add_dialog.filesystems_combo.set_active_id(fstype)
        add_dialog.size_areas[0][0].selected_size = size
        add_dialog.label_entry.set_text(label)
        add_dialog.mountpoint_entry.set_text(mountpoint)
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text(password)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "partition")
        self.assertEqual(selection.size, size)
        self.assertEqual(selection.filesystem, fstype)
        self.assertTrue(selection.name in (None, ""))
        self.assertEqual(selection.label, label)
        self.assertEqual(selection.mountpoint, mountpoint)
        self.assertTrue(selection.encrypt)
        self.assertEqual(selection.passphrase, password)
        self.assertEqual(selection.parents, [[parent_device, size]])
        self.assertIsNone(selection.btrfs_type)
        self.assertIsNone(selection.raid_level)
    def test_btrfs_selection(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device, size=Size("8 GiB"), is_free_region=False,
                                            is_empty_disk=True)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)], self.supported_filesystems, [])

        add_dialog.devices_combo.set_active_id("btrfs volume")

        name = "name"

        add_dialog.name_entry.set_text(name)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "btrfs volume")
        self.assertEqual(selection.size_selection.total_size, free_device.size)
        self.assertTrue(selection.filesystem in (None, ""))
        self.assertEqual(selection.name, name)
        self.assertTrue(selection.label in (None, ""))
        self.assertTrue(selection.mountpoint in (None, ""))
        self.assertFalse(selection.encrypt)
        self.assertTrue(selection.passphrase in (None, ""))
        self.assertEqual(selection.size_selection.parents[0].parent_device, parent_device)
        self.assertEqual(selection.size_selection.parents[0].selected_size, free_device.size)
        self.assertEqual(selection.raid_level, "single")
    def test_parents_selection(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(
            self.parent_window,
            parent_device,
            free_device,
            [("free", free_device), ("free", self._get_free_device()), ("free", self._get_free_device())],
            [],
        )

        # partition -- only one parent, shouldn't be allowed to deselect it
        add_dialog.devices_combo.set_active_id("partition")
        add_dialog.on_cell_toggled(None, 0)
        self.assertTrue(add_dialog.parents_store[0][2])
        self.assertTrue(add_dialog.parents_store[0][3])

        # lvm -- allow secting other parents
        add_dialog.devices_combo.set_active_id("lvm")
        # it is not possible to the emmit toggle programmatically, we need to call the signal handler manually and
        # set the value in the TreeStore to True
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True

        self.assertTrue(add_dialog.parents_store[1][3])

        # deselect second parent
        add_dialog.parents_store[1][2] = False
        add_dialog.on_cell_toggled(None, 1)

        self.assertFalse(add_dialog.parents_store[1][3])
Exemple #10
0
    def test_parents_selection(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, "disk", parent_device, free_device, [],
                               [free_device, self._get_free_device(), self._get_free_device()],
                               self.supported_raids, self.supported_fs, [])

        # partition -- only one parent, shouldn't be allowed to deselect it
        add_dialog.devices_combo.set_active_id("partition")
        add_dialog.on_cell_toggled(None, 0)
        self.assertTrue(add_dialog.parents_store[0][2])
        self.assertTrue(add_dialog.parents_store[0][3])

        # lvm -- allow secting other parents
        add_dialog.devices_combo.set_active_id("lvm")
        # it is not possible to the emmit toggle programmatically, we need to call the signal handler manually and
        # set the value in the TreeStore to True
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True

        self.assertTrue(add_dialog.parents_store[1][3])
        self.assertEqual(len(add_dialog.size_areas), 2)  # two parents --> two size areas

        # deselect second parent
        add_dialog.parents_store[1][2] = False
        add_dialog.on_cell_toggled(None, 1)

        self.assertFalse(add_dialog.parents_store[1][3])
        self.assertEqual(len(add_dialog.size_areas), 1)  # only one size area again
    def test_encrypt_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)], [])

        # passphrases specified and matches
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("aaaaa")
        add_dialog.pass2_entry.set_text("aaaaa")
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrases specified and matches --> no error
        self.error_dialog.reset_mock()

        # passphrases specified but don't matche
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("aaaaa")
        add_dialog.pass2_entry.set_text("bbbb")
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("Provided passphrases do not match."), True)
        self.error_dialog.reset_mock()

        # no passphrase specified
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("")
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("Passphrase not specified."), True)
        self.error_dialog.reset_mock()
    def test_mountpoint_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)], self.supported_filesystems, ["/root"], True)

        # reset mock
        self.error_dialog.reset_mock()

        # valid mountpoint
        add_dialog.mountpoint_entry.set_text("/home")
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid mountpoint
        mnt = "home"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("\"{0}\" is not a valid mountpoint.").format(mnt), False)
        self.error_dialog.reset_mock()

        # duplicate mountpoint
        mnt = "/root"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("Selected mountpoint \"{0}\" is already set for another device.").format(mnt), False)
        self.error_dialog.reset_mock()
    def test_allowed_device_types(self):
        # disk with disklabel and enough free space, other disks available
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device), ("free", self._get_free_device())],
                               self.supported_filesystems, [])

        types = sorted([i[1] for i in add_dialog.devices_combo.get_model()])

        self.assertTrue(sorted(["partition", "lvm", "btrfs volume", "mdraid"]) == types)
        self.assertTrue(add_dialog.devices_combo.get_sensitive())

        # disk with disklabel and not enough free space, no other disks available
        parent_device = self._get_parent_device(size=Size("200 MiB"))
        free_device = self._get_free_device(size=parent_device.size, parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)], self.supported_filesystems, [])

        types = sorted([i[1] for i in add_dialog.devices_combo.get_model()])

        self.assertTrue(sorted(["partition", "lvm"]) == types)
        self.assertTrue(add_dialog.devices_combo.get_sensitive())

        # lvmpv
        parent_device = self._get_parent_device(dtype="partition", ftype="lvmpv")
        parent_device.format.configure_mock(vg_name=None)
        free_device = parent_device

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("lvmpv", free_device)], self.supported_filesystems, [])

        types = sorted([i[1] for i in add_dialog.devices_combo.get_model()])
        self.assertTrue(sorted(["lvmvg"]) == types)
        self.assertFalse(add_dialog.devices_combo.get_sensitive())

        # lvmpv on disk
        parent_device = self._get_parent_device(dtype="disk", ftype="lvmpv")
        free_device = self._get_free_device(size=parent_device.size, parent=parent_device)
        parent_device.format.configure_mock(vg_name=None)
        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("lvmpv", free_device)], self.supported_filesystems, [])

        types = sorted([i[1] for i in add_dialog.devices_combo.get_model()])
        self.assertTrue(sorted(["lvmvg"]) == types)
        self.assertFalse(add_dialog.devices_combo.get_sensitive())
    def test_fs_chooser(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)], self.supported_filesystems,
                               [], True)  # with installer_mode=True

        # swap -- mountpoint entry shouldn't be visible, label entry should be visible
        add_dialog.filesystems_combo.set_active_id("swap")
        self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "swap")
        self.assertFalse(add_dialog.mountpoint_entry.get_visible())
        self.assertTrue(add_dialog.label_entry.get_visible())

        # lvmpv -- both mountpoint and label entries shouldn't be visible
        add_dialog.filesystems_combo.set_active_id("lvmpv")
        self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "lvmpv")
        self.assertFalse(add_dialog.mountpoint_entry.get_visible())
        self.assertFalse(add_dialog.label_entry.get_visible())

        # ext4 -- mountpoint and label entries should be visible
        add_dialog.filesystems_combo.set_active_id("ext4")
        self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "ext4")
        self.assertTrue(add_dialog.mountpoint_entry.get_visible())
        self.assertTrue(add_dialog.label_entry.get_visible())
    def test_md_selection(self):
        parent_device1 = self._get_parent_device()
        parent_device2 = self._get_parent_device()
        free_device1 = self._get_free_device(parent=parent_device1)
        free_device2 = self._get_free_device(parent=parent_device2)

        add_dialog = AddDialog(
            self.parent_window, parent_device1, free_device1, [("free", free_device1), ("free", free_device2)], [], True
        )

        fstype = next((fs.type for fs in supported_filesystems()), None)
        if fstype is None:
            self.skipTest("No supported filesystems found.")

        raidtype = "raid0"
        size = Size("4 GiB")
        name = "name"

        add_dialog.devices_combo.set_active_id("mdraid")

        # select second free space
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True

        add_dialog.raid_combo.set_active_id(raidtype)

        # raid 0 --> second size area should be updated
        add_dialog.size_area.parent_area.choosers[0].selected_size = size

        add_dialog.name_entry.set_text(name)

        add_dialog.md_type_combo.set_active_id("partition")
        add_dialog.filesystems_combo.set_active_id(fstype)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "mdraid")
        self.assertEqual(selection.size, 2 * size)
        self.assertEqual(selection.filesystem, fstype)
        self.assertEqual(selection.name, name)
        self.assertTrue(selection.label in (None, ""))
        self.assertTrue(selection.mountpoint in (None, ""))
        self.assertFalse(selection.encrypt)
        self.assertTrue(selection.passphrase in (None, ""))
        self.assertEqual(selection.parents, [(parent_device1, size), (parent_device2, size)])
        self.assertEqual(selection.raid_level, "raid0")
    def test_mountpoint_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], ["/root"], True)

        # reset mock
        self.error_dialog.reset_mock()

        # valid mountpoint
        add_dialog.mountpoint_entry.set_text("/home")
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid mountpoint
        mnt = "home"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _('"{0}" is not a valid mountpoint.').format(mnt), False)
        self.error_dialog.reset_mock()

        # duplicate mountpoint
        mnt = "/root"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(
            add_dialog, _('Selected mountpoint "{0}" is already set for another device.').format(mnt), False
        )
        self.error_dialog.reset_mock()
    def test_encrypt_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], [])

        # passphrases specified and matches
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("aaaaa")
        add_dialog.pass2_entry.set_text("aaaaa")
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrases specified and matches --> no error
        self.error_dialog.reset_mock()

        # passphrases specified but don't matche
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("aaaaa")
        add_dialog.pass2_entry.set_text("bbbb")
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("Provided passphrases do not match."), True)
        self.error_dialog.reset_mock()

        # no passphrase specified
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("")
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("Passphrase not specified."), True)
        self.error_dialog.reset_mock()
Exemple #18
0
    def test_mountpoint_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, "disk", parent_device, free_device, [],
                               [free_device], self.supported_raids, self.supported_fs, ["/root"], True)

        # valid mountpoint
        add_dialog.mountpoint_entry.set_text("/home")
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid mountpoint
        mnt = "home"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("\"{0}\" is not a valid mountpoint.").format(mnt))
        self.error_dialog.reset_mock()

        # duplicate mountpoint
        mnt = "/root"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("Selected mountpoint \"{0}\" is already set for another device.").format(mnt))
        self.error_dialog.reset_mock()
    def test_parents_max_size_limit(self):
        parent_device1 = self._get_parent_device(size=Size("8 TiB"))
        free_device1 = self._get_free_device(parent=parent_device1, size=parent_device1.size)

        # simple case -- partition
        add_dialog = AddDialog(self.parent_window, parent_device1, free_device1,
                               [("free", free_device1)], self.supported_filesystems, [], True)

        add_dialog.devices_combo.set_active_id("partition")
        # select "unformatted" just to be sure there is no filesystem size limit
        add_dialog.filesystems_combo.set_active_id("unformatted")

        # partition max size should me limited to disklabel max size limit
        limit = parent_device1.format.parted_disk.maxPartitionLength * parent_device1.format.sector_size
        self.assertEqual(add_dialog.size_area.main_chooser.max_size, limit)

        # more complicated case -- LVM with two parents
        parent_device2 = self._get_parent_device(size=Size("1 GiB"))
        free_device2 = self._get_free_device(parent=parent_device2, size=parent_device2.size)

        add_dialog = AddDialog(self.parent_window, parent_device1, free_device1,
                               [("free", free_device1), ("free", free_device2)],
                               self.supported_filesystems, [], True)

        add_dialog.devices_combo.set_active_id("lvm")
        # select "unformatted" just to be sure there is no filesystem size limit
        add_dialog.filesystems_combo.set_active_id("unformatted")

        # select second free space
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True

        # LVM limit should be disklabel limit (from first parent) + 1 GiB (from second parent)
        limit = free_device2.size + parent_device1.format.parted_disk.maxPartitionLength * parent_device1.format.sector_size
        self.assertEqual(add_dialog.size_area.main_chooser.max_size, limit)
    def test_raid_type(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device, size=Size("8 GiB"))

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device), ("free", self._get_free_device(size=Size("4 GiB")))], [])

        add_dialog.devices_combo.set_active_id("mdraid")

        self.assertEqual(len(add_dialog.parents_store), 2)
        # select second parent --> raid combo should be visible
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True
        self.assertTrue(add_dialog._raid_chooser.get_visible())
        self.assertEqual(add_dialog._raid_chooser.selected_level.name, "raid0")  # linear is default value for mdraid

        # raid0 type is selected --> we should have 2 size areas, both with max size 4 GiB (smaller free space size)
        self.assertEqual(add_dialog.size_area.max_size, Size("8 GiB"))
Exemple #21
0
    def test_md_selection(self):
        parent_device1 = self._get_parent_device()
        parent_device2 = self._get_parent_device()
        free_device1 = self._get_free_device(parent=parent_device1)
        free_device2 = self._get_free_device(parent=parent_device2)

        add_dialog = AddDialog(self.parent_window, "disk", parent_device1, free_device1, [],
                               [free_device1, free_device2], self.supported_raids,
                               self.supported_fs, [], True)

        fstype = "xfs"
        raidtype = "raid0"
        size = Size("4 GiB")
        name = "name"

        add_dialog.devices_combo.set_active_id("mdraid")

        # select second free space
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True

        add_dialog.raid_combo.set_active_id(raidtype)

        # raid 0 --> second size area should be updated
        add_dialog.size_areas[0][0].selected_size = size

        add_dialog.name_entry.set_text(name)

        add_dialog.md_type_combo.set_active_id("partition")
        add_dialog.filesystems_combo.set_active_id(fstype)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "mdraid")
        self.assertEqual(selection.size, 2 * size)
        self.assertEqual(selection.filesystem, fstype)
        self.assertEqual(selection.name, name)
        self.assertTrue(selection.label in (None, ""))
        self.assertTrue(selection.mountpoint in (None, ""))
        self.assertFalse(selection.encrypt)
        self.assertTrue(selection.passphrase in (None, ""))
        self.assertEqual(selection.parents, [[parent_device1, size], [parent_device2, size]])
        self.assertIsNone(selection.btrfs_type)
        self.assertEqual(selection.raid_level, "raid0")
Exemple #22
0
    def test_mdraid_widgets(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, "disk", parent_device, free_device, [],
                               [free_device, self._get_free_device()], self.supported_raids, self.supported_fs, [])

        add_dialog.devices_combo.set_active_id("mdraid")
        self.assertEqual(add_dialog._get_selected_device_type(), "mdraid")

        self.assertIsNone(add_dialog.free_type_chooser)
        self.assertTrue(add_dialog.filesystems_combo.get_visible())
        self.assertTrue(add_dialog.name_entry.get_visible())
        self.assertFalse(add_dialog.encrypt_check.get_visible())
        self.assertFalse(add_dialog.raid_combo.get_visible())
        self.assertTrue(len(add_dialog.size_areas) == 1)
        self.assertIsNone(add_dialog.advanced)
        self.assertTrue(add_dialog.md_type_combo.get_visible())
        self.assertTrue(add_dialog.size_areas[0][0].get_sensitive())
Exemple #23
0
    def test_lvmvg_widgets(self):
        parent_device = self._get_parent_device(dtype="lvmpv", ftype=None)
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, "lvmpv", parent_device, free_device,
                               [(parent_device, free_device)], [free_device], self.supported_raids,
                               self.supported_fs, [])

        # for lvmpv 'parent' only lvmvg should be available
        self.assertFalse(add_dialog.devices_combo.get_sensitive())
        self.assertEqual(add_dialog._get_selected_device_type(), "lvmvg")

        self.assertIsNone(add_dialog.free_type_chooser)
        self.assertFalse(add_dialog.filesystems_combo.get_visible())
        self.assertTrue(add_dialog.name_entry.get_visible())
        self.assertFalse(add_dialog.encrypt_check.get_visible())
        self.assertFalse(add_dialog.raid_combo.get_visible())
        self.assertTrue(len(add_dialog.size_areas) == 1)
        self.assertIsNotNone(add_dialog.advanced)
        self.assertFalse(add_dialog.md_type_combo.get_visible())
        self.assertFalse(add_dialog.size_areas[0][0].get_sensitive())
    def test_name_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], [])

        add_dialog.devices_combo.set_active_id("lvm")  # select device type that has a name option

        # valid name
        name = "aaaaa"
        add_dialog.name_entry.set_text(name)
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid name
        name = "?*#%@"
        add_dialog.name_entry.set_text(name)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _('"{0}" is not a valid name.').format(name), True)
        self.error_dialog.reset_mock()
    def test_md_type(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [],
                               [("free", free_device), ("free", self._get_free_device())], [])

        add_dialog.devices_combo.set_active_id("mdraid")

        # select partition --> filesystem chooser should be visible
        add_dialog.md_type_combo.set_active_id("partition")
        self.assertTrue(add_dialog.filesystems_combo.get_visible())
Exemple #26
0
    def test_label_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)],
                               self.supported_filesystems, [])

        add_dialog.devices_combo.set_active_id(
            "partition")  # select device type that has a label option
        add_dialog.filesystems_combo.set_active_id("ext4")

        # valid label for ext4
        label = "a" * 5
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.assertFalse(
            self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid label for ext4
        label = "a" * 50
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(
            add_dialog,
            _("\"{0}\" is not a valid label.").format(label), True)
        self.error_dialog.reset_mock()
Exemple #27
0
    def test_name_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)],
                               self.supported_filesystems, [])

        add_dialog.devices_combo.set_active_id(
            "lvm")  # select device type that has a name option

        # valid name
        name = "aaaaa"
        add_dialog.name_entry.set_text(name)
        add_dialog.validate_user_input()
        self.assertFalse(
            self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid name
        name = "?*#%@"
        add_dialog.name_entry.set_text(name)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(
            add_dialog,
            _("\"{0}\" is not a valid name.").format(name), True)
        self.error_dialog.reset_mock()
    def test_lvm_selection(self):
        parent_device1 = self._get_parent_device()
        parent_device2 = self._get_parent_device()
        free_device1 = self._get_free_device(parent=parent_device1)
        free_device2 = self._get_free_device(parent=parent_device2)

        add_dialog = AddDialog(self.parent_window, parent_device1, free_device1,
                               [("free", free_device1), ("free", free_device2)],
                               self.supported_filesystems, [], True)

        name = "name"
        size1 = Size("4 GiB")
        size2 = Size("6 GiB")

        add_dialog.devices_combo.set_active_id("lvm")

        # select second free space
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True

        add_dialog.size_area.main_chooser.selected_size = size1 + size2

        add_dialog.name_entry.set_text(name)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "lvm")
        self.assertEqual(selection.size_selection.total_size, size1 + size2)
        self.assertEqual(selection.filesystem, None)
        self.assertEqual(selection.name, name)
        self.assertTrue(selection.label in (None, ""))
        self.assertTrue(selection.mountpoint in (None, ""))
        self.assertFalse(selection.encrypt)
        self.assertTrue(selection.passphrase in (None, ""))
        self.assertIsNone(selection.raid_level)
Exemple #29
0
    def test_partition_selection(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)],
                               self.supported_filesystems, [], True)

        fstype = next((fs.type for fs in supported_filesystems()), None)
        if fstype is None:
            self.skipTest("No supported filesystems found.")

        label = "label"
        size = Size("1 GiB")
        mountpoint = "/home"
        password = "******"

        add_dialog.devices_combo.set_active_id("partition")
        add_dialog.filesystems_combo.set_active_id(fstype)
        add_dialog.size_area.main_chooser.selected_size = size
        add_dialog.label_entry.set_text(label)
        add_dialog.mountpoint_entry.set_text(mountpoint)
        add_dialog._encryption_chooser.encrypt = True
        add_dialog._encryption_chooser._passphrase_entry.set_text(password)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "partition")
        self.assertEqual(selection.size_selection.total_size, size)
        self.assertEqual(selection.filesystem, fstype)
        self.assertTrue(selection.name in (None, ""))
        self.assertEqual(selection.label, label)
        self.assertEqual(selection.mountpoint, mountpoint)
        self.assertTrue(selection.encrypt)
        self.assertEqual(selection.passphrase, password)
        self.assertEqual(selection.size_selection.parents[0].parent_device,
                         parent_device)
        self.assertEqual(selection.size_selection.parents[0].selected_size,
                         size)
        self.assertIsNone(selection.raid_level)
    def test_label_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], [])

        add_dialog.devices_combo.set_active_id("partition")  # select device type that has a label option
        add_dialog.filesystems_combo.set_active_id("ext4")

        # valid label for ext4
        label = "a" * 5
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid label for ext4
        label = "a" * 50
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _('"{0}" is not a valid label.').format(label), True)
        self.error_dialog.reset_mock()
    def test_btrfs_parents(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device), ("free", self._get_free_device(size=Size("200 MiB"))), ("free", self._get_free_device(size=Size("4 GiB")))], [])
        add_dialog.devices_combo.set_active_id("btrfs volume")

        # lvm allows multiple parents -- make sure we have all available (= larger than 256 MiB) and the right one is selected
        self.assertEqual(len(add_dialog.parents_store), 2)  # third device is smaller than min size for btrfs
        self.assertEqual(add_dialog.parents_store[0][0], parent_device)
        self.assertEqual(add_dialog.parents_store[0][1], free_device)
        self.assertTrue(add_dialog.parents_store[0][2])
        self.assertFalse(add_dialog.parents_store[1][2])  # other free device shouldn't be selected
Exemple #32
0
    def test_label_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, "disk", parent_device, free_device, [],
                               [free_device], self.supported_raids, self.supported_fs, [])

        add_dialog.devices_combo.set_active_id("partition")  # select device type that has a label option
        add_dialog.filesystems_combo.set_active_id("ext4")

        # valid label for ext4
        label = "a" * 5
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid label for ext4
        label = "a" * 50
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, "\"%s\" is not a valid label." % label)
        self.error_dialog.reset_mock()
    def test_parents_update(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device), ("free", self._get_free_device()), ("free", self._get_free_device())], [])

        # partition -- only one parent
        add_dialog.devices_combo.set_active_id("partition")
        self.assertEqual(len(add_dialog.parents_store), 1)

        # lvm -- all available parents
        add_dialog.devices_combo.set_active_id("lvm")
        self.assertEqual(len(add_dialog.parents_store), 3)
    def test_lvm_parents(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device), ("free", self._get_free_device(size=Size("4 GiB"))), ("free", self._get_free_device(size=Size("4 GiB")))], [])
        add_dialog.devices_combo.set_active_id("lvm")

        # lvm allows multiple parents -- make sure we have all available and the right one is selected
        self.assertEqual(len(add_dialog.parents_store), 3)
        self.assertEqual(add_dialog.parents_store[0][0], parent_device)
        self.assertEqual(add_dialog.parents_store[0][1], free_device)
        self.assertTrue(add_dialog.parents_store[0][2])
        self.assertFalse(add_dialog.parents_store[1][2])  # other two free devices shouldn't be selected
        self.assertFalse(add_dialog.parents_store[2][2])
    def test_mdraid_widgets(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device), ("free", self._get_free_device())], [])

        add_dialog.devices_combo.set_active_id("mdraid")
        self.assertEqual(add_dialog.selected_type, "mdraid")

        self.assertTrue(add_dialog.filesystems_combo.get_visible())
        self.assertTrue(add_dialog.name_entry.get_visible())
        self.assertTrue(add_dialog.encrypt_check.get_visible())
        self.assertIsNotNone(add_dialog.advanced)
        self.assertFalse(add_dialog.md_type_combo.get_visible())
    def test_lvmlv_parents(self):
        parent_device = self._get_parent_device(dtype="lvmvg", ftype=None)
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device), ("free", self._get_free_device()), ("free", self._get_free_device())], [])
        add_dialog.devices_combo.set_active_id("lvmlv")

        # lvmlv allows only one parent -- make sure we have the right one and it is selected
        self.assertEqual(len(add_dialog.parents_store), 1)
        self.assertEqual(add_dialog.parents_store[0][0], parent_device)
        self.assertEqual(add_dialog.parents_store[0][1], free_device)
        self.assertTrue(add_dialog.parents_store[0][2])
        self.assertTrue(add_dialog.parents_store[0][3])
        self.assertEqual(add_dialog.parents_store[0][5], "lvmvg")
    def test_partition_parents(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device), ("free", self._get_free_device()), ("free", self._get_free_device())],
                               self.supported_filesystems, [])
        add_dialog.devices_combo.set_active_id("partition")

        # partition allows only one parent -- make sure we have the right one and it is selected
        self.assertEqual(len(add_dialog.parents_store), 1)
        self.assertEqual(add_dialog.parents_store[0][0], parent_device)
        self.assertEqual(add_dialog.parents_store[0][1], free_device)
        self.assertTrue(add_dialog.parents_store[0][2])
        self.assertTrue(add_dialog.parents_store[0][3])
        self.assertEqual(add_dialog.parents_store[0][5], "disk")
Exemple #38
0
    def test_md_selection(self):
        parent_device1 = self._get_parent_device()
        parent_device2 = self._get_parent_device()
        free_device1 = self._get_free_device(parent=parent_device1)
        free_device2 = self._get_free_device(parent=parent_device2)

        add_dialog = AddDialog(self.parent_window, parent_device1,
                               free_device1, [("free", free_device1),
                                              ("free", free_device2)],
                               self.supported_filesystems, [], True)

        fstype = next((fs.type for fs in supported_filesystems()), None)
        if fstype is None:
            self.skipTest("No supported filesystems found.")

        raidtype = "raid0"
        size = Size("4 GiB")
        name = "name"

        add_dialog.devices_combo.set_active_id("mdraid")

        # select second free space
        add_dialog.on_cell_toggled(None, 1)
        add_dialog.parents_store[1][2] = True

        add_dialog._raid_chooser._combobox_raid.set_active_id(raidtype)

        # raid 0 --> second size area should be updated
        add_dialog.size_area._parent_area.choosers[0].selected_size = size

        add_dialog.name_entry.set_text(name)

        add_dialog.md_type_combo.set_active_id("partition")
        add_dialog.filesystems_combo.set_active_id(fstype)

        selection = add_dialog.get_selection()

        self.assertEqual(selection.device_type, "mdraid")
        self.assertEqual(selection.size_selection.total_size, 2 * size)
        self.assertEqual(selection.filesystem, fstype)
        self.assertEqual(selection.name, name)
        self.assertTrue(selection.label in (None, ""))
        self.assertTrue(selection.mountpoint in (None, ""))
        self.assertFalse(selection.encrypt)
        self.assertTrue(selection.passphrase in (None, ""))
        self.assertEqual(selection.size_selection.parents[0].parent_device,
                         parent_device1)
        self.assertEqual(selection.size_selection.parents[0].selected_size,
                         size)
        self.assertEqual(selection.size_selection.parents[1].parent_device,
                         parent_device2)
        self.assertEqual(selection.size_selection.parents[1].selected_size,
                         size)
        self.assertEqual(selection.raid_level, raidtype)
    def test_btrfsvolume_widgets(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)], self.supported_filesystems, [])

        add_dialog.devices_combo.set_active_id("btrfs volume")
        self.assertEqual(add_dialog.selected_type, "btrfs volume")

        self.assertFalse(add_dialog.filesystems_combo.get_visible())
        self.assertTrue(add_dialog.name_entry.get_visible())
        self.assertTrue(add_dialog._encryption_chooser._encrypt_check.get_visible())
        self.assertTrue(add_dialog._raid_chooser.get_visible())
        self.assertIsNone(add_dialog.advanced)
        self.assertFalse(add_dialog.md_type_combo.get_visible())
        self.assertTrue(add_dialog.size_area.get_sensitive())
    def test_passphrase_entry(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [],
                               [("free", free_device)], [])

        add_dialog.encrypt_check.set_active(True)

        # passphrases don't match -> error icon
        add_dialog.pass_entry.set_text("aa")
        add_dialog.pass2_entry.set_text("bb")
        self.assertEqual(add_dialog.pass2_entry.get_icon_name(Gtk.EntryIconPosition.SECONDARY), "dialog-error-symbolic.symbolic")

        # passphrases match -> ok icon
        add_dialog.pass2_entry.set_text("aa")
        self.assertEqual(add_dialog.pass2_entry.get_icon_name(Gtk.EntryIconPosition.SECONDARY), "emblem-ok-symbolic.symbolic")
    def test_encrypt_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [],
                               [("free", free_device)], [])

        min_size = add_dialog.size_area.min_size  # device minimal size before update
        # check the encrypt check, passphrase entries should be visible and 2 MiB should be added to device min size
        add_dialog.encrypt_check.set_active(True)
        self.assertTrue(add_dialog.pass_entry.get_visible())
        self.assertTrue(add_dialog.pass2_entry.get_visible())
        self.assertEqual(add_dialog.size_area.min_size, min_size + Size("2 MiB"))

        # check the encrypt check, passphrase entries should be hidden and min size should be back to original min size
        add_dialog.encrypt_check.set_active(False)
        self.assertFalse(add_dialog.pass_entry.get_visible())
        self.assertFalse(add_dialog.pass2_entry.get_visible())
        self.assertEqual(add_dialog.size_area.min_size, min_size)
    def test_fs_chooser_biosboot(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        _filesystems = self.supported_filesystems[:]
        _filesystems.append(formats.biosboot.BIOSBoot())
        _filesystems.append(formats.fs.BTRFS())

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)], _filesystems,
                               [], True)  # with installer_mode=True

        # switch from biosboot to btrfs and ext4 (rhbz#1881472)
        add_dialog.filesystems_combo.set_active_id("biosboot")
        self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "biosboot")
        add_dialog.filesystems_combo.set_active_id("btrfs")
        self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "btrfs")
        add_dialog.filesystems_combo.set_active_id("biosboot")
        self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "biosboot")
        add_dialog.filesystems_combo.set_active_id("ext4")
        self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "ext4")