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

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 5150
Proposed branch: lp:~blake-rouse/maas/fix-1597787
Merge into: lp:~maas-committers/maas/trunk
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
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+298950@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
Mike Pontillo (mpontillo) wrote :

Looks good to me, assuming it was tested end-to-end.

review: Approve
Revision history for this message
Blake Rouse (blake-rouse) wrote :

It was tested end to end.

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-03-28 13:54:47 +0000
+++ src/maasserver/preseed_storage.py 2016-07-01 20:22:59 +0000
@@ -9,13 +9,16 @@
99
10from operator import attrgetter10from operator import attrgetter
1111
12from django.db.models import Sum
12from maasserver.enum import (13from maasserver.enum import (
13 FILESYSTEM_GROUP_TYPE,14 FILESYSTEM_GROUP_TYPE,
14 FILESYSTEM_TYPE,15 FILESYSTEM_TYPE,
15 PARTITION_TABLE_TYPE,16 PARTITION_TABLE_TYPE,
16)17)
18from maasserver.models.partition import Partition
17from maasserver.models.partitiontable import (19from maasserver.models.partitiontable import (
18 INITIAL_PARTITION_OFFSET,20 INITIAL_PARTITION_OFFSET,
21 PARTITION_TABLE_EXTRA_SPACE,
19 PREP_PARTITION_SIZE,22 PREP_PARTITION_SIZE,
20)23)
21from maasserver.models.physicalblockdevice import PhysicalBlockDevice24from maasserver.models.physicalblockdevice import PhysicalBlockDevice
@@ -287,16 +290,39 @@
287 # Fifth partition on an MBR partition, must add the extend290 # Fifth partition on an MBR partition, must add the extend
288 # partition operation. So the remaining partitions can be added.291 # partition operation. So the remaining partitions can be added.
289 if partition_number == 5:292 if partition_number == 5:
293 # Calculate the remaining size of the disk available for the
294 # extended partition.
295 extended_size = block_device.size - PARTITION_TABLE_EXTRA_SPACE
296 previous_partitions = Partition.objects.filter(
297 id__lt=partition.id, partition_table=partition_table)
298 extended_size = extended_size - (
299 previous_partitions.aggregate(Sum('size'))['size__sum'])
300 # Curtin adds 1MiB between each logical partition inside the
301 # extended partition. It incorrectly adds onto the size
302 # automatically so we have to extract that size from the
303 # overall size of the extended partition.
304 following_partitions = Partition.objects.filter(
305 id__gte=partition.id, partition_table=partition_table)
306 logical_extra_space = following_partitions.count() * (1 << 20)
307 extended_size = extended_size - logical_extra_space
290 self.storage_config.append({308 self.storage_config.append({
291 "id": "%s-part4" % block_device.get_name(),309 "id": "%s-part4" % block_device.get_name(),
292 "type": "partition",310 "type": "partition",
293 "number": 4,311 "number": 4,
294 "device": block_device.get_name(),312 "device": block_device.get_name(),
295 "flag": "extended",313 "flag": "extended",
314 "size": "%sB" % extended_size,
296 })315 })
297 partition_operation["flag"] = "logical"316 partition_operation["flag"] = "logical"
317 partition_operation["size"] = "%sB" % (
318 partition.size - (1 << 20))
298 elif partition_number > 5:319 elif partition_number > 5:
320 # Curtin adds 1MiB between each logical partition. We subtract
321 # the 1MiB from the size of the partition so all the partitions
322 # fit within the extended partition.
299 partition_operation["flag"] = "logical"323 partition_operation["flag"] = "logical"
324 partition_operation["size"] = "%sB" % (
325 partition.size - (1 << 20))
300 self.storage_config.append(partition_operation)326 self.storage_config.append(partition_operation)
301327
302 def _generate_format_operations(self):328 def _generate_format_operations(self):
303329
=== modified file 'src/maasserver/tests/test_preseed_storage.py'
--- src/maasserver/tests/test_preseed_storage.py 2016-03-28 13:54:47 +0000
+++ src/maasserver/tests/test_preseed_storage.py 2016-07-01 20:22:59 +0000
@@ -256,12 +256,13 @@
256 number: 4256 number: 4
257 device: sda257 device: sda
258 flag: extended258 flag: extended
259 size: 4287627264B
259 - id: sda-part5260 - id: sda-part5
260 name: sda-part5261 name: sda-part5
261 type: partition262 type: partition
262 number: 5263 number: 5
263 uuid: 1b59e74f-6189-41a1-ba8e-fbf38df19820264 uuid: 1b59e74f-6189-41a1-ba8e-fbf38df19820
264 size: 2147483648B265 size: 2146435072B
265 device: sda266 device: sda
266 wipe: superblock267 wipe: superblock
267 flag: logical268 flag: logical
@@ -270,7 +271,7 @@
270 type: partition271 type: partition
271 number: 6272 number: 6
272 uuid: 8c365c80-900b-40a1-a8c7-1e445878d19a273 uuid: 8c365c80-900b-40a1-a8c7-1e445878d19a
273 size: 2139095040B274 size: 2138046464B
274 device: sda275 device: sda
275 wipe: superblock276 wipe: superblock
276 flag: logical277 flag: logical