Merge lp:~blake-rouse/maas/fix-1597787-1.9 into lp:maas/1.9

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 4588
Proposed branch: lp:~blake-rouse/maas/fix-1597787-1.9
Merge into: lp:maas/1.9
Diff against target: 88 lines (+29/-2)
2 files modified
src/maasserver/preseed_storage.py (+26/-0)
src/maasserver/tests/test_preseed_storage.py (+3/-2)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1597787-1.9
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+298993@code.launchpad.net

Commit message

Send size with the extended partition for MBR partition tables.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Backport, self-review.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/preseed_storage.py'
--- src/maasserver/preseed_storage.py 2016-02-24 14:34:16 +0000
+++ src/maasserver/preseed_storage.py 2016-07-03 15:25:45 +0000
@@ -17,13 +17,16 @@
1717
18from operator import attrgetter18from operator import attrgetter
1919
20from django.db.models import Sum
20from maasserver.enum import (21from maasserver.enum import (
21 FILESYSTEM_GROUP_TYPE,22 FILESYSTEM_GROUP_TYPE,
22 FILESYSTEM_TYPE,23 FILESYSTEM_TYPE,
23 PARTITION_TABLE_TYPE,24 PARTITION_TABLE_TYPE,
24)25)
26from maasserver.models.partition import Partition
25from maasserver.models.partitiontable import (27from maasserver.models.partitiontable import (
26 INITIAL_PARTITION_OFFSET,28 INITIAL_PARTITION_OFFSET,
29 PARTITION_TABLE_EXTRA_SPACE,
27 PREP_PARTITION_SIZE,30 PREP_PARTITION_SIZE,
28)31)
29from maasserver.models.physicalblockdevice import PhysicalBlockDevice32from maasserver.models.physicalblockdevice import PhysicalBlockDevice
@@ -295,16 +298,39 @@
295 # Fifth partition on an MBR partition, must add the extend298 # Fifth partition on an MBR partition, must add the extend
296 # partition operation. So the remaining partitions can be added.299 # partition operation. So the remaining partitions can be added.
297 if partition_number == 5:300 if partition_number == 5:
301 # Calculate the remaining size of the disk available for the
302 # extended partition.
303 extended_size = block_device.size - PARTITION_TABLE_EXTRA_SPACE
304 previous_partitions = Partition.objects.filter(
305 id__lt=partition.id, partition_table=partition_table)
306 extended_size = extended_size - (
307 previous_partitions.aggregate(Sum('size'))['size__sum'])
308 # Curtin adds 1MiB between each logical partition inside the
309 # extended partition. It incorrectly adds onto the size
310 # automatically so we have to extract that size from the
311 # overall size of the extended partition.
312 following_partitions = Partition.objects.filter(
313 id__gte=partition.id, partition_table=partition_table)
314 logical_extra_space = following_partitions.count() * (1 << 20)
315 extended_size = extended_size - logical_extra_space
298 self.storage_config.append({316 self.storage_config.append({
299 "id": "%s-part4" % block_device.get_name(),317 "id": "%s-part4" % block_device.get_name(),
300 "type": "partition",318 "type": "partition",
301 "number": 4,319 "number": 4,
302 "device": block_device.get_name(),320 "device": block_device.get_name(),
303 "flag": "extended",321 "flag": "extended",
322 "size": "%sB" % extended_size,
304 })323 })
305 partition_operation["flag"] = "logical"324 partition_operation["flag"] = "logical"
325 partition_operation["size"] = "%sB" % (
326 partition.size - (1 << 20))
306 elif partition_number > 5:327 elif partition_number > 5:
328 # Curtin adds 1MiB between each logical partition. We subtract
329 # the 1MiB from the size of the partition so all the partitions
330 # fit within the extended partition.
307 partition_operation["flag"] = "logical"331 partition_operation["flag"] = "logical"
332 partition_operation["size"] = "%sB" % (
333 partition.size - (1 << 20))
308 self.storage_config.append(partition_operation)334 self.storage_config.append(partition_operation)
309335
310 def _generate_format_operations(self):336 def _generate_format_operations(self):
311337
=== modified file 'src/maasserver/tests/test_preseed_storage.py'
--- src/maasserver/tests/test_preseed_storage.py 2016-02-24 14:34:16 +0000
+++ src/maasserver/tests/test_preseed_storage.py 2016-07-03 15:25:45 +0000
@@ -222,12 +222,13 @@
222 number: 4222 number: 4
223 device: sda223 device: sda
224 flag: extended224 flag: extended
225 size: 4287627264B
225 - id: sda-part5226 - id: sda-part5
226 name: sda-part5227 name: sda-part5
227 type: partition228 type: partition
228 number: 5229 number: 5
229 uuid: 1b59e74f-6189-41a1-ba8e-fbf38df19820230 uuid: 1b59e74f-6189-41a1-ba8e-fbf38df19820
230 size: 2147483648B231 size: 2146435072B
231 device: sda232 device: sda
232 wipe: superblock233 wipe: superblock
233 flag: logical234 flag: logical
@@ -236,7 +237,7 @@
236 type: partition237 type: partition
237 number: 6238 number: 6
238 uuid: 8c365c80-900b-40a1-a8c7-1e445878d19a239 uuid: 8c365c80-900b-40a1-a8c7-1e445878d19a
239 size: 2139095040B240 size: 2138046464B
240 device: sda241 device: sda
241 wipe: superblock242 wipe: superblock
242 flag: logical243 flag: logical

Subscribers

People subscribed via source and target branches