Merge lp:~blake-rouse/maas/fix-mbr-max-partition-size into lp:~maas-committers/maas/trunk
- fix-mbr-max-partition-size
- Merge into trunk
Proposed by
Blake Rouse
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Blake Rouse | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 4361 | ||||
Proposed branch: | lp:~blake-rouse/maas/fix-mbr-max-partition-size | ||||
Merge into: | lp:~maas-committers/maas/trunk | ||||
Diff against target: |
339 lines (+162/-12) 7 files modified
src/maasserver/models/partition.py (+19/-0) src/maasserver/models/partitiontable.py (+7/-3) src/maasserver/models/tests/test_filesystemgroup.py (+5/-2) src/maasserver/models/tests/test_partition.py (+35/-0) src/maasserver/models/tests/test_partitiontable.py (+12/-0) src/maasserver/storage_layouts.py (+36/-7) src/maasserver/tests/test_storage_layouts.py (+48/-0) |
||||
To merge this branch: | bzr merge lp:~blake-rouse/maas/fix-mbr-max-partition-size | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ricardo Bánffy (community) | Approve | ||
Review via email: mp+273641@code.launchpad.net |
Commit message
Don't allow creating partitions larger than 2TiB for MBR partition tables. When creating the LVM storage layout add extra partitions to fill the disks.
Description of the change
To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote : | # |
Thanks for the review. I made the suggested changes.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/maasserver/models/partition.py' | |||
2 | --- src/maasserver/models/partition.py 2015-09-28 17:43:23 +0000 | |||
3 | +++ src/maasserver/models/partition.py 2015-10-07 14:48:54 +0000 | |||
4 | @@ -44,6 +44,7 @@ | |||
5 | 44 | 44 | ||
6 | 45 | 45 | ||
7 | 46 | MIN_PARTITION_SIZE = MIN_BLOCK_DEVICE_SIZE | 46 | MIN_PARTITION_SIZE = MIN_BLOCK_DEVICE_SIZE |
8 | 47 | MAX_PARTITION_SIZE_FOR_MBR = 2 * (1024 ** 4) # 2TiB | ||
9 | 47 | 48 | ||
10 | 48 | 49 | ||
11 | 49 | class PartitionManager(Manager): | 50 | class PartitionManager(Manager): |
12 | @@ -247,6 +248,24 @@ | |||
13 | 247 | else: | 248 | else: |
14 | 248 | self.size = adjusted_size | 249 | self.size = adjusted_size |
15 | 249 | 250 | ||
16 | 251 | # Check that the size is not larger than MBR allows. | ||
17 | 252 | if (self.partition_table.table_type == PARTITION_TABLE_TYPE.MBR and | ||
18 | 253 | self.size > MAX_PARTITION_SIZE_FOR_MBR): | ||
19 | 254 | if self.id is not None: | ||
20 | 255 | raise ValidationError({ | ||
21 | 256 | "size": [ | ||
22 | 257 | "Partition %s cannot be resized to fit on the " | ||
23 | 258 | "block device; size is larger than the MBR " | ||
24 | 259 | "2TiB maximum." % ( | ||
25 | 260 | self.id)], | ||
26 | 261 | }) | ||
27 | 262 | else: | ||
28 | 263 | raise ValidationError({ | ||
29 | 264 | "size": [ | ||
30 | 265 | "Partition cannot be saved; size is larger than " | ||
31 | 266 | "the MBR 2TiB maximum."], | ||
32 | 267 | }) | ||
33 | 268 | |||
34 | 250 | def delete(self): | 269 | def delete(self): |
35 | 251 | """Delete the partition. | 270 | """Delete the partition. |
36 | 252 | 271 | ||
37 | 253 | 272 | ||
38 | === modified file 'src/maasserver/models/partitiontable.py' | |||
39 | --- src/maasserver/models/partitiontable.py 2015-09-24 16:22:12 +0000 | |||
40 | +++ src/maasserver/models/partitiontable.py 2015-10-07 14:48:54 +0000 | |||
41 | @@ -29,7 +29,10 @@ | |||
42 | 29 | ) | 29 | ) |
43 | 30 | from maasserver.models.blockdevice import BlockDevice | 30 | from maasserver.models.blockdevice import BlockDevice |
44 | 31 | from maasserver.models.cleansave import CleanSave | 31 | from maasserver.models.cleansave import CleanSave |
46 | 32 | from maasserver.models.partition import Partition | 32 | from maasserver.models.partition import ( |
47 | 33 | MAX_PARTITION_SIZE_FOR_MBR, | ||
48 | 34 | Partition, | ||
49 | 35 | ) | ||
50 | 33 | from maasserver.models.timestampedmodel import TimestampedModel | 36 | from maasserver.models.timestampedmodel import TimestampedModel |
51 | 34 | from maasserver.utils.converters import round_size_to_nearest_block | 37 | from maasserver.utils.converters import round_size_to_nearest_block |
52 | 35 | 38 | ||
53 | @@ -109,8 +112,9 @@ | |||
54 | 109 | """ | 112 | """ |
55 | 110 | if size is None: | 113 | if size is None: |
56 | 111 | size = self.get_available_size() | 114 | size = self.get_available_size() |
59 | 112 | else: | 115 | if self.table_type == PARTITION_TABLE_TYPE.MBR: |
60 | 113 | size = round_size_to_nearest_block(size, self.get_block_size()) | 116 | size = min(size, MAX_PARTITION_SIZE_FOR_MBR) |
61 | 117 | size = round_size_to_nearest_block(size, self.get_block_size()) | ||
62 | 114 | return Partition.objects.create( | 118 | return Partition.objects.create( |
63 | 115 | partition_table=self, size=size, uuid=uuid, bootable=bootable) | 119 | partition_table=self, size=size, uuid=uuid, bootable=bootable) |
64 | 116 | 120 | ||
65 | 117 | 121 | ||
66 | === modified file 'src/maasserver/models/tests/test_filesystemgroup.py' | |||
67 | --- src/maasserver/models/tests/test_filesystemgroup.py 2015-09-24 16:22:12 +0000 | |||
68 | +++ src/maasserver/models/tests/test_filesystemgroup.py 2015-10-07 14:48:54 +0000 | |||
69 | @@ -29,6 +29,7 @@ | |||
70 | 29 | FILESYSTEM_GROUP_TYPE, | 29 | FILESYSTEM_GROUP_TYPE, |
71 | 30 | FILESYSTEM_TYPE, | 30 | FILESYSTEM_TYPE, |
72 | 31 | NODE_PERMISSION, | 31 | NODE_PERMISSION, |
73 | 32 | PARTITION_TABLE_TYPE, | ||
74 | 32 | ) | 33 | ) |
75 | 33 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE | 34 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE |
76 | 34 | from maasserver.models.filesystem import Filesystem | 35 | from maasserver.models.filesystem import Filesystem |
77 | @@ -1927,10 +1928,11 @@ | |||
78 | 1927 | way as to make the RAID invalid (a 1-device RAID-0/1, a 2-device RAID-5 | 1928 | way as to make the RAID invalid (a 1-device RAID-0/1, a 2-device RAID-5 |
79 | 1928 | etc). The goal is to make sure we trigger the RAID internal validation. | 1929 | etc). The goal is to make sure we trigger the RAID internal validation. |
80 | 1929 | """ | 1930 | """ |
82 | 1930 | node = factory.make_Node() | 1931 | node = factory.make_Node(bios_boot_method="uefi") |
83 | 1931 | device_size = 10 * 1000 ** 4 | 1932 | device_size = 10 * 1000 ** 4 |
84 | 1932 | partitions = [ | 1933 | partitions = [ |
85 | 1933 | factory.make_PartitionTable( | 1934 | factory.make_PartitionTable( |
86 | 1935 | table_type=PARTITION_TABLE_TYPE.GPT, | ||
87 | 1934 | block_device=factory.make_PhysicalBlockDevice( | 1936 | block_device=factory.make_PhysicalBlockDevice( |
88 | 1935 | node=node, size=device_size)).add_partition() | 1937 | node=node, size=device_size)).add_partition() |
89 | 1936 | for _ in range(4) | 1938 | for _ in range(4) |
90 | @@ -1997,10 +1999,11 @@ | |||
91 | 1997 | self.assertEqual(6 * partition_size, raid.get_size()) | 1999 | self.assertEqual(6 * partition_size, raid.get_size()) |
92 | 1998 | 2000 | ||
93 | 1999 | def test_remove_invalid_partition_from_array_fails(self): | 2001 | def test_remove_invalid_partition_from_array_fails(self): |
95 | 2000 | node = factory.make_Node() | 2002 | node = factory.make_Node(bios_boot_method="uefi") |
96 | 2001 | device_size = 10 * 1000 ** 4 | 2003 | device_size = 10 * 1000 ** 4 |
97 | 2002 | partitions = [ | 2004 | partitions = [ |
98 | 2003 | factory.make_PartitionTable( | 2005 | factory.make_PartitionTable( |
99 | 2006 | table_type=PARTITION_TABLE_TYPE.GPT, | ||
100 | 2004 | block_device=factory.make_PhysicalBlockDevice( | 2007 | block_device=factory.make_PhysicalBlockDevice( |
101 | 2005 | node=node, size=device_size)).add_partition() | 2008 | node=node, size=device_size)).add_partition() |
102 | 2006 | for _ in range(10) | 2009 | for _ in range(10) |
103 | 2007 | 2010 | ||
104 | === modified file 'src/maasserver/models/tests/test_partition.py' | |||
105 | --- src/maasserver/models/tests/test_partition.py 2015-09-24 16:22:12 +0000 | |||
106 | +++ src/maasserver/models/tests/test_partition.py 2015-10-07 14:48:54 +0000 | |||
107 | @@ -243,6 +243,41 @@ | |||
108 | 243 | "block device; not enough free space." % partition.id], | 243 | "block device; not enough free space." % partition.id], |
109 | 244 | }, error.error_dict) | 244 | }, error.error_dict) |
110 | 245 | 245 | ||
111 | 246 | def test_test_cannot_create_mbr_partition_larger_than_2TiB(self): | ||
112 | 247 | block_device = factory.make_BlockDevice(size=3 * (1024 ** 4)) # 3TiB | ||
113 | 248 | partition_table = factory.make_PartitionTable( | ||
114 | 249 | block_device=block_device, table_type=PARTITION_TABLE_TYPE.MBR) | ||
115 | 250 | error = self.assertRaises( | ||
116 | 251 | ValidationError, factory.make_Partition, | ||
117 | 252 | partition_table=partition_table, | ||
118 | 253 | size=partition_table.get_available_size()) | ||
119 | 254 | self.assertEquals({ | ||
120 | 255 | "size": [ | ||
121 | 256 | "Partition cannot be saved; size is larger than " | ||
122 | 257 | "the MBR 2TiB maximum."], | ||
123 | 258 | }, error.error_dict) | ||
124 | 259 | |||
125 | 260 | def test_test_cannot_resize_mbr_partition_to_more_than_2TiB(self): | ||
126 | 261 | block_device = factory.make_BlockDevice(size=3 * (1024 ** 4)) # 3TiB | ||
127 | 262 | partition_table = factory.make_PartitionTable( | ||
128 | 263 | block_device=block_device, table_type=PARTITION_TABLE_TYPE.MBR) | ||
129 | 264 | partition = partition_table.add_partition(size=1 * (1024 ** 4)) | ||
130 | 265 | partition.size = 2.5 * (1024 ** 4) | ||
131 | 266 | error = self.assertRaises(ValidationError, partition.save) | ||
132 | 267 | self.assertEquals({ | ||
133 | 268 | "size": [ | ||
134 | 269 | "Partition %s cannot be resized to fit on the " | ||
135 | 270 | "block device; size is larger than the MBR " | ||
136 | 271 | "2TiB maximum." % partition.id], | ||
137 | 272 | }, error.error_dict) | ||
138 | 273 | |||
139 | 274 | def test_validate_can_save_gpt_larger_than_2TiB(self): | ||
140 | 275 | block_device = factory.make_BlockDevice(size=3 * (1024 ** 4)) # 3TiB | ||
141 | 276 | partition_table = factory.make_PartitionTable( | ||
142 | 277 | block_device=block_device, table_type=PARTITION_TABLE_TYPE.GPT) | ||
143 | 278 | # Test is that an error is not raised. | ||
144 | 279 | partition_table.add_partition() | ||
145 | 280 | |||
146 | 246 | def test_validate_enough_space_will_round_down_a_block(self): | 281 | def test_validate_enough_space_will_round_down_a_block(self): |
147 | 247 | partition_table = factory.make_PartitionTable() | 282 | partition_table = factory.make_PartitionTable() |
148 | 248 | partition = partition_table.add_partition() | 283 | partition = partition_table.add_partition() |
149 | 249 | 284 | ||
150 | === modified file 'src/maasserver/models/tests/test_partitiontable.py' | |||
151 | --- src/maasserver/models/tests/test_partitiontable.py 2015-08-14 13:48:59 +0000 | |||
152 | +++ src/maasserver/models/tests/test_partitiontable.py 2015-10-07 14:48:54 +0000 | |||
153 | @@ -17,6 +17,7 @@ | |||
154 | 17 | from django.core.exceptions import ValidationError | 17 | from django.core.exceptions import ValidationError |
155 | 18 | from maasserver.enum import PARTITION_TABLE_TYPE | 18 | from maasserver.enum import PARTITION_TABLE_TYPE |
156 | 19 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE | 19 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE |
157 | 20 | from maasserver.models.partition import MAX_PARTITION_SIZE_FOR_MBR | ||
158 | 20 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE | 21 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE |
159 | 21 | from maasserver.testing.factory import factory | 22 | from maasserver.testing.factory import factory |
160 | 22 | from maasserver.testing.testcase import MAASServerTestCase | 23 | from maasserver.testing.testcase import MAASServerTestCase |
161 | @@ -70,6 +71,17 @@ | |||
162 | 70 | self.assertEqual( | 71 | self.assertEqual( |
163 | 71 | partition.size, MIN_BLOCK_DEVICE_SIZE * 2) | 72 | partition.size, MIN_BLOCK_DEVICE_SIZE * 2) |
164 | 72 | 73 | ||
165 | 74 | def test_add_partition_no_size_sets_mbr_max(self): | ||
166 | 75 | block_size = 4096 | ||
167 | 76 | device = factory.make_BlockDevice( | ||
168 | 77 | size=3 * (1024 ** 4), | ||
169 | 78 | block_size=block_size) | ||
170 | 79 | partition_table = factory.make_PartitionTable( | ||
171 | 80 | table_type=PARTITION_TABLE_TYPE.MBR, block_device=device) | ||
172 | 81 | partition = partition_table.add_partition() | ||
173 | 82 | self.assertEqual( | ||
174 | 83 | partition.size, MAX_PARTITION_SIZE_FOR_MBR) | ||
175 | 84 | |||
176 | 73 | def test_add_second_partition_no_size(self): | 85 | def test_add_second_partition_no_size(self): |
177 | 74 | """Tests whether a second partition with no specified size starts from | 86 | """Tests whether a second partition with no specified size starts from |
178 | 75 | the end of the previous partition and stretches to the end of the | 87 | the end of the previous partition and stretches to the end of the |
179 | 76 | 88 | ||
180 | === modified file 'src/maasserver/storage_layouts.py' | |||
181 | --- src/maasserver/storage_layouts.py 2015-09-24 16:22:12 +0000 | |||
182 | +++ src/maasserver/storage_layouts.py 2015-10-07 14:48:54 +0000 | |||
183 | @@ -31,6 +31,10 @@ | |||
184 | 31 | is_precentage, | 31 | is_precentage, |
185 | 32 | ) | 32 | ) |
186 | 33 | from maasserver.models.cacheset import CacheSet | 33 | from maasserver.models.cacheset import CacheSet |
187 | 34 | from maasserver.models.partition import ( | ||
188 | 35 | MAX_PARTITION_SIZE_FOR_MBR, | ||
189 | 36 | MIN_PARTITION_SIZE, | ||
190 | 37 | ) | ||
191 | 34 | from maasserver.utils.forms import ( | 38 | from maasserver.utils.forms import ( |
192 | 35 | compose_invalid_choice_text, | 39 | compose_invalid_choice_text, |
193 | 36 | set_form_error, | 40 | set_form_error, |
194 | @@ -193,15 +197,29 @@ | |||
195 | 193 | label="boot", | 197 | label="boot", |
196 | 194 | mount_point="/boot") | 198 | mount_point="/boot") |
197 | 195 | root_device = self.get_root_device() | 199 | root_device = self.get_root_device() |
198 | 200 | root_size = self.get_root_size() | ||
199 | 196 | if root_device is None or root_device == self.boot_disk: | 201 | if root_device is None or root_device == self.boot_disk: |
200 | 202 | # Fix the maximum root_size for MBR. | ||
201 | 203 | max_mbr_size = ( | ||
202 | 204 | MAX_PARTITION_SIZE_FOR_MBR - self.boot_disk.block_size) | ||
203 | 205 | if (boot_partition_table.table_type == PARTITION_TABLE_TYPE.MBR and | ||
204 | 206 | root_size is not None and root_size > max_mbr_size): | ||
205 | 207 | root_size = max_mbr_size | ||
206 | 197 | root_partition = boot_partition_table.add_partition( | 208 | root_partition = boot_partition_table.add_partition( |
208 | 198 | size=self.get_root_size()) | 209 | size=root_size) |
209 | 210 | return root_partition, boot_partition_table | ||
210 | 199 | else: | 211 | else: |
211 | 200 | root_partition_table = PartitionTable.objects.create( | 212 | root_partition_table = PartitionTable.objects.create( |
212 | 201 | block_device=root_device) | 213 | block_device=root_device) |
213 | 214 | # Fix the maximum root_size for MBR. | ||
214 | 215 | max_mbr_size = ( | ||
215 | 216 | MAX_PARTITION_SIZE_FOR_MBR - root_device.block_size) | ||
216 | 217 | if (root_partition_table.table_type == PARTITION_TABLE_TYPE.MBR and | ||
217 | 218 | root_size is not None and root_size > max_mbr_size): | ||
218 | 219 | root_size = max_mbr_size | ||
219 | 202 | root_partition = root_partition_table.add_partition( | 220 | root_partition = root_partition_table.add_partition( |
222 | 203 | size=self.get_root_size()) | 221 | size=root_size) |
223 | 204 | return root_partition | 222 | return root_partition, root_partition_table |
224 | 205 | 223 | ||
225 | 206 | def configure(self, allow_fallback=True): | 224 | def configure(self, allow_fallback=True): |
226 | 207 | """Configure the storage for the node.""" | 225 | """Configure the storage for the node.""" |
227 | @@ -231,7 +249,7 @@ | |||
228 | 231 | """Create the flat configuration.""" | 249 | """Create the flat configuration.""" |
229 | 232 | # Circular imports. | 250 | # Circular imports. |
230 | 233 | from maasserver.models.filesystem import Filesystem | 251 | from maasserver.models.filesystem import Filesystem |
232 | 234 | root_partition = self.create_basic_layout() | 252 | root_partition, _ = self.create_basic_layout() |
233 | 235 | Filesystem.objects.create( | 253 | Filesystem.objects.create( |
234 | 236 | partition=root_partition, | 254 | partition=root_partition, |
235 | 237 | fstype=FILESYSTEM_TYPE.EXT4, | 255 | fstype=FILESYSTEM_TYPE.EXT4, |
236 | @@ -320,9 +338,20 @@ | |||
237 | 320 | # Circular imports. | 338 | # Circular imports. |
238 | 321 | from maasserver.models.filesystem import Filesystem | 339 | from maasserver.models.filesystem import Filesystem |
239 | 322 | from maasserver.models.filesystemgroup import VolumeGroup | 340 | from maasserver.models.filesystemgroup import VolumeGroup |
241 | 323 | root_partition = self.create_basic_layout() | 341 | root_partition, root_partition_table = self.create_basic_layout() |
242 | 342 | |||
243 | 343 | # Add extra partitions if MBR and extra space. | ||
244 | 344 | partitions = [root_partition] | ||
245 | 345 | if root_partition_table.table_type == PARTITION_TABLE_TYPE.MBR: | ||
246 | 346 | available_size = root_partition_table.get_available_size() | ||
247 | 347 | while available_size > MIN_PARTITION_SIZE: | ||
248 | 348 | part = root_partition_table.add_partition() | ||
249 | 349 | partitions.append(part) | ||
250 | 350 | available_size -= part.size | ||
251 | 351 | |||
252 | 352 | # Create the volume group and logical volume. | ||
253 | 324 | volume_group = VolumeGroup.objects.create_volume_group( | 353 | volume_group = VolumeGroup.objects.create_volume_group( |
255 | 325 | self.get_vg_name(), block_devices=[], partitions=[root_partition]) | 354 | self.get_vg_name(), block_devices=[], partitions=partitions) |
256 | 326 | logical_volume = volume_group.create_logical_volume( | 355 | logical_volume = volume_group.create_logical_volume( |
257 | 327 | self.get_lv_name(), self.get_calculated_lv_size(volume_group)) | 356 | self.get_lv_name(), self.get_calculated_lv_size(volume_group)) |
258 | 328 | Filesystem.objects.create( | 357 | Filesystem.objects.create( |
259 | @@ -488,7 +517,7 @@ | |||
260 | 488 | boot_size = self.get_boot_size() | 517 | boot_size = self.get_boot_size() |
261 | 489 | if boot_size == 0: | 518 | if boot_size == 0: |
262 | 490 | boot_size = 1 * 1024 ** 3 | 519 | boot_size = 1 * 1024 ** 3 |
264 | 491 | root_partition = self.create_basic_layout(boot_size=boot_size) | 520 | root_partition, _ = self.create_basic_layout(boot_size=boot_size) |
265 | 492 | cache_set = self.create_cache_set() | 521 | cache_set = self.create_cache_set() |
266 | 493 | bcache = Bcache.objects.create_bcache( | 522 | bcache = Bcache.objects.create_bcache( |
267 | 494 | cache_mode=self.get_cache_mode(), cache_set=cache_set, | 523 | cache_mode=self.get_cache_mode(), cache_set=cache_set, |
268 | 495 | 524 | ||
269 | === modified file 'src/maasserver/tests/test_storage_layouts.py' | |||
270 | --- src/maasserver/tests/test_storage_layouts.py 2015-09-24 16:22:12 +0000 | |||
271 | +++ src/maasserver/tests/test_storage_layouts.py 2015-10-07 14:48:54 +0000 | |||
272 | @@ -25,6 +25,7 @@ | |||
273 | 25 | ) | 25 | ) |
274 | 26 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE | 26 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE |
275 | 27 | from maasserver.models.filesystemgroup import VolumeGroup | 27 | from maasserver.models.filesystemgroup import VolumeGroup |
276 | 28 | from maasserver.models.partition import MAX_PARTITION_SIZE_FOR_MBR | ||
277 | 28 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE | 29 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE |
278 | 29 | from maasserver.storage_layouts import ( | 30 | from maasserver.storage_layouts import ( |
279 | 30 | BcacheStorageLayout, | 31 | BcacheStorageLayout, |
280 | @@ -484,6 +485,34 @@ | |||
281 | 484 | mount_point="/", | 485 | mount_point="/", |
282 | 485 | )) | 486 | )) |
283 | 486 | 487 | ||
284 | 488 | def test__creates_layout_with_maximum_mbr_partition_size(self): | ||
285 | 489 | node = factory.make_Node() | ||
286 | 490 | boot_disk = factory.make_PhysicalBlockDevice( | ||
287 | 491 | node=node, size=3 * (1024 ** 4)) | ||
288 | 492 | layout = FlatStorageLayout(node) | ||
289 | 493 | layout.configure() | ||
290 | 494 | |||
291 | 495 | # Validate partition table. | ||
292 | 496 | partition_table = boot_disk.get_partitiontable() | ||
293 | 497 | self.assertEquals(PARTITION_TABLE_TYPE.MBR, partition_table.table_type) | ||
294 | 498 | |||
295 | 499 | # Validate root partition. | ||
296 | 500 | partitions = partition_table.partitions.order_by('id').all() | ||
297 | 501 | root_partition = partitions[0] | ||
298 | 502 | self.assertIsNotNone(root_partition) | ||
299 | 503 | self.assertEquals( | ||
300 | 504 | round_size_by_blocks( | ||
301 | 505 | MAX_PARTITION_SIZE_FOR_MBR, | ||
302 | 506 | boot_disk.block_size), | ||
303 | 507 | root_partition.size) | ||
304 | 508 | self.assertThat( | ||
305 | 509 | root_partition.get_effective_filesystem(), | ||
306 | 510 | MatchesStructure.byEquality( | ||
307 | 511 | fstype=FILESYSTEM_TYPE.EXT4, | ||
308 | 512 | label="root", | ||
309 | 513 | mount_point="/", | ||
310 | 514 | )) | ||
311 | 515 | |||
312 | 487 | def test__creates_layout_with_uefi_defaults(self): | 516 | def test__creates_layout_with_uefi_defaults(self): |
313 | 488 | node = make_Node_with_uefi_boot_method() | 517 | node = make_Node_with_uefi_boot_method() |
314 | 489 | boot_disk = factory.make_PhysicalBlockDevice( | 518 | boot_disk = factory.make_PhysicalBlockDevice( |
315 | @@ -961,6 +990,25 @@ | |||
316 | 961 | mount_point="/", | 990 | mount_point="/", |
317 | 962 | )) | 991 | )) |
318 | 963 | 992 | ||
319 | 993 | def test__creates_layout_with_multiple_mbr_partitions(self): | ||
320 | 994 | node = factory.make_Node() | ||
321 | 995 | boot_disk = factory.make_PhysicalBlockDevice( | ||
322 | 996 | node=node, size=7 * (1024 ** 4)) | ||
323 | 997 | layout = LVMStorageLayout(node) | ||
324 | 998 | layout.configure() | ||
325 | 999 | |||
326 | 1000 | # Validate the volume group on root partition. | ||
327 | 1001 | partition_table = boot_disk.get_partitiontable() | ||
328 | 1002 | partitions = partition_table.partitions.order_by('id').all() | ||
329 | 1003 | root_partition = partitions[0] | ||
330 | 1004 | volume_group = VolumeGroup.objects.get( | ||
331 | 1005 | filesystems__partition=root_partition) | ||
332 | 1006 | self.assertIsNotNone(volume_group) | ||
333 | 1007 | self.assertEquals( | ||
334 | 1008 | 4, partition_table.partitions.count(), | ||
335 | 1009 | "Should have 4 partitions.") | ||
336 | 1010 | self.assertEquals(MAX_PARTITION_SIZE_FOR_MBR, root_partition.size) | ||
337 | 1011 | |||
338 | 964 | 1012 | ||
339 | 965 | class TestBcacheStorageLayoutBase(MAASServerTestCase): | 1013 | class TestBcacheStorageLayoutBase(MAASServerTestCase): |
340 | 966 | 1014 |
Looks good. I'd rename a couple tests to make the expected result more explicit (I had to read the code to get what was being tested).