Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
0
def make_controller(bootloader=None):
    app = MiniApplication()
    app.base_model = bm = Thing()
    app.context = Context.new(app)
    bm.filesystem = make_model(bootloader)
    controller = FilesystemController(app)
    return controller
Esempio n. 4
0
def make_controller(bootloader=None):
    common = defaultdict(type(None))
    bm = Thing()
    bm.filesystem = make_model(bootloader)
    common['base_model'] = bm
    common['answers'] = {}
    opts = Thing()
    opts.dry_run = True
    opts.bootloader = None
    common['opts'] = opts
    controller = FilesystemController(common)
    return controller
Esempio n. 5
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)
Esempio n. 6
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'])
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
0
def make_manipulator(bootloader=None):
    manipulator = FilesystemManipulator()
    manipulator.model = make_model(bootloader)
    manipulator.supports_resilient_boot = True
    return manipulator
Esempio n. 11
0
 def test_raid_action_REMOVE(self):
     model = make_model()
     raids = [make_raid(model) for i in range(5)]
     self._test_remove_action(model, raids)
Esempio 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)
Esempio n. 13
0
 def test_disk_action_REMOVE(self):
     model = make_model()
     disks = [make_disk(model) for i in range(5)]
     self._test_remove_action(model, disks)