Merge lp:~blake-rouse/maas/mbr-2tb-smaller into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Andres Rodriguez
Approved revision: no longer in the source branch.
Merged at revision: 4367
Proposed branch: lp:~blake-rouse/maas/mbr-2tb-smaller
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 166 lines (+30/-17)
7 files modified
src/maasserver/models/filesystemgroup.py (+1/-1)
src/maasserver/models/partition.py (+13/-2)
src/maasserver/models/partitiontable.py (+3/-5)
src/maasserver/models/tests/test_filesystemgroup.py (+2/-2)
src/maasserver/models/tests/test_partitiontable.py (+2/-1)
src/maasserver/storage_layouts.py (+5/-5)
src/maasserver/tests/test_storage_layouts.py (+4/-1)
To merge this branch: bzr merge lp:~blake-rouse/maas/mbr-2tb-smaller
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+273946@code.launchpad.net

Commit message

Make the maximum size for MBR 2TiB to be 1MiB smaller. Fix the calculation of the available size of a volume group.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/filesystemgroup.py'
2--- src/maasserver/models/filesystemgroup.py 2015-09-24 16:22:12 +0000
3+++ src/maasserver/models/filesystemgroup.py 2015-10-09 04:37:09 +0000
4@@ -375,7 +375,7 @@
5 for filesystem in filesystems
6 )
7 number_of_extents, _ = divmod(pv_total_size, LVM_PE_SIZE)
8- return number_of_extents * LVM_PE_SIZE
9+ return (number_of_extents - 1) * LVM_PE_SIZE
10
11 def get_smallest_filesystem_size(self):
12 """Return the smallest filesystem size."""
13
14=== modified file 'src/maasserver/models/partition.py'
15--- src/maasserver/models/partition.py 2015-10-07 05:01:27 +0000
16+++ src/maasserver/models/partition.py 2015-10-09 04:37:09 +0000
17@@ -44,7 +44,7 @@
18
19
20 MIN_PARTITION_SIZE = MIN_BLOCK_DEVICE_SIZE
21-MAX_PARTITION_SIZE_FOR_MBR = 2 * (1024 ** 4) # 2TiB
22+MAX_PARTITION_SIZE_FOR_MBR = (((2 ** 32) - 1) * 512) - (1024 ** 2) # 2 TiB
23
24
25 class PartitionManager(Manager):
26@@ -219,6 +219,17 @@
27 self.size = round_size_to_nearest_block(
28 self.size, self.partition_table.get_block_size())
29
30+ @classmethod
31+ def _get_mbr_max_for_block_device(self, block_device):
32+ """Get the maximum partition size for MBR for this block device."""
33+ return round_size_to_nearest_block(
34+ MAX_PARTITION_SIZE_FOR_MBR, block_device.block_size)
35+
36+ def _get_mbr_max_for_partition(self):
37+ """Get the maximum partition size for MBR for this partition."""
38+ return self._get_mbr_max_for_block_device(
39+ self.partition_table.block_device)
40+
41 def _validate_enough_space(self):
42 """Validate that the partition table has enough space for this
43 partition."""
44@@ -250,7 +261,7 @@
45
46 # Check that the size is not larger than MBR allows.
47 if (self.partition_table.table_type == PARTITION_TABLE_TYPE.MBR and
48- self.size > MAX_PARTITION_SIZE_FOR_MBR):
49+ self.size > self._get_mbr_max_for_partition()):
50 if self.id is not None:
51 raise ValidationError({
52 "size": [
53
54=== modified file 'src/maasserver/models/partitiontable.py'
55--- src/maasserver/models/partitiontable.py 2015-10-07 05:01:27 +0000
56+++ src/maasserver/models/partitiontable.py 2015-10-09 04:37:09 +0000
57@@ -29,10 +29,7 @@
58 )
59 from maasserver.models.blockdevice import BlockDevice
60 from maasserver.models.cleansave import CleanSave
61-from maasserver.models.partition import (
62- MAX_PARTITION_SIZE_FOR_MBR,
63- Partition,
64-)
65+from maasserver.models.partition import Partition
66 from maasserver.models.timestampedmodel import TimestampedModel
67 from maasserver.utils.converters import round_size_to_nearest_block
68
69@@ -113,7 +110,8 @@
70 if size is None:
71 size = self.get_available_size()
72 if self.table_type == PARTITION_TABLE_TYPE.MBR:
73- size = min(size, MAX_PARTITION_SIZE_FOR_MBR)
74+ size = min(size, Partition._get_mbr_max_for_block_device(
75+ self.block_device))
76 size = round_size_to_nearest_block(size, self.get_block_size())
77 return Partition.objects.create(
78 partition_table=self, size=size, uuid=uuid, bootable=bootable)
79
80=== modified file 'src/maasserver/models/tests/test_filesystemgroup.py'
81--- src/maasserver/models/tests/test_filesystemgroup.py 2015-10-07 05:01:27 +0000
82+++ src/maasserver/models/tests/test_filesystemgroup.py 2015-10-09 04:37:09 +0000
83@@ -662,7 +662,7 @@
84 fstype=FILESYSTEM_TYPE.LVM_PV, block_device=block_device))
85 fsgroup = factory.make_FilesystemGroup(
86 group_type=FILESYSTEM_GROUP_TYPE.LVM_VG, filesystems=filesystems)
87- extents = int(total_size / LVM_PE_SIZE)
88+ extents = int(total_size / LVM_PE_SIZE) - 1
89 self.assertEquals(extents * LVM_PE_SIZE, fsgroup.get_size())
90
91 def test_get_size_returns_0_if_raid_without_filesystems(self):
92@@ -1230,7 +1230,7 @@
93 block_device=block_device)
94 # Total space should be 50 GB minus the overhead.
95 pv_total_size = 50 * 1000 ** 3
96- extents = int(pv_total_size / LVM_PE_SIZE)
97+ extents = int(pv_total_size / LVM_PE_SIZE) - 1
98 usable_size = extents * LVM_PE_SIZE
99 self.assertEqual(usable_size, fsgroup.get_size())
100
101
102=== modified file 'src/maasserver/models/tests/test_partitiontable.py'
103--- src/maasserver/models/tests/test_partitiontable.py 2015-10-07 14:48:28 +0000
104+++ src/maasserver/models/tests/test_partitiontable.py 2015-10-09 04:37:09 +0000
105@@ -80,7 +80,8 @@
106 table_type=PARTITION_TABLE_TYPE.MBR, block_device=device)
107 partition = partition_table.add_partition()
108 self.assertEqual(
109- partition.size, MAX_PARTITION_SIZE_FOR_MBR)
110+ partition.size, round_size_to_nearest_block(
111+ MAX_PARTITION_SIZE_FOR_MBR, block_size))
112
113 def test_add_second_partition_no_size(self):
114 """Tests whether a second partition with no specified size starts from
115
116=== modified file 'src/maasserver/storage_layouts.py'
117--- src/maasserver/storage_layouts.py 2015-10-07 05:01:27 +0000
118+++ src/maasserver/storage_layouts.py 2015-10-09 04:37:09 +0000
119@@ -32,8 +32,8 @@
120 )
121 from maasserver.models.cacheset import CacheSet
122 from maasserver.models.partition import (
123- MAX_PARTITION_SIZE_FOR_MBR,
124 MIN_PARTITION_SIZE,
125+ Partition,
126 )
127 from maasserver.utils.forms import (
128 compose_invalid_choice_text,
129@@ -200,8 +200,8 @@
130 root_size = self.get_root_size()
131 if root_device is None or root_device == self.boot_disk:
132 # Fix the maximum root_size for MBR.
133- max_mbr_size = (
134- MAX_PARTITION_SIZE_FOR_MBR - self.boot_disk.block_size)
135+ max_mbr_size = Partition._get_mbr_max_for_block_device(
136+ self.boot_disk)
137 if (boot_partition_table.table_type == PARTITION_TABLE_TYPE.MBR and
138 root_size is not None and root_size > max_mbr_size):
139 root_size = max_mbr_size
140@@ -212,8 +212,8 @@
141 root_partition_table = PartitionTable.objects.create(
142 block_device=root_device)
143 # Fix the maximum root_size for MBR.
144- max_mbr_size = (
145- MAX_PARTITION_SIZE_FOR_MBR - root_device.block_size)
146+ max_mbr_size = Partition._get_mbr_max_for_block_device(
147+ root_device)
148 if (root_partition_table.table_type == PARTITION_TABLE_TYPE.MBR and
149 root_size is not None and root_size > max_mbr_size):
150 root_size = max_mbr_size
151
152=== modified file 'src/maasserver/tests/test_storage_layouts.py'
153--- src/maasserver/tests/test_storage_layouts.py 2015-10-07 05:01:27 +0000
154+++ src/maasserver/tests/test_storage_layouts.py 2015-10-09 04:37:09 +0000
155@@ -1007,7 +1007,10 @@
156 self.assertEquals(
157 4, partition_table.partitions.count(),
158 "Should have 4 partitions.")
159- self.assertEquals(MAX_PARTITION_SIZE_FOR_MBR, root_partition.size)
160+ self.assertEquals(
161+ round_size_by_blocks(
162+ MAX_PARTITION_SIZE_FOR_MBR, boot_disk.block_size),
163+ root_partition.size)
164
165
166 class TestBcacheStorageLayoutBase(MAASServerTestCase):