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
diff --git a/src/maasserver/api/tests/test_raid.py b/src/maasserver/api/tests/test_raid.py
index 832d9f5..23629e9 100644
--- a/src/maasserver/api/tests/test_raid.py
+++ b/src/maasserver/api/tests/test_raid.py
@@ -1,9 +1,6 @@
1# Copyright 2015-2016 Canonical Ltd. This software is licensed under the1# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Tests for raid API."""
5
6
7import http.client4import http.client
8import json5import json
9import uuid6import uuid
@@ -15,7 +12,7 @@ from testtools.matchers import ContainsDict, Equals
15from maasserver.enum import FILESYSTEM_GROUP_TYPE, FILESYSTEM_TYPE, NODE_STATUS12from maasserver.enum import FILESYSTEM_GROUP_TYPE, FILESYSTEM_TYPE, NODE_STATUS
16from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE13from maasserver.models.blockdevice import MIN_BLOCK_DEVICE_SIZE
17from maasserver.models.filesystem import Filesystem14from maasserver.models.filesystem import Filesystem
18from maasserver.models.filesystemgroup import RAID_SUPERBLOCK_OVERHEAD15from maasserver.models.filesystemgroup import RAID, RAID_SUPERBLOCK_OVERHEAD
19from maasserver.models.partition import MIN_PARTITION_SIZE16from maasserver.models.partition import MIN_PARTITION_SIZE
20from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE17from maasserver.models.partitiontable import PARTITION_TABLE_EXTRA_SPACE
21from maasserver.testing.api import APITestCase18from maasserver.testing.api import APITestCase
@@ -227,9 +224,8 @@ class TestRaidsAPI(APITestCase.ForUser):
227 parsed_block_device_spares,224 parsed_block_device_spares,
228 parsed_partition_spares,225 parsed_partition_spares,
229 ) = get_devices_from_raid(parsed_device)226 ) = get_devices_from_raid(parsed_device)
230 self.assertEqual(227 raid = RAID.objects.get(id=parsed_device["id"])
231 (10 * PART_SIZE) - RAID_SUPERBLOCK_OVERHEAD, parsed_device["size"]228 self.assertEqual(parsed_device["size"], raid.get_size())
232 )
233 self.assertEqual(uuid4, parsed_device["uuid"])229 self.assertEqual(uuid4, parsed_device["uuid"])
234 self.assertCountEqual(block_devices, parsed_block_devices)230 self.assertCountEqual(block_devices, parsed_block_devices)
235 self.assertCountEqual(partitions, parsed_partitions)231 self.assertCountEqual(partitions, parsed_partitions)
diff --git a/src/maasserver/models/filesystemgroup.py b/src/maasserver/models/filesystemgroup.py
index ed40c01..42e8ada 100644
--- a/src/maasserver/models/filesystemgroup.py
+++ b/src/maasserver/models/filesystemgroup.py
@@ -458,10 +458,7 @@ class FilesystemGroup(CleanSave, TimestampedModel):
458458
459 def get_total_size(self):459 def get_total_size(self):
460 """Return the size of all filesystems combined."""460 """Return the size of all filesystems combined."""
461 total = 0461 return sum(fs.get_size() for fs in self.filesystems.all())
462 for fs in self.filesystems.all():
463 total += fs.get_size()
464 return total
465462
466 def get_raid_size(self):463 def get_raid_size(self):
467 """Size of this RAID.464 """Size of this RAID.
@@ -479,9 +476,9 @@ class FilesystemGroup(CleanSave, TimestampedModel):
479 # Possible when no filesytems are attached to this group.476 # Possible when no filesytems are attached to this group.
480 return 0477 return 0
481 elif self.group_type == FILESYSTEM_GROUP_TYPE.RAID_0:478 elif self.group_type == FILESYSTEM_GROUP_TYPE.RAID_0:
482 return (479 return self.get_total_size() - (
483 min_size * self.filesystems.count()480 RAID_SUPERBLOCK_OVERHEAD * self.filesystems.count()
484 ) - RAID_SUPERBLOCK_OVERHEAD481 )
485 elif self.group_type == FILESYSTEM_GROUP_TYPE.RAID_1:482 elif self.group_type == FILESYSTEM_GROUP_TYPE.RAID_1:
486 return min_size - RAID_SUPERBLOCK_OVERHEAD483 return min_size - RAID_SUPERBLOCK_OVERHEAD
487 else:484 else:
diff --git a/src/maasserver/models/tests/test_filesystemgroup.py b/src/maasserver/models/tests/test_filesystemgroup.py
index e1742bd..78b0e98 100644
--- a/src/maasserver/models/tests/test_filesystemgroup.py
+++ b/src/maasserver/models/tests/test_filesystemgroup.py
@@ -1,8 +1,6 @@
1# Copyright 2015-2019 Canonical Ltd. This software is licensed under the1# Copyright 2015-2019 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Tests for `FilesystemGroup`."""
5
64
7import random5import random
8import re6import re
@@ -783,7 +781,7 @@ class TestFilesystemGroup(MAASServerTestCase):
783 fsgroup = FilesystemGroup(group_type=FILESYSTEM_GROUP_TYPE.RAID_0)781 fsgroup = FilesystemGroup(group_type=FILESYSTEM_GROUP_TYPE.RAID_0)
784 self.assertEqual(0, fsgroup.get_size())782 self.assertEqual(0, fsgroup.get_size())
785783
786 def test_get_size_returns_smallest_disk_size_for_raid_0(self):784 def test_get_size_returns_sum_of_disk_size_for_raid_0(self):
787 node = factory.make_Node()785 node = factory.make_Node()
788 small_size = random.randint(786 small_size = random.randint(
789 MIN_BLOCK_DEVICE_SIZE, MIN_BLOCK_DEVICE_SIZE ** 2787 MIN_BLOCK_DEVICE_SIZE, MIN_BLOCK_DEVICE_SIZE ** 2
@@ -806,10 +804,9 @@ class TestFilesystemGroup(MAASServerTestCase):
806 fsgroup = factory.make_FilesystemGroup(804 fsgroup = factory.make_FilesystemGroup(
807 group_type=FILESYSTEM_GROUP_TYPE.RAID_0, filesystems=filesystems805 group_type=FILESYSTEM_GROUP_TYPE.RAID_0, filesystems=filesystems
808 )806 )
809 # Size should be twice the smallest device (the rest of the larger
810 # device remains unused.
811 self.assertEqual(807 self.assertEqual(
812 (small_size * 2) - RAID_SUPERBLOCK_OVERHEAD, fsgroup.get_size()808 fsgroup.get_size(),
809 (small_size + large_size) - RAID_SUPERBLOCK_OVERHEAD * 2,
813 )810 )
814811
815 def test_get_size_returns_smallest_disk_size_for_raid_1(self):812 def test_get_size_returns_smallest_disk_size_for_raid_1(self):
diff --git a/src/maasserver/models/tests/test_virtualblockdevice.py b/src/maasserver/models/tests/test_virtualblockdevice.py
index 6775581..ecbed05 100644
--- a/src/maasserver/models/tests/test_virtualblockdevice.py
+++ b/src/maasserver/models/tests/test_virtualblockdevice.py
@@ -90,9 +90,11 @@ class TestVirtualBlockDeviceManager(MAASServerTestCase):
90 # The new size of the RAID-0 array should be the size of the smallest90 # The new size of the RAID-0 array should be the size of the smallest
91 # filesystem (in this case, they are all the same) times the number of91 # filesystem (in this case, they are all the same) times the number of
92 # filesystems in it.92 # filesystems in it.
93 array_size = new_size * filesystem_group.filesystems.count()93 array_size = (
94 new_size - RAID_SUPERBLOCK_OVERHEAD
95 ) * filesystem_group.filesystems.count()
94 self.assertEqual(96 self.assertEqual(
95 array_size - RAID_SUPERBLOCK_OVERHEAD,97 array_size,
96 reload_object(filesystem_group.virtual_device).size,98 reload_object(filesystem_group.virtual_device).size,
97 )99 )
98100

Subscribers

People subscribed via source and target branches