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

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 5144
Proposed branch: lp:~blake-rouse/maas/fix-1597787-2.0
Merge into: lp:maas/2.0
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-2.0
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+298992@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
1=== modified file 'src/maasserver/preseed_storage.py'
2--- src/maasserver/preseed_storage.py 2016-03-28 13:54:47 +0000
3+++ src/maasserver/preseed_storage.py 2016-07-03 15:21:41 +0000
4@@ -9,13 +9,16 @@
5
6 from operator import attrgetter
7
8+from django.db.models import Sum
9 from maasserver.enum import (
10 FILESYSTEM_GROUP_TYPE,
11 FILESYSTEM_TYPE,
12 PARTITION_TABLE_TYPE,
13 )
14+from maasserver.models.partition import Partition
15 from maasserver.models.partitiontable import (
16 INITIAL_PARTITION_OFFSET,
17+ PARTITION_TABLE_EXTRA_SPACE,
18 PREP_PARTITION_SIZE,
19 )
20 from maasserver.models.physicalblockdevice import PhysicalBlockDevice
21@@ -287,16 +290,39 @@
22 # Fifth partition on an MBR partition, must add the extend
23 # partition operation. So the remaining partitions can be added.
24 if partition_number == 5:
25+ # Calculate the remaining size of the disk available for the
26+ # extended partition.
27+ extended_size = block_device.size - PARTITION_TABLE_EXTRA_SPACE
28+ previous_partitions = Partition.objects.filter(
29+ id__lt=partition.id, partition_table=partition_table)
30+ extended_size = extended_size - (
31+ previous_partitions.aggregate(Sum('size'))['size__sum'])
32+ # Curtin adds 1MiB between each logical partition inside the
33+ # extended partition. It incorrectly adds onto the size
34+ # automatically so we have to extract that size from the
35+ # overall size of the extended partition.
36+ following_partitions = Partition.objects.filter(
37+ id__gte=partition.id, partition_table=partition_table)
38+ logical_extra_space = following_partitions.count() * (1 << 20)
39+ extended_size = extended_size - logical_extra_space
40 self.storage_config.append({
41 "id": "%s-part4" % block_device.get_name(),
42 "type": "partition",
43 "number": 4,
44 "device": block_device.get_name(),
45 "flag": "extended",
46+ "size": "%sB" % extended_size,
47 })
48 partition_operation["flag"] = "logical"
49+ partition_operation["size"] = "%sB" % (
50+ partition.size - (1 << 20))
51 elif partition_number > 5:
52+ # Curtin adds 1MiB between each logical partition. We subtract
53+ # the 1MiB from the size of the partition so all the partitions
54+ # fit within the extended partition.
55 partition_operation["flag"] = "logical"
56+ partition_operation["size"] = "%sB" % (
57+ partition.size - (1 << 20))
58 self.storage_config.append(partition_operation)
59
60 def _generate_format_operations(self):
61
62=== modified file 'src/maasserver/tests/test_preseed_storage.py'
63--- src/maasserver/tests/test_preseed_storage.py 2016-03-28 13:54:47 +0000
64+++ src/maasserver/tests/test_preseed_storage.py 2016-07-03 15:21:41 +0000
65@@ -256,12 +256,13 @@
66 number: 4
67 device: sda
68 flag: extended
69+ size: 4287627264B
70 - id: sda-part5
71 name: sda-part5
72 type: partition
73 number: 5
74 uuid: 1b59e74f-6189-41a1-ba8e-fbf38df19820
75- size: 2147483648B
76+ size: 2146435072B
77 device: sda
78 wipe: superblock
79 flag: logical
80@@ -270,7 +271,7 @@
81 type: partition
82 number: 6
83 uuid: 8c365c80-900b-40a1-a8c7-1e445878d19a
84- size: 2139095040B
85+ size: 2138046464B
86 device: sda
87 wipe: superblock
88 flag: logical

Subscribers

People subscribed via source and target branches

to all changes: