def get_candidate_disks(storage): """Return a list of disks to be used for autopart/reqpart. Disks must be partitioned and have a single free region large enough for a default-sized (500MiB) partition. :param storage: an InstallerStorage instance :type storage: :class:`~.storage.InstallerStorage` :return: a list of partitioned disks with at least 500MiB of free space :rtype: list of :class:`blivet.devices.StorageDevice` """ disks = [] for disk in storage.partitioned: if not disk.format.supported or disk.protected: continue if get_next_partition_type(disk.format.parted_disk) is None: # new partition can't be added to the disk -- there is no free slot # for a primary partition and no extended partition continue part = disk.format.first_partition while part: if not part.type & parted.PARTITION_FREESPACE: part = part.nextPartition() continue if Size(part.getLength(unit="B")) > PartitionDevice.default_size: disks.append(disk) break part = part.nextPartition() return disks
def test_next_partition_type(self): # # DOS # # empty disk, any type disk = self.get_disk(disk_type="dos") self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # three primaries and no extended -> extended disk = self.get_disk(disk_type="dos", primary_count=3) self.assertEqual(get_next_partition_type(disk), parted.PARTITION_EXTENDED) # three primaries and an extended -> primary disk = self.get_disk(disk_type="dos", primary_count=3, has_extended=True) self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # three primaries and an extended w/ no_primary -> logical disk = self.get_disk(disk_type="dos", primary_count=3, has_extended=True) self.assertEqual(get_next_partition_type(disk, no_primary=True), parted.PARTITION_LOGICAL) # four primaries and an extended, available logical -> logical disk = self.get_disk(disk_type="dos", primary_count=4, has_extended=True, logical_count=9) self.assertEqual(get_next_partition_type(disk), parted.PARTITION_LOGICAL) # four primaries and an extended -> logical disk = self.get_disk(disk_type="dos", primary_count=4, has_extended=True, logical_count=11) self.assertEqual(get_next_partition_type(disk), parted.PARTITION_LOGICAL) # four primaries and no extended -> None disk = self.get_disk(disk_type="dos", primary_count=4, has_extended=False) self.assertEqual(get_next_partition_type(disk), None) # free primary slot, extended -> primary disk = self.get_disk(disk_type="dos", primary_count=3, has_extended=True, logical_count=11) self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # free primary slot, extended w/ no_primary -> logical disk = self.get_disk(disk_type="dos", primary_count=3, has_extended=True, logical_count=11) self.assertEqual(get_next_partition_type(disk, no_primary=True), parted.PARTITION_LOGICAL) # # GPT # # empty disk, any partition type disk = self.get_disk(disk_type="gpt") self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # no empty slots -> None disk = self.get_disk(disk_type="gpt", primary_count=128) self.assertEqual(get_next_partition_type(disk), None) # no_primary -> None disk = self.get_disk(disk_type="gpt") self.assertEqual(get_next_partition_type(disk, no_primary=True), None) # # MAC # # empty disk, any partition type disk = self.get_disk(disk_type="mac") self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # no empty slots -> None disk = self.get_disk(disk_type="mac", primary_count=62) self.assertEqual(get_next_partition_type(disk), None) # no_primary -> None disk = self.get_disk(disk_type="mac") self.assertEqual(get_next_partition_type(disk, no_primary=True), None)
def test_next_partition_type(self): # # DOS # # empty disk, any type disk = self.get_disk(disk_type="dos") self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # three primaries and no extended -> extended disk = self.get_disk(disk_type="dos", primary_count=3) self.assertEqual(get_next_partition_type(disk), parted.PARTITION_EXTENDED) # three primaries and an extended -> primary disk = self.get_disk(disk_type="dos", primary_count=3, has_extended=True) self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # three primaries and an extended w/ no_primary -> logical disk = self.get_disk(disk_type="dos", primary_count=3, has_extended=True) self.assertEqual(get_next_partition_type(disk, no_primary=True), parted.PARTITION_LOGICAL) # four primaries and an extended, available logical -> logical disk = self.get_disk(disk_type="dos", primary_count=4, has_extended=True, logical_count=9) self.assertEqual(get_next_partition_type(disk), parted.PARTITION_LOGICAL) # four primaries and an extended, no available logical -> None disk = self.get_disk(disk_type="dos", primary_count=4, has_extended=True, logical_count=11) self.assertEqual(get_next_partition_type(disk), None) # four primaries and no extended -> None disk = self.get_disk(disk_type="dos", primary_count=4, has_extended=False) self.assertEqual(get_next_partition_type(disk), None) # free primary slot, extended, no free logical slot -> primary disk = self.get_disk(disk_type="dos", primary_count=3, has_extended=True, logical_count=11) self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # free primary slot, extended, no free logical slot w/ no_primary # -> None disk = self.get_disk(disk_type="dos", primary_count=3, has_extended=True, logical_count=11) self.assertEqual(get_next_partition_type(disk, no_primary=True), None) # # GPT # # empty disk, any partition type disk = self.get_disk(disk_type="gpt") self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # no empty slots -> None disk = self.get_disk(disk_type="gpt", primary_count=128) self.assertEqual(get_next_partition_type(disk), None) # no_primary -> None disk = self.get_disk(disk_type="gpt") self.assertEqual(get_next_partition_type(disk, no_primary=True), None) # # MAC # # empty disk, any partition type disk = self.get_disk(disk_type="mac") self.assertEqual(get_next_partition_type(disk), parted.PARTITION_NORMAL) # no empty slots -> None disk = self.get_disk(disk_type="mac", primary_count=62) self.assertEqual(get_next_partition_type(disk), None) # no_primary -> None disk = self.get_disk(disk_type="mac") self.assertEqual(get_next_partition_type(disk, no_primary=True), None)