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:
parent
3b0742e5fe
commit
0afda56696
|
@ -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,7 +1815,8 @@ class FilesystemModel(object):
|
|||
|
||||
def should_add_swapfile(self):
|
||||
mount = self._mount_for_path('/')
|
||||
if mount is not None and mount.device.fstype == 'btrfs':
|
||||
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():
|
||||
|
|
|
@ -1237,13 +1237,17 @@ 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), '/')
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue