disks: Workaround issue in parted during resize

Currently, if parted is given --script option it still asks for
confirmation during resize when the partition is mounted.  Implement a
workaround to the problem by first trying the proper way and then
trying a workaround described in
https://bugs.launchpad.net/ubuntu/+source/parted/+bug/1270203

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2017-04-03 16:49:07 +05:30 committed by James Valleroy
parent eed31ae7f5
commit c46cba8134
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -72,11 +72,20 @@ def _resize_partition(device, requested_partition, free_space):
command = ['parted', '--align=optimal', '--script', device, 'unit', 'B',
'resizepart', requested_partition['number'],
str(free_space['end'])]
# XXX: Remove workaround after bug in parted is fixed:
# https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24215
fallback_command = ['parted', '--align=optimal', device,
'---pretend-input-tty', 'unit', 'B', 'resizepart',
requested_partition['number'], 'yes',
str(free_space['end'])]
try:
subprocess.run(command, check=True)
except subprocess.CalledProcessError as exception:
print('Error expanding partition:', exception, file=sys.stderr)
sys.exit(5)
try:
subprocess.run(fallback_command, check=True)
except subprocess.CalledProcessError as exception:
print('Error expanding partition:', exception, file=sys.stderr)
sys.exit(5)
def _resize_file_system(device, requested_partition, free_space):