Merge pull request #1698 from dbungert/zfs-swap

zfs: no swapfile
This commit is contained in:
Dan Bungert 2023-07-17 17:19:26 -06:00 committed by GitHub
commit f82067c50e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 5 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
@ -1599,7 +1600,7 @@ class FilesystemModel(object):
}
if self.swap is not None:
config['swap'] = self.swap
elif not self._should_add_swapfile():
elif not self.should_add_swapfile():
config['swap'] = {'size': 0}
if self.grub is not None:
config['grub'] = self.grub
@ -1827,9 +1828,10 @@ class FilesystemModel(object):
return (self.is_root_mounted()
and not self.needs_bootloader_partition())
def _should_add_swapfile(self):
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():

View File

@ -1223,10 +1223,42 @@ class TestAlignmentData(unittest.TestCase):
class TestSwap(unittest.TestCase):
def test_basic(self):
m = make_model()
with mock.patch.object(m, '_should_add_swapfile', return_value=False):
with mock.patch.object(m, 'should_add_swapfile', return_value=False):
cfg = m.render()
self.assertEqual({'size': 0}, cfg['swap'])
@parameterized.expand([
['ext4'],
['btrfs'],
])
def test_should_add_swapfile_nomount(self, fs):
m, d1 = make_model_and_disk(Bootloader.BIOS)
d1p1 = make_partition(m, d1)
m.add_filesystem(d1p1, fs)
self.assertTrue(m.should_add_swapfile())
@parameterized.expand([
['ext4', None, True],
['btrfs', 5, True],
['btrfs', 4, False],
['zfs', None, False],
])
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):
m, d1 = make_model_and_disk(Bootloader.BIOS)
d1p1 = make_partition(m, d1)
d1p2 = make_partition(m, d1)
m.add_mount(m.add_filesystem(d1p1, 'ext4'), '/')
m.add_mount(m.add_filesystem(d1p2, 'swap'), '')
self.assertFalse(m.should_add_swapfile())
class TestPartition(unittest.TestCase):