filesystem: ask curtin about swapfiles

Curtin and Subiquity both have swap file decision logic, let curtin be
the source of truth.  We can tweak the desired behavior in curtin.
This commit is contained in:
Dan Bungert 2023-06-13 15:32:44 -06:00
parent 3b0742e5fe
commit 0afda56696
2 changed files with 12 additions and 6 deletions

View File

@ -32,6 +32,7 @@ import more_itertools
from curtin import storage_config
from curtin.block import partition_kname
from curtin.swap import can_use_swapfile
from curtin.util import human2bytes
from probert.storage import StorageInfo
@ -1814,8 +1815,9 @@ class FilesystemModel(object):
def should_add_swapfile(self):
mount = self._mount_for_path('/')
if mount is not None and mount.device.fstype == 'btrfs':
return False
if mount is not None:
if not can_use_swapfile('/', mount.device.fstype):
return False
for swap in self._all(type='format', fstype='swap'):
if swap.mount():
return False

View File

@ -1237,14 +1237,18 @@ class TestSwap(unittest.TestCase):
self.assertTrue(m.should_add_swapfile())
@parameterized.expand([
['ext4', True],
['btrfs', False],
['ext4', None, True],
['btrfs', 5, True],
['btrfs', 4, False],
['zfs', None, False],
])
def test_should_add_swapfile(self, fs, expected):
def test_should_add_swapfile(self, fs, kern_maj_ver, expected):
m, d1 = make_model_and_disk(Bootloader.BIOS)
d1p1 = make_partition(m, d1)
m.add_mount(m.add_filesystem(d1p1, fs), '/')
self.assertEqual(expected, m.should_add_swapfile())
with mock.patch('curtin.swap.get_target_kernel_version',
return_value={'major': kern_maj_ver}):
self.assertEqual(expected, m.should_add_swapfile())
def test_should_add_swapfile_has_swappart(self):
m, d1 = make_model_and_disk(Bootloader.BIOS)