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
1diff --git a/src/maasserver/storage_layouts.py b/src/maasserver/storage_layouts.py
2index 2bb5b34..dcf4c34 100644
3--- a/src/maasserver/storage_layouts.py
4+++ b/src/maasserver/storage_layouts.py
5@@ -138,13 +138,15 @@ class StorageLayoutBase(Form):
6 def get_root_device(self):
7 """Get the device that should be the root partition.
8
9- Return of None means to use the boot disk.
10+ Return the boot_disk if no root_device was defined.
11 """
12 if self.cleaned_data.get('root_device'):
13 root_id = self.cleaned_data['root_device']
14 return self.node.physicalblockdevice_set.get(id=root_id)
15 else:
16- return None
17+ # User didn't specify a root disk so use the currently defined
18+ # boot disk.
19+ return self.boot_disk
20
21 def get_boot_size(self):
22 """Get the size of the boot partition."""
23@@ -209,7 +211,7 @@ class StorageLayoutBase(Form):
24 mount_point="/boot")
25 root_device = self.get_root_device()
26 root_size = self.get_root_size()
27- if root_device is None or root_device == self.boot_disk:
28+ if root_device == self.boot_disk:
29 partition_table = boot_partition_table
30 root_device = self.boot_disk
31 else:
32@@ -566,7 +568,7 @@ class VMFS6Layout(StorageLayoutBase):
33 from maasserver.models.partitiontable import PartitionTable
34
35 boot_partition_table = PartitionTable.objects.create(
36- block_device=self.boot_disk,
37+ block_device=self.get_root_device(),
38 table_type=PARTITION_TABLE_TYPE.GPT)
39 now = datetime.now()
40 new_part = partial(
41@@ -598,7 +600,11 @@ class VMFS6Layout(StorageLayoutBase):
42 new_part(size=2560 * 1024 ** 2),
43 ])
44 vmfs_part = boot_partition_table.partitions.get(size=0)
45- vmfs_part.size = boot_partition_table.get_available_size()
46+ root_size = self.get_root_size()
47+ if root_size is not None:
48+ vmfs_part.size = root_size
49+ else:
50+ vmfs_part.size = boot_partition_table.get_available_size()
51 vmfs_part.save()
52 # datastore1 is the default name VMware uses.
53 VMFS.objects.create_vmfs(name="datastore1", partitions=[vmfs_part])
54diff --git a/src/maasserver/tests/test_storage_layouts.py b/src/maasserver/tests/test_storage_layouts.py
55index ef2df86..8daa2ee 100644
56--- a/src/maasserver/tests/test_storage_layouts.py
57+++ b/src/maasserver/tests/test_storage_layouts.py
58@@ -391,14 +391,14 @@ class TestStorageLayoutBase(MAASServerTestCase):
59 self.assertTrue(layout.is_valid(), layout.errors)
60 self.assertEqual(boot_size, layout.get_boot_size())
61
62- def test_get_root_device_returns_None_if_not_set(self):
63+ def test_get_root_device_returns_boot_disk_if_not_set(self):
64 node = make_Node_with_uefi_boot_method()
65 factory.make_PhysicalBlockDevice(
66 node=node, size=LARGE_BLOCK_DEVICE)
67 layout = StorageLayoutBase(node, {
68 })
69 self.assertTrue(layout.is_valid(), layout.errors)
70- self.assertIsNone(layout.get_root_device())
71+ self.assertEquals(node.get_boot_disk(), layout.get_root_device())
72
73 def test_get_root_device_returns_root_device_if_set(self):
74 node = make_Node_with_uefi_boot_method()
75@@ -1652,6 +1652,48 @@ class TestVMFS6Layout(MAASServerTestCase):
76 "size": ["Boot disk must be atleast 10G."],
77 }, error.message_dict)
78
79+ def test__accepts_root_device_param(self):
80+ # Regression test for LP:1825241
81+ node = factory.make_Node(with_boot_disk=False)
82+ node.boot_disk = factory.make_PhysicalBlockDevice(
83+ node=node, size=LARGE_BLOCK_DEVICE)
84+ root_disk = factory.make_PhysicalBlockDevice(
85+ node=node, size=LARGE_BLOCK_DEVICE)
86+ layout = VMFS6Layout(node, {'root_device': root_disk.id})
87+ self.assertEqual('VMFS6', layout.configure())
88+ pt = root_disk.get_partitiontable()
89+ self.assertDictEqual({
90+ '%s-part1' % root_disk.name: 3 * 1024 ** 2,
91+ '%s-part2' % root_disk.name: 4 * 1024 ** 3,
92+ '%s-part3' % root_disk.name: (
93+ root_disk.size - 3 * 1024 ** 2 - 4 * 1024 ** 3 -
94+ 249 * 1024 ** 2 - 249 * 1024 ** 2 - 109 * 1024 ** 2 -
95+ 285 * 1024 ** 2 - 2560 * 1024 ** 2 - 5 * 1024 ** 2),
96+ '%s-part4' % root_disk.name: 249 * 1024 ** 2,
97+ '%s-part5' % root_disk.name: 249 * 1024 ** 2,
98+ '%s-part6' % root_disk.name: 109 * 1024 ** 2,
99+ '%s-part7' % root_disk.name: 285 * 1024 ** 2,
100+ '%s-part8' % root_disk.name: 2560 * 1024 ** 2,
101+ }, {part.name: part.size for part in pt.partitions.all()})
102+
103+ def test__accepts_root_size_param(self):
104+ node = factory.make_Node(with_boot_disk=False)
105+ node.boot_disk = factory.make_PhysicalBlockDevice(
106+ node=node, size=LARGE_BLOCK_DEVICE)
107+ layout = VMFS6Layout(node, {'root_size': 10 * 1024 ** 3})
108+ self.assertEqual('VMFS6', layout.configure())
109+ pt = node.boot_disk.get_partitiontable()
110+ self.assertDictEqual({
111+ '%s-part1' % node.boot_disk.name: 3 * 1024 ** 2,
112+ '%s-part2' % node.boot_disk.name: 4 * 1024 ** 3,
113+ '%s-part3' % node.boot_disk.name: 10 * 1024 ** 3,
114+ '%s-part4' % node.boot_disk.name: 249 * 1024 ** 2,
115+ '%s-part5' % node.boot_disk.name: 249 * 1024 ** 2,
116+ '%s-part6' % node.boot_disk.name: 109 * 1024 ** 2,
117+ '%s-part7' % node.boot_disk.name: 285 * 1024 ** 2,
118+ '%s-part8' % node.boot_disk.name: 2560 * 1024 ** 2,
119+ }, {part.name: part.size for part in pt.partitions.all()})
120+
121
122 class TestBlankStorageLayout(MAASServerTestCase):
123

Subscribers

People subscribed via source and target branches