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 import storage_config
|
||||||
from curtin.block import partition_kname
|
from curtin.block import partition_kname
|
||||||
|
from curtin.swap import can_use_swapfile
|
||||||
from curtin.util import human2bytes
|
from curtin.util import human2bytes
|
||||||
|
|
||||||
from probert.storage import StorageInfo
|
from probert.storage import StorageInfo
|
||||||
|
@ -1814,8 +1815,9 @@ class FilesystemModel(object):
|
||||||
|
|
||||||
def should_add_swapfile(self):
|
def should_add_swapfile(self):
|
||||||
mount = self._mount_for_path('/')
|
mount = self._mount_for_path('/')
|
||||||
if mount is not None and mount.device.fstype == 'btrfs':
|
if mount is not None:
|
||||||
return False
|
if not can_use_swapfile('/', mount.device.fstype):
|
||||||
|
return False
|
||||||
for swap in self._all(type='format', fstype='swap'):
|
for swap in self._all(type='format', fstype='swap'):
|
||||||
if swap.mount():
|
if swap.mount():
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1237,14 +1237,18 @@ class TestSwap(unittest.TestCase):
|
||||||
self.assertTrue(m.should_add_swapfile())
|
self.assertTrue(m.should_add_swapfile())
|
||||||
|
|
||||||
@parameterized.expand([
|
@parameterized.expand([
|
||||||
['ext4', True],
|
['ext4', None, True],
|
||||||
['btrfs', False],
|
['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)
|
m, d1 = make_model_and_disk(Bootloader.BIOS)
|
||||||
d1p1 = make_partition(m, d1)
|
d1p1 = make_partition(m, d1)
|
||||||
m.add_mount(m.add_filesystem(d1p1, fs), '/')
|
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):
|
def test_should_add_swapfile_has_swappart(self):
|
||||||
m, d1 = make_model_and_disk(Bootloader.BIOS)
|
m, d1 = make_model_and_disk(Bootloader.BIOS)
|
||||||
|
|
Loading…
Reference in New Issue