Esempio n. 1
0
def start_clear_holders_deps():
    """
    prepare system for clear holders to be able to scan old devices
    """
    # a mdadm scan has to be started in case there is a md device that needs to
    # be detected. if the scan fails, it is either because there are no mdadm
    # devices on the system, or because there is a mdadm device in a damaged
    # state that could not be started. due to the nature of mdadm tools, it is
    # difficult to know which is the case. if any errors did occur, then ignore
    # them, since no action needs to be taken if there were no mdadm devices on
    # the system, and in the case where there is some mdadm metadata on a disk,
    # but there was not enough to start the array, the call to wipe_volume on
    # all disks and partitions should be sufficient to remove the mdadm
    # metadata
    mdadm.mdadm_assemble(scan=True, ignore_errors=True)
    # scan and activate for logical volumes
    lvm.lvm_scan()
    lvm.activate_volgroups()
    # the bcache module needs to be present to properly detect bcache devs
    # on some systems (precise without hwe kernel) it may not be possible to
    # lad the bcache module bcause it is not present in the kernel. if this
    # happens then there is no need to halt installation, as the bcache devices
    # will never appear and will never prevent the disk from being reformatted
    util.load_kernel_module('bcache')

    if not zfs.zfs_supported():
        LOG.warning('zfs filesystem is not supported in this environment')
Esempio n. 2
0
    def test_load_kernel_module_skips_modprobe_if_loaded(self):
        """ test modprobe skipped if module already loaded"""
        self.m_is_kmod_loaded.return_value = True
        util.load_kernel_module(self.modname)

        self.assertEqual(1, self.m_is_kmod_loaded.call_count)
        self.m_is_kmod_loaded.assert_called_with(self.modname)
        self.assertEqual(0, self.m_subp.call_count)
Esempio n. 3
0
    def test_load_kernel_module_loaded(self):
        """ test modprobe called with check_loaded=False"""
        self.m_is_kmod_loaded.return_value = True
        util.load_kernel_module(self.modname, check_loaded=False)

        self.assertEqual(0, self.m_is_kmod_loaded.call_count)
        self.m_subp.assert_called_with(
            ['modprobe', '--use-blacklist', self.modname])
Esempio n. 4
0
    def test_load_kernel_module_unloaded(self):
        """ test unloaded kmod is loaded via call to modprobe"""
        self.m_is_kmod_loaded.return_value = False

        util.load_kernel_module(self.modname)

        self.m_is_kmod_loaded.assert_called_with(self.modname)
        self.m_subp.assert_called_with(
            ['modprobe', '--use-blacklist', self.modname])
Esempio n. 5
0
def zkey_supported(strict=True):
    """ Return True if zkey cmd present and can generate keys, else False."""
    LOG.debug('Checking if zkey encryption is supported...')
    try:
        util.load_kernel_module('pkey')
    except util.ProcessExecutionError as err:
        msg = "Failed to load 'pkey' kernel module"
        LOG.error(msg + ": %s" % err) if strict else LOG.warning(msg)
        return False

    try:
        with tempfile.NamedTemporaryFile() as tf:
            util.subp(['zkey', 'generate', tf.name], capture=True)
            LOG.debug('zkey encryption supported.')
            return True
    except util.ProcessExecutionError as err:
        msg = "zkey not supported"
        LOG.error(msg + ": %s" % err) if strict else LOG.warning(msg)

    return False
Esempio n. 6
0
def zfs_assert_supported():
    """ Determine if the runtime system supports zfs.
    returns: True if system supports zfs
    raises: RuntimeError: if system does not support zfs
    """
    arch = util.get_platform_arch()
    if arch in ZFS_UNSUPPORTED_ARCHES:
        raise RuntimeError("zfs is not supported on architecture: %s" % arch)

    release = util.lsb_release()['codename']
    if release in ZFS_UNSUPPORTED_RELEASES:
        raise RuntimeError("zfs is not supported on release: %s" % release)

    if 'zfs' not in get_supported_filesystems():
        try:
            util.load_kernel_module('zfs')
        except util.ProcessExecutionError as err:
            raise RuntimeError("Failed to load 'zfs' kernel module: %s" % err)

    missing_progs = [p for p in ('zpool', 'zfs') if not util.which(p)]
    if missing_progs:
        raise RuntimeError("Missing zfs utils: %s" % ','.join(missing_progs))
Esempio n. 7
0
def start_clear_holders_deps():
    """
    prepare system for clear holders to be able to scan old devices
    """
    # a mdadm scan has to be started in case there is a md device that needs to
    # be detected. if the scan fails, it is either because there are no mdadm
    # devices on the system, or because there is a mdadm device in a damaged
    # state that could not be started. due to the nature of mdadm tools, it is
    # difficult to know which is the case. if any errors did occur, then ignore
    # them, since no action needs to be taken if there were no mdadm devices on
    # the system, and in the case where there is some mdadm metadata on a disk,
    # but there was not enough to start the array, the call to wipe_volume on
    # all disks and partitions should be sufficient to remove the mdadm
    # metadata
    mdadm.mdadm_assemble(scan=True, ignore_errors=True)
    # collect detail on any assembling arrays
    for md in [
            md for md in glob.glob('/dev/md*')
            if not os.path.isdir(md) and not identify_partition(md)
    ]:
        mdstat = None
        if os.path.exists('/proc/mdstat'):
            mdstat = util.load_file('/proc/mdstat')
            LOG.debug("/proc/mdstat:\n%s", mdstat)
            found = [
                line for line in mdstat.splitlines()
                if os.path.basename(md) in line
            ]
            # in some cases we have a /dev/md0 device node
            # but the kernel has already renamed the device /dev/md127
            if len(found) == 0:
                LOG.debug('Ignoring md device %s, not present in mdstat', md)
                continue

        # give it a second poke to encourage running
        try:
            LOG.debug('Activating mdadm array %s', md)
            (out, err) = mdadm.mdadm_run(md)
            LOG.debug('MDADM run on %s stdout:\n%s\nstderr:\n%s', md, out, err)
        except util.ProcessExecutionError:
            LOG.debug('Non-fatal error when starting mdadm device %s', md)

        # extract details if we can
        try:
            (out, err) = mdadm.mdadm_query_detail(md,
                                                  export=False,
                                                  rawoutput=True)
            LOG.debug('MDADM detail on %s stdout:\n%s\nstderr:\n%s', md, out,
                      err)
        except util.ProcessExecutionError:
            LOG.debug('Non-fatal error when querying mdadm detail on %s', md)

    # scan and activate for logical volumes
    lvm.lvm_scan()
    lvm.activate_volgroups()
    # the bcache module needs to be present to properly detect bcache devs
    # on some systems (precise without hwe kernel) it may not be possible to
    # lad the bcache module bcause it is not present in the kernel. if this
    # happens then there is no need to halt installation, as the bcache devices
    # will never appear and will never prevent the disk from being reformatted
    util.load_kernel_module('bcache')

    if not zfs.zfs_supported():
        LOG.warning('zfs filesystem is not supported in this environment')
Esempio n. 8
0
 def test_load_kernel_module_invalid_module(self):
     """ test raise ValueError on invalid module parameter"""
     for module_name in ['', None]:
         with self.assertRaises(ValueError):
             util.load_kernel_module(module_name)