Skip to content

Commit

Permalink
Simplify results from partitionTargetDisk
Browse files Browse the repository at this point in the history
Instead of coding lot of logic in the "return" line use a
"part_nums" list.
This will make easier to change the partition layout avoiding
long and hard to understand lines.

Signed-off-by: Frediano Ziglio <[email protected]>
  • Loading branch information
freddy77 committed Nov 14, 2024
1 parent 14f4fbc commit edb48fd
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,22 +527,24 @@ def configureNTP(mounts, ntp_config_method, ntp_servers):
def partitionTargetDisk(disk, existing, preserve_first_partition, create_sr_part):
logger.log("Installer booted in %s mode" % ("UEFI" if constants.UEFI_INSTALLER else "legacy"))

(PRIMARY, BACKUP, STORAGE, BOOT, LOGS, SWAP) = list(range(6))

primary_part = 1
if existing:
# upgrade, use existing partitioning scheme
tool = PartitionTool(existing.primary_disk)

primary_part = tool.partitionNumber(existing.root_device)

part_nums = list(range(primary_part, primary_part+6))

# Determine target install's boot mode and boot partition number
target_boot_mode = TARGET_BOOT_MODE_LEGACY
if existing.boot_device:
boot_partnum = tool.partitionNumber(existing.boot_device)
boot_part = tool.getPartition(boot_partnum)
part_nums[BOOT] = tool.partitionNumber(existing.boot_device)
boot_part = tool.getPartition(part_nums[BOOT])
if 'id' in boot_part and boot_part['id'] == GPTPartitionTool.ID_EFI_BOOT:
target_boot_mode = TARGET_BOOT_MODE_UEFI
else:
boot_partnum = primary_part + 3

if (target_boot_mode == TARGET_BOOT_MODE_UEFI and not constants.UEFI_INSTALLER) or \
(target_boot_mode == TARGET_BOOT_MODE_LEGACY and constants.UEFI_INSTALLER):
Expand All @@ -552,11 +554,10 @@ def partitionTargetDisk(disk, existing, preserve_first_partition, create_sr_part
logger.log("Upgrading, target_boot_mode: %s" % target_boot_mode)

# Return install mode and numbers of primary, backup, SR, boot, log and swap partitions
storage_partition = tool.getPartition(primary_part+2)
if storage_partition:
return (target_boot_mode, primary_part, primary_part+1, primary_part+2, boot_partnum, primary_part+4, primary_part+5)
else:
return (target_boot_mode, primary_part, primary_part+1, 0, boot_partnum, primary_part+4, primary_part+5)
storage_partition = tool.getPartition(part_nums[STORAGE])
if not storage_partition:
part_nums[STORAGE] = 0
return tuple([target_boot_mode] + part_nums)

tool = PartitionTool(disk)

Expand All @@ -576,17 +577,18 @@ def partitionTargetDisk(disk, existing, preserve_first_partition, create_sr_part
if primary_part > 2:
raise RuntimeError("Installer only supports a single Utility Partition at partition 1, but found Utility Partitions at %s" % str(utilparts))

sr_part = -1
if create_sr_part:
sr_part = primary_part+2
part_nums = list(range(primary_part, primary_part+6))

if not create_sr_part:
part_nums[STORAGE] = -1

boot_part = max(primary_part + 1, sr_part) + 1
part_nums[BOOT] = max(primary_part + 1, part_nums[STORAGE]) + 1

target_boot_mode = TARGET_BOOT_MODE_UEFI if constants.UEFI_INSTALLER else TARGET_BOOT_MODE_LEGACY

logger.log("Fresh install, target_boot_mode: %s" % target_boot_mode)

return (target_boot_mode, primary_part, primary_part + 1, sr_part, boot_part, primary_part + 4, primary_part + 5)
return tuple([target_boot_mode] + part_nums)

def removeBlockingVGs(disks):
for vg in diskutil.findProblematicVGs(disks):
Expand Down

0 comments on commit edb48fd

Please sign in to comment.