Exemple #1
0
 def test_get_device_info_from_zpool_handles_no_zpool(self, m_sub, m_os):
     """Handle case where there is no zpool command"""
     # mock /dev/zfs exists
     m_os.path.exists.return_value = True
     m_sub.side_effect = util.ProcessExecutionError("No zpool cmd")
     ret = util.get_device_info_from_zpool('vmzroot')
     self.assertIsNone(ret)
Exemple #2
0
 def test_get_device_info_from_zpool_handles_no_zpool(self, m_sub, m_os):
     """Handle case where there is no zpool command"""
     # mock /dev/zfs exists
     m_os.path.exists.return_value = True
     m_sub.side_effect = util.ProcessExecutionError("No zpool cmd")
     ret = util.get_device_info_from_zpool('vmzroot')
     self.assertIsNone(ret)
Exemple #3
0
 def test_get_device_info_from_zpool_on_error(self, zpool_output, m_os):
     # mock /dev/zfs exists
     m_os.path.exists.return_value = True
     # mock subp command from util.get_mount_info_fs_on_zpool
     zpool_output.return_value = (
         helpers.readResource('zpool_status_simple.txt'), 'error')
     # save function return values and do asserts
     ret = util.get_device_info_from_zpool('vmzroot')
     self.assertIsNone(ret)
Exemple #4
0
 def test_get_device_info_from_zpool_on_error(self, zpool_output, m_os):
     # mock /dev/zfs exists
     m_os.path.exists.return_value = True
     # mock subp command from util.get_mount_info_fs_on_zpool
     zpool_output.return_value = (
         helpers.readResource('zpool_status_simple.txt'), 'error'
     )
     # save function return values and do asserts
     ret = util.get_device_info_from_zpool('vmzroot')
     self.assertIsNone(ret)
Exemple #5
0
 def test_get_device_info_from_zpool(self, zpool_output, m_os):
     # mock /dev/zfs exists
     m_os.path.exists.return_value = True
     # 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)
     m_os.path.exists.assert_called_with('/dev/zfs')
Exemple #6
0
 def test_get_device_info_from_zpool_no_dev_zfs(self, m_os):
     # mock /dev/zfs missing
     m_os.path.exists.return_value = False
     # save function return values and do asserts
     ret = util.get_device_info_from_zpool('vmzroot')
     self.assertIsNone(ret)
Exemple #7
0
def handle(name, cfg, _cloud, log, args):
    if len(args) != 0:
        resize_root = args[0]
    else:
        resize_root = util.get_cfg_option_str(cfg, "resize_rootfs", True)
    validate_cloudconfig_schema(cfg, schema)
    if not util.translate_bool(resize_root, addons=[NOBLOCK]):
        log.debug("Skipping module named %s, resizing disabled", name)
        return

    # TODO(harlowja): allow what is to be resized to be configurable??
    resize_what = "/"
    result = util.get_mount_info(resize_what, log)
    if not result:
        log.warning("Could not determine filesystem type of %s", resize_what)
        return

    (devpth, fs_type, mount_point) = result

    # if we have a zfs then our device path at this point
    # is the zfs label. For example: vmzroot/ROOT/freebsd
    # we will have to get the zpool name out of this
    # and set the resize_what variable to the zpool
    # so the _resize_zfs function gets the right attribute.
    if fs_type == 'zfs':
        zpool = devpth.split('/')[0]
        devpth = util.get_device_info_from_zpool(zpool)
        if not devpth:
            return  # could not find device from zpool
        resize_what = zpool

    info = "dev=%s mnt_point=%s path=%s" % (devpth, mount_point, resize_what)
    log.debug("resize_info: %s" % info)

    devpth = maybe_get_writable_device_path(devpth, info, log)
    if not devpth:
        return  # devpath was not a writable block device

    resizer = None
    if can_skip_resize(fs_type, resize_what, devpth):
        log.debug("Skip resize filesystem type %s for %s",
                  fs_type, resize_what)
        return

    fstype_lc = fs_type.lower()
    for (pfix, root_cmd) in RESIZE_FS_PREFIXES_CMDS:
        if fstype_lc.startswith(pfix):
            resizer = root_cmd
            break

    if not resizer:
        log.warning("Not resizing unknown filesystem type %s for %s",
                    fs_type, resize_what)
        return

    resize_cmd = resizer(resize_what, devpth)
    log.debug("Resizing %s (%s) using %s", resize_what, fs_type,
              ' '.join(resize_cmd))

    if resize_root == NOBLOCK:
        # Fork to a child that will run
        # the resize command
        util.fork_cb(
            util.log_time, logfunc=log.debug, msg="backgrounded Resizing",
            func=do_resize, args=(resize_cmd, log))
    else:
        util.log_time(logfunc=log.debug, msg="Resizing",
                      func=do_resize, args=(resize_cmd, log))

    action = 'Resized'
    if resize_root == NOBLOCK:
        action = 'Resizing (via forking)'
    log.debug("%s root filesystem (type=%s, val=%s)", action, fs_type,
              resize_root)
Exemple #8
0
 def test_get_device_info_from_zpool_no_dev_zfs(self, m_os):
     # mock /dev/zfs missing
     m_os.path.exists.return_value = False
     # save function return values and do asserts
     ret = util.get_device_info_from_zpool('vmzroot')
     self.assertIsNone(ret)
