Skip to content

Commit

Permalink
Merge pull request #2092 from ogayot/target-reformat-not-in-list
Browse files Browse the repository at this point in the history
storage: when handling a partition, ignore any FS at the disk level
  • Loading branch information
ogayot authored Sep 25, 2024
2 parents 79d8fc5 + 8c5f293 commit a57ed5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
10 changes: 5 additions & 5 deletions subiquity/common/filesystem/gaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def within(self):


@functools.singledispatch
def parts_and_gaps(device):
def parts_and_gaps(device, ignore_disk_fs=False):
raise NotImplementedError(device)


Expand Down Expand Up @@ -191,8 +191,8 @@ def maybe_add_gap(start, end, in_extended):

@parts_and_gaps.register(Disk)
@parts_and_gaps.register(Raid)
def parts_and_gaps_disk(device):
if device._fs is not None:
def parts_and_gaps_disk(device, ignore_disk_fs=False):
if device._fs is not None and not ignore_disk_fs:
return []
if device._m.storage_version == 1:
return find_disk_gaps_v1(device)
Expand All @@ -201,7 +201,7 @@ def parts_and_gaps_disk(device):


@parts_and_gaps.register(LVM_VolGroup)
def _parts_and_gaps_vg(device):
def _parts_and_gaps_vg(device, ignore_disk_fs=False):
used = 0
r = []
for lv in device._partitions:
Expand Down Expand Up @@ -277,7 +277,7 @@ def movable_trailing_partitions_and_gap_size(partition):
def _movable_trailing_partitions_and_gap_size_partition(
partition: Partition,
) -> Tuple[List[Partition], int]:
pgs = parts_and_gaps(partition.device)
pgs = parts_and_gaps(partition.device, ignore_disk_fs=True)
part_idx = pgs.index(partition)
trailing_partitions = []
in_extended = partition.is_logical
Expand Down
28 changes: 26 additions & 2 deletions subiquity/common/filesystem/tests/test_gaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import unittest
from functools import partial
from unittest import mock

from subiquity.common.filesystem import gaps
Expand Down Expand Up @@ -44,7 +43,11 @@ def use_alignment_data(self, alignment_data):
m = mock.patch("subiquity.common.filesystem.gaps.parts_and_gaps")
p = m.start()
self.addCleanup(m.stop)
p.side_effect = partial(gaps.find_disk_gaps_v2, info=alignment_data)

def fake_parts_and_gaps(device, ignore_disk_fs=False):
return gaps.find_disk_gaps_v2(device)

p.side_effect = fake_parts_and_gaps

for cls in Disk, Raid:
md = mock.patch.object(cls, "alignment_data")
Expand All @@ -59,6 +62,27 @@ def test_basic(self):
self.assertTrue(isinstance(gap, gaps.Gap))
self.assertEqual(MiB, gap.offset)

def test_disk_with_filesystem(self):
disk = make_disk()
disk._fs = mock.Mock()

self.assertFalse(gaps.parts_and_gaps(disk))
[gap] = gaps.parts_and_gaps(disk, ignore_disk_fs=True)
self.assertTrue(isinstance(gap, gaps.Gap))
self.assertEqual(MiB, gap.offset)

def test_disk_with_filesystem_and_partitions(self):
model, disk = make_model_and_disk()
make_partition(model, disk, size=20 * MiB)

disk._fs = mock.Mock()

self.assertFalse(gaps.parts_and_gaps(disk))
[part, gap] = gaps.parts_and_gaps(disk, ignore_disk_fs=True)
self.assertTrue(isinstance(part, gaps.Partition))
self.assertTrue(isinstance(gap, gaps.Gap))
self.assertEqual(MiB + 20 * MiB, gap.offset)


class TestSplitGap(GapTestCase):
def test_equal(self):
Expand Down

0 comments on commit a57ed5a

Please sign in to comment.