mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
Account for PartitioGap in a few more places
This commit is contained in:
parent
31b9cb5caa
commit
016fef606f
3 changed files with 26 additions and 3 deletions
|
@ -75,6 +75,9 @@ class AbstractPartitionMap(FSMProxy):
|
||||||
'{device_path} (?P<blk_offset>\d+)$'
|
'{device_path} (?P<blk_offset>\d+)$'
|
||||||
.format(device_path=volume.device_path))
|
.format(device_path=volume.device_path))
|
||||||
log_check_call(['kpartx', '-as', 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
|
import os.path
|
||||||
# Run through the kpartx output and map the paths to the partitions
|
# Run through the kpartx output and map the paths to the partitions
|
||||||
for mapping in mappings:
|
for mapping in mappings:
|
||||||
|
@ -83,19 +86,19 @@ class AbstractPartitionMap(FSMProxy):
|
||||||
raise PartitionError('Unable to parse kpartx output: ' + mapping)
|
raise PartitionError('Unable to parse kpartx output: ' + mapping)
|
||||||
partition_path = os.path.join('/dev/mapper', match.group('name'))
|
partition_path = os.path.join('/dev/mapper', match.group('name'))
|
||||||
p_idx = int(match.group('p_idx')) - 1
|
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
|
# Check if any partition was not mapped
|
||||||
for idx, partition in enumerate(self.partitions):
|
for idx, partition in enumerate(self.partitions):
|
||||||
if isinstance(partition, PartitionGap):
|
if isinstance(partition, PartitionGap):
|
||||||
continue
|
continue
|
||||||
if partition.fsm.current not in ['mapped', 'formatted']:
|
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:
|
except PartitionError:
|
||||||
# Revert any mapping and reraise the error
|
# Revert any mapping and reraise the error
|
||||||
for partition in self.partitions:
|
for partition in self.partitions:
|
||||||
if not partition.fsm.can('unmap'):
|
if partition.fsm.can('unmap'):
|
||||||
partition.unmap()
|
partition.unmap()
|
||||||
log_check_call(['kpartx', '-ds', volume.device_path])
|
log_check_call(['kpartx', '-ds', volume.device_path])
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -15,3 +15,20 @@ class PartitionGap(BasePartition):
|
||||||
:param BasePartition previous: The partition that preceeds this one
|
:param BasePartition previous: The partition that preceeds this one
|
||||||
"""
|
"""
|
||||||
super(PartitionGap, self).__init__(size, None, None, previous)
|
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()
|
||||||
|
|
|
@ -68,7 +68,10 @@ class InstallGrub_1_99(Task):
|
||||||
with open(device_map_path, 'w') as device_map:
|
with open(device_map_path, 'w') as device_map:
|
||||||
device_map.write('(hd0) {device_path}\n'.format(device_path=device_path))
|
device_map.write('(hd0) {device_path}\n'.format(device_path=device_path))
|
||||||
if not isinstance(p_map, partitionmaps.none.NoPartitions):
|
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):
|
for idx, partition in enumerate(info.volume.partition_map.partitions):
|
||||||
|
if isinstance(partition, PartitionGap):
|
||||||
|
continue
|
||||||
device_map.write('(hd0,{prefix}{idx}) {device_path}\n'
|
device_map.write('(hd0,{prefix}{idx}) {device_path}\n'
|
||||||
.format(device_path=partition.device_path,
|
.format(device_path=partition.device_path,
|
||||||
prefix=partition_prefix,
|
prefix=partition_prefix,
|
||||||
|
|
Loading…
Add table
Reference in a new issue