summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_handler/test_handler_resizefs.py58
-rw-r--r--tests/unittests/test_util.py50
2 files changed, 107 insertions, 1 deletions
diff --git a/tests/unittests/test_handler/test_handler_resizefs.py b/tests/unittests/test_handler/test_handler_resizefs.py
index c2a7f9fb..7a7ba1ff 100644
--- a/tests/unittests/test_handler/test_handler_resizefs.py
+++ b/tests/unittests/test_handler/test_handler_resizefs.py
@@ -1,7 +1,8 @@
# This file is part of cloud-init. See LICENSE file for license information.
from cloudinit.config.cc_resizefs import (
- can_skip_resize, handle, maybe_get_writable_device_path, _resize_btrfs)
+ can_skip_resize, handle, maybe_get_writable_device_path, _resize_btrfs,
+ _resize_zfs, _resize_xfs, _resize_ext, _resize_ufs)
from collections import namedtuple
import logging
@@ -60,6 +61,9 @@ class TestResizefs(CiTestCase):
res = can_skip_resize(fs_type, resize_what, devpth)
self.assertTrue(res)
+ def test_can_skip_resize_ext(self):
+ self.assertFalse(can_skip_resize('ext', '/', '/dev/sda1'))
+
def test_handle_noops_on_disabled(self):
"""The handle function logs when the configuration disables resize."""
cfg = {'resize_rootfs': False}
@@ -122,6 +126,51 @@ class TestResizefs(CiTestCase):
logs = self.logs.getvalue()
self.assertIn("WARNING: Unable to find device '/dev/root'", logs)
+ def test_resize_zfs_cmd_return(self):
+ zpool = 'zroot'
+ devpth = 'gpt/system'
+ self.assertEqual(('zpool', 'online', '-e', zpool, devpth),
+ _resize_zfs(zpool, devpth))
+
+ def test_resize_xfs_cmd_return(self):
+ mount_point = '/mnt/test'
+ devpth = '/dev/sda1'
+ self.assertEqual(('xfs_growfs', mount_point),
+ _resize_xfs(mount_point, devpth))
+
+ def test_resize_ext_cmd_return(self):
+ mount_point = '/'
+ devpth = '/dev/sdb1'
+ self.assertEqual(('resize2fs', devpth),
+ _resize_ext(mount_point, devpth))
+
+ def test_resize_ufs_cmd_return(self):
+ mount_point = '/'
+ devpth = '/dev/sda2'
+ self.assertEqual(('growfs', devpth),
+ _resize_ufs(mount_point, devpth))
+
+ @mock.patch('cloudinit.util.get_mount_info')
+ @mock.patch('cloudinit.util.get_device_info_from_zpool')
+ @mock.patch('cloudinit.util.parse_mount')
+ def test_handle_zfs_root(self, mount_info, zpool_info, parse_mount):
+ devpth = 'vmzroot/ROOT/freebsd'
+ disk = 'gpt/system'
+ fs_type = 'zfs'
+ mount_point = '/'
+
+ mount_info.return_value = (devpth, fs_type, mount_point)
+ zpool_info.return_value = disk
+ parse_mount.return_value = (devpth, fs_type, mount_point)
+
+ cfg = {'resize_rootfs': True}
+
+ with mock.patch('cloudinit.config.cc_resizefs.do_resize') as dresize:
+ handle('cc_resizefs', cfg, _cloud=None, log=LOG, args=[])
+ ret = dresize.call_args[0][0]
+
+ self.assertEqual(('zpool', 'online', '-e', 'vmzroot', disk), ret)
+
class TestRootDevFromCmdline(CiTestCase):
@@ -305,5 +354,12 @@ class TestMaybeGetDevicePathAsWritableBlock(CiTestCase):
('btrfs', 'filesystem', 'resize', 'max', '/'),
_resize_btrfs("/", "/dev/sda1"))
+ @mock.patch('cloudinit.util.is_FreeBSD')
+ def test_maybe_get_writable_device_path_zfs_freebsd(self, freebsd):
+ freebsd.return_value = True
+ info = 'dev=gpt/system mnt_point=/ path=/'
+ devpth = maybe_get_writable_device_path('gpt/system', info, LOG)
+ self.assertEqual('gpt/system', devpth)
+
# vi: ts=4 expandtab
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 67d9607d..8685b8e2 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -366,6 +366,56 @@ class TestMountinfoParsing(helpers.ResourceUsingTestCase):
expected = ('none', 'tmpfs', '/run/lock')
self.assertEqual(expected, util.parse_mount_info('/run/lock', lines))
+ @mock.patch('cloudinit.util.subp')
+ def test_get_device_info_from_zpool(self, zpool_output):
+ # mock subp command from util.get_mount_info_fs_on_zpool
+ zpool_output.return_value = (
+ self.readResource('zpool_status_simple.txt'), ''
+ )
+ # save function return values and do asserts
+ ret = util.get_device_info_from_zpool('vmzroot')
+ self.assertEqual('gpt/system', ret)
+ self.assertIsNotNone(ret)
+
+ @mock.patch('cloudinit.util.subp')
+ def test_get_device_info_from_zpool_on_error(self, zpool_output):
+ # mock subp command from util.get_mount_info_fs_on_zpool
+ zpool_output.return_value = (
+ self.readResource('zpool_status_simple.txt'), 'error'
+ )
+ # save function return values and do asserts
+ ret = util.get_device_info_from_zpool('vmzroot')
+ self.assertIsNone(ret)
+
+ @mock.patch('cloudinit.util.subp')
+ def test_parse_mount_with_ext(self, mount_out):
+ mount_out.return_value = (self.readResource('mount_parse_ext.txt'), '')
+ # this one is valid and exists in mount_parse_ext.txt
+ ret = util.parse_mount('/var')
+ self.assertEqual(('/dev/mapper/vg00-lv_var', 'ext4', '/var'), ret)
+ # another one that is valid and exists
+ ret = util.parse_mount('/')
+ self.assertEqual(('/dev/mapper/vg00-lv_root', 'ext4', '/'), ret)
+ # this one exists in mount_parse_ext.txt
+ ret = util.parse_mount('/sys/kernel/debug')
+ self.assertIsNone(ret)
+ # this one does not even exist in mount_parse_ext.txt
+ ret = util.parse_mount('/not/existing/mount')
+ self.assertIsNone(ret)
+
+ @mock.patch('cloudinit.util.subp')
+ def test_parse_mount_with_zfs(self, mount_out):
+ mount_out.return_value = (self.readResource('mount_parse_zfs.txt'), '')
+ # this one is valid and exists in mount_parse_zfs.txt
+ ret = util.parse_mount('/var')
+ self.assertEqual(('vmzroot/ROOT/freebsd/var', 'zfs', '/var'), ret)
+ # this one is the root, valid and also exists in mount_parse_zfs.txt
+ ret = util.parse_mount('/')
+ self.assertEqual(('vmzroot/ROOT/freebsd', 'zfs', '/'), ret)
+ # this one does not even exist in mount_parse_ext.txt
+ ret = util.parse_mount('/not/existing/mount')
+ self.assertIsNone(ret)
+
class TestReadDMIData(helpers.FilesystemMockingTestCase):