Exemplo n.º 1
0
    def test_raid_action_REFORMAT(self):
        model = make_model()

        raid1 = make_raid(model)
        self.assertActionNotPossible(raid1, DeviceAction.REFORMAT)
        raid1p1 = make_partition(model, raid1)
        self.assertActionPossible(raid1, DeviceAction.REFORMAT)
        model.add_volgroup('vg0', {raid1p1})
        self.assertActionNotPossible(raid1, DeviceAction.REFORMAT)

        raid2 = make_raid(model)
        raid2.preserve = True
        self.assertActionNotPossible(raid2, DeviceAction.REFORMAT)
        raid2p1 = make_partition(model, raid2, preserve=True)
        self.assertActionPossible(raid2, DeviceAction.REFORMAT)
        model.add_volgroup('vg1', {raid2p1})
        self.assertActionNotPossible(raid2, DeviceAction.REFORMAT)

        raid3 = make_raid(model)
        model.add_volgroup('vg2', {raid3})
        self.assertActionNotPossible(raid3, DeviceAction.REFORMAT)

        raid4 = make_raid(model)
        raid4.preserve = True
        model.add_volgroup('vg2', {raid4})
        self.assertActionNotPossible(raid4, DeviceAction.REFORMAT)
Exemplo n.º 2
0
 def test_raid_action_FORMAT(self):
     model, raid = make_model_and_raid()
     self.assertActionPossible(raid, DeviceAction.FORMAT)
     make_partition(model, raid)
     self.assertActionNotPossible(raid, DeviceAction.FORMAT)
     raid2 = make_raid(model)
     model.add_volgroup('vg1', {raid2})
     self.assertActionNotPossible(raid2, DeviceAction.FORMAT)
Exemplo n.º 3
0
 def test_disk_action_FORMAT(self):
     model, disk = make_model_and_disk()
     self.assertActionPossible(disk, DeviceAction.FORMAT)
     make_partition(model, disk)
     self.assertActionNotPossible(disk, DeviceAction.FORMAT)
     disk2 = make_disk(model)
     model.add_volgroup('vg1', {disk2})
     self.assertActionNotPossible(disk2, DeviceAction.FORMAT)
Exemplo n.º 4
0
    def test_raid_action_EDIT(self):
        model = make_model()
        raid1 = make_raid(model)
        self.assertActionPossible(raid1, DeviceAction.EDIT)
        model.add_volgroup('vg1', {raid1})
        self.assertActionNotPossible(raid1, DeviceAction.EDIT)
        raid2 = make_raid(model)
        make_partition(model, raid2)
        self.assertActionNotPossible(raid2, DeviceAction.EDIT)

        raid3 = make_raid(model)
        raid3.preserve = True
        self.assertActionNotPossible(raid3, DeviceAction.EDIT)
Exemplo n.º 5
0
    def test_partition_action_DELETE(self):
        model = make_model()
        part1 = make_partition(model)
        self.assertActionPossible(part1, DeviceAction.DELETE)
        fs = model.add_filesystem(part1, 'ext4')
        self.assertActionPossible(part1, DeviceAction.DELETE)
        model.add_mount(fs, '/')
        self.assertActionPossible(part1, DeviceAction.DELETE)

        part2 = make_partition(model)
        model.add_volgroup('vg1', {part2})
        self.assertActionNotPossible(part2, DeviceAction.DELETE)

        part = make_partition(make_model(Bootloader.BIOS), flag='bios_grub')
        self.assertActionNotPossible(part, DeviceAction.DELETE)
        part = make_partition(make_model(Bootloader.UEFI), flag='boot')
        self.assertActionNotPossible(part, DeviceAction.DELETE)
        part = make_partition(make_model(Bootloader.PREP), flag='prep')
        self.assertActionNotPossible(part, DeviceAction.DELETE)

        # You cannot delete a partition from a disk that has
        # pre-existing partitions (only reformat)
        disk2 = make_disk(model, preserve=True)
        disk2p1 = make_partition(model, disk2, preserve=True)
        self.assertActionNotPossible(disk2p1, DeviceAction.DELETE)
Exemplo n.º 6
0
    def test_disk_action_REFORMAT(self):
        model = make_model()

        disk1 = make_disk(model, preserve=False)
        self.assertActionNotPossible(disk1, DeviceAction.REFORMAT)
        disk1p1 = make_partition(model, disk1, preserve=False)
        self.assertActionPossible(disk1, DeviceAction.REFORMAT)
        model.add_volgroup('vg0', {disk1p1})
        self.assertActionNotPossible(disk1, DeviceAction.REFORMAT)

        disk2 = make_disk(model, preserve=True)
        self.assertActionNotPossible(disk2, DeviceAction.REFORMAT)
        disk2p1 = make_partition(model, disk2, preserve=True)
        self.assertActionPossible(disk2, DeviceAction.REFORMAT)
        model.add_volgroup('vg1', {disk2p1})
        self.assertActionNotPossible(disk2, DeviceAction.REFORMAT)

        disk3 = make_disk(model, preserve=False)
        model.add_volgroup('vg2', {disk3})
        self.assertActionNotPossible(disk3, DeviceAction.REFORMAT)

        disk4 = make_disk(model, preserve=True)
        model.add_volgroup('vg2', {disk4})
        self.assertActionNotPossible(disk4, DeviceAction.REFORMAT)
Exemplo n.º 7
0
    def test_raid_action_PARTITION(self):
        model, raid = make_model_and_raid()
        self.assertActionPossible(raid, DeviceAction.PARTITION)
        make_partition(model, raid, size=raid.free_for_partitions // 2)
        self.assertActionPossible(raid, DeviceAction.PARTITION)
        make_partition(model, raid, size=raid.free_for_partitions)
        self.assertActionNotPossible(raid, DeviceAction.PARTITION)

        # Can partition a raid with .preserve=True
        raid2 = make_raid(model)
        raid2.preserve = True
        self.assertActionPossible(raid2, DeviceAction.PARTITION)
        # But not if it has a partition.
        make_partition(model, raid2, preserve=True)
        self.assertActionNotPossible(raid2, DeviceAction.PARTITION)
Exemplo n.º 8
0
    def test_disk_action_PARTITION(self):
        model, disk = make_model_and_disk()
        self.assertActionPossible(disk, DeviceAction.PARTITION)
        make_partition(model, disk, size=disk.free_for_partitions // 2)
        self.assertActionPossible(disk, DeviceAction.PARTITION)
        make_partition(model, disk, size=disk.free_for_partitions)
        self.assertActionNotPossible(disk, DeviceAction.PARTITION)

        # Can partition a disk with .preserve=True
        disk2 = make_disk(model)
        disk2.preserve = True
        self.assertActionPossible(disk2, DeviceAction.PARTITION)
        # But not if it has a partition.
        make_partition(model, disk2, preserve=True)
        self.assertActionNotPossible(disk2, DeviceAction.PARTITION)
Exemplo n.º 9
0
    def test_partition_annotations(self):
        model = make_model()
        part = make_partition(model)
        self.assertEqual(annotations(part), ['new'])
        part.preserve = True
        self.assertEqual(annotations(part), ['existing'])

        model = make_model()
        part = make_partition(model, flag="bios_grub")
        self.assertEqual(
            annotations(part), ['new', 'BIOS grub spacer'])
        part.preserve = True
        self.assertEqual(
            annotations(part),
            ['existing', 'unconfigured', 'BIOS grub spacer'])
        part.device.grub_device = True
        self.assertEqual(
            annotations(part),
            ['existing', 'configured', 'BIOS grub spacer'])

        model = make_model()
        part = make_partition(model, flag="boot", grub_device=True)
        self.assertEqual(annotations(part), ['new', 'backup ESP'])
        fs = model.add_filesystem(part, fstype="fat32")
        model.add_mount(fs, "/boot/efi")
        self.assertEqual(annotations(part), ['new', 'primary ESP'])

        model = make_model()
        part = make_partition(model, flag="boot", preserve=True)
        self.assertEqual(annotations(part), ['existing', 'unused ESP'])
        part.grub_device = True
        self.assertEqual(annotations(part), ['existing', 'backup ESP'])
        fs = model.add_filesystem(part, fstype="fat32")
        model.add_mount(fs, "/boot/efi")
        self.assertEqual(annotations(part), ['existing', 'primary ESP'])

        model = make_model()
        part = make_partition(model, flag="prep", grub_device=True)
        self.assertEqual(annotations(part), ['new', 'PReP'])

        model = make_model()
        part = make_partition(model, flag="prep", preserve=True)
        self.assertEqual(
            annotations(part), ['existing', 'PReP', 'unconfigured'])
        part.grub_device = True
        self.assertEqual(
            annotations(part), ['existing', 'PReP', 'configured'])
Exemplo n.º 10
0
    def test_raid_action_DELETE(self):
        model, raid = make_model_and_raid()

        raid1 = make_raid(model)
        self.assertActionPossible(raid1, DeviceAction.DELETE)
        part = make_partition(model, raid1)
        self.assertActionPossible(raid1, DeviceAction.DELETE)
        fs = model.add_filesystem(part, 'ext4')
        self.assertActionPossible(raid1, DeviceAction.DELETE)
        model.add_mount(fs, '/')
        self.assertActionNotPossible(raid1, DeviceAction.DELETE)

        raid2 = make_raid(model)
        self.assertActionPossible(raid2, DeviceAction.DELETE)
        fs = model.add_filesystem(raid2, 'ext4')
        self.assertActionPossible(raid2, DeviceAction.DELETE)
        model.add_mount(fs, '/')
        self.assertActionPossible(raid2, DeviceAction.DELETE)

        raid2 = make_raid(model)
        model.add_volgroup('vg0', {raid2})
        self.assertActionNotPossible(raid2, DeviceAction.DELETE)
Exemplo n.º 11
0
    def _test_TOGGLE_BOOT_boot_partition(self, bl, flag):
        # The logic for when TOGGLE_BOOT is enabled for both UEFI and PREP
        # bootloaders turns out to be the same, modulo the special flag that
        # has to be present on a partition.
        model = make_model(bl)
        # A disk with a new partition table can always be the UEFI/PREP boot
        # disk.
        new_disk = make_disk(model, preserve=False)
        self.assertActionPossible(new_disk, DeviceAction.TOGGLE_BOOT)
        # Even if they are filled with partitions (we resize partitions to fit)
        make_partition(model, new_disk, size=new_disk.free_for_partitions)
        self.assertActionPossible(new_disk, DeviceAction.TOGGLE_BOOT)

        # A disk with an existing but empty partitions can also be the
        # UEFI/PREP boot disk.
        old_disk = make_disk(model, preserve=True, ptable='gpt')
        self.assertActionPossible(old_disk, DeviceAction.TOGGLE_BOOT)
        # If there is an existing partition though, it cannot.
        make_partition(model, old_disk, preserve=True)
        self.assertActionNotPossible(old_disk, DeviceAction.TOGGLE_BOOT)
        # If there is an existing ESP/PReP partition though, fine!
        make_partition(model, old_disk, flag=flag, preserve=True)
        self.assertActionPossible(old_disk, DeviceAction.TOGGLE_BOOT)
Exemplo n.º 12
0
 def test_partition_action_REMOVE(self):
     model = make_model()
     parts = []
     for i in range(5):
         parts.append(make_partition(model))
     self._test_remove_action(model, parts)
Exemplo n.º 13
0
    def test_disk_action_TOGGLE_BOOT_BIOS(self):
        model = make_model(Bootloader.BIOS)
        # Disks with msdos partition tables can always be the BIOS boot disk.
        dos_disk = make_disk(model, ptable='msdos', preserve=True)
        self.assertActionPossible(dos_disk, DeviceAction.TOGGLE_BOOT)
        # Even if they have existing partitions
        make_partition(model,
                       dos_disk,
                       size=dos_disk.free_for_partitions,
                       preserve=True)
        self.assertActionPossible(dos_disk, DeviceAction.TOGGLE_BOOT)
        # (we never create dos partition tables so no need to test
        # preserve=False case).

        # GPT disks with new partition tables can always be the BIOS boot disk
        gpt_disk = make_disk(model, ptable='gpt', preserve=False)
        self.assertActionPossible(gpt_disk, DeviceAction.TOGGLE_BOOT)
        # Even if they are filled with partitions (we resize partitions to fit)
        make_partition(model, gpt_disk, size=dos_disk.free_for_partitions)
        self.assertActionPossible(gpt_disk, DeviceAction.TOGGLE_BOOT)

        # GPT disks with existing partition tables but no partitions can be the
        # BIOS boot disk (in general we ignore existing empty partition tables)
        gpt_disk2 = make_disk(model, ptable='gpt', preserve=True)
        self.assertActionPossible(gpt_disk2, DeviceAction.TOGGLE_BOOT)
        # If there is an existing *partition* though, it cannot be the boot
        # disk
        make_partition(model, gpt_disk2, preserve=True)
        self.assertActionNotPossible(gpt_disk2, DeviceAction.TOGGLE_BOOT)
        # Unless there is already a bios_grub partition we can reuse
        gpt_disk3 = make_disk(model, ptable='gpt', preserve=True)
        make_partition(model, gpt_disk3, flag="bios_grub", preserve=True)
        make_partition(model, gpt_disk3, preserve=True)
        self.assertActionPossible(gpt_disk3, DeviceAction.TOGGLE_BOOT)
        # Edge case city: the bios_grub partition has to be first
        gpt_disk4 = make_disk(model, ptable='gpt', preserve=True)
        make_partition(model, gpt_disk4, preserve=True)
        make_partition(model, gpt_disk4, flag="bios_grub", preserve=True)
        self.assertActionNotPossible(gpt_disk4, DeviceAction.TOGGLE_BOOT)