Skip to content

Conversation

@xiachen-rh
Copy link
Contributor

When checking GPT partition layout using sfdisk, handle the case where a disk has no partition table yet.
Previously, it would raise an exception.
Because check_partition_gpt_layout_sfdisk calls "sfdisk -l -J ", the command exits with code 1 and the error "does not contain a recognized partition table". The code doesn't handle it and raises an error.
Now it returns an empty list.
I also add unit test to cover this empty disk scenario.

Fixes GH-6682

Test Steps

I run test on OpenStack with an additional empty disk with config data as below

# cat /etc/cloud/cloud.cfg.d/disk.cfg 
#cloud-config
disk_setup:
  /dev/vdb:
    table_type: 'gpt'
    layout: True
    overwrite: True

steps

  1. Create a volume and attach it to a instance
  2. login, and prepare configuration data for cloud-init to do disk setup
  3. clean cloud-init and reboot
  4. check the result

After fix, no unexpected error about sfdisk, and the additional disk /dev/vdb is parted

# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda    252:0    0   20G  0 disk 
├─vda1 252:1    0    1M  0 part 
├─vda2 252:2    0  200M  0 part /boot/efi
└─vda3 252:3    0 19.8G  0 part /
vdb    252:16   0   50G  0 disk 
└─vdb1 252:17   0   50G  0 part 

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

When checking GPT partition layout using sfdisk, handle the case
where a disk has no partition table yet. Previously, this would
raise an exception. Now it returns an empty list when sfdisk
returns "does not contain a recognized partition table".

Add unit test to cover this empty disk scenario.

Fixes canonicalGH-6682

Signed-off-by: Amy Chen <xiachen@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud-init fails to partition and empty disk with sfdisk when the type is gpt

1 participant