Merge lp:~ltrager/maas/lp1519397 into lp:maas/trunk

Proposed by Lee Trager on 2015-11-25
Status: Merged
Approved by: Lee Trager on 2015-11-25
Approved revision: 4519
Merged at revision: 4520
Proposed branch: lp:~ltrager/maas/lp1519397
Merge into: lp:maas/trunk
Diff against target: 48 lines (+23/-0)
2 files modified
src/maasserver/models/tests/test_virtualblockdevice.py (+17/-0)
src/maasserver/models/virtualblockdevice.py (+6/-0)
To merge this branch: bzr merge lp:~ltrager/maas/lp1519397
Reviewer Review Type Date Requested Status
Blake Rouse 2015-11-25 Approve on 2015-11-25
Review via email: mp+278537@code.launchpad.net

Commit message

Don't check empty cache_set filesystem_groups when finding parent devices

To post a comment you must log in.
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve
lp:~ltrager/maas/lp1519397 updated on 2015-11-25
4519. By Lee Trager on 2015-11-25

Don't use sort

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/tests/test_virtualblockdevice.py'
2--- src/maasserver/models/tests/test_virtualblockdevice.py 2015-11-17 00:35:12 +0000
3+++ src/maasserver/models/tests/test_virtualblockdevice.py 2015-11-25 04:24:02 +0000
4@@ -20,6 +20,7 @@
5
6 from django.core.exceptions import ValidationError
7 from maasserver.enum import FILESYSTEM_GROUP_TYPE
8+from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE
9 from maasserver.models.virtualblockdevice import VirtualBlockDevice
10 from maasserver.testing.factory import factory
11 from maasserver.testing.orm import reload_object
12@@ -173,3 +174,19 @@
13 virtualblockdevice = node.virtualblockdevice_set.first()
14 self.assertEqual(
15 len(fs_group_disks), len(virtualblockdevice.get_parents()))
16+
17+ def test_get_parents_handles_cache_set(self):
18+ # Regression test for lp1519397
19+ node = factory.make_Node(with_boot_disk=False)
20+ volume_group = factory.make_VolumeGroup(node=node)
21+ name = factory.make_name()
22+ vguuid = "%s" % uuid4()
23+ size = random.randint(MIN_BLOCK_DEVICE_SIZE, volume_group.get_size())
24+ logical_volume = volume_group.create_logical_volume(
25+ name=name, uuid=vguuid, size=size)
26+ logical_volume = reload_object(logical_volume)
27+ sdb = factory.make_PhysicalBlockDevice(node=node)
28+ factory.make_CacheSet(block_device=sdb, node=node)
29+ self.assertItemsEqual(
30+ [fs.block_device_id for fs in volume_group.filesystems.all()],
31+ [parent.id for parent in logical_volume.get_parents()])
32
33=== modified file 'src/maasserver/models/virtualblockdevice.py'
34--- src/maasserver/models/virtualblockdevice.py 2015-11-17 23:03:36 +0000
35+++ src/maasserver/models/virtualblockdevice.py 2015-11-25 04:24:02 +0000
36@@ -149,6 +149,12 @@
37 elif fs.cache_set is not None:
38 # A block device/partition can only have one cache_set
39 fs_group = fs.cache_set.filesystemgroup_set.first()
40+ # bcache devices only show up in cache_set.filesystemgroup_set,
41+ # not in fs.filesystem_group. However if only a cache_set has
42+ # been created and not a bcache device
43+ # cache_set.filesystemgroup_set will be empty.
44+ if fs_group is None:
45+ return False
46 else:
47 return False
48 for virtual_device in fs_group.virtual_devices.all():