Account for PartitioGap in a few more places

This commit is contained in:
Anders Ingemann 2015-01-19 01:20:29 +01:00
parent 31b9cb5caa
commit 016fef606f
3 changed files with 26 additions and 3 deletions

View file

@ -75,6 +75,9 @@ class AbstractPartitionMap(FSMProxy):
'{device_path} (?P<blk_offset>\d+)$'
.format(device_path=volume.device_path))
log_check_call(['kpartx', '-as', volume.device_path])
mappable_partitions = filter(lambda p: not isinstance(p, PartitionGap), self.partitions)
import os.path
# Run through the kpartx output and map the paths to the partitions
for mapping in mappings:
@ -83,19 +86,19 @@ class AbstractPartitionMap(FSMProxy):
raise PartitionError('Unable to parse kpartx output: ' + mapping)
partition_path = os.path.join('/dev/mapper', match.group('name'))
p_idx = int(match.group('p_idx')) - 1
self.partitions[p_idx].map(partition_path)
mappable_partitions[p_idx].map(partition_path)
# Check if any partition was not mapped
for idx, partition in enumerate(self.partitions):
if isinstance(partition, PartitionGap):
continue
if partition.fsm.current not in ['mapped', 'formatted']:
raise PartitionError('kpartx did not map partition #' + str(idx + 1))
raise PartitionError('kpartx did not map partition #' + str(partition.get_index()))
except PartitionError:
# Revert any mapping and reraise the error
for partition in self.partitions:
if not partition.fsm.can('unmap'):
if partition.fsm.can('unmap'):
partition.unmap()
log_check_call(['kpartx', '-ds', volume.device_path])
raise

View file

@ -15,3 +15,20 @@ class PartitionGap(BasePartition):
:param BasePartition previous: The partition that preceeds this one
"""
super(PartitionGap, self).__init__(size, None, None, previous)
def get_index(self):
"""Gets the index of this partition in the partition map
Note that PartitionGap.get_index() simply returns the index of the
previous partition, since a gap does not count towards
the number of partitions.
If there is no previous partition 0 will be returned
(although partitions really are 1 indexed)
:return: The index of the partition in the partition map
:rtype: int
"""
if self.previous is None:
return 0
else:
# Recursive call to the previous partition, walking up the chain...
return self.previous.get_index()

View file

@ -68,7 +68,10 @@ class InstallGrub_1_99(Task):
with open(device_map_path, 'w') as device_map:
device_map.write('(hd0) {device_path}\n'.format(device_path=device_path))
if not isinstance(p_map, partitionmaps.none.NoPartitions):
from bootstrapvz.base.fs.partitions.gap import PartitionGap
for idx, partition in enumerate(info.volume.partition_map.partitions):
if isinstance(partition, PartitionGap):
continue
device_map.write('(hd0,{prefix}{idx}) {device_path}\n'
.format(device_path=partition.device_path,
prefix=partition_prefix,