From b749548a9eb43b34cce64f8688107645411abc8c Mon Sep 17 00:00:00 2001 From: Eduardo Otubo Date: Tue, 18 Aug 2020 23:12:02 +0200 Subject: Detect kernel version before swap file creation (#428) According to man page `man 8 swapon', "Preallocated swap files are supported on XFS since Linux 4.18". This patch checks for kernel version before attepting to create swapfile, using dd for XFS only on kernel versions <= 4.18 or btrfs. Add new func util.kernel_version which returns a tuple of ints (major, minor) Signed-off-by: Eduardo Otubo otubo@redhat.com --- tests/unittests/test_util.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/unittests/test_util.py') diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index aa5352e9..fc557469 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -968,6 +968,22 @@ class TestGetProcEnv(helpers.TestCase): self.assertEqual(my_ppid, util.get_proc_ppid(my_pid)) +class TestKernelVersion(): + """test kernel version function""" + + params = [ + ('5.6.19-300.fc32.x86_64', (5, 6)), + ('4.15.0-101-generic', (4, 15)), + ('3.10.0-1062.12.1.vz7.131.10', (3, 10)), + ('4.18.0-144.el8.x86_64', (4, 18))] + + @mock.patch('os.uname') + @pytest.mark.parametrize("uname_release,expected", params) + def test_kernel_version(self, m_uname, uname_release, expected): + m_uname.return_value.release = uname_release + assert expected == util.kernel_version() + + class TestFindDevs: @mock.patch('cloudinit.subp.subp') def test_find_devs_with(self, m_subp): -- cgit v1.2.3