diff options
author | Eduardo Otubo <otubo@redhat.com> | 2020-08-18 23:12:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-18 15:12:02 -0600 |
commit | b749548a9eb43b34cce64f8688107645411abc8c (patch) | |
tree | 9e8d5c68d9c027f4d6008cd3c755cafda913887b /tests/unittests/test_util.py | |
parent | a4b6b96f30bdd994ab535b222cf4b4bf09f20668 (diff) | |
download | vyos-cloud-init-b749548a9eb43b34cce64f8688107645411abc8c.tar.gz vyos-cloud-init-b749548a9eb43b34cce64f8688107645411abc8c.zip |
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
Diffstat (limited to 'tests/unittests/test_util.py')
-rw-r--r-- | tests/unittests/test_util.py | 16 |
1 files changed, 16 insertions, 0 deletions
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): |