Merge ~ltrager/maas:lp1825241 into maas:master

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: fd38000ae921b31032377d9fba4d9b976579f5c8
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1825241
Merge into: maas:master
Diff against target: 122 lines (+55/-7)
2 files modified
src/maasserver/storage_layouts.py (+11/-5)
src/maasserver/tests/test_storage_layouts.py (+44/-2)
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
Review via email: mp+366244@code.launchpad.net

Commit message

LP: #1825241 - Allow VMFS6 layout to be applied to any disk

To post a comment you must log in.
Revision history for this message
Newell Jensen (newell-jensen) wrote :

You should fix the docstring as mentioned inline. You should also update line 212 in maasserver.storage_layouts if you are doing to keep the change that you added for get_root_device as this will not be returning None anymore.

review: Needs Fixing
~ltrager/maas:lp1825241 updated
4f42134... by Lee Trager

Merge branch 'master' into lp1825241

fd38000... by Lee Trager

newell-jensen fixes

Revision history for this message
Lee Trager (ltrager) wrote :

Thanks for the review. I forgot about the docstring, and I updated line 212 as requested.

Revision history for this message
Newell Jensen (newell-jensen) wrote :

Thanks for the fixes. LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/storage_layouts.py b/src/maasserver/storage_layouts.py
index 2bb5b34..dcf4c34 100644
--- a/src/maasserver/storage_layouts.py
+++ b/src/maasserver/storage_layouts.py
@@ -138,13 +138,15 @@ class StorageLayoutBase(Form):
138 def get_root_device(self):138 def get_root_device(self):
139 """Get the device that should be the root partition.139 """Get the device that should be the root partition.
140140
141 Return of None means to use the boot disk.141 Return the boot_disk if no root_device was defined.
142 """142 """
143 if self.cleaned_data.get('root_device'):143 if self.cleaned_data.get('root_device'):
144 root_id = self.cleaned_data['root_device']144 root_id = self.cleaned_data['root_device']
145 return self.node.physicalblockdevice_set.get(id=root_id)145 return self.node.physicalblockdevice_set.get(id=root_id)
146 else:146 else:
147 return None147 # User didn't specify a root disk so use the currently defined
148 # boot disk.
149 return self.boot_disk
148150
149 def get_boot_size(self):151 def get_boot_size(self):
150 """Get the size of the boot partition."""152 """Get the size of the boot partition."""
@@ -209,7 +211,7 @@ class StorageLayoutBase(Form):
209 mount_point="/boot")211 mount_point="/boot")
210 root_device = self.get_root_device()212 root_device = self.get_root_device()
211 root_size = self.get_root_size()213 root_size = self.get_root_size()
212 if root_device is None or root_device == self.boot_disk:214 if root_device == self.boot_disk:
213 partition_table = boot_partition_table215 partition_table = boot_partition_table
214 root_device = self.boot_disk216 root_device = self.boot_disk
215 else:217 else:
@@ -566,7 +568,7 @@ class VMFS6Layout(StorageLayoutBase):
566 from maasserver.models.partitiontable import PartitionTable568 from maasserver.models.partitiontable import PartitionTable
567569
568 boot_partition_table = PartitionTable.objects.create(570 boot_partition_table = PartitionTable.objects.create(
569 block_device=self.boot_disk,571 block_device=self.get_root_device(),
570 table_type=PARTITION_TABLE_TYPE.GPT)572 table_type=PARTITION_TABLE_TYPE.GPT)
571 now = datetime.now()573 now = datetime.now()
572 new_part = partial(574 new_part = partial(
@@ -598,7 +600,11 @@ class VMFS6Layout(StorageLayoutBase):
598 new_part(size=2560 * 1024 ** 2),600 new_part(size=2560 * 1024 ** 2),
599 ])601 ])
600 vmfs_part = boot_partition_table.partitions.get(size=0)602 vmfs_part = boot_partition_table.partitions.get(size=0)
601 vmfs_part.size = boot_partition_table.get_available_size()603 root_size = self.get_root_size()
604 if root_size is not None:
605 vmfs_part.size = root_size
606 else:
607 vmfs_part.size = boot_partition_table.get_available_size()
602 vmfs_part.save()608 vmfs_part.save()
603 # datastore1 is the default name VMware uses.609 # datastore1 is the default name VMware uses.
604 VMFS.objects.create_vmfs(name="datastore1", partitions=[vmfs_part])610 VMFS.objects.create_vmfs(name="datastore1", partitions=[vmfs_part])
diff --git a/src/maasserver/tests/test_storage_layouts.py b/src/maasserver/tests/test_storage_layouts.py
index ef2df86..8daa2ee 100644
--- a/src/maasserver/tests/test_storage_layouts.py
+++ b/src/maasserver/tests/test_storage_layouts.py
@@ -391,14 +391,14 @@ class TestStorageLayoutBase(MAASServerTestCase):
391 self.assertTrue(layout.is_valid(), layout.errors)391 self.assertTrue(layout.is_valid(), layout.errors)
392 self.assertEqual(boot_size, layout.get_boot_size())392 self.assertEqual(boot_size, layout.get_boot_size())
393393
394 def test_get_root_device_returns_None_if_not_set(self):394 def test_get_root_device_returns_boot_disk_if_not_set(self):
395 node = make_Node_with_uefi_boot_method()395 node = make_Node_with_uefi_boot_method()
396 factory.make_PhysicalBlockDevice(396 factory.make_PhysicalBlockDevice(
397 node=node, size=LARGE_BLOCK_DEVICE)397 node=node, size=LARGE_BLOCK_DEVICE)
398 layout = StorageLayoutBase(node, {398 layout = StorageLayoutBase(node, {
399 })399 })
400 self.assertTrue(layout.is_valid(), layout.errors)400 self.assertTrue(layout.is_valid(), layout.errors)
401 self.assertIsNone(layout.get_root_device())401 self.assertEquals(node.get_boot_disk(), layout.get_root_device())
402402
403 def test_get_root_device_returns_root_device_if_set(self):403 def test_get_root_device_returns_root_device_if_set(self):
404 node = make_Node_with_uefi_boot_method()404 node = make_Node_with_uefi_boot_method()
@@ -1652,6 +1652,48 @@ class TestVMFS6Layout(MAASServerTestCase):
1652 "size": ["Boot disk must be atleast 10G."],1652 "size": ["Boot disk must be atleast 10G."],
1653 }, error.message_dict)1653 }, error.message_dict)
16541654
1655 def test__accepts_root_device_param(self):
1656 # Regression test for LP:1825241
1657 node = factory.make_Node(with_boot_disk=False)
1658 node.boot_disk = factory.make_PhysicalBlockDevice(
1659 node=node, size=LARGE_BLOCK_DEVICE)
1660 root_disk = factory.make_PhysicalBlockDevice(
1661 node=node, size=LARGE_BLOCK_DEVICE)
1662 layout = VMFS6Layout(node, {'root_device': root_disk.id})
1663 self.assertEqual('VMFS6', layout.configure())
1664 pt = root_disk.get_partitiontable()
1665 self.assertDictEqual({
1666 '%s-part1' % root_disk.name: 3 * 1024 ** 2,
1667 '%s-part2' % root_disk.name: 4 * 1024 ** 3,
1668 '%s-part3' % root_disk.name: (
1669 root_disk.size - 3 * 1024 ** 2 - 4 * 1024 ** 3 -
1670 249 * 1024 ** 2 - 249 * 1024 ** 2 - 109 * 1024 ** 2 -
1671 285 * 1024 ** 2 - 2560 * 1024 ** 2 - 5 * 1024 ** 2),
1672 '%s-part4' % root_disk.name: 249 * 1024 ** 2,
1673 '%s-part5' % root_disk.name: 249 * 1024 ** 2,
1674 '%s-part6' % root_disk.name: 109 * 1024 ** 2,
1675 '%s-part7' % root_disk.name: 285 * 1024 ** 2,
1676 '%s-part8' % root_disk.name: 2560 * 1024 ** 2,
1677 }, {part.name: part.size for part in pt.partitions.all()})
1678
1679 def test__accepts_root_size_param(self):
1680 node = factory.make_Node(with_boot_disk=False)
1681 node.boot_disk = factory.make_PhysicalBlockDevice(
1682 node=node, size=LARGE_BLOCK_DEVICE)
1683 layout = VMFS6Layout(node, {'root_size': 10 * 1024 ** 3})
1684 self.assertEqual('VMFS6', layout.configure())
1685 pt = node.boot_disk.get_partitiontable()
1686 self.assertDictEqual({
1687 '%s-part1' % node.boot_disk.name: 3 * 1024 ** 2,
1688 '%s-part2' % node.boot_disk.name: 4 * 1024 ** 3,
1689 '%s-part3' % node.boot_disk.name: 10 * 1024 ** 3,
1690 '%s-part4' % node.boot_disk.name: 249 * 1024 ** 2,
1691 '%s-part5' % node.boot_disk.name: 249 * 1024 ** 2,
1692 '%s-part6' % node.boot_disk.name: 109 * 1024 ** 2,
1693 '%s-part7' % node.boot_disk.name: 285 * 1024 ** 2,
1694 '%s-part8' % node.boot_disk.name: 2560 * 1024 ** 2,
1695 }, {part.name: part.size for part in pt.partitions.all()})
1696
16551697
1656class TestBlankStorageLayout(MAASServerTestCase):1698class TestBlankStorageLayout(MAASServerTestCase):
16571699

Subscribers

People subscribed via source and target branches