summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIgor Galić <igalic@brainsware.at>2018-11-14 22:02:18 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-11-14 22:02:18 +0000
commita3812a4ab4eeb2aa185eb4a2de186cc60ddd7c03 (patch)
treefec2e54908fb77409acc56ad57a00910c5b0cfd0 /tests
parent6062595b83e08e0f12e1fe6d8e367d8db9d91ef8 (diff)
downloadvyos-cloud-init-a3812a4ab4eeb2aa185eb4a2de186cc60ddd7c03.tar.gz
vyos-cloud-init-a3812a4ab4eeb2aa185eb4a2de186cc60ddd7c03.zip
resizefs: Prefix discovered devpath with '/dev/' when path does not exist
In some environments, like FreeBSD, gpart can return the device basename instead of the full path. If this discovered devpath does not exist and is missing the '/dev/' prefix, add that prefix in an attempt to find the device.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_handler/test_handler_resizefs.py48
1 files changed, 40 insertions, 8 deletions
diff --git a/tests/unittests/test_handler/test_handler_resizefs.py b/tests/unittests/test_handler/test_handler_resizefs.py
index feca56c2..6ebacb1a 100644
--- a/tests/unittests/test_handler/test_handler_resizefs.py
+++ b/tests/unittests/test_handler/test_handler_resizefs.py
@@ -173,6 +173,38 @@ class TestResizefs(CiTestCase):
self.assertEqual(('zpool', 'online', '-e', 'vmzroot', disk), ret)
+ @mock.patch('cloudinit.util.is_container', return_value=False)
+ @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_modern_zfsroot(self, mount_info, zpool_info, parse_mount,
+ is_container):
+ devpth = 'zroot/ROOT/default'
+ disk = 'da0p3'
+ 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}
+
+ def fake_stat(devpath):
+ if devpath == disk:
+ raise OSError("not here")
+ FakeStat = namedtuple(
+ 'FakeStat', ['st_mode', 'st_size', 'st_mtime']) # minimal stat
+ return FakeStat(25008, 0, 1) # fake char block device
+
+ with mock.patch('cloudinit.config.cc_resizefs.do_resize') as dresize:
+ with mock.patch('cloudinit.config.cc_resizefs.os.stat') as m_stat:
+ m_stat.side_effect = fake_stat
+ handle('cc_resizefs', cfg, _cloud=None, log=LOG, args=[])
+
+ self.assertEqual(('zpool', 'online', '-e', 'zroot', '/dev/' + disk),
+ dresize.call_args[0][0])
+
class TestRootDevFromCmdline(CiTestCase):
@@ -246,39 +278,39 @@ class TestMaybeGetDevicePathAsWritableBlock(CiTestCase):
def test_maybe_get_writable_device_path_does_not_exist(self):
"""When devpath does not exist, a warning is logged."""
- info = 'dev=/I/dont/exist mnt_point=/ path=/dev/none'
+ info = 'dev=/dev/I/dont/exist mnt_point=/ path=/dev/none'
devpath = wrap_and_call(
'cloudinit.config.cc_resizefs.util',
{'is_container': {'return_value': False}},
- maybe_get_writable_device_path, '/I/dont/exist', info, LOG)
+ maybe_get_writable_device_path, '/dev/I/dont/exist', info, LOG)
self.assertIsNone(devpath)
self.assertIn(
- "WARNING: Device '/I/dont/exist' did not exist."
+ "WARNING: Device '/dev/I/dont/exist' did not exist."
' cannot resize: %s' % info,
self.logs.getvalue())
def test_maybe_get_writable_device_path_does_not_exist_in_container(self):
"""When devpath does not exist in a container, log a debug message."""
- info = 'dev=/I/dont/exist mnt_point=/ path=/dev/none'
+ info = 'dev=/dev/I/dont/exist mnt_point=/ path=/dev/none'
devpath = wrap_and_call(
'cloudinit.config.cc_resizefs.util',
{'is_container': {'return_value': True}},
- maybe_get_writable_device_path, '/I/dont/exist', info, LOG)
+ maybe_get_writable_device_path, '/dev/I/dont/exist', info, LOG)
self.assertIsNone(devpath)
self.assertIn(
- "DEBUG: Device '/I/dont/exist' did not exist in container."
+ "DEBUG: Device '/dev/I/dont/exist' did not exist in container."
' cannot resize: %s' % info,
self.logs.getvalue())
def test_maybe_get_writable_device_path_raises_oserror(self):
"""When unexpected OSError is raises by os.stat it is reraised."""
- info = 'dev=/I/dont/exist mnt_point=/ path=/dev/none'
+ info = 'dev=/dev/I/dont/exist mnt_point=/ path=/dev/none'
with self.assertRaises(OSError) as context_manager:
wrap_and_call(
'cloudinit.config.cc_resizefs',
{'util.is_container': {'return_value': True},
'os.stat': {'side_effect': OSError('Something unexpected')}},
- maybe_get_writable_device_path, '/I/dont/exist', info, LOG)
+ maybe_get_writable_device_path, '/dev/I/dont/exist', info, LOG)
self.assertEqual(
'Something unexpected', str(context_manager.exception))