Merge ~ack/maas:1947013-raid0-size into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 8313041175be29f18f69e92e3a05d63fff0ced1b
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1947013-raid0-size
Merge into: maas:master
Diff against target: 116 lines (+14/-22)
4 files modified
src/maasserver/api/tests/test_raid.py (+3/-7)
src/maasserver/models/filesystemgroup.py (+4/-7)
src/maasserver/models/tests/test_filesystemgroup.py (+3/-6)
src/maasserver/models/tests/test_virtualblockdevice.py (+4/-2)
Reviewer Review Type Date Requested Status
Björn Tillenius Approve
MAAS Lander Approve
Review via email: mp+410355@code.launchpad.net

Commit message

LP:1947013 fix size for raid0 with unequal devices

Linux raid0 allows to use all space on each device, so the total size is
effectively the sum of device size (minus partition overhead)

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 1947013-raid0-size lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/11313/console
COMMIT: 8626844fa97413c635c2597c195163435abc6198

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 1947013-raid0-size lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 8313041175be29f18f69e92e3a05d63fff0ced1b

review: Approve
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/tests/test_raid.py b/src/maasserver/api/tests/test_raid.py
2index 832d9f5..23629e9 100644
3--- a/src/maasserver/api/tests/test_raid.py
4+++ b/src/maasserver/api/tests/test_raid.py
5@@ -1,9 +1,6 @@
6 # Copyright 2015-2016 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9-"""Tests for raid API."""
10-
11-
12 import http.client
13 import json
14 import uuid
15@@ -15,7 +12,7 @@ from testtools.matchers import ContainsDict, Equals
16 from maasserver.enum import FILESYSTEM_GROUP_TYPE, FILESYSTEM_TYPE, NODE_STATUS
17 from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE
18 from maasserver.models.filesystem import Filesystem
19-from maasserver.models.filesystemgroup import RAID_SUPERBLOCK_OVERHEAD
20+from maasserver.models.filesystemgroup import RAID, RAID_SUPERBLOCK_OVERHEAD
21 from maasserver.models.partition import MIN_PARTITION_SIZE
22 from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE
23 from maasserver.testing.api import APITestCase
24@@ -227,9 +224,8 @@ class TestRaidsAPI(APITestCase.ForUser):
25 parsed_block_device_spares,
26 parsed_partition_spares,
27 ) = get_devices_from_raid(parsed_device)
28- self.assertEqual(
29- (10 * PART_SIZE) - RAID_SUPERBLOCK_OVERHEAD, parsed_device["size"]
30- )
31+ raid = RAID.objects.get(id=parsed_device["id"])
32+ self.assertEqual(parsed_device["size"], raid.get_size())
33 self.assertEqual(uuid4, parsed_device["uuid"])
34 self.assertCountEqual(block_devices, parsed_block_devices)
35 self.assertCountEqual(partitions, parsed_partitions)
36diff --git a/src/maasserver/models/filesystemgroup.py b/src/maasserver/models/filesystemgroup.py
37index ed40c01..42e8ada 100644
38--- a/src/maasserver/models/filesystemgroup.py
39+++ b/src/maasserver/models/filesystemgroup.py
40@@ -458,10 +458,7 @@ class FilesystemGroup(CleanSave, TimestampedModel):
41
42 def get_total_size(self):
43 """Return the size of all filesystems combined."""
44- total = 0
45- for fs in self.filesystems.all():
46- total += fs.get_size()
47- return total
48+ return sum(fs.get_size() for fs in self.filesystems.all())
49
50 def get_raid_size(self):
51 """Size of this RAID.
52@@ -479,9 +476,9 @@ class FilesystemGroup(CleanSave, TimestampedModel):
53 # Possible when no filesytems are attached to this group.
54 return 0
55 elif self.group_type == FILESYSTEM_GROUP_TYPE.RAID_0:
56- return (
57- min_size * self.filesystems.count()
58- ) - RAID_SUPERBLOCK_OVERHEAD
59+ return self.get_total_size() - (
60+ RAID_SUPERBLOCK_OVERHEAD * self.filesystems.count()
61+ )
62 elif self.group_type == FILESYSTEM_GROUP_TYPE.RAID_1:
63 return min_size - RAID_SUPERBLOCK_OVERHEAD
64 else:
65diff --git a/src/maasserver/models/tests/test_filesystemgroup.py b/src/maasserver/models/tests/test_filesystemgroup.py
66index e1742bd..78b0e98 100644
67--- a/src/maasserver/models/tests/test_filesystemgroup.py
68+++ b/src/maasserver/models/tests/test_filesystemgroup.py
69@@ -1,8 +1,6 @@
70 # Copyright 2015-2019 Canonical Ltd. This software is licensed under the
71 # GNU Affero General Public License version 3 (see the file LICENSE).
72
73-"""Tests for `FilesystemGroup`."""
74-
75
76 import random
77 import re
78@@ -783,7 +781,7 @@ class TestFilesystemGroup(MAASServerTestCase):
79 fsgroup = FilesystemGroup(group_type=FILESYSTEM_GROUP_TYPE.RAID_0)
80 self.assertEqual(0, fsgroup.get_size())
81
82- def test_get_size_returns_smallest_disk_size_for_raid_0(self):
83+ def test_get_size_returns_sum_of_disk_size_for_raid_0(self):
84 node = factory.make_Node()
85 small_size = random.randint(
86 MIN_BLOCK_DEVICE_SIZE, MIN_BLOCK_DEVICE_SIZE ** 2
87@@ -806,10 +804,9 @@ class TestFilesystemGroup(MAASServerTestCase):
88 fsgroup = factory.make_FilesystemGroup(
89 group_type=FILESYSTEM_GROUP_TYPE.RAID_0, filesystems=filesystems
90 )
91- # Size should be twice the smallest device (the rest of the larger
92- # device remains unused.
93 self.assertEqual(
94- (small_size * 2) - RAID_SUPERBLOCK_OVERHEAD, fsgroup.get_size()
95+ fsgroup.get_size(),
96+ (small_size + large_size) - RAID_SUPERBLOCK_OVERHEAD * 2,
97 )
98
99 def test_get_size_returns_smallest_disk_size_for_raid_1(self):
100diff --git a/src/maasserver/models/tests/test_virtualblockdevice.py b/src/maasserver/models/tests/test_virtualblockdevice.py
101index 6775581..ecbed05 100644
102--- a/src/maasserver/models/tests/test_virtualblockdevice.py
103+++ b/src/maasserver/models/tests/test_virtualblockdevice.py
104@@ -90,9 +90,11 @@ class TestVirtualBlockDeviceManager(MAASServerTestCase):
105 # The new size of the RAID-0 array should be the size of the smallest
106 # filesystem (in this case, they are all the same) times the number of
107 # filesystems in it.
108- array_size = new_size * filesystem_group.filesystems.count()
109+ array_size = (
110+ new_size - RAID_SUPERBLOCK_OVERHEAD
111+ ) * filesystem_group.filesystems.count()
112 self.assertEqual(
113- array_size - RAID_SUPERBLOCK_OVERHEAD,
114+ array_size,
115 reload_object(filesystem_group.virtual_device).size,
116 )
117

Subscribers

People subscribed via source and target branches