diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index 0d9220dc..71cc5ee6 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -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 diff --git a/subiquity/models/tests/test_filesystem.py b/subiquity/models/tests/test_filesystem.py index 3a990a05..7c563d55 100644 --- a/subiquity/models/tests/test_filesystem.py +++ b/subiquity/models/tests/test_filesystem.py @@ -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)