From 52f1ca52f810169cd7640d5c3310880fb15406c7 Mon Sep 17 00:00:00 2001 From: Eduardo Otubo Date: Mon, 6 Jul 2020 17:48:26 +0200 Subject: [PATCH] Splitting test_swap_creation_method() test into 3 Splitting test_swap_creation_method into 3 different cases for different filesystems. Leaving the methods way of asserting the test with only cc_mounts.handle() function. Like test_swap_integrity() does. Signed-off-by: Eduardo Otubo [0] https://github.com/pytest-dev/pytest/issues/3484 --- .../test_handler/test_handler_mounts.py | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/tests/unittests/test_handler/test_handler_mounts.py b/tests/unittests/test_handler/test_handler_mounts.py index 8ab8558d70e..8b7c264cc0a 100644 --- a/tests/unittests/test_handler/test_handler_mounts.py +++ b/tests/unittests/test_handler/test_handler_mounts.py @@ -7,8 +7,6 @@ from cloudinit.tests import helpers as test_helpers -from cloudinit import util - class TestSanitizeDevname(test_helpers.FilesystemMockingTestCase): @@ -187,8 +185,8 @@ def device_name_to_device(self, path): @mock.patch('cloudinit.util.kernel_version') @mock.patch('cloudinit.util.get_mount_info') - def test_swap_creation_method(self, m_kernel_version, m_get_mount_info): - log = mock.MagicMock() + def test_swap_creation_method_xfs( + self, m_kernel_version, m_get_mount_info): m_kernel_version.return_value = (3, 18) m_get_mount_info.return_value = ["", "xfs"] fstab = '/swap.img swap swap defaults 0 0\n' @@ -198,43 +196,32 @@ def test_swap_creation_method(self, m_kernel_version, m_get_mount_info): cc = {'swap': ['filename: /swap.img', 'size: 512', 'maxsize: 512']} cc_mounts.handle(None, cc, self.mock_cloud, self.mock_log, []) - swap_log = 'Creating swapfile in /swap.img on fstype xfs using dd' - util.multi_log('{0}\n'.format(swap_log), log=log) - self.assertEqual((mock.ANY, swap_log), log.log.call_args[0]) - - m_kernel_version.reset_mock() - m_get_mount_info.reset_mock() - + @mock.patch('cloudinit.util.kernel_version') + @mock.patch('cloudinit.util.get_mount_info') + def test_swap_creation_method_btrfs( + self, m_kernel_version, m_get_mount_info): m_kernel_version.return_value = (4, 20) m_get_mount_info.return_value = ["", "btrfs"] - fstab = '/swap2.img swap swap defaults 0 0\n' + fstab = '/swap.img swap swap defaults 0 0\n' with open(cc_mounts.FSTAB_PATH, 'w') as fd: fd.write(fstab) - cc = {'swap': ['filename: /swap2.img', 'size: 512', 'maxsize: 512']} + cc = {'swap': ['filename: /swap.img', 'size: 512', 'maxsize: 512']} cc_mounts.handle(None, cc, self.mock_cloud, self.mock_log, []) - swap_log = 'Creating swapfile in /swap.img on fstype btrfs using dd' - util.multi_log('{0}\n'.format(swap_log), log=log) - self.assertEqual((mock.ANY, swap_log), log.log.call_args[0]) - - m_kernel_version.reset_mock() - m_get_mount_info.reset_mock() - + @mock.patch('cloudinit.util.kernel_version') + @mock.patch('cloudinit.util.get_mount_info') + def test_swap_creation_method_ext4( + self, m_kernel_version, m_get_mount_info): m_kernel_version.return_value = (4, 20) m_get_mount_info.return_value = ["", "ext4"] - fstab = '/swap3.img swap swap defaults 0 0\n' + fstab = '/swap.img swap swap defaults 0 0\n' with open(cc_mounts.FSTAB_PATH, 'w') as fd: fd.write(fstab) - cc = {'swap': ['filename: /swap3.img', 'size: 512', 'maxsize: 512']} + cc = {'swap': ['filename: /swap.img', 'size: 512', 'maxsize: 512']} cc_mounts.handle(None, cc, self.mock_cloud, self.mock_log, []) - swap_log = 'Creating swapfile in /swap.img on fstype btrfs using' \ - ' fallocate' - util.multi_log('{0}\n'.format(swap_log), log=log) - self.assertEqual((mock.ANY, swap_log), log.log.call_args[0]) - def test_swap_integrity(self): '''Ensure that the swap file is correctly created and can swapon successfully. Fixing the corner case of: