Merge lp:~blake-rouse/maas/fix-1510121-and-1510109 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 4414
Proposed branch: lp:~blake-rouse/maas/fix-1510121-and-1510109
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 47 lines (+13/-4)
2 files modified
src/maasserver/models/partitiontable.py (+6/-1)
src/maasserver/models/tests/test_partitiontable.py (+7/-3)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1510121-and-1510109
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Andres Rodriguez (community) Approve
Review via email: mp+275752@code.launchpad.net

Commit message

Make sure the block_device and boot_disk are compared by id.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

You need to figure out a test that breaks with the old code.

review: Needs Fixing
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve
Revision history for this message
Blake Rouse (blake-rouse) wrote :

I added the needed test.

Revision history for this message
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/partitiontable.py'
2--- src/maasserver/models/partitiontable.py 2015-10-19 17:56:35 +0000
3+++ src/maasserver/models/partitiontable.py 2015-10-26 21:09:25 +0000
4@@ -132,7 +132,12 @@
5 self.block_device.node is not None):
6 node = self.block_device.node
7 boot_disk = node.get_boot_disk()
8- if boot_disk is not None and self.block_device == boot_disk:
9+ # Compare the block_device.id and boot_disk.id because it is
10+ # possible they are not the same type. One being an instance
11+ # of PhysicalBlockDevice and the other being just a BlockDevice.
12+ # Without this comparison the wrong partition table type will be
13+ # placed on the boot disk.
14+ if boot_disk is not None and self.block_device.id == boot_disk.id:
15 bios_boot_method = node.get_bios_boot_method()
16 if bios_boot_method == "uefi":
17 # UEFI must always use a GPT table.
18
19=== modified file 'src/maasserver/models/tests/test_partitiontable.py'
20--- src/maasserver/models/tests/test_partitiontable.py 2015-10-11 06:12:21 +0000
21+++ src/maasserver/models/tests/test_partitiontable.py 2015-10-26 21:09:25 +0000
22@@ -16,7 +16,10 @@
23
24 from django.core.exceptions import ValidationError
25 from maasserver.enum import PARTITION_TABLE_TYPE
26-from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE
27+from maasserver.models.blockdevice import (
28+ BlockDevice,
29+ MIN_BLOCK_DEVICE_SIZE,
30+)
31 from maasserver.models.partition import MAX_PARTITION_SIZE_FOR_MBR
32 from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE
33 from maasserver.testing.factory import factory
34@@ -134,10 +137,11 @@
35 partition_table.get_available_size(
36 ignore_partitions=ignore_partitions))
37
38- def test_save_sets_table_type_to_mbr_for_pxe_boot(self):
39+ def test_save_sets_table_type_to_mbr_for_boot_when_type_miss_match(self):
40 node = factory.make_Node(bios_boot_method="pxe")
41 boot_disk = factory.make_PhysicalBlockDevice(node=node)
42- partition_table = factory.make_PartitionTable(block_device=boot_disk)
43+ partition_table = factory.make_PartitionTable(
44+ block_device=BlockDevice.objects.get(id=boot_disk.id))
45 self.assertEquals(PARTITION_TABLE_TYPE.MBR, partition_table.table_type)
46
47 def test_save_sets_table_type_to_gpt_for_uefi_boot(self):