def test_handle_noops_on_disabled(self): """The handle function logs when the configuration disables resize.""" cfg = {'resize_rootfs': False} handle('cc_resizefs', cfg, _cloud=None, log=LOG, args=[]) self.assertIn( 'DEBUG: Skipping module named cc_resizefs, resizing disabled\n', self.logs.getvalue())
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])
def test_handle_warns_on_unknown_mount_info(self, m_get_mount_info): """handle warns when get_mount_info sees unknown filesystem for /.""" m_get_mount_info.return_value = None cfg = {"resize_rootfs": True} handle("cc_resizefs", cfg, _cloud=None, log=LOG, args=[]) logs = self.logs.getvalue() self.assertNotIn( "WARNING: Invalid cloud-config provided:\nresize_rootfs:", logs) self.assertIn("WARNING: Could not determine filesystem type of /\n", logs) self.assertEqual([mock.call("/", LOG)], m_get_mount_info.call_args_list)
def test_handle_warns_on_unknown_mount_info(self, m_get_mount_info): """handle warns when get_mount_info sees unknown filesystem for /.""" m_get_mount_info.return_value = None cfg = {'resize_rootfs': True} handle('cc_resizefs', cfg, _cloud=None, log=LOG, args=[]) logs = self.logs.getvalue() self.assertNotIn("WARNING: Invalid config:\nresize_rootfs:", logs) self.assertIn( 'WARNING: Could not determine filesystem type of /\n', logs) self.assertEqual( [mock.call('/', LOG)], m_get_mount_info.call_args_list)
def test_handle_schema_validation_logs_invalid_resize_rootfs_value(self): """The handle reports json schema violations as a warning. Invalid values for resize_rootfs result in disabling the module. """ cfg = {'resize_rootfs': 'junk'} handle('cc_resizefs', cfg, _cloud=None, log=LOG, args=[]) logs = self.logs.getvalue() self.assertIn( "WARNING: Invalid config:\nresize_rootfs: 'junk' is not one of" " [True, False, 'noblock']", logs) self.assertIn( 'DEBUG: Skipping module named cc_resizefs, resizing disabled\n', logs)
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)
def test_handle_zfs_root(self, mount_info, zpool_info, parse_mount, is_container): 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)
def test_handle_zfs_root(self, mount_info, zpool_info, parse_mount, is_container): 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)