Don't quote names with sgdisk

Our sgdisk calls are putting extra double-quotes around the names of
partitions.  This confuses sfdisk, which confuses growpart, which
confuses growroot ... and you don't get your partition grown for EFI
boot.

Ensure we just bunch arguments into the list directly (for Popen)
rather than string split and have to worry about quoting.  Add a check
for this to our GPT unit test, extending it to include a space in the
name of the root partition.

Change-Id: I0a8cb69bb4c9c0865fbaa63ba0d7210028da552e
This commit is contained in:
Ian Wienand 2018-06-27 13:51:04 +10:00
parent e39adcd65f
commit b0da703f46
3 changed files with 15 additions and 12 deletions

View File

@ -136,7 +136,7 @@ class Partitioning(PluginBase):
for p in self.partitions:
args = {}
args['pnum'] = pnum
args['name'] = '"%s"' % p.get_name()
args['name'] = '%s' % p.get_name()
args['type'] = '%s' % p.get_type()
# convert from a relative/string size to bytes
@ -149,9 +149,11 @@ class Partitioning(PluginBase):
assert size <= disk_free
args['size'] = size // (1024 * 1024)
new_cmd = ("-n {pnum}:0:+{size}M -t {pnum}:{type} "
"-c {pnum}:{name}".format(**args))
cmd.extend(new_cmd.strip().split(' '))
new_cmd = ("-n", "{pnum}:0:+{size}M".format(**args),
"-t", "{pnum}:{type}".format(**args),
# Careful with this one, as {name} could have spaces
"-c", "{pnum}:{name}".format(**args))
cmd.extend(new_cmd)
# Fill the state; we mount all partitions with kpartx
# below once we're done. So the device this partition

View File

@ -20,7 +20,9 @@
- name: BSP
type: 'EF02'
size: 8MiB
- name: root
# spaces are probably a bad idea for max compatability, but
# we're deliberatly testing it here.
- name: Root Part
type: '8300'
size: 100%
mkfs:

View File

@ -63,13 +63,12 @@ class TestGPT(tc.TestGraphGeneration):
node.create()
# check the parted call looks right
parted_cmd = ('sgdisk %s '
'-n 1:0:+8M -t 1:EF00 -c 1:"ESP" '
'-n 2:0:+8M -t 2:EF02 -c 2:"BSP" '
'-n 3:0:+1006M -t 3:8300 -c 3:"root"'
% self.image_path)
parted_cmd = ['sgdisk', self.image_path,
'-n', '1:0:+8M', '-t', '1:EF00', '-c', '1:ESP',
'-n', '2:0:+8M', '-t', '2:EF02', '-c', '2:BSP',
'-n', '3:0:+1006M', '-t', '3:8300', '-c', '3:Root Part']
cmd_sequence = [
mock.call(parted_cmd.split(' ')),
mock.call(parted_cmd),
mock.call(['sync']),
mock.call(['kpartx', '-avs', '/dev/loopX'])
]
@ -81,5 +80,5 @@ class TestGPT(tc.TestGraphGeneration):
{'device': '/dev/mapper/loopXp1'})
self.assertDictEqual(state['blockdev']['BSP'],
{'device': '/dev/mapper/loopXp2'})
self.assertDictEqual(state['blockdev']['root'],
self.assertDictEqual(state['blockdev']['Root Part'],
{'device': '/dev/mapper/loopXp3'})