Merge lp:~trapnine/maas/fix-1513085 into lp:~maas-committers/maas/trunk
- fix-1513085
- Merge into trunk
Proposed by
Jeffrey C Jones
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jeffrey C Jones | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 4504 | ||||
Proposed branch: | lp:~trapnine/maas/fix-1513085 | ||||
Merge into: | lp:~maas-committers/maas/trunk | ||||
Diff against target: |
1347 lines (+256/-192) 21 files modified
src/maasserver/api/tests/test_raid.py (+6/-12) src/maasserver/api/tests/test_volume_groups.py (+13/-4) src/maasserver/forms.py (+2/-1) src/maasserver/models/blockdevice.py (+1/-1) src/maasserver/models/partition.py (+7/-7) src/maasserver/models/partitiontable.py (+21/-17) src/maasserver/models/tests/test_blockdevice.py (+4/-2) src/maasserver/models/tests/test_filesystemgroup.py (+27/-33) src/maasserver/models/tests/test_partition.py (+9/-8) src/maasserver/models/tests/test_partitiontable.py (+27/-18) src/maasserver/models/virtualblockdevice.py (+21/-11) src/maasserver/testing/factory.py (+1/-3) src/maasserver/tests/test_forms_blockdevice.py (+5/-1) src/maasserver/tests/test_forms_partition.py (+5/-5) src/maasserver/tests/test_forms_raid.py (+5/-9) src/maasserver/tests/test_forms_volume_group.py (+7/-2) src/maasserver/tests/test_preseed_storage.py (+14/-14) src/maasserver/tests/test_storage_layouts.py (+43/-32) src/maasserver/utils/converters.py (+5/-3) src/maasserver/utils/tests/test_converters.py (+22/-6) src/maasserver/websockets/handlers/tests/test_node.py (+11/-3) |
||||
To merge this branch: | bzr merge lp:~trapnine/maas/fix-1513085 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Blake Rouse (community) | Approve | ||
Review via email: mp+277409@code.launchpad.net |
Commit message
Align partitions and logical volumes to 4MiB.
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/maasserver/api/tests/test_raid.py' | |||
2 | --- src/maasserver/api/tests/test_raid.py 2015-10-28 17:32:43 +0000 | |||
3 | +++ src/maasserver/api/tests/test_raid.py 2015-11-16 07:08:21 +0000 | |||
4 | @@ -403,10 +403,8 @@ | |||
5 | 403 | (parsed_block_devices, parsed_partitions, | 403 | (parsed_block_devices, parsed_partitions, |
6 | 404 | parsed_block_device_spares, parsed_partition_spares) = ( | 404 | parsed_block_device_spares, parsed_partition_spares) = ( |
7 | 405 | get_devices_from_raid(parsed_device)) | 405 | get_devices_from_raid(parsed_device)) |
12 | 406 | # Size is equivalent to 7 devices of 9 TB each. | 406 | # Size is equivalent to 7 of the smallest device (the partitions). |
13 | 407 | self.assertEqual( | 407 | self.assertEqual(7 * large_partitions[0].size, parsed_device['size']) |
10 | 408 | 7 * ((9 * 1000 ** 4) - PARTITION_TABLE_EXTRA_SPACE), | ||
11 | 409 | parsed_device['size']) | ||
14 | 410 | self.assertItemsEqual(block_devices, parsed_block_devices) | 408 | self.assertItemsEqual(block_devices, parsed_block_devices) |
15 | 411 | self.assertItemsEqual(partitions, parsed_partitions) | 409 | self.assertItemsEqual(partitions, parsed_partitions) |
16 | 412 | self.assertItemsEqual(spare_devices, parsed_block_device_spares) | 410 | self.assertItemsEqual(spare_devices, parsed_block_device_spares) |
17 | @@ -450,10 +448,8 @@ | |||
18 | 450 | (parsed_block_devices, parsed_partitions, | 448 | (parsed_block_devices, parsed_partitions, |
19 | 451 | parsed_block_device_spares, parsed_partition_spares) = ( | 449 | parsed_block_device_spares, parsed_partition_spares) = ( |
20 | 452 | get_devices_from_raid(parsed_device)) | 450 | get_devices_from_raid(parsed_device)) |
25 | 453 | # Size is equivalent to 6 devices of 9 TB each. | 451 | # Size is equivalent to 6 of the smallest device (the partitions). |
26 | 454 | self.assertEqual( | 452 | self.assertEqual(6 * large_partitions[0].size, parsed_device['size']) |
23 | 455 | 6 * ((9 * 1000 ** 4) - PARTITION_TABLE_EXTRA_SPACE), | ||
24 | 456 | parsed_device['size']) | ||
27 | 457 | self.assertItemsEqual(block_devices, parsed_block_devices) | 453 | self.assertItemsEqual(block_devices, parsed_block_devices) |
28 | 458 | self.assertItemsEqual(partitions, parsed_partitions) | 454 | self.assertItemsEqual(partitions, parsed_partitions) |
29 | 459 | self.assertItemsEqual(spare_devices, parsed_block_device_spares) | 455 | self.assertItemsEqual(spare_devices, parsed_block_device_spares) |
30 | @@ -497,10 +493,8 @@ | |||
31 | 497 | (parsed_block_devices, parsed_partitions, | 493 | (parsed_block_devices, parsed_partitions, |
32 | 498 | parsed_block_device_spares, parsed_partition_spares) = ( | 494 | parsed_block_device_spares, parsed_partition_spares) = ( |
33 | 499 | get_devices_from_raid(parsed_device)) | 495 | get_devices_from_raid(parsed_device)) |
38 | 500 | # Size is equivalent to 4 devices of 9 TB each. | 496 | # Size is equivalent to 4 of the smallest device (the partitions). |
39 | 501 | self.assertEqual( | 497 | self.assertEqual(4 * large_partitions[0].size, parsed_device['size']) |
36 | 502 | 4 * ((9 * 1000 ** 4) - PARTITION_TABLE_EXTRA_SPACE), | ||
37 | 503 | parsed_device['size']) | ||
40 | 504 | self.assertItemsEqual(block_devices, parsed_block_devices) | 498 | self.assertItemsEqual(block_devices, parsed_block_devices) |
41 | 505 | self.assertItemsEqual(partitions, parsed_partitions) | 499 | self.assertItemsEqual(partitions, parsed_partitions) |
42 | 506 | self.assertItemsEqual(spare_devices, parsed_block_device_spares) | 500 | self.assertItemsEqual(spare_devices, parsed_block_device_spares) |
43 | 507 | 501 | ||
44 | === modified file 'src/maasserver/api/tests/test_volume_groups.py' | |||
45 | --- src/maasserver/api/tests/test_volume_groups.py 2015-09-24 16:22:12 +0000 | |||
46 | +++ src/maasserver/api/tests/test_volume_groups.py 2015-11-16 07:08:21 +0000 | |||
47 | @@ -26,11 +26,18 @@ | |||
48 | 26 | NODE_STATUS, | 26 | NODE_STATUS, |
49 | 27 | ) | 27 | ) |
50 | 28 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE | 28 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE |
51 | 29 | from maasserver.models.partition import ( | ||
52 | 30 | MIN_PARTITION_SIZE, | ||
53 | 31 | PARTITION_ALIGNMENT_SIZE, | ||
54 | 32 | ) | ||
55 | 29 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE | 33 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE |
56 | 30 | from maasserver.testing.api import APITestCase | 34 | from maasserver.testing.api import APITestCase |
57 | 31 | from maasserver.testing.factory import factory | 35 | from maasserver.testing.factory import factory |
58 | 32 | from maasserver.testing.orm import reload_object | 36 | from maasserver.testing.orm import reload_object |
60 | 33 | from maasserver.utils.converters import human_readable_bytes | 37 | from maasserver.utils.converters import ( |
61 | 38 | human_readable_bytes, | ||
62 | 39 | round_size_to_nearest_block, | ||
63 | 40 | ) | ||
64 | 34 | from testtools.matchers import ( | 41 | from testtools.matchers import ( |
65 | 35 | ContainsDict, | 42 | ContainsDict, |
66 | 36 | Equals, | 43 | Equals, |
67 | @@ -132,11 +139,11 @@ | |||
68 | 132 | ] | 139 | ] |
69 | 133 | block_device = factory.make_PhysicalBlockDevice( | 140 | block_device = factory.make_PhysicalBlockDevice( |
70 | 134 | node=node, | 141 | node=node, |
72 | 135 | size=(MIN_BLOCK_DEVICE_SIZE * 3) + PARTITION_TABLE_EXTRA_SPACE) | 142 | size=MIN_PARTITION_SIZE * 3 + PARTITION_TABLE_EXTRA_SPACE) |
73 | 136 | partition_table = factory.make_PartitionTable( | 143 | partition_table = factory.make_PartitionTable( |
74 | 137 | block_device=block_device) | 144 | block_device=block_device) |
75 | 138 | partitions = [ | 145 | partitions = [ |
77 | 139 | partition_table.add_partition(size=MIN_BLOCK_DEVICE_SIZE) | 146 | partition_table.add_partition(size=MIN_PARTITION_SIZE) |
78 | 140 | for _ in range(2) | 147 | for _ in range(2) |
79 | 141 | ] | 148 | ] |
80 | 142 | partition_ids = [ | 149 | partition_ids = [ |
81 | @@ -411,10 +418,12 @@ | |||
82 | 411 | }) | 418 | }) |
83 | 412 | self.assertEqual(httplib.OK, response.status_code, response.content) | 419 | self.assertEqual(httplib.OK, response.status_code, response.content) |
84 | 413 | logical_volume = json.loads(response.content) | 420 | logical_volume = json.loads(response.content) |
85 | 421 | expected_size = round_size_to_nearest_block( | ||
86 | 422 | size, PARTITION_ALIGNMENT_SIZE, False) | ||
87 | 414 | self.assertThat(logical_volume, ContainsDict({ | 423 | self.assertThat(logical_volume, ContainsDict({ |
88 | 415 | "name": Equals("%s-%s" % (volume_group.name, name)), | 424 | "name": Equals("%s-%s" % (volume_group.name, name)), |
89 | 416 | "uuid": Equals(vguuid), | 425 | "uuid": Equals(vguuid), |
91 | 417 | "size": Equals(size), | 426 | "size": Equals(expected_size), |
92 | 418 | })) | 427 | })) |
93 | 419 | 428 | ||
94 | 420 | def test_delete_logical_volume_204_when_invalid_id(self): | 429 | def test_delete_logical_volume_204_when_invalid_id(self): |
95 | 421 | 430 | ||
96 | === modified file 'src/maasserver/forms.py' | |||
97 | --- src/maasserver/forms.py 2015-11-02 16:32:29 +0000 | |||
98 | +++ src/maasserver/forms.py 2015-11-16 07:08:21 +0000 | |||
99 | @@ -154,6 +154,7 @@ | |||
100 | 154 | nodegroup_fqdn, | 154 | nodegroup_fqdn, |
101 | 155 | ) | 155 | ) |
102 | 156 | from maasserver.models.nodegroup import NODEGROUP_CLUSTER_NAME_TEMPLATE | 156 | from maasserver.models.nodegroup import NODEGROUP_CLUSTER_NAME_TEMPLATE |
103 | 157 | from maasserver.models.partition import MIN_PARTITION_SIZE | ||
104 | 157 | from maasserver.models.subnet import ( | 158 | from maasserver.models.subnet import ( |
105 | 158 | create_cidr, | 159 | create_cidr, |
106 | 159 | Subnet, | 160 | Subnet, |
107 | @@ -3253,7 +3254,7 @@ | |||
108 | 3253 | This needs to be done on the fly so that we can pass the maximum size. | 3254 | This needs to be done on the fly so that we can pass the maximum size. |
109 | 3254 | """ | 3255 | """ |
110 | 3255 | self.fields['size'] = BytesField( | 3256 | self.fields['size'] = BytesField( |
112 | 3256 | min_value=MIN_BLOCK_DEVICE_SIZE, | 3257 | min_value=MIN_PARTITION_SIZE, |
113 | 3257 | max_value=self.block_device.size, | 3258 | max_value=self.block_device.size, |
114 | 3258 | required=True) | 3259 | required=True) |
115 | 3259 | 3260 | ||
116 | 3260 | 3261 | ||
117 | === modified file 'src/maasserver/models/blockdevice.py' | |||
118 | --- src/maasserver/models/blockdevice.py 2015-10-28 01:59:30 +0000 | |||
119 | +++ src/maasserver/models/blockdevice.py 2015-11-16 07:08:21 +0000 | |||
120 | @@ -51,7 +51,7 @@ | |||
121 | 51 | ) | 51 | ) |
122 | 52 | 52 | ||
123 | 53 | 53 | ||
125 | 54 | MIN_BLOCK_DEVICE_SIZE = 2 * 1024 * 1024 # 2MiB | 54 | MIN_BLOCK_DEVICE_SIZE = 4 * 1024 * 1024 # 4MiB |
126 | 55 | MIN_BLOCK_DEVICE_BLOCK_SIZE = 512 # A ProDOS block | 55 | MIN_BLOCK_DEVICE_BLOCK_SIZE = 512 # A ProDOS block |
127 | 56 | 56 | ||
128 | 57 | 57 | ||
129 | 58 | 58 | ||
130 | === modified file 'src/maasserver/models/partition.py' | |||
131 | --- src/maasserver/models/partition.py 2015-10-20 15:02:19 +0000 | |||
132 | +++ src/maasserver/models/partition.py 2015-11-16 07:08:21 +0000 | |||
133 | @@ -32,7 +32,6 @@ | |||
134 | 32 | from django.dispatch import receiver | 32 | from django.dispatch import receiver |
135 | 33 | from maasserver import DefaultMeta | 33 | from maasserver import DefaultMeta |
136 | 34 | from maasserver.enum import PARTITION_TABLE_TYPE | 34 | from maasserver.enum import PARTITION_TABLE_TYPE |
137 | 35 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE | ||
138 | 36 | from maasserver.models.cleansave import CleanSave | 35 | from maasserver.models.cleansave import CleanSave |
139 | 37 | from maasserver.models.timestampedmodel import TimestampedModel | 36 | from maasserver.models.timestampedmodel import TimestampedModel |
140 | 38 | from maasserver.utils.converters import ( | 37 | from maasserver.utils.converters import ( |
141 | @@ -45,8 +44,10 @@ | |||
142 | 45 | ) | 44 | ) |
143 | 46 | 45 | ||
144 | 47 | 46 | ||
145 | 48 | MIN_PARTITION_SIZE = MIN_BLOCK_DEVICE_SIZE | ||
146 | 49 | MAX_PARTITION_SIZE_FOR_MBR = (((2 ** 32) - 1) * 512) - (1024 ** 2) # 2 TiB | 47 | MAX_PARTITION_SIZE_FOR_MBR = (((2 ** 32) - 1) * 512) - (1024 ** 2) # 2 TiB |
147 | 48 | # All partitions are aligned down to 4MiB blocks for performance (lp:1513085) | ||
148 | 49 | PARTITION_ALIGNMENT_SIZE = 4 * 1024 * 1024 | ||
149 | 50 | MIN_PARTITION_SIZE = PARTITION_ALIGNMENT_SIZE | ||
150 | 50 | 51 | ||
151 | 51 | 52 | ||
152 | 52 | class PartitionManager(Manager): | 53 | class PartitionManager(Manager): |
153 | @@ -216,17 +217,16 @@ | |||
154 | 216 | bd=self.partition_table.block_device.__unicode__()) | 217 | bd=self.partition_table.block_device.__unicode__()) |
155 | 217 | 218 | ||
156 | 218 | def _round_size(self): | 219 | def _round_size(self): |
158 | 219 | """Round the size of this partition to the nearest block.""" | 220 | """Round the size of this partition down for alignment.""" |
159 | 220 | if self.size is not None and self.partition_table is not None: | 221 | if self.size is not None and self.partition_table is not None: |
160 | 221 | self.size = round_size_to_nearest_block( | 222 | self.size = round_size_to_nearest_block( |
162 | 222 | self.size, self.partition_table.get_block_size()) | 223 | self.size, PARTITION_ALIGNMENT_SIZE, False) |
163 | 223 | 224 | ||
164 | 224 | @classmethod | 225 | @classmethod |
165 | 225 | def _get_mbr_max_for_block_device(self, block_device): | 226 | def _get_mbr_max_for_block_device(self, block_device): |
166 | 226 | """Get the maximum partition size for MBR for this block device.""" | 227 | """Get the maximum partition size for MBR for this block device.""" |
170 | 227 | block_size = block_device.block_size | 228 | return round_size_to_nearest_block( |
171 | 228 | number_of_blocks = MAX_PARTITION_SIZE_FOR_MBR / block_size | 229 | MAX_PARTITION_SIZE_FOR_MBR, PARTITION_ALIGNMENT_SIZE, False) |
169 | 229 | return block_size * (number_of_blocks - 1) | ||
172 | 230 | 230 | ||
173 | 231 | def _get_mbr_max_for_partition(self): | 231 | def _get_mbr_max_for_partition(self): |
174 | 232 | """Get the maximum partition size for MBR for this partition.""" | 232 | """Get the maximum partition size for MBR for this partition.""" |
175 | 233 | 233 | ||
176 | === modified file 'src/maasserver/models/partitiontable.py' | |||
177 | --- src/maasserver/models/partitiontable.py 2015-11-04 04:27:46 +0000 | |||
178 | +++ src/maasserver/models/partitiontable.py 2015-11-16 07:08:21 +0000 | |||
179 | @@ -29,13 +29,17 @@ | |||
180 | 29 | ) | 29 | ) |
181 | 30 | from maasserver.models.blockdevice import BlockDevice | 30 | from maasserver.models.blockdevice import BlockDevice |
182 | 31 | from maasserver.models.cleansave import CleanSave | 31 | from maasserver.models.cleansave import CleanSave |
184 | 32 | from maasserver.models.partition import Partition | 32 | from maasserver.models.partition import ( |
185 | 33 | Partition, | ||
186 | 34 | PARTITION_ALIGNMENT_SIZE, | ||
187 | 35 | ) | ||
188 | 33 | from maasserver.models.timestampedmodel import TimestampedModel | 36 | from maasserver.models.timestampedmodel import TimestampedModel |
189 | 34 | from maasserver.utils.converters import round_size_to_nearest_block | 37 | from maasserver.utils.converters import round_size_to_nearest_block |
190 | 35 | 38 | ||
194 | 36 | # The first partition on the disk must start at 2MiB, as all previous bytes | 39 | # The first 2MiB of the device are used by the partition table and grub. We'll |
195 | 37 | # will be used by the partition table and grub. | 40 | # reserve the first 4MiB to make sure all partitions stay aligned to 4MB across |
196 | 38 | INITIAL_PARTITION_OFFSET = 2 * 1024 * 1024 | 41 | # the device. |
197 | 42 | INITIAL_PARTITION_OFFSET = 4 * 1024 * 1024 | ||
198 | 39 | 43 | ||
199 | 40 | # An additional 1MiB of space is left open at the end of the disk to allow for | 44 | # An additional 1MiB of space is left open at the end of the disk to allow for |
200 | 41 | # the extra MBR table. | 45 | # the extra MBR table. |
201 | @@ -67,11 +71,11 @@ | |||
202 | 67 | return self.block_device.node | 71 | return self.block_device.node |
203 | 68 | 72 | ||
204 | 69 | def get_size(self): | 73 | def get_size(self): |
210 | 70 | """Size of partition table.""" | 74 | """Total usable size of partition table.""" |
211 | 71 | return ( | 75 | return round_size_to_nearest_block( |
212 | 72 | self.block_device.size - | 76 | self.block_device.size - PARTITION_TABLE_EXTRA_SPACE, |
213 | 73 | round_size_to_nearest_block( | 77 | PARTITION_ALIGNMENT_SIZE, |
214 | 74 | PARTITION_TABLE_EXTRA_SPACE, self.get_block_size())) | 78 | False) |
215 | 75 | 79 | ||
216 | 76 | def get_block_size(self): | 80 | def get_block_size(self): |
217 | 77 | """Block size of partition table.""" | 81 | """Block size of partition table.""" |
218 | @@ -89,15 +93,15 @@ | |||
219 | 89 | if used_size is None: | 93 | if used_size is None: |
220 | 90 | used_size = 0 | 94 | used_size = 0 |
221 | 91 | # The extra space taken by the partition table header is used space. | 95 | # The extra space taken by the partition table header is used space. |
226 | 92 | used_size += round_size_to_nearest_block( | 96 | return used_size + PARTITION_TABLE_EXTRA_SPACE |
223 | 93 | PARTITION_TABLE_EXTRA_SPACE, self.get_block_size()) | ||
224 | 94 | return round_size_to_nearest_block( | ||
225 | 95 | used_size, self.get_block_size()) | ||
227 | 96 | 97 | ||
228 | 97 | def get_available_size(self, ignore_partitions=[]): | 98 | def get_available_size(self, ignore_partitions=[]): |
229 | 98 | """Return the remaining size available for partitions.""" | 99 | """Return the remaining size available for partitions.""" |
230 | 99 | used_size = self.get_used_size(ignore_partitions=ignore_partitions) | 100 | used_size = self.get_used_size(ignore_partitions=ignore_partitions) |
232 | 100 | return self.block_device.size - used_size | 101 | # Only report 'alignable' space as available for new partitions |
233 | 102 | return round_size_to_nearest_block( | ||
234 | 103 | self.block_device.size - used_size, | ||
235 | 104 | PARTITION_ALIGNMENT_SIZE, False) | ||
236 | 101 | 105 | ||
237 | 102 | def add_partition(self, size=None, bootable=False, uuid=None): | 106 | def add_partition(self, size=None, bootable=False, uuid=None): |
238 | 103 | """Adds a partition to this partition table, returns the added | 107 | """Adds a partition to this partition table, returns the added |
239 | @@ -105,15 +109,15 @@ | |||
240 | 105 | 109 | ||
241 | 106 | If size is omitted, the partition will extend to the end of the device. | 110 | If size is omitted, the partition will extend to the end of the device. |
242 | 107 | 111 | ||
245 | 108 | If size is not a multiple of the device's block size, the size will be | 112 | All partition sizes will be aligned down to PARTITION_ALIGNMENT_SIZE. |
244 | 109 | rounded up to the next multiple. | ||
246 | 110 | """ | 113 | """ |
247 | 111 | if size is None: | 114 | if size is None: |
248 | 112 | size = self.get_available_size() | 115 | size = self.get_available_size() |
249 | 113 | if self.table_type == PARTITION_TABLE_TYPE.MBR: | 116 | if self.table_type == PARTITION_TABLE_TYPE.MBR: |
250 | 114 | size = min(size, Partition._get_mbr_max_for_block_device( | 117 | size = min(size, Partition._get_mbr_max_for_block_device( |
251 | 115 | self.block_device)) | 118 | self.block_device)) |
253 | 116 | size = round_size_to_nearest_block(size, self.get_block_size()) | 119 | size = round_size_to_nearest_block( |
254 | 120 | size, PARTITION_ALIGNMENT_SIZE, False) | ||
255 | 117 | return Partition.objects.create( | 121 | return Partition.objects.create( |
256 | 118 | partition_table=self, size=size, uuid=uuid, bootable=bootable) | 122 | partition_table=self, size=size, uuid=uuid, bootable=bootable) |
257 | 119 | 123 | ||
258 | 120 | 124 | ||
259 | === modified file 'src/maasserver/models/tests/test_blockdevice.py' | |||
260 | --- src/maasserver/models/tests/test_blockdevice.py 2015-10-28 01:59:30 +0000 | |||
261 | +++ src/maasserver/models/tests/test_blockdevice.py 2015-11-16 07:08:21 +0000 | |||
262 | @@ -34,6 +34,7 @@ | |||
263 | 34 | VirtualBlockDevice, | 34 | VirtualBlockDevice, |
264 | 35 | VolumeGroup, | 35 | VolumeGroup, |
265 | 36 | ) | 36 | ) |
266 | 37 | from maasserver.models.partition import PARTITION_ALIGNMENT_SIZE | ||
267 | 37 | from maasserver.testing.factory import factory | 38 | from maasserver.testing.factory import factory |
268 | 38 | from maasserver.testing.orm import reload_object | 39 | from maasserver.testing.orm import reload_object |
269 | 39 | from maasserver.testing.testcase import MAASServerTestCase | 40 | from maasserver.testing.testcase import MAASServerTestCase |
270 | @@ -428,8 +429,9 @@ | |||
271 | 428 | boot_disk = factory.make_PhysicalBlockDevice(node=node) | 429 | boot_disk = factory.make_PhysicalBlockDevice(node=node) |
272 | 429 | partition = boot_disk.create_partition_if_boot_disk() | 430 | partition = boot_disk.create_partition_if_boot_disk() |
273 | 430 | self.assertIsNotNone(partition) | 431 | self.assertIsNotNone(partition) |
276 | 431 | self.assertEquals( | 432 | available_size = boot_disk.get_available_size() |
277 | 432 | boot_disk.get_available_size(), 0, | 433 | self.assertTrue( |
278 | 434 | available_size >= 0 and available_size < PARTITION_ALIGNMENT_SIZE, | ||
279 | 433 | "Should create a partition for the entire disk.") | 435 | "Should create a partition for the entire disk.") |
280 | 434 | 436 | ||
281 | 435 | 437 | ||
282 | 436 | 438 | ||
283 | === modified file 'src/maasserver/models/tests/test_filesystemgroup.py' | |||
284 | --- src/maasserver/models/tests/test_filesystemgroup.py 2015-11-10 16:55:24 +0000 | |||
285 | +++ src/maasserver/models/tests/test_filesystemgroup.py 2015-11-16 07:08:21 +0000 | |||
286 | @@ -43,6 +43,7 @@ | |||
287 | 43 | VolumeGroup, | 43 | VolumeGroup, |
288 | 44 | VolumeGroupManager, | 44 | VolumeGroupManager, |
289 | 45 | ) | 45 | ) |
290 | 46 | from maasserver.models.partition import PARTITION_ALIGNMENT_SIZE | ||
291 | 46 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE | 47 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE |
292 | 47 | from maasserver.models.physicalblockdevice import PhysicalBlockDevice | 48 | from maasserver.models.physicalblockdevice import PhysicalBlockDevice |
293 | 48 | from maasserver.models.virtualblockdevice import VirtualBlockDevice | 49 | from maasserver.models.virtualblockdevice import VirtualBlockDevice |
294 | @@ -52,7 +53,10 @@ | |||
295 | 52 | reload_objects, | 53 | reload_objects, |
296 | 53 | ) | 54 | ) |
297 | 54 | from maasserver.testing.testcase import MAASServerTestCase | 55 | from maasserver.testing.testcase import MAASServerTestCase |
299 | 55 | from maasserver.utils.converters import machine_readable_bytes | 56 | from maasserver.utils.converters import ( |
300 | 57 | machine_readable_bytes, | ||
301 | 58 | round_size_to_nearest_block, | ||
302 | 59 | ) | ||
303 | 56 | from maastesting.matchers import ( | 60 | from maastesting.matchers import ( |
304 | 57 | MockCalledOnceWith, | 61 | MockCalledOnceWith, |
305 | 58 | MockNotCalled, | 62 | MockNotCalled, |
306 | @@ -327,13 +331,16 @@ | |||
307 | 327 | [filesystem_group.id], result_filesystem_group_ids) | 331 | [filesystem_group.id], result_filesystem_group_ids) |
308 | 328 | 332 | ||
309 | 329 | def test__bcache_on_partitions(self): | 333 | def test__bcache_on_partitions(self): |
311 | 330 | block_device = factory.make_PhysicalBlockDevice() | 334 | device_size = random.randint( |
312 | 335 | MIN_BLOCK_DEVICE_SIZE * 4, MIN_BLOCK_DEVICE_SIZE * 1024) | ||
313 | 336 | block_device = factory.make_PhysicalBlockDevice( | ||
314 | 337 | size=device_size + PARTITION_TABLE_EXTRA_SPACE) | ||
315 | 331 | partition_table = factory.make_PartitionTable( | 338 | partition_table = factory.make_PartitionTable( |
316 | 332 | block_device=block_device) | 339 | block_device=block_device) |
317 | 333 | partition_one = factory.make_Partition( | 340 | partition_one = factory.make_Partition( |
319 | 334 | partition_table=partition_table) | 341 | partition_table=partition_table, size=device_size / 2) |
320 | 335 | partition_two = factory.make_Partition( | 342 | partition_two = factory.make_Partition( |
322 | 336 | partition_table=partition_table) | 343 | partition_table=partition_table, size=device_size / 2) |
323 | 337 | cache_set = factory.make_CacheSet(partition=partition_one) | 344 | cache_set = factory.make_CacheSet(partition=partition_one) |
324 | 338 | filesystem_backing = factory.make_Filesystem( | 345 | filesystem_backing = factory.make_Filesystem( |
325 | 339 | fstype=FILESYSTEM_TYPE.BCACHE_BACKING, partition=partition_two) | 346 | fstype=FILESYSTEM_TYPE.BCACHE_BACKING, partition=partition_two) |
326 | @@ -1324,9 +1331,11 @@ | |||
327 | 1324 | factory.make_VirtualBlockDevice( | 1331 | factory.make_VirtualBlockDevice( |
328 | 1325 | filesystem_group=fsgroup, size=5 * 1000 ** 3) | 1332 | filesystem_group=fsgroup, size=5 * 1000 ** 3) |
329 | 1326 | 1333 | ||
331 | 1327 | self.assertEqual(40 * 1000 ** 3, fsgroup.get_lvm_allocated_size()) | 1334 | expected_size = round_size_to_nearest_block( |
332 | 1335 | 40 * 1000 ** 3, PARTITION_ALIGNMENT_SIZE, False) | ||
333 | 1336 | self.assertEqual(expected_size, fsgroup.get_lvm_allocated_size()) | ||
334 | 1328 | self.assertEqual( | 1337 | self.assertEqual( |
336 | 1329 | usable_size - (40 * 1000 ** 3), fsgroup.get_lvm_free_space()) | 1338 | usable_size - expected_size, fsgroup.get_lvm_free_space()) |
337 | 1330 | 1339 | ||
338 | 1331 | def test_get_virtual_block_device_block_size_returns_backing_for_bc(self): | 1340 | def test_get_virtual_block_device_block_size_returns_backing_for_bc(self): |
339 | 1332 | # This test is not included in the scenario below | 1341 | # This test is not included in the scenario below |
340 | @@ -1567,10 +1576,12 @@ | |||
341 | 1567 | logical_volume = volume_group.create_logical_volume( | 1576 | logical_volume = volume_group.create_logical_volume( |
342 | 1568 | name=name, uuid=vguuid, size=size) | 1577 | name=name, uuid=vguuid, size=size) |
343 | 1569 | logical_volume = reload_object(logical_volume) | 1578 | logical_volume = reload_object(logical_volume) |
344 | 1579 | expected_size = round_size_to_nearest_block( | ||
345 | 1580 | size, PARTITION_ALIGNMENT_SIZE, False) | ||
346 | 1570 | self.assertThat(logical_volume, MatchesStructure.byEquality( | 1581 | self.assertThat(logical_volume, MatchesStructure.byEquality( |
347 | 1571 | name=name, | 1582 | name=name, |
348 | 1572 | uuid=vguuid, | 1583 | uuid=vguuid, |
350 | 1573 | size=size, | 1584 | size=expected_size, |
351 | 1574 | block_size=volume_group.get_virtual_block_device_block_size(), | 1585 | block_size=volume_group.get_virtual_block_device_block_size(), |
352 | 1575 | )) | 1586 | )) |
353 | 1576 | 1587 | ||
354 | @@ -1597,8 +1608,6 @@ | |||
355 | 1597 | bd.get_partitiontable().add_partition() | 1608 | bd.get_partitiontable().add_partition() |
356 | 1598 | for bd in block_devices[5:] | 1609 | for bd in block_devices[5:] |
357 | 1599 | ] | 1610 | ] |
358 | 1600 | # Partition size will be smaller than the disk, because of overhead. | ||
359 | 1601 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
360 | 1602 | spare_block_device = block_devices[0] | 1611 | spare_block_device = block_devices[0] |
361 | 1603 | spare_partition = partitions[0] | 1612 | spare_partition = partitions[0] |
362 | 1604 | uuid = unicode(uuid4()) | 1613 | uuid = unicode(uuid4()) |
363 | @@ -1611,7 +1620,7 @@ | |||
364 | 1611 | spare_devices=[spare_block_device], | 1620 | spare_devices=[spare_block_device], |
365 | 1612 | spare_partitions=[spare_partition]) | 1621 | spare_partitions=[spare_partition]) |
366 | 1613 | self.assertEqual('md0', raid.name) | 1622 | self.assertEqual('md0', raid.name) |
368 | 1614 | self.assertEqual(6 * partition_size, raid.get_size()) | 1623 | self.assertEqual(6 * partitions[1].size, raid.get_size()) |
369 | 1615 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_6, raid.group_type) | 1624 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_6, raid.group_type) |
370 | 1616 | self.assertEqual(uuid, raid.uuid) | 1625 | self.assertEqual(uuid, raid.uuid) |
371 | 1617 | self.assertEqual(10, raid.filesystems.count()) | 1626 | self.assertEqual(10, raid.filesystems.count()) |
372 | @@ -1689,7 +1698,6 @@ | |||
373 | 1689 | for bd in block_devices[5:] | 1698 | for bd in block_devices[5:] |
374 | 1690 | ] | 1699 | ] |
375 | 1691 | # Partition size will be smaller than the disk, because of overhead. | 1700 | # Partition size will be smaller than the disk, because of overhead. |
376 | 1692 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
377 | 1693 | spare_block_device = block_devices[0] | 1701 | spare_block_device = block_devices[0] |
378 | 1694 | spare_partition = partitions[0] | 1702 | spare_partition = partitions[0] |
379 | 1695 | uuid = unicode(uuid4()) | 1703 | uuid = unicode(uuid4()) |
380 | @@ -1702,7 +1710,7 @@ | |||
381 | 1702 | spare_devices=[spare_block_device], | 1710 | spare_devices=[spare_block_device], |
382 | 1703 | spare_partitions=[spare_partition]) | 1711 | spare_partitions=[spare_partition]) |
383 | 1704 | self.assertEqual('md0', raid.name) | 1712 | self.assertEqual('md0', raid.name) |
385 | 1705 | self.assertEqual(partition_size, raid.get_size()) | 1713 | self.assertEqual(partitions[1].size, raid.get_size()) |
386 | 1706 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_1, raid.group_type) | 1714 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_1, raid.group_type) |
387 | 1707 | self.assertEqual(uuid, raid.uuid) | 1715 | self.assertEqual(uuid, raid.uuid) |
388 | 1708 | self.assertEqual(10, raid.filesystems.count()) | 1716 | self.assertEqual(10, raid.filesystems.count()) |
389 | @@ -1742,8 +1750,6 @@ | |||
390 | 1742 | bd.get_partitiontable().add_partition() | 1750 | bd.get_partitiontable().add_partition() |
391 | 1743 | for bd in block_devices[5:] | 1751 | for bd in block_devices[5:] |
392 | 1744 | ] | 1752 | ] |
393 | 1745 | # Partition size will be smaller than the disk, because of overhead. | ||
394 | 1746 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
395 | 1747 | spare_block_device = block_devices[0] | 1753 | spare_block_device = block_devices[0] |
396 | 1748 | spare_partition = partitions[0] | 1754 | spare_partition = partitions[0] |
397 | 1749 | uuid = unicode(uuid4()) | 1755 | uuid = unicode(uuid4()) |
398 | @@ -1756,7 +1762,7 @@ | |||
399 | 1756 | spare_devices=[spare_block_device], | 1762 | spare_devices=[spare_block_device], |
400 | 1757 | spare_partitions=[spare_partition]) | 1763 | spare_partitions=[spare_partition]) |
401 | 1758 | self.assertEqual('md0', raid.name) | 1764 | self.assertEqual('md0', raid.name) |
403 | 1759 | self.assertEqual(7 * partition_size, raid.get_size()) | 1765 | self.assertEqual(7 * partitions[1].size, raid.get_size()) |
404 | 1760 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_5, raid.group_type) | 1766 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_5, raid.group_type) |
405 | 1761 | self.assertEqual(uuid, raid.uuid) | 1767 | self.assertEqual(uuid, raid.uuid) |
406 | 1762 | self.assertEqual(10, raid.filesystems.count()) | 1768 | self.assertEqual(10, raid.filesystems.count()) |
407 | @@ -1906,11 +1912,9 @@ | |||
408 | 1906 | partition = factory.make_PartitionTable( | 1912 | partition = factory.make_PartitionTable( |
409 | 1907 | block_device=factory.make_PhysicalBlockDevice( | 1913 | block_device=factory.make_PhysicalBlockDevice( |
410 | 1908 | node=node, size=device_size)).add_partition() | 1914 | node=node, size=device_size)).add_partition() |
411 | 1909 | # Partition size will be smaller than the disk, because of overhead. | ||
412 | 1910 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
413 | 1911 | raid.add_partition(partition, FILESYSTEM_TYPE.RAID) | 1915 | raid.add_partition(partition, FILESYSTEM_TYPE.RAID) |
414 | 1912 | self.assertEqual(11, raid.filesystems.count()) | 1916 | self.assertEqual(11, raid.filesystems.count()) |
416 | 1913 | self.assertEqual(10 * partition_size, raid.get_size()) | 1917 | self.assertEqual(10 * partition.size, raid.get_size()) |
417 | 1914 | 1918 | ||
418 | 1915 | def test_add_spare_partition_to_array(self): | 1919 | def test_add_spare_partition_to_array(self): |
419 | 1916 | node = factory.make_Node() | 1920 | node = factory.make_Node() |
420 | @@ -1928,11 +1932,9 @@ | |||
421 | 1928 | partition = factory.make_PartitionTable( | 1932 | partition = factory.make_PartitionTable( |
422 | 1929 | block_device=factory.make_PhysicalBlockDevice( | 1933 | block_device=factory.make_PhysicalBlockDevice( |
423 | 1930 | node=node, size=device_size)).add_partition() | 1934 | node=node, size=device_size)).add_partition() |
424 | 1931 | # Partition size will be smaller than the disk, because of overhead. | ||
425 | 1932 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
426 | 1933 | raid.add_partition(partition, FILESYSTEM_TYPE.RAID_SPARE) | 1935 | raid.add_partition(partition, FILESYSTEM_TYPE.RAID_SPARE) |
427 | 1934 | self.assertEqual(11, raid.filesystems.count()) | 1936 | self.assertEqual(11, raid.filesystems.count()) |
429 | 1935 | self.assertEqual(9 * partition_size, raid.get_size()) | 1937 | self.assertEqual(9 * partition.size, raid.get_size()) |
430 | 1936 | 1938 | ||
431 | 1937 | def test_add_device_from_another_node_to_array_fails(self): | 1939 | def test_add_device_from_another_node_to_array_fails(self): |
432 | 1938 | node = factory.make_Node() | 1940 | node = factory.make_Node() |
433 | @@ -2054,8 +2056,6 @@ | |||
434 | 2054 | node=node, size=device_size)).add_partition() | 2056 | node=node, size=device_size)).add_partition() |
435 | 2055 | for _ in range(4) | 2057 | for _ in range(4) |
436 | 2056 | ] | 2058 | ] |
437 | 2057 | # Partition size will be smaller than the disk, because of overhead. | ||
438 | 2058 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
439 | 2059 | uuid = unicode(uuid4()) | 2059 | uuid = unicode(uuid4()) |
440 | 2060 | raid = RAID.objects.create_raid( | 2060 | raid = RAID.objects.create_raid( |
441 | 2061 | name='md0', | 2061 | name='md0', |
442 | @@ -2070,7 +2070,7 @@ | |||
443 | 2070 | "devices and any number of spares.']}")): | 2070 | "devices and any number of spares.']}")): |
444 | 2071 | raid.remove_partition(partitions[0]) | 2071 | raid.remove_partition(partitions[0]) |
445 | 2072 | self.assertEqual(4, raid.filesystems.count()) | 2072 | self.assertEqual(4, raid.filesystems.count()) |
447 | 2073 | self.assertEqual(2 * partition_size, raid.get_size()) | 2073 | self.assertEqual(2 * partitions[0].size, raid.get_size()) |
448 | 2074 | # Ensure the filesystems are the exact same before and after. | 2074 | # Ensure the filesystems are the exact same before and after. |
449 | 2075 | self.assertItemsEqual( | 2075 | self.assertItemsEqual( |
450 | 2076 | fsids_before, [fs.id for fs in raid.filesystems.all()]) | 2076 | fsids_before, [fs.id for fs in raid.filesystems.all()]) |
451 | @@ -2102,8 +2102,6 @@ | |||
452 | 2102 | node=node, size=device_size)).add_partition() | 2102 | node=node, size=device_size)).add_partition() |
453 | 2103 | for _ in range(10) | 2103 | for _ in range(10) |
454 | 2104 | ] | 2104 | ] |
455 | 2105 | # Partition size will be smaller than the disk, because of overhead. | ||
456 | 2106 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
457 | 2107 | uuid = unicode(uuid4()) | 2105 | uuid = unicode(uuid4()) |
458 | 2108 | raid = RAID.objects.create_raid( | 2106 | raid = RAID.objects.create_raid( |
459 | 2109 | name='md0', | 2107 | name='md0', |
460 | @@ -2113,7 +2111,7 @@ | |||
461 | 2113 | spare_partitions=partitions[-2:]) | 2111 | spare_partitions=partitions[-2:]) |
462 | 2114 | raid.remove_partition(partitions[0]) | 2112 | raid.remove_partition(partitions[0]) |
463 | 2115 | self.assertEqual(9, raid.filesystems.count()) | 2113 | self.assertEqual(9, raid.filesystems.count()) |
465 | 2116 | self.assertEqual(6 * partition_size, raid.get_size()) | 2114 | self.assertEqual(6 * partitions[0].size, raid.get_size()) |
466 | 2117 | 2115 | ||
467 | 2118 | def test_remove_invalid_partition_from_array_fails(self): | 2116 | def test_remove_invalid_partition_from_array_fails(self): |
468 | 2119 | node = factory.make_Node(bios_boot_method="uefi") | 2117 | node = factory.make_Node(bios_boot_method="uefi") |
469 | @@ -2125,8 +2123,6 @@ | |||
470 | 2125 | node=node, size=device_size)).add_partition() | 2123 | node=node, size=device_size)).add_partition() |
471 | 2126 | for _ in range(10) | 2124 | for _ in range(10) |
472 | 2127 | ] | 2125 | ] |
473 | 2128 | # Partition size will be smaller than the disk, because of overhead. | ||
474 | 2129 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
475 | 2130 | uuid = unicode(uuid4()) | 2126 | uuid = unicode(uuid4()) |
476 | 2131 | raid = RAID.objects.create_raid( | 2127 | raid = RAID.objects.create_raid( |
477 | 2132 | name='md0', | 2128 | name='md0', |
478 | @@ -2142,7 +2138,7 @@ | |||
479 | 2142 | block_device=factory.make_PhysicalBlockDevice( | 2138 | block_device=factory.make_PhysicalBlockDevice( |
480 | 2143 | node=node, size=device_size)).add_partition()) | 2139 | node=node, size=device_size)).add_partition()) |
481 | 2144 | self.assertEqual(10, raid.filesystems.count()) | 2140 | self.assertEqual(10, raid.filesystems.count()) |
483 | 2145 | self.assertEqual(9 * partition_size, raid.get_size()) | 2141 | self.assertEqual(9 * partitions[0].size, raid.get_size()) |
484 | 2146 | 2142 | ||
485 | 2147 | def test_remove_device_from_array_fails(self): | 2143 | def test_remove_device_from_array_fails(self): |
486 | 2148 | node = factory.make_Node() | 2144 | node = factory.make_Node() |
487 | @@ -2251,8 +2247,6 @@ | |||
488 | 2251 | backing_partition = factory.make_PartitionTable( | 2247 | backing_partition = factory.make_PartitionTable( |
489 | 2252 | block_device=factory.make_PhysicalBlockDevice( | 2248 | block_device=factory.make_PhysicalBlockDevice( |
490 | 2253 | node=node, size=backing_size)).add_partition() | 2249 | node=node, size=backing_size)).add_partition() |
491 | 2254 | # Partition size will be smaller than the disk, because of overhead. | ||
492 | 2255 | partition_size = backing_size - PARTITION_TABLE_EXTRA_SPACE | ||
493 | 2256 | uuid = unicode(uuid4()) | 2250 | uuid = unicode(uuid4()) |
494 | 2257 | bcache = Bcache.objects.create_bcache( | 2251 | bcache = Bcache.objects.create_bcache( |
495 | 2258 | name='bcache0', | 2252 | name='bcache0', |
496 | @@ -2262,7 +2256,7 @@ | |||
497 | 2262 | cache_mode=CACHE_MODE_TYPE.WRITEBACK) | 2256 | cache_mode=CACHE_MODE_TYPE.WRITEBACK) |
498 | 2263 | 2257 | ||
499 | 2264 | # Verify the filesystems were properly created on the target devices | 2258 | # Verify the filesystems were properly created on the target devices |
501 | 2265 | self.assertEqual(partition_size, bcache.get_size()) | 2259 | self.assertEqual(backing_partition.size, bcache.get_size()) |
502 | 2266 | self.assertEqual( | 2260 | self.assertEqual( |
503 | 2267 | FILESYSTEM_TYPE.BCACHE_CACHE, | 2261 | FILESYSTEM_TYPE.BCACHE_CACHE, |
504 | 2268 | cache_partition.get_effective_filesystem().fstype) | 2262 | cache_partition.get_effective_filesystem().fstype) |
505 | 2269 | 2263 | ||
506 | === modified file 'src/maasserver/models/tests/test_partition.py' | |||
507 | --- src/maasserver/models/tests/test_partition.py 2015-11-04 19:39:51 +0000 | |||
508 | +++ src/maasserver/models/tests/test_partition.py 2015-11-16 07:08:21 +0000 | |||
509 | @@ -29,6 +29,7 @@ | |||
510 | 29 | from maasserver.models.partition import ( | 29 | from maasserver.models.partition import ( |
511 | 30 | MIN_PARTITION_SIZE, | 30 | MIN_PARTITION_SIZE, |
512 | 31 | Partition, | 31 | Partition, |
513 | 32 | PARTITION_ALIGNMENT_SIZE, | ||
514 | 32 | ) | 33 | ) |
515 | 33 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE | 34 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE |
516 | 34 | from maasserver.testing.factory import factory | 35 | from maasserver.testing.factory import factory |
517 | @@ -45,18 +46,18 @@ | |||
518 | 45 | node = factory.make_Node() | 46 | node = factory.make_Node() |
519 | 46 | block_device = factory.make_PhysicalBlockDevice( | 47 | block_device = factory.make_PhysicalBlockDevice( |
520 | 47 | node=node, | 48 | node=node, |
522 | 48 | size=(MIN_BLOCK_DEVICE_SIZE * 4) + PARTITION_TABLE_EXTRA_SPACE) | 49 | size=(MIN_PARTITION_SIZE * 4) + PARTITION_TABLE_EXTRA_SPACE) |
523 | 49 | partition_table = factory.make_PartitionTable( | 50 | partition_table = factory.make_PartitionTable( |
524 | 50 | block_device=block_device) | 51 | block_device=block_device) |
525 | 51 | free_partitions = [ | 52 | free_partitions = [ |
527 | 52 | partition_table.add_partition(size=MIN_BLOCK_DEVICE_SIZE) | 53 | partition_table.add_partition(size=MIN_PARTITION_SIZE) |
528 | 53 | for _ in range(2) | 54 | for _ in range(2) |
529 | 54 | ] | 55 | ] |
530 | 55 | # Make used partitions. | 56 | # Make used partitions. |
531 | 56 | for _ in range(2): | 57 | for _ in range(2): |
532 | 57 | factory.make_Filesystem( | 58 | factory.make_Filesystem( |
533 | 58 | partition=partition_table.add_partition( | 59 | partition=partition_table.add_partition( |
535 | 59 | size=MIN_BLOCK_DEVICE_SIZE)) | 60 | size=MIN_PARTITION_SIZE)) |
536 | 60 | self.assertItemsEqual( | 61 | self.assertItemsEqual( |
537 | 61 | free_partitions, | 62 | free_partitions, |
538 | 62 | Partition.objects.get_free_partitions_for_node(node)) | 63 | Partition.objects.get_free_partitions_for_node(node)) |
539 | @@ -213,12 +214,12 @@ | |||
540 | 213 | partition.save() | 214 | partition.save() |
541 | 214 | self.assertEquals('%s' % uuid, partition.uuid) | 215 | self.assertEquals('%s' % uuid, partition.uuid) |
542 | 215 | 216 | ||
544 | 216 | def test_size_is_rounded_to_next_block(self): | 217 | def test_size_is_rounded_to_current_block(self): |
545 | 217 | partition = factory.make_Partition() | 218 | partition = factory.make_Partition() |
547 | 218 | partition.size = partition.get_block_size() * 4096 | 219 | partition.size = PARTITION_ALIGNMENT_SIZE * 4 |
548 | 219 | partition.size += 1 | 220 | partition.size += 1 |
549 | 220 | partition.save() | 221 | partition.save() |
551 | 221 | self.assertEquals(4097, partition.size / partition.get_block_size()) | 222 | self.assertEquals(PARTITION_ALIGNMENT_SIZE * 4, partition.size) |
552 | 222 | 223 | ||
553 | 223 | def test_validate_enough_space_for_new_partition(self): | 224 | def test_validate_enough_space_for_new_partition(self): |
554 | 224 | partition_table = factory.make_PartitionTable() | 225 | partition_table = factory.make_PartitionTable() |
555 | @@ -235,7 +236,7 @@ | |||
556 | 235 | def test_validate_enough_space_for_resize_partition(self): | 236 | def test_validate_enough_space_for_resize_partition(self): |
557 | 236 | partition_table = factory.make_PartitionTable() | 237 | partition_table = factory.make_PartitionTable() |
558 | 237 | partition = partition_table.add_partition() | 238 | partition = partition_table.add_partition() |
560 | 238 | partition.size += partition_table.get_block_size() * 2 | 239 | partition.size += PARTITION_ALIGNMENT_SIZE * 2 |
561 | 239 | error = self.assertRaises(ValidationError, partition.save) | 240 | error = self.assertRaises(ValidationError, partition.save) |
562 | 240 | self.assertEquals({ | 241 | self.assertEquals({ |
563 | 241 | "size": [ | 242 | "size": [ |
564 | @@ -298,7 +299,7 @@ | |||
565 | 298 | node = factory.make_Node(bios_boot_method="uefi") | 299 | node = factory.make_Node(bios_boot_method="uefi") |
566 | 299 | block_device = factory.make_PhysicalBlockDevice( | 300 | block_device = factory.make_PhysicalBlockDevice( |
567 | 300 | node=node, | 301 | node=node, |
569 | 301 | size=(MIN_BLOCK_DEVICE_SIZE * 4) + PARTITION_TABLE_EXTRA_SPACE) | 302 | size=(MIN_PARTITION_SIZE * 4) + PARTITION_TABLE_EXTRA_SPACE) |
570 | 302 | partition_table = factory.make_PartitionTable( | 303 | partition_table = factory.make_PartitionTable( |
571 | 303 | block_device=block_device, table_type=PARTITION_TABLE_TYPE.GPT) | 304 | block_device=block_device, table_type=PARTITION_TABLE_TYPE.GPT) |
572 | 304 | partitions = [ | 305 | partitions = [ |
573 | 305 | 306 | ||
574 | === modified file 'src/maasserver/models/tests/test_partitiontable.py' | |||
575 | --- src/maasserver/models/tests/test_partitiontable.py 2015-11-04 04:27:46 +0000 | |||
576 | +++ src/maasserver/models/tests/test_partitiontable.py 2015-11-16 07:08:21 +0000 | |||
577 | @@ -23,7 +23,11 @@ | |||
578 | 23 | BlockDevice, | 23 | BlockDevice, |
579 | 24 | MIN_BLOCK_DEVICE_SIZE, | 24 | MIN_BLOCK_DEVICE_SIZE, |
580 | 25 | ) | 25 | ) |
582 | 26 | from maasserver.models.partition import MAX_PARTITION_SIZE_FOR_MBR | 26 | from maasserver.models.partition import ( |
583 | 27 | MAX_PARTITION_SIZE_FOR_MBR, | ||
584 | 28 | MIN_PARTITION_SIZE, | ||
585 | 29 | PARTITION_ALIGNMENT_SIZE, | ||
586 | 30 | ) | ||
587 | 27 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE | 31 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE |
588 | 28 | from maasserver.testing.factory import factory | 32 | from maasserver.testing.factory import factory |
589 | 29 | from maasserver.testing.testcase import MAASServerTestCase | 33 | from maasserver.testing.testcase import MAASServerTestCase |
590 | @@ -41,7 +45,11 @@ | |||
591 | 41 | def test_get_size_returns_block_device_size_minus_initial_offset(self): | 45 | def test_get_size_returns_block_device_size_minus_initial_offset(self): |
592 | 42 | partition_table = factory.make_PartitionTable() | 46 | partition_table = factory.make_PartitionTable() |
593 | 43 | self.assertEquals( | 47 | self.assertEquals( |
595 | 44 | partition_table.block_device.size - PARTITION_TABLE_EXTRA_SPACE, | 48 | round_size_to_nearest_block( |
596 | 49 | partition_table.block_device.size - | ||
597 | 50 | PARTITION_TABLE_EXTRA_SPACE, | ||
598 | 51 | PARTITION_ALIGNMENT_SIZE, | ||
599 | 52 | False), | ||
600 | 45 | partition_table.get_size()) | 53 | partition_table.get_size()) |
601 | 46 | 54 | ||
602 | 47 | def test_get_block_size_returns_block_device_block_size(self): | 55 | def test_get_block_size_returns_block_device_block_size(self): |
603 | @@ -52,17 +60,17 @@ | |||
604 | 52 | 60 | ||
605 | 53 | def test_add_misaligned_partition(self): | 61 | def test_add_misaligned_partition(self): |
606 | 54 | """Tests whether a partition size are adjusted according to | 62 | """Tests whether a partition size are adjusted according to |
608 | 55 | device block size.""" | 63 | partition alignment size (4MiB).""" |
609 | 56 | block_size = 4096 | 64 | block_size = 4096 |
610 | 57 | device = factory.make_BlockDevice( | 65 | device = factory.make_BlockDevice( |
612 | 58 | size=MIN_BLOCK_DEVICE_SIZE * 2 + PARTITION_TABLE_EXTRA_SPACE, | 66 | size=MIN_PARTITION_SIZE * 2 + PARTITION_TABLE_EXTRA_SPACE, |
613 | 59 | block_size=block_size) | 67 | block_size=block_size) |
614 | 60 | partition_table = factory.make_PartitionTable(block_device=device) | 68 | partition_table = factory.make_PartitionTable(block_device=device) |
615 | 61 | partition = partition_table.add_partition( | 69 | partition = partition_table.add_partition( |
617 | 62 | size=MIN_BLOCK_DEVICE_SIZE + 54) | 70 | size=MIN_PARTITION_SIZE + 54) |
618 | 63 | self.assertEqual( | 71 | self.assertEqual( |
619 | 64 | round_size_to_nearest_block( | 72 | round_size_to_nearest_block( |
621 | 65 | MIN_BLOCK_DEVICE_SIZE + 54, block_size), | 73 | MIN_PARTITION_SIZE + 54, PARTITION_ALIGNMENT_SIZE, False), |
622 | 66 | partition.size) | 74 | partition.size) |
623 | 67 | 75 | ||
624 | 68 | def test_add_partition_no_size(self): | 76 | def test_add_partition_no_size(self): |
625 | @@ -85,9 +93,10 @@ | |||
626 | 85 | partition_table = factory.make_PartitionTable( | 93 | partition_table = factory.make_PartitionTable( |
627 | 86 | table_type=PARTITION_TABLE_TYPE.MBR, block_device=device) | 94 | table_type=PARTITION_TABLE_TYPE.MBR, block_device=device) |
628 | 87 | partition = partition_table.add_partition() | 95 | partition = partition_table.add_partition() |
629 | 88 | number_of_blocks = MAX_PARTITION_SIZE_FOR_MBR / block_size | ||
630 | 89 | self.assertEqual( | 96 | self.assertEqual( |
632 | 90 | partition.size, block_size * (number_of_blocks - 1)) | 97 | round_size_to_nearest_block( |
633 | 98 | MAX_PARTITION_SIZE_FOR_MBR, PARTITION_ALIGNMENT_SIZE, False), | ||
634 | 99 | partition.size) | ||
635 | 91 | 100 | ||
636 | 92 | def test_add_second_partition_no_size(self): | 101 | def test_add_second_partition_no_size(self): |
637 | 93 | """Tests whether a second partition with no specified size starts from | 102 | """Tests whether a second partition with no specified size starts from |
638 | @@ -95,12 +104,12 @@ | |||
639 | 95 | device.""" | 104 | device.""" |
640 | 96 | block_size = 4096 | 105 | block_size = 4096 |
641 | 97 | device = factory.make_BlockDevice( | 106 | device = factory.make_BlockDevice( |
643 | 98 | size=MIN_BLOCK_DEVICE_SIZE * 3 + PARTITION_TABLE_EXTRA_SPACE, | 107 | size=MIN_PARTITION_SIZE * 3 + PARTITION_TABLE_EXTRA_SPACE, |
644 | 99 | block_size=block_size) | 108 | block_size=block_size) |
645 | 100 | partition_table = factory.make_PartitionTable(block_device=device) | 109 | partition_table = factory.make_PartitionTable(block_device=device) |
647 | 101 | partition_table.add_partition(size=MIN_BLOCK_DEVICE_SIZE) | 110 | partition_table.add_partition(size=MIN_PARTITION_SIZE) |
648 | 102 | partition = partition_table.add_partition() | 111 | partition = partition_table.add_partition() |
650 | 103 | self.assertEqual(MIN_BLOCK_DEVICE_SIZE * 2, partition.size) | 112 | self.assertEqual(MIN_PARTITION_SIZE * 2, partition.size) |
651 | 104 | 113 | ||
652 | 105 | def test_add_partition_to_full_device(self): | 114 | def test_add_partition_to_full_device(self): |
653 | 106 | """Tests whether we fail to add a partition to an already full device. | 115 | """Tests whether we fail to add a partition to an already full device. |
654 | @@ -117,26 +126,26 @@ | |||
655 | 117 | def test_get_available_size(self): | 126 | def test_get_available_size(self): |
656 | 118 | block_size = 4096 | 127 | block_size = 4096 |
657 | 119 | device = factory.make_BlockDevice( | 128 | device = factory.make_BlockDevice( |
659 | 120 | size=MIN_BLOCK_DEVICE_SIZE * 3 + PARTITION_TABLE_EXTRA_SPACE, | 129 | size=MIN_PARTITION_SIZE * 3 + PARTITION_TABLE_EXTRA_SPACE, |
660 | 121 | block_size=block_size) | 130 | block_size=block_size) |
661 | 122 | partition_table = factory.make_PartitionTable(block_device=device) | 131 | partition_table = factory.make_PartitionTable(block_device=device) |
663 | 123 | partition_table.add_partition(size=MIN_BLOCK_DEVICE_SIZE) | 132 | partition_table.add_partition(size=MIN_PARTITION_SIZE) |
664 | 124 | self.assertEquals( | 133 | self.assertEquals( |
666 | 125 | MIN_BLOCK_DEVICE_SIZE * 2, partition_table.get_available_size()) | 134 | MIN_PARTITION_SIZE * 2, partition_table.get_available_size()) |
667 | 126 | 135 | ||
668 | 127 | def test_get_available_size_skips_partitions(self): | 136 | def test_get_available_size_skips_partitions(self): |
669 | 128 | block_size = 4096 | 137 | block_size = 4096 |
670 | 129 | device = factory.make_BlockDevice( | 138 | device = factory.make_BlockDevice( |
672 | 130 | size=MIN_BLOCK_DEVICE_SIZE * 3 + PARTITION_TABLE_EXTRA_SPACE, | 139 | size=MIN_PARTITION_SIZE * 3 + PARTITION_TABLE_EXTRA_SPACE, |
673 | 131 | block_size=block_size) | 140 | block_size=block_size) |
674 | 132 | partition_table = factory.make_PartitionTable(block_device=device) | 141 | partition_table = factory.make_PartitionTable(block_device=device) |
675 | 133 | ignore_partitions = [ | 142 | ignore_partitions = [ |
677 | 134 | partition_table.add_partition(size=MIN_BLOCK_DEVICE_SIZE) | 143 | partition_table.add_partition(size=MIN_PARTITION_SIZE) |
678 | 135 | for _ in range(2) | 144 | for _ in range(2) |
679 | 136 | ] | 145 | ] |
681 | 137 | partition_table.add_partition(size=MIN_BLOCK_DEVICE_SIZE) | 146 | partition_table.add_partition(size=MIN_PARTITION_SIZE) |
682 | 138 | self.assertEquals( | 147 | self.assertEquals( |
684 | 139 | MIN_BLOCK_DEVICE_SIZE * 2, | 148 | MIN_PARTITION_SIZE * 2, |
685 | 140 | partition_table.get_available_size( | 149 | partition_table.get_available_size( |
686 | 141 | ignore_partitions=ignore_partitions)) | 150 | ignore_partitions=ignore_partitions)) |
687 | 142 | 151 | ||
688 | 143 | 152 | ||
689 | === modified file 'src/maasserver/models/virtualblockdevice.py' | |||
690 | --- src/maasserver/models/virtualblockdevice.py 2015-08-14 13:48:59 +0000 | |||
691 | +++ src/maasserver/models/virtualblockdevice.py 2015-11-16 07:08:21 +0000 | |||
692 | @@ -30,7 +30,11 @@ | |||
693 | 30 | ) | 30 | ) |
694 | 31 | from maasserver.models.filesystemgroup import FilesystemGroup | 31 | from maasserver.models.filesystemgroup import FilesystemGroup |
695 | 32 | from maasserver.models.node import Node | 32 | from maasserver.models.node import Node |
697 | 33 | from maasserver.utils.converters import human_readable_bytes | 33 | from maasserver.models.partition import PARTITION_ALIGNMENT_SIZE |
698 | 34 | from maasserver.utils.converters import ( | ||
699 | 35 | human_readable_bytes, | ||
700 | 36 | round_size_to_nearest_block, | ||
701 | 37 | ) | ||
702 | 34 | from maasserver.utils.orm import get_one | 38 | from maasserver.utils.orm import get_one |
703 | 35 | 39 | ||
704 | 36 | 40 | ||
705 | @@ -109,16 +113,22 @@ | |||
706 | 109 | 113 | ||
707 | 110 | # Check if the size of this is not larger than the free size of | 114 | # Check if the size of this is not larger than the free size of |
708 | 111 | # its filesystem group if its lvm. | 115 | # its filesystem group if its lvm. |
719 | 112 | if (self.filesystem_group.is_lvm() and | 116 | if self.filesystem_group.is_lvm(): |
720 | 113 | self.size > self.filesystem_group.get_lvm_free_space( | 117 | |
721 | 114 | skip_volumes=[self])): | 118 | # align virtual partition to partition alignment size |
722 | 115 | raise ValidationError( | 119 | # otherwise on creation it may be rounded up, overfilling group |
723 | 116 | "There is not enough free space (%s) " | 120 | self.size = round_size_to_nearest_block( |
724 | 117 | "on volume group %s." % ( | 121 | self.size, PARTITION_ALIGNMENT_SIZE, False) |
725 | 118 | human_readable_bytes(self.size), | 122 | |
726 | 119 | self.filesystem_group.name, | 123 | if self.size > self.filesystem_group.get_lvm_free_space( |
727 | 120 | )) | 124 | skip_volumes=[self]): |
728 | 121 | elif not self.filesystem_group.is_lvm(): | 125 | raise ValidationError( |
729 | 126 | "There is not enough free space (%s) " | ||
730 | 127 | "on volume group %s." % ( | ||
731 | 128 | human_readable_bytes(self.size), | ||
732 | 129 | self.filesystem_group.name, | ||
733 | 130 | )) | ||
734 | 131 | else: | ||
735 | 122 | # If not a volume group the size of the virtual block device | 132 | # If not a volume group the size of the virtual block device |
736 | 123 | # must equal the size of the filesystem group. | 133 | # must equal the size of the filesystem group. |
737 | 124 | assert self.size == self.filesystem_group.get_size() | 134 | assert self.size == self.filesystem_group.get_size() |
738 | 125 | 135 | ||
739 | === modified file 'src/maasserver/testing/factory.py' | |||
740 | --- src/maasserver/testing/factory.py 2015-11-02 22:17:02 +0000 | |||
741 | +++ src/maasserver/testing/factory.py 2015-11-16 07:08:21 +0000 | |||
742 | @@ -1287,9 +1287,7 @@ | |||
743 | 1287 | raise ValueError( | 1287 | raise ValueError( |
744 | 1288 | "Cannot make another partition on partition_table not " | 1288 | "Cannot make another partition on partition_table not " |
745 | 1289 | "enough free space.") | 1289 | "enough free space.") |
749 | 1290 | size = round_size_to_nearest_block( | 1290 | size = random.randint(MIN_PARTITION_SIZE, available_size) |
747 | 1291 | random.randint(MIN_PARTITION_SIZE, available_size), | ||
748 | 1292 | partition_table.get_block_size()) | ||
750 | 1293 | if bootable is None: | 1291 | if bootable is None: |
751 | 1294 | bootable = random.choice([True, False]) | 1292 | bootable = random.choice([True, False]) |
752 | 1295 | return Partition.objects.create( | 1293 | return Partition.objects.create( |
753 | 1296 | 1294 | ||
754 | === modified file 'src/maasserver/tests/test_forms_blockdevice.py' | |||
755 | --- src/maasserver/tests/test_forms_blockdevice.py 2015-09-24 19:54:30 +0000 | |||
756 | +++ src/maasserver/tests/test_forms_blockdevice.py 2015-11-16 07:08:21 +0000 | |||
757 | @@ -31,9 +31,11 @@ | |||
758 | 31 | ) | 31 | ) |
759 | 32 | from maasserver.models import Filesystem | 32 | from maasserver.models import Filesystem |
760 | 33 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE | 33 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE |
761 | 34 | from maasserver.models.partition import PARTITION_ALIGNMENT_SIZE | ||
762 | 34 | from maasserver.testing.factory import factory | 35 | from maasserver.testing.factory import factory |
763 | 35 | from maasserver.testing.orm import reload_object | 36 | from maasserver.testing.orm import reload_object |
764 | 36 | from maasserver.testing.testcase import MAASServerTestCase | 37 | from maasserver.testing.testcase import MAASServerTestCase |
765 | 38 | from maasserver.utils.converters import round_size_to_nearest_block | ||
766 | 37 | from maasserver.utils.orm import get_one | 39 | from maasserver.utils.orm import get_one |
767 | 38 | from testtools.matchers import MatchesStructure | 40 | from testtools.matchers import MatchesStructure |
768 | 39 | 41 | ||
769 | @@ -379,8 +381,10 @@ | |||
770 | 379 | }) | 381 | }) |
771 | 380 | self.assertTrue(form.is_valid(), form.errors) | 382 | self.assertTrue(form.is_valid(), form.errors) |
772 | 381 | block_device = form.save() | 383 | block_device = form.save() |
773 | 384 | expected_size = round_size_to_nearest_block( | ||
774 | 385 | size, PARTITION_ALIGNMENT_SIZE, False) | ||
775 | 382 | self.assertThat(block_device, MatchesStructure.byEquality( | 386 | self.assertThat(block_device, MatchesStructure.byEquality( |
776 | 383 | name=name, | 387 | name=name, |
777 | 384 | uuid=vguuid, | 388 | uuid=vguuid, |
779 | 385 | size=size, | 389 | size=expected_size, |
780 | 386 | )) | 390 | )) |
781 | 387 | 391 | ||
782 | === modified file 'src/maasserver/tests/test_forms_partition.py' | |||
783 | --- src/maasserver/tests/test_forms_partition.py 2015-09-24 19:54:30 +0000 | |||
784 | +++ src/maasserver/tests/test_forms_partition.py 2015-11-16 07:08:21 +0000 | |||
785 | @@ -26,9 +26,11 @@ | |||
786 | 26 | ) | 26 | ) |
787 | 27 | from maasserver.models import Filesystem | 27 | from maasserver.models import Filesystem |
788 | 28 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE | 28 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE |
789 | 29 | from maasserver.models.partition import PARTITION_ALIGNMENT_SIZE | ||
790 | 29 | from maasserver.testing.factory import factory | 30 | from maasserver.testing.factory import factory |
791 | 30 | from maasserver.testing.orm import reload_object | 31 | from maasserver.testing.orm import reload_object |
792 | 31 | from maasserver.testing.testcase import MAASServerTestCase | 32 | from maasserver.testing.testcase import MAASServerTestCase |
793 | 33 | from maasserver.utils.converters import round_size_to_nearest_block | ||
794 | 32 | from maasserver.utils.orm import get_one | 34 | from maasserver.utils.orm import get_one |
795 | 33 | 35 | ||
796 | 34 | 36 | ||
797 | @@ -84,15 +86,13 @@ | |||
798 | 84 | form.is_valid(), | 86 | form.is_valid(), |
799 | 85 | "Should be valid because size is large enough and a string.") | 87 | "Should be valid because size is large enough and a string.") |
800 | 86 | 88 | ||
802 | 87 | def test_size_rounded_up_and_placed_on_block_boundry(self): | 89 | def test_size_rounded_down_and_placed_on_alignment_boundry(self): |
803 | 88 | block_size = 4096 | 90 | block_size = 4096 |
804 | 89 | block_device = factory.make_PhysicalBlockDevice(block_size=block_size) | 91 | block_device = factory.make_PhysicalBlockDevice(block_size=block_size) |
805 | 90 | k_size = (MIN_BLOCK_DEVICE_SIZE / 1000) + 1 | 92 | k_size = (MIN_BLOCK_DEVICE_SIZE / 1000) + 1 |
806 | 91 | size = "%sk" % k_size | 93 | size = "%sk" % k_size |
811 | 92 | block_count = (k_size * 1000) / block_size | 94 | rounded_size = round_size_to_nearest_block( |
812 | 93 | if (k_size * 1000) % block_size > 0: | 95 | k_size * 1000, PARTITION_ALIGNMENT_SIZE, False) |
809 | 94 | block_count += 1 | ||
810 | 95 | rounded_size = block_count * block_size | ||
813 | 96 | data = { | 96 | data = { |
814 | 97 | 'size': size, | 97 | 'size': size, |
815 | 98 | } | 98 | } |
816 | 99 | 99 | ||
817 | === modified file 'src/maasserver/tests/test_forms_raid.py' | |||
818 | --- src/maasserver/tests/test_forms_raid.py 2015-10-29 16:39:49 +0000 | |||
819 | +++ src/maasserver/tests/test_forms_raid.py 2015-11-16 07:08:21 +0000 | |||
820 | @@ -26,7 +26,6 @@ | |||
821 | 26 | UpdateRaidForm, | 26 | UpdateRaidForm, |
822 | 27 | ) | 27 | ) |
823 | 28 | from maasserver.models.filesystemgroup import RAID | 28 | from maasserver.models.filesystemgroup import RAID |
824 | 29 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE | ||
825 | 30 | from maasserver.testing.factory import factory | 29 | from maasserver.testing.factory import factory |
826 | 31 | from maasserver.testing.testcase import MAASServerTestCase | 30 | from maasserver.testing.testcase import MAASServerTestCase |
827 | 32 | 31 | ||
828 | @@ -126,12 +125,11 @@ | |||
829 | 126 | for bd in bds | 125 | for bd in bds |
830 | 127 | if bd.get_partitiontable() is None | 126 | if bd.get_partitiontable() is None |
831 | 128 | ] | 127 | ] |
834 | 129 | partitions = [ | 128 | partition_objs = [ |
835 | 130 | bd.get_partitiontable().add_partition().id | 129 | bd.get_partitiontable().add_partition() |
836 | 131 | for bd in bds[5:] | 130 | for bd in bds[5:] |
837 | 132 | ] | 131 | ] |
840 | 133 | # Partition size will be smaller than the disk, because of overhead. | 132 | partitions = [partition.id for partition in partition_objs] |
839 | 134 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
841 | 135 | form = CreateRaidForm(node=node, data={ | 133 | form = CreateRaidForm(node=node, data={ |
842 | 136 | 'name': 'md1', | 134 | 'name': 'md1', |
843 | 137 | 'level': FILESYSTEM_GROUP_TYPE.RAID_6, | 135 | 'level': FILESYSTEM_GROUP_TYPE.RAID_6, |
844 | @@ -141,7 +139,7 @@ | |||
845 | 141 | self.assertTrue(form.is_valid(), form.errors) | 139 | self.assertTrue(form.is_valid(), form.errors) |
846 | 142 | raid = form.save() | 140 | raid = form.save() |
847 | 143 | self.assertEqual('md1', raid.name) | 141 | self.assertEqual('md1', raid.name) |
849 | 144 | self.assertEqual(8 * partition_size, raid.get_size()) | 142 | self.assertEqual(8 * partition_objs[0].size, raid.get_size()) |
850 | 145 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_6, raid.group_type) | 143 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_6, raid.group_type) |
851 | 146 | self.assertItemsEqual( | 144 | self.assertItemsEqual( |
852 | 147 | block_devices, | 145 | block_devices, |
853 | @@ -183,8 +181,6 @@ | |||
854 | 183 | part.name | 181 | part.name |
855 | 184 | for part in partitions | 182 | for part in partitions |
856 | 185 | ] | 183 | ] |
857 | 186 | # Partition size will be smaller than the disk, because of overhead. | ||
858 | 187 | partition_size = device_size - PARTITION_TABLE_EXTRA_SPACE | ||
859 | 188 | form = CreateRaidForm(node=node, data={ | 184 | form = CreateRaidForm(node=node, data={ |
860 | 189 | 'name': 'md1', | 185 | 'name': 'md1', |
861 | 190 | 'level': FILESYSTEM_GROUP_TYPE.RAID_6, | 186 | 'level': FILESYSTEM_GROUP_TYPE.RAID_6, |
862 | @@ -194,7 +190,7 @@ | |||
863 | 194 | self.assertTrue(form.is_valid(), form.errors) | 190 | self.assertTrue(form.is_valid(), form.errors) |
864 | 195 | raid = form.save() | 191 | raid = form.save() |
865 | 196 | self.assertEqual('md1', raid.name) | 192 | self.assertEqual('md1', raid.name) |
867 | 197 | self.assertEqual(8 * partition_size, raid.get_size()) | 193 | self.assertEqual(8 * partitions[0].size, raid.get_size()) |
868 | 198 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_6, raid.group_type) | 194 | self.assertEqual(FILESYSTEM_GROUP_TYPE.RAID_6, raid.group_type) |
869 | 199 | self.assertItemsEqual( | 195 | self.assertItemsEqual( |
870 | 200 | block_devices_ids, | 196 | block_devices_ids, |
871 | 201 | 197 | ||
872 | === modified file 'src/maasserver/tests/test_forms_volume_group.py' | |||
873 | --- src/maasserver/tests/test_forms_volume_group.py 2015-10-28 01:59:30 +0000 | |||
874 | +++ src/maasserver/tests/test_forms_volume_group.py 2015-11-16 07:08:21 +0000 | |||
875 | @@ -24,9 +24,11 @@ | |||
876 | 24 | UpdateVolumeGroupForm, | 24 | UpdateVolumeGroupForm, |
877 | 25 | ) | 25 | ) |
878 | 26 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE | 26 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE |
879 | 27 | from maasserver.models.partition import PARTITION_ALIGNMENT_SIZE | ||
880 | 27 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE | 28 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE |
881 | 28 | from maasserver.testing.factory import factory | 29 | from maasserver.testing.factory import factory |
882 | 29 | from maasserver.testing.testcase import MAASServerTestCase | 30 | from maasserver.testing.testcase import MAASServerTestCase |
883 | 31 | from maasserver.utils.converters import round_size_to_nearest_block | ||
884 | 30 | from testtools.matchers import MatchesStructure | 32 | from testtools.matchers import MatchesStructure |
885 | 31 | 33 | ||
886 | 32 | 34 | ||
887 | @@ -512,9 +514,10 @@ | |||
888 | 512 | factory.make_name("lv"), | 514 | factory.make_name("lv"), |
889 | 513 | size=volume_group.get_size() - MIN_BLOCK_DEVICE_SIZE - 1) | 515 | size=volume_group.get_size() - MIN_BLOCK_DEVICE_SIZE - 1) |
890 | 514 | name = factory.make_name("lv") | 516 | name = factory.make_name("lv") |
891 | 517 | free_space = volume_group.get_lvm_free_space() | ||
892 | 515 | data = { | 518 | data = { |
893 | 516 | 'name': name, | 519 | 'name': name, |
895 | 517 | 'size': MIN_BLOCK_DEVICE_SIZE + 2, | 520 | 'size': free_space + 2, |
896 | 518 | } | 521 | } |
897 | 519 | form = CreateLogicalVolumeForm(volume_group, data=data) | 522 | form = CreateLogicalVolumeForm(volume_group, data=data) |
898 | 520 | self.assertFalse( | 523 | self.assertFalse( |
899 | @@ -560,9 +563,11 @@ | |||
900 | 560 | form = CreateLogicalVolumeForm(volume_group, data=data) | 563 | form = CreateLogicalVolumeForm(volume_group, data=data) |
901 | 561 | self.assertTrue(form.is_valid(), form._errors) | 564 | self.assertTrue(form.is_valid(), form._errors) |
902 | 562 | logical_volume = form.save() | 565 | logical_volume = form.save() |
903 | 566 | expected_size = round_size_to_nearest_block( | ||
904 | 567 | size, PARTITION_ALIGNMENT_SIZE, False) | ||
905 | 563 | self.assertThat( | 568 | self.assertThat( |
906 | 564 | logical_volume, MatchesStructure.byEquality( | 569 | logical_volume, MatchesStructure.byEquality( |
907 | 565 | name=name, | 570 | name=name, |
908 | 566 | uuid=vguuid, | 571 | uuid=vguuid, |
910 | 567 | size=size, | 572 | size=expected_size, |
911 | 568 | )) | 573 | )) |
912 | 569 | 574 | ||
913 | === modified file 'src/maasserver/tests/test_preseed_storage.py' | |||
914 | --- src/maasserver/tests/test_preseed_storage.py 2015-11-04 04:27:46 +0000 | |||
915 | +++ src/maasserver/tests/test_preseed_storage.py 2015-11-16 07:08:21 +0000 | |||
916 | @@ -83,7 +83,7 @@ | |||
917 | 83 | size: 536870912B | 83 | size: 536870912B |
918 | 84 | device: sda | 84 | device: sda |
919 | 85 | wipe: superblock | 85 | wipe: superblock |
921 | 86 | offset: 2097152B | 86 | offset: 4194304B |
922 | 87 | flag: boot | 87 | flag: boot |
923 | 88 | - id: sda-part2 | 88 | - id: sda-part2 |
924 | 89 | name: sda-part2 | 89 | name: sda-part2 |
925 | @@ -99,7 +99,7 @@ | |||
926 | 99 | type: partition | 99 | type: partition |
927 | 100 | number: 3 | 100 | number: 3 |
928 | 101 | uuid: f74ff260-2a5b-4a36-b1b8-37f746b946bf | 101 | uuid: f74ff260-2a5b-4a36-b1b8-37f746b946bf |
930 | 102 | size: 6976176128B | 102 | size: 6970933248B |
931 | 103 | wipe: superblock | 103 | wipe: superblock |
932 | 104 | device: sda | 104 | device: sda |
933 | 105 | - id: sda-part1_format | 105 | - id: sda-part1_format |
934 | @@ -195,7 +195,7 @@ | |||
935 | 195 | size: 536870912B | 195 | size: 536870912B |
936 | 196 | device: sda | 196 | device: sda |
937 | 197 | wipe: superblock | 197 | wipe: superblock |
939 | 198 | offset: 2097152B | 198 | offset: 4194304B |
940 | 199 | flag: boot | 199 | flag: boot |
941 | 200 | - id: sda-part2 | 200 | - id: sda-part2 |
942 | 201 | name: sda-part2 | 201 | name: sda-part2 |
943 | @@ -233,7 +233,7 @@ | |||
944 | 233 | type: partition | 233 | type: partition |
945 | 234 | number: 6 | 234 | number: 6 |
946 | 235 | uuid: 8c365c80-900b-40a1-a8c7-1e445878d19a | 235 | uuid: 8c365c80-900b-40a1-a8c7-1e445878d19a |
948 | 236 | size: 2144337920B | 236 | size: 2139095040B |
949 | 237 | device: sda | 237 | device: sda |
950 | 238 | wipe: superblock | 238 | wipe: superblock |
951 | 239 | flag: logical | 239 | flag: logical |
952 | @@ -370,10 +370,10 @@ | |||
953 | 370 | type: partition | 370 | type: partition |
954 | 371 | number: 1 | 371 | number: 1 |
955 | 372 | uuid: 6efc2c3d-bc9d-4ee5-a7ed-c6e1574d5398 | 372 | uuid: 6efc2c3d-bc9d-4ee5-a7ed-c6e1574d5398 |
957 | 373 | size: 8586788864B | 373 | size: 8581545984B |
958 | 374 | device: sda | 374 | device: sda |
959 | 375 | wipe: superblock | 375 | wipe: superblock |
961 | 376 | offset: 2097152B | 376 | offset: 4194304B |
962 | 377 | - id: sda-part1_format | 377 | - id: sda-part1_format |
963 | 378 | type: format | 378 | type: format |
964 | 379 | fstype: ext4 | 379 | fstype: ext4 |
965 | @@ -435,10 +435,10 @@ | |||
966 | 435 | type: partition | 435 | type: partition |
967 | 436 | number: 1 | 436 | number: 1 |
968 | 437 | uuid: 6efc2c3d-bc9d-4ee5-a7ed-c6e1574d5398 | 437 | uuid: 6efc2c3d-bc9d-4ee5-a7ed-c6e1574d5398 |
970 | 438 | size: 8586788864B | 438 | size: 8581545984B |
971 | 439 | device: sda | 439 | device: sda |
972 | 440 | wipe: superblock | 440 | wipe: superblock |
974 | 441 | offset: 2097152B | 441 | offset: 4194304B |
975 | 442 | - id: sda-part1_format | 442 | - id: sda-part1_format |
976 | 443 | type: format | 443 | type: format |
977 | 444 | fstype: ext4 | 444 | fstype: ext4 |
978 | @@ -548,7 +548,7 @@ | |||
979 | 548 | size: 536870912B | 548 | size: 536870912B |
980 | 549 | device: sda | 549 | device: sda |
981 | 550 | wipe: superblock | 550 | wipe: superblock |
983 | 551 | offset: 2097152B | 551 | offset: 4194304B |
984 | 552 | flag: boot | 552 | flag: boot |
985 | 553 | - id: sda-part2 | 553 | - id: sda-part2 |
986 | 554 | name: sda-part2 | 554 | name: sda-part2 |
987 | @@ -564,16 +564,16 @@ | |||
988 | 564 | type: partition | 564 | type: partition |
989 | 565 | number: 3 | 565 | number: 3 |
990 | 566 | uuid: f74ff260-2a5b-4a36-b1b8-37f746b946bf | 566 | uuid: f74ff260-2a5b-4a36-b1b8-37f746b946bf |
992 | 567 | size: 6976176128B | 567 | size: 6970933248B |
993 | 568 | device: sda | 568 | device: sda |
994 | 569 | wipe: superblock | 569 | wipe: superblock |
995 | 570 | - id: sdb-part1 | 570 | - id: sdb-part1 |
996 | 571 | name: sdb-part1 | 571 | name: sdb-part1 |
997 | 572 | type: partition | 572 | type: partition |
998 | 573 | number: 1 | 573 | number: 1 |
1000 | 574 | offset: 2097152B | 574 | offset: 4194304B |
1001 | 575 | uuid: f3281144-a0b6-46f1-90af-8541f97f7b1f | 575 | uuid: f3281144-a0b6-46f1-90af-8541f97f7b1f |
1003 | 576 | size: 2144337920B | 576 | size: 2139095040B |
1004 | 577 | wipe: superblock | 577 | wipe: superblock |
1005 | 578 | device: sdb | 578 | device: sdb |
1006 | 579 | - id: bcache0 | 579 | - id: bcache0 |
1007 | @@ -610,9 +610,9 @@ | |||
1008 | 610 | name: md0-part1 | 610 | name: md0-part1 |
1009 | 611 | type: partition | 611 | type: partition |
1010 | 612 | number: 1 | 612 | number: 1 |
1012 | 613 | offset: 2097152B | 613 | offset: 4194304B |
1013 | 614 | uuid: 18a6e885-3e6d-4505-8a0d-cf34df11a8b0 | 614 | uuid: 18a6e885-3e6d-4505-8a0d-cf34df11a8b0 |
1015 | 615 | size: 2199020109824B | 615 | size: 2199014866944B |
1016 | 616 | wipe: superblock | 616 | wipe: superblock |
1017 | 617 | device: md0 | 617 | device: md0 |
1018 | 618 | - id: sda-part1_format | 618 | - id: sda-part1_format |
1019 | 619 | 619 | ||
1020 | === modified file 'src/maasserver/tests/test_storage_layouts.py' | |||
1021 | --- src/maasserver/tests/test_storage_layouts.py 2015-10-27 20:53:16 +0000 | |||
1022 | +++ src/maasserver/tests/test_storage_layouts.py 2015-11-16 07:08:21 +0000 | |||
1023 | @@ -25,7 +25,10 @@ | |||
1024 | 25 | ) | 25 | ) |
1025 | 26 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE | 26 | from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE |
1026 | 27 | from maasserver.models.filesystemgroup import VolumeGroup | 27 | from maasserver.models.filesystemgroup import VolumeGroup |
1028 | 28 | from maasserver.models.partition import MAX_PARTITION_SIZE_FOR_MBR | 28 | from maasserver.models.partition import ( |
1029 | 29 | MAX_PARTITION_SIZE_FOR_MBR, | ||
1030 | 30 | PARTITION_ALIGNMENT_SIZE, | ||
1031 | 31 | ) | ||
1032 | 29 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE | 32 | from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE |
1033 | 30 | from maasserver.storage_layouts import ( | 33 | from maasserver.storage_layouts import ( |
1034 | 31 | BcacheStorageLayout, | 34 | BcacheStorageLayout, |
1035 | @@ -46,6 +49,7 @@ | |||
1036 | 46 | ) | 49 | ) |
1037 | 47 | from maasserver.testing.factory import factory | 50 | from maasserver.testing.factory import factory |
1038 | 48 | from maasserver.testing.testcase import MAASServerTestCase | 51 | from maasserver.testing.testcase import MAASServerTestCase |
1039 | 52 | from maasserver.utils.converters import round_size_to_nearest_block | ||
1040 | 49 | from maastesting.matchers import MockCalledOnceWith | 53 | from maastesting.matchers import MockCalledOnceWith |
1041 | 50 | from testtools.matchers import MatchesStructure | 54 | from testtools.matchers import MatchesStructure |
1042 | 51 | 55 | ||
1043 | @@ -53,13 +57,6 @@ | |||
1044 | 53 | LARGE_BLOCK_DEVICE = 10 * 1024 * 1024 * 1024 # 10 GiB | 57 | LARGE_BLOCK_DEVICE = 10 * 1024 * 1024 * 1024 # 10 GiB |
1045 | 54 | 58 | ||
1046 | 55 | 59 | ||
1047 | 56 | def round_size_by_blocks(size, block_size): | ||
1048 | 57 | number_of_blocks = size / block_size | ||
1049 | 58 | if size % block_size > 0: | ||
1050 | 59 | number_of_blocks += 1 | ||
1051 | 60 | return number_of_blocks * block_size | ||
1052 | 61 | |||
1053 | 62 | |||
1054 | 63 | def make_Node_with_uefi_boot_method(*args, **kwargs): | 60 | def make_Node_with_uefi_boot_method(*args, **kwargs): |
1055 | 64 | kwargs['bios_boot_method'] = "uefi" | 61 | kwargs['bios_boot_method'] = "uefi" |
1056 | 65 | kwargs['with_boot_disk'] = False | 62 | kwargs['with_boot_disk'] = False |
1057 | @@ -435,7 +432,8 @@ | |||
1058 | 435 | def assertEFIPartition(self, partition, boot_disk): | 432 | def assertEFIPartition(self, partition, boot_disk): |
1059 | 436 | self.assertIsNotNone(partition) | 433 | self.assertIsNotNone(partition) |
1060 | 437 | self.assertEquals( | 434 | self.assertEquals( |
1062 | 438 | round_size_by_blocks(EFI_PARTITION_SIZE, boot_disk.block_size), | 435 | round_size_to_nearest_block( |
1063 | 436 | EFI_PARTITION_SIZE, boot_disk.block_size), | ||
1064 | 439 | partition.size) | 437 | partition.size) |
1065 | 440 | self.assertThat( | 438 | self.assertThat( |
1066 | 441 | partition.get_effective_filesystem(), MatchesStructure.byEquality( | 439 | partition.get_effective_filesystem(), MatchesStructure.byEquality( |
1067 | @@ -474,9 +472,10 @@ | |||
1068 | 474 | root_partition = partitions[0] | 472 | root_partition = partitions[0] |
1069 | 475 | self.assertIsNotNone(root_partition) | 473 | self.assertIsNotNone(root_partition) |
1070 | 476 | self.assertEquals( | 474 | self.assertEquals( |
1072 | 477 | round_size_by_blocks( | 475 | round_size_to_nearest_block( |
1073 | 478 | boot_disk.size - PARTITION_TABLE_EXTRA_SPACE, | 476 | boot_disk.size - PARTITION_TABLE_EXTRA_SPACE, |
1075 | 479 | boot_disk.block_size), | 477 | PARTITION_ALIGNMENT_SIZE, |
1076 | 478 | False), | ||
1077 | 480 | root_partition.size) | 479 | root_partition.size) |
1078 | 481 | self.assertThat( | 480 | self.assertThat( |
1079 | 482 | root_partition.get_effective_filesystem(), | 481 | root_partition.get_effective_filesystem(), |
1080 | @@ -500,10 +499,12 @@ | |||
1081 | 500 | # Validate root partition. | 499 | # Validate root partition. |
1082 | 501 | partitions = partition_table.partitions.order_by('id').all() | 500 | partitions = partition_table.partitions.order_by('id').all() |
1083 | 502 | root_partition = partitions[0] | 501 | root_partition = partitions[0] |
1084 | 503 | number_of_blocks = MAX_PARTITION_SIZE_FOR_MBR / boot_disk.block_size | ||
1085 | 504 | self.assertIsNotNone(root_partition) | 502 | self.assertIsNotNone(root_partition) |
1086 | 505 | self.assertEquals( | 503 | self.assertEquals( |
1088 | 506 | (boot_disk.block_size * (number_of_blocks - 1)), | 504 | round_size_to_nearest_block( |
1089 | 505 | MAX_PARTITION_SIZE_FOR_MBR, | ||
1090 | 506 | PARTITION_ALIGNMENT_SIZE, | ||
1091 | 507 | False), | ||
1092 | 507 | root_partition.size) | 508 | root_partition.size) |
1093 | 508 | self.assertThat( | 509 | self.assertThat( |
1094 | 509 | root_partition.get_effective_filesystem(), | 510 | root_partition.get_effective_filesystem(), |
1095 | @@ -533,10 +534,11 @@ | |||
1096 | 533 | root_partition = partitions[1] | 534 | root_partition = partitions[1] |
1097 | 534 | self.assertIsNotNone(root_partition) | 535 | self.assertIsNotNone(root_partition) |
1098 | 535 | self.assertEquals( | 536 | self.assertEquals( |
1100 | 536 | round_size_by_blocks( | 537 | round_size_to_nearest_block( |
1101 | 537 | boot_disk.size - EFI_PARTITION_SIZE - | 538 | boot_disk.size - EFI_PARTITION_SIZE - |
1102 | 538 | PARTITION_TABLE_EXTRA_SPACE, | 539 | PARTITION_TABLE_EXTRA_SPACE, |
1104 | 539 | boot_disk.block_size), | 540 | PARTITION_ALIGNMENT_SIZE, |
1105 | 541 | False), | ||
1106 | 540 | root_partition.size) | 542 | root_partition.size) |
1107 | 541 | self.assertThat( | 543 | self.assertThat( |
1108 | 542 | root_partition.get_effective_filesystem(), | 544 | root_partition.get_effective_filesystem(), |
1109 | @@ -570,8 +572,8 @@ | |||
1110 | 570 | boot_partition = partitions[1] | 572 | boot_partition = partitions[1] |
1111 | 571 | self.assertIsNotNone(boot_partition) | 573 | self.assertIsNotNone(boot_partition) |
1112 | 572 | self.assertEquals( | 574 | self.assertEquals( |
1115 | 573 | round_size_by_blocks( | 575 | round_size_to_nearest_block( |
1116 | 574 | boot_size, boot_disk.block_size), | 576 | boot_size, PARTITION_ALIGNMENT_SIZE, False), |
1117 | 575 | boot_partition.size) | 577 | boot_partition.size) |
1118 | 576 | self.assertThat( | 578 | self.assertThat( |
1119 | 577 | boot_partition.get_effective_filesystem(), | 579 | boot_partition.get_effective_filesystem(), |
1120 | @@ -585,10 +587,11 @@ | |||
1121 | 585 | root_partition = partitions[2] | 587 | root_partition = partitions[2] |
1122 | 586 | self.assertIsNotNone(root_partition) | 588 | self.assertIsNotNone(root_partition) |
1123 | 587 | self.assertEquals( | 589 | self.assertEquals( |
1125 | 588 | round_size_by_blocks( | 590 | round_size_to_nearest_block( |
1126 | 589 | boot_disk.size - boot_partition.size - | 591 | boot_disk.size - boot_partition.size - |
1127 | 590 | EFI_PARTITION_SIZE - PARTITION_TABLE_EXTRA_SPACE, | 592 | EFI_PARTITION_SIZE - PARTITION_TABLE_EXTRA_SPACE, |
1129 | 591 | boot_disk.block_size), | 593 | PARTITION_ALIGNMENT_SIZE, |
1130 | 594 | False), | ||
1131 | 592 | root_partition.size) | 595 | root_partition.size) |
1132 | 593 | self.assertThat( | 596 | self.assertThat( |
1133 | 594 | root_partition.get_effective_filesystem(), | 597 | root_partition.get_effective_filesystem(), |
1134 | @@ -622,7 +625,8 @@ | |||
1135 | 622 | root_partition = partitions[1] | 625 | root_partition = partitions[1] |
1136 | 623 | self.assertIsNotNone(root_partition) | 626 | self.assertIsNotNone(root_partition) |
1137 | 624 | self.assertEquals( | 627 | self.assertEquals( |
1139 | 625 | round_size_by_blocks(root_size, boot_disk.block_size), | 628 | round_size_to_nearest_block( |
1140 | 629 | root_size, PARTITION_ALIGNMENT_SIZE, False), | ||
1141 | 626 | root_partition.size) | 630 | root_partition.size) |
1142 | 627 | self.assertThat( | 631 | self.assertThat( |
1143 | 628 | root_partition.get_effective_filesystem(), | 632 | root_partition.get_effective_filesystem(), |
1144 | @@ -659,8 +663,8 @@ | |||
1145 | 659 | boot_partition = partitions[1] | 663 | boot_partition = partitions[1] |
1146 | 660 | self.assertIsNotNone(boot_partition) | 664 | self.assertIsNotNone(boot_partition) |
1147 | 661 | self.assertEquals( | 665 | self.assertEquals( |
1150 | 662 | round_size_by_blocks( | 666 | round_size_to_nearest_block( |
1151 | 663 | boot_size, boot_disk.block_size), | 667 | boot_size, PARTITION_ALIGNMENT_SIZE, False), |
1152 | 664 | boot_partition.size) | 668 | boot_partition.size) |
1153 | 665 | self.assertThat( | 669 | self.assertThat( |
1154 | 666 | boot_partition.get_effective_filesystem(), | 670 | boot_partition.get_effective_filesystem(), |
1155 | @@ -674,7 +678,8 @@ | |||
1156 | 674 | root_partition = partitions[2] | 678 | root_partition = partitions[2] |
1157 | 675 | self.assertIsNotNone(root_partition) | 679 | self.assertIsNotNone(root_partition) |
1158 | 676 | self.assertEquals( | 680 | self.assertEquals( |
1160 | 677 | round_size_by_blocks(root_size, boot_disk.block_size), | 681 | round_size_to_nearest_block( |
1161 | 682 | root_size, PARTITION_ALIGNMENT_SIZE, False), | ||
1162 | 678 | root_partition.size) | 683 | root_partition.size) |
1163 | 679 | self.assertThat( | 684 | self.assertThat( |
1164 | 680 | root_partition.get_effective_filesystem(), | 685 | root_partition.get_effective_filesystem(), |
1165 | @@ -716,7 +721,8 @@ | |||
1166 | 716 | 'id').all()[0] | 721 | 'id').all()[0] |
1167 | 717 | self.assertIsNotNone(root_partition) | 722 | self.assertIsNotNone(root_partition) |
1168 | 718 | self.assertEquals( | 723 | self.assertEquals( |
1170 | 719 | round_size_by_blocks(root_size, root_device.block_size), | 724 | round_size_to_nearest_block( |
1171 | 725 | root_size, PARTITION_ALIGNMENT_SIZE, False), | ||
1172 | 720 | root_partition.size) | 726 | root_partition.size) |
1173 | 721 | self.assertThat( | 727 | self.assertThat( |
1174 | 722 | root_partition.get_effective_filesystem(), | 728 | root_partition.get_effective_filesystem(), |
1175 | @@ -980,7 +986,9 @@ | |||
1176 | 980 | 1, volume_group.virtual_devices.count(), | 986 | 1, volume_group.virtual_devices.count(), |
1177 | 981 | "Should have only 1 logical volume.") | 987 | "Should have only 1 logical volume.") |
1178 | 982 | logical_volume = volume_group.virtual_devices.first() | 988 | logical_volume = volume_group.virtual_devices.first() |
1180 | 983 | self.assertEquals(lv_size, logical_volume.size) | 989 | expected_size = round_size_to_nearest_block( |
1181 | 990 | lv_size, PARTITION_ALIGNMENT_SIZE, False) | ||
1182 | 991 | self.assertEquals(expected_size, logical_volume.size) | ||
1183 | 984 | self.assertEquals(layout.DEFAULT_LV_NAME, logical_volume.name) | 992 | self.assertEquals(layout.DEFAULT_LV_NAME, logical_volume.name) |
1184 | 985 | self.assertThat( | 993 | self.assertThat( |
1185 | 986 | logical_volume.get_effective_filesystem(), | 994 | logical_volume.get_effective_filesystem(), |
1186 | @@ -1003,14 +1011,13 @@ | |||
1187 | 1003 | root_partition = partitions[0] | 1011 | root_partition = partitions[0] |
1188 | 1004 | volume_group = VolumeGroup.objects.get( | 1012 | volume_group = VolumeGroup.objects.get( |
1189 | 1005 | filesystems__partition=root_partition) | 1013 | filesystems__partition=root_partition) |
1190 | 1006 | number_of_blocks = MAX_PARTITION_SIZE_FOR_MBR / boot_disk.block_size | ||
1191 | 1007 | self.assertIsNotNone(volume_group) | 1014 | self.assertIsNotNone(volume_group) |
1192 | 1008 | self.assertEquals( | 1015 | self.assertEquals( |
1193 | 1009 | 4, partition_table.partitions.count(), | 1016 | 4, partition_table.partitions.count(), |
1194 | 1010 | "Should have 4 partitions.") | 1017 | "Should have 4 partitions.") |
1198 | 1011 | self.assertEquals( | 1018 | expected_size = round_size_to_nearest_block( |
1199 | 1012 | boot_disk.block_size * (number_of_blocks - 1), | 1019 | MAX_PARTITION_SIZE_FOR_MBR, PARTITION_ALIGNMENT_SIZE, False) |
1200 | 1013 | root_partition.size) | 1020 | self.assertEquals(expected_size, root_partition.size) |
1201 | 1014 | 1021 | ||
1202 | 1015 | 1022 | ||
1203 | 1016 | class TestBcacheStorageLayoutBase(MAASServerTestCase): | 1023 | class TestBcacheStorageLayoutBase(MAASServerTestCase): |
1204 | @@ -1185,7 +1192,7 @@ | |||
1205 | 1185 | ssd = factory.make_PhysicalBlockDevice( | 1192 | ssd = factory.make_PhysicalBlockDevice( |
1206 | 1186 | node=node, size=5 * 1024 * 1024 * 1024, block_size=4096, | 1193 | node=node, size=5 * 1024 * 1024 * 1024, block_size=4096, |
1207 | 1187 | tags=['ssd']) | 1194 | tags=['ssd']) |
1209 | 1188 | cache_size = round_size_by_blocks( | 1195 | cache_size = round_size_to_nearest_block( |
1210 | 1189 | random.randint( | 1196 | random.randint( |
1211 | 1190 | 3 * 1024 * 1024 * 1024, 5 * 1024 * 1024 * 1024), | 1197 | 3 * 1024 * 1024 * 1024, 5 * 1024 * 1024 * 1024), |
1212 | 1191 | 4096) | 1198 | 4096) |
1213 | @@ -1200,7 +1207,10 @@ | |||
1214 | 1200 | self.assertIsNotNone(partition_table) | 1207 | self.assertIsNotNone(partition_table) |
1215 | 1201 | partition = partition_table.partitions.order_by('id').all()[0] | 1208 | partition = partition_table.partitions.order_by('id').all()[0] |
1216 | 1202 | self.assertEquals(partition, cache_device) | 1209 | self.assertEquals(partition, cache_device) |
1218 | 1203 | self.assertEquals(cache_size, partition.size) | 1210 | self.assertEquals( |
1219 | 1211 | round_size_to_nearest_block( | ||
1220 | 1212 | cache_size, PARTITION_ALIGNMENT_SIZE, False), | ||
1221 | 1213 | partition.size) | ||
1222 | 1204 | 1214 | ||
1223 | 1205 | def test_raises_error_when_invalid_cache_device(self): | 1215 | def test_raises_error_when_invalid_cache_device(self): |
1224 | 1206 | node = make_Node_with_uefi_boot_method() | 1216 | node = make_Node_with_uefi_boot_method() |
1225 | @@ -1234,7 +1244,8 @@ | |||
1226 | 1234 | "Cannot use cache_size and cache_no_part at the same time."], | 1244 | "Cannot use cache_size and cache_no_part at the same time."], |
1227 | 1235 | "cache_no_part": [ | 1245 | "cache_no_part": [ |
1228 | 1236 | "Cannot use cache_size and cache_no_part at the same time."], | 1246 | "Cannot use cache_size and cache_no_part at the same time."], |
1230 | 1237 | }, layout.errors) | 1247 | }, |
1231 | 1248 | layout.errors) | ||
1232 | 1238 | 1249 | ||
1233 | 1239 | def test_raises_error_when_precentage_to_low_for_cache_size(self): | 1250 | def test_raises_error_when_precentage_to_low_for_cache_size(self): |
1234 | 1240 | node = make_Node_with_uefi_boot_method() | 1251 | node = make_Node_with_uefi_boot_method() |
1235 | 1241 | 1252 | ||
1236 | === modified file 'src/maasserver/utils/converters.py' | |||
1237 | --- src/maasserver/utils/converters.py 2015-10-11 00:26:09 +0000 | |||
1238 | +++ src/maasserver/utils/converters.py 2015-11-16 07:08:21 +0000 | |||
1239 | @@ -100,12 +100,14 @@ | |||
1240 | 100 | return int(humanized) | 100 | return int(humanized) |
1241 | 101 | 101 | ||
1242 | 102 | 102 | ||
1244 | 103 | def round_size_to_nearest_block(size, block_size): | 103 | def round_size_to_nearest_block(size, block_size, round_up=True): |
1245 | 104 | """Round the size to the nearest block returning the new size. | 104 | """Round the size to the nearest block returning the new size. |
1246 | 105 | 105 | ||
1248 | 106 | :param round_up: Round the size to fill an entire block. | 106 | :param size: The requested size to round. |
1249 | 107 | :param block_size: The block size to round to. | ||
1250 | 108 | :param round_up: If True, will round up to fill current block, else down. | ||
1251 | 107 | """ | 109 | """ |
1252 | 108 | number_of_blocks = size / block_size | 110 | number_of_blocks = size / block_size |
1254 | 109 | if size % block_size > 0: | 111 | if round_up and size % block_size > 0: |
1255 | 110 | number_of_blocks += 1 | 112 | number_of_blocks += 1 |
1256 | 111 | return block_size * number_of_blocks | 113 | return block_size * number_of_blocks |
1257 | 112 | 114 | ||
1258 | === modified file 'src/maasserver/utils/tests/test_converters.py' | |||
1259 | --- src/maasserver/utils/tests/test_converters.py 2015-08-14 13:48:59 +0000 | |||
1260 | +++ src/maasserver/utils/tests/test_converters.py 2015-11-16 07:08:21 +0000 | |||
1261 | @@ -114,18 +114,34 @@ | |||
1262 | 114 | 114 | ||
1263 | 115 | class TestRoundSizeToNearestBlock(MAASTestCase): | 115 | class TestRoundSizeToNearestBlock(MAASTestCase): |
1264 | 116 | 116 | ||
1266 | 117 | def test__adds_extra_block(self): | 117 | def test__round_up_adds_extra_block(self): |
1267 | 118 | block_size = 4096 | 118 | block_size = 4096 |
1268 | 119 | size = block_size + 1 | 119 | size = block_size + 1 |
1269 | 120 | self.assertEquals( | 120 | self.assertEquals( |
1270 | 121 | 2 * block_size, | 121 | 2 * block_size, |
1273 | 122 | round_size_to_nearest_block(size, block_size), | 122 | round_size_to_nearest_block(size, block_size, True), |
1274 | 123 | "Should add another block to the size.") | 123 | "Should add an extra block to the size.") |
1275 | 124 | 124 | ||
1277 | 125 | def test__doesnt_add_extra_block(self): | 125 | def test__round_up_doesnt_add_extra_block(self): |
1278 | 126 | block_size = 4096 | 126 | block_size = 4096 |
1279 | 127 | size = block_size | 127 | size = block_size |
1280 | 128 | self.assertEquals( | 128 | self.assertEquals( |
1281 | 129 | size, | 129 | size, |
1284 | 130 | round_size_to_nearest_block(size, block_size), | 130 | round_size_to_nearest_block(size, block_size, True), |
1285 | 131 | "Shouldn't add another block to the size.") | 131 | "Shouldn't add an extra block to the size.") |
1286 | 132 | |||
1287 | 133 | def test__round_down_removes_block(self): | ||
1288 | 134 | block_size = 4096 | ||
1289 | 135 | size = block_size + 1 | ||
1290 | 136 | self.assertEquals( | ||
1291 | 137 | 1 * block_size, | ||
1292 | 138 | round_size_to_nearest_block(size, block_size, False), | ||
1293 | 139 | "Should remove block from the size.") | ||
1294 | 140 | |||
1295 | 141 | def test__round_down_doesnt_remove_block(self): | ||
1296 | 142 | block_size = 4096 | ||
1297 | 143 | size = block_size * 2 | ||
1298 | 144 | self.assertEquals( | ||
1299 | 145 | size, | ||
1300 | 146 | round_size_to_nearest_block(size, block_size, False), | ||
1301 | 147 | "Shouldn't remove a block from the size.") | ||
1302 | 132 | 148 | ||
1303 | === modified file 'src/maasserver/websockets/handlers/tests/test_node.py' | |||
1304 | --- src/maasserver/websockets/handlers/tests/test_node.py 2015-11-10 23:41:49 +0000 | |||
1305 | +++ src/maasserver/websockets/handlers/tests/test_node.py 2015-11-16 07:08:21 +0000 | |||
1306 | @@ -48,7 +48,10 @@ | |||
1307 | 48 | from maasserver.models.interface import Interface | 48 | from maasserver.models.interface import Interface |
1308 | 49 | from maasserver.models.node import Node | 49 | from maasserver.models.node import Node |
1309 | 50 | from maasserver.models.nodeprobeddetails import get_single_probed_details | 50 | from maasserver.models.nodeprobeddetails import get_single_probed_details |
1311 | 51 | from maasserver.models.partition import Partition | 51 | from maasserver.models.partition import ( |
1312 | 52 | Partition, | ||
1313 | 53 | PARTITION_ALIGNMENT_SIZE, | ||
1314 | 54 | ) | ||
1315 | 52 | from maasserver.node_action import compile_node_actions | 55 | from maasserver.node_action import compile_node_actions |
1316 | 53 | from maasserver.rpc.testing.fixtures import MockLiveRegionToClusterRPCFixture | 56 | from maasserver.rpc.testing.fixtures import MockLiveRegionToClusterRPCFixture |
1317 | 54 | from maasserver.testing.architecture import make_usable_architecture | 57 | from maasserver.testing.architecture import make_usable_architecture |
1318 | @@ -66,6 +69,7 @@ | |||
1319 | 66 | from maasserver.third_party_drivers import get_third_party_driver | 69 | from maasserver.third_party_drivers import get_third_party_driver |
1320 | 67 | from maasserver.utils.converters import ( | 70 | from maasserver.utils.converters import ( |
1321 | 68 | human_readable_bytes, | 71 | human_readable_bytes, |
1322 | 72 | round_size_to_nearest_block, | ||
1323 | 69 | XMLToYAML, | 73 | XMLToYAML, |
1324 | 70 | ) | 74 | ) |
1325 | 71 | from maasserver.utils.orm import ( | 75 | from maasserver.utils.orm import ( |
1326 | @@ -1477,7 +1481,9 @@ | |||
1327 | 1477 | self.assertEquals( | 1481 | self.assertEquals( |
1328 | 1478 | 1, Partition.objects.count()) | 1482 | 1, Partition.objects.count()) |
1329 | 1479 | self.assertEquals( | 1483 | self.assertEquals( |
1331 | 1480 | human_readable_bytes(size), | 1484 | human_readable_bytes( |
1332 | 1485 | round_size_to_nearest_block( | ||
1333 | 1486 | size, PARTITION_ALIGNMENT_SIZE, False)), | ||
1334 | 1481 | human_readable_bytes(Partition.objects.first().size)) | 1487 | human_readable_bytes(Partition.objects.first().size)) |
1335 | 1482 | 1488 | ||
1336 | 1483 | def test_create_partition_with_filesystem(self): | 1489 | def test_create_partition_with_filesystem(self): |
1337 | @@ -1502,7 +1508,9 @@ | |||
1338 | 1502 | self.assertEquals( | 1508 | self.assertEquals( |
1339 | 1503 | 1, Partition.objects.count()) | 1509 | 1, Partition.objects.count()) |
1340 | 1504 | self.assertEquals( | 1510 | self.assertEquals( |
1342 | 1505 | human_readable_bytes(size), | 1511 | human_readable_bytes( |
1343 | 1512 | round_size_to_nearest_block( | ||
1344 | 1513 | size, PARTITION_ALIGNMENT_SIZE, False)), | ||
1345 | 1506 | human_readable_bytes(Partition.objects.first().size)) | 1514 | human_readable_bytes(Partition.objects.first().size)) |
1346 | 1507 | self.assertEquals( | 1515 | self.assertEquals( |
1347 | 1508 | fstype, | 1516 | fstype, |
Looks really good. Good work. Please backport his change as well. Let me know if you need help with this.