From 016fef606fdf29960d1cdb8a1b89cb880153d782 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Mon, 19 Jan 2015 01:20:29 +0100 Subject: [PATCH] Account for PartitioGap in a few more places --- bootstrapvz/base/fs/partitionmaps/abstract.py | 9 ++++++--- bootstrapvz/base/fs/partitions/gap.py | 17 +++++++++++++++++ bootstrapvz/common/tasks/grub.py | 3 +++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/bootstrapvz/base/fs/partitionmaps/abstract.py b/bootstrapvz/base/fs/partitionmaps/abstract.py index b4475a4..ed25770 100644 --- a/bootstrapvz/base/fs/partitionmaps/abstract.py +++ b/bootstrapvz/base/fs/partitionmaps/abstract.py @@ -75,6 +75,9 @@ class AbstractPartitionMap(FSMProxy): '{device_path} (?P\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 diff --git a/bootstrapvz/base/fs/partitions/gap.py b/bootstrapvz/base/fs/partitions/gap.py index 9aadb97..e7b197b 100644 --- a/bootstrapvz/base/fs/partitions/gap.py +++ b/bootstrapvz/base/fs/partitions/gap.py @@ -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() diff --git a/bootstrapvz/common/tasks/grub.py b/bootstrapvz/common/tasks/grub.py index b528712..ab5bec2 100644 --- a/bootstrapvz/common/tasks/grub.py +++ b/bootstrapvz/common/tasks/grub.py @@ -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,