Exemple #9
0
def handle(name, cfg, _cloud, log, args):
    if len(args) != 0:
        resize_enabled = args[0]
    else:
        resize_enabled = util.get_cfg_option_str(cfg, "resizefs_enabled", True)

        # Warn about the old-style configuration
        resize_rootfs_option = util.get_cfg_option_str(cfg, "resize_rootfs")
        if resize_rootfs_option:
            log.warning("""The resize_rootfs option is deprecated, please use
                        resizefs_enabled instead!""")
            resize_enabled = resize_rootfs_option

    # Renamed to schema_vyos to pass build tests without modifying upstream
    validate_cloudconfig_schema(cfg, schema_vyos)
    if not util.translate_bool(resize_enabled, addons=[NOBLOCK]):
        log.debug("Skipping module named %s, resizing disabled", name)
        return

    # Get list of partitions to resize
    resize_what = util.get_cfg_option_list(cfg, "resizefs_list",
                                           RESIZEFS_LIST_DEFAULT)
    log.debug("Filesystems to resize: %s", resize_what)

    # Resize all filesystems from resize_what
    for resize_item in resize_what:

        result = util.get_mount_info(resize_item, log)
        if not result:
            log.warning("Could not determine filesystem type of %s",
                        resize_item)
            return

        (devpth, fs_type, mount_point) = result

        # if we have a zfs then our device path at this point
        # is the zfs label. For example: vmzroot/ROOT/freebsd
        # we will have to get the zpool name out of this
        # and set the resize_item variable to the zpool
        # so the _resize_zfs function gets the right attribute.
        if fs_type == 'zfs':
            zpool = devpth.split('/')[0]
            devpth = util.get_device_info_from_zpool(zpool)
            if not devpth:
                return  # could not find device from zpool
            resize_item = zpool

        info = "dev=%s mnt_point=%s path=%s" % (devpth, mount_point,
                                                resize_item)
        log.debug("resize_info: %s" % info)

        devpth = maybe_get_writable_device_path(devpth, info, log)
        if not devpth:
            return  # devpath was not a writable block device

        resizer = None
        if can_skip_resize(fs_type, resize_item, devpth):
            log.debug("Skip resize filesystem type %s for %s", fs_type,
                      resize_item)
            return

        fstype_lc = fs_type.lower()
        for (pfix, root_cmd) in RESIZE_FS_PREFIXES_CMDS:
            if fstype_lc.startswith(pfix):
                resizer = root_cmd
                break

        if not resizer:
            log.warning("Not resizing unknown filesystem type %s for %s",
                        fs_type, resize_item)
            return

        resize_cmd = resizer(resize_item, devpth)
        log.debug("Resizing %s (%s) using %s", resize_item, fs_type,
                  ' '.join(resize_cmd))

        if resize_enabled == NOBLOCK:
            # Fork to a child that will run
            # the resize command
            util.fork_cb(util.log_time,
                         logfunc=log.debug,
                         msg="backgrounded Resizing",
                         func=do_resize,
                         args=(resize_cmd, log))
        else:
            util.log_time(logfunc=log.debug,
                          msg="Resizing",
                          func=do_resize,
                          args=(resize_cmd, log))

        action = 'Resized'
        if resize_enabled == NOBLOCK:
            action = 'Resizing (via forking)'
        log.debug("%s filesystem on %s (type=%s, val=%s)", action, resize_item,
                  fs_type, resize_enabled)
Exemple #10
0
def handle(name, cfg, _cloud, log, args):
    if len(args) != 0:
        resize_root = args[0]
    else:
        resize_root = util.get_cfg_option_str(cfg, "resize_rootfs", True)
    validate_cloudconfig_schema(cfg, schema)
    if not util.translate_bool(resize_root, addons=[NOBLOCK]):
        log.debug("Skipping module named %s, resizing disabled", name)
        return

    # TODO(harlowja): allow what is to be resized to be configurable??
    resize_what = "/"
    result = util.get_mount_info(resize_what, log)
    if not result:
        log.warn("Could not determine filesystem type of %s", resize_what)
        return

    (devpth, fs_type, mount_point) = result

    # if we have a zfs then our device path at this point
    # is the zfs label. For example: vmzroot/ROOT/freebsd
    # we will have to get the zpool name out of this
    # and set the resize_what variable to the zpool
    # so the _resize_zfs function gets the right attribute.
    if fs_type == 'zfs':
        zpool = devpth.split('/')[0]
        devpth = util.get_device_info_from_zpool(zpool)
        if not devpth:
            return  # could not find device from zpool
        resize_what = zpool

    info = "dev=%s mnt_point=%s path=%s" % (devpth, mount_point, resize_what)
    log.debug("resize_info: %s" % info)

    devpth = maybe_get_writable_device_path(devpth, info, log)
    if not devpth:
        return  # devpath was not a writable block device

    resizer = None
    if can_skip_resize(fs_type, resize_what, devpth):
        log.debug("Skip resize filesystem type %s for %s",
                  fs_type, resize_what)
        return

    fstype_lc = fs_type.lower()
    for (pfix, root_cmd) in RESIZE_FS_PREFIXES_CMDS:
        if fstype_lc.startswith(pfix):
            resizer = root_cmd
            break

    if not resizer:
        log.warn("Not resizing unknown filesystem type %s for %s",
                 fs_type, resize_what)
        return

    resize_cmd = resizer(resize_what, devpth)
    log.debug("Resizing %s (%s) using %s", resize_what, fs_type,
              ' '.join(resize_cmd))

    if resize_root == NOBLOCK:
        # Fork to a child that will run
        # the resize command
        util.fork_cb(
            util.log_time, logfunc=log.debug, msg="backgrounded Resizing",
            func=do_resize, args=(resize_cmd, log))
    else:
        util.log_time(logfunc=log.debug, msg="Resizing",
                      func=do_resize, args=(resize_cmd, log))

    action = 'Resized'
    if resize_root == NOBLOCK:
        action = 'Resizing (via forking)'
    log.debug("%s root filesystem (type=%s, val=%s)", action, fs_type,
              resize_root)