Best Python code snippet using avocado_python
linux_modules.py
Source:linux_modules.py  
...71        return module_info72    else:73        # return empty dict to be consistent74        return {}75def loaded_module_info(module_name):76    """77    Get loaded module details: Size and Submodules.78    :param module_name: Name of module to search for79    :type module_name: str80    :return: Dictionary of module info, name, size, submodules if present81    :rtype: dict82    """83    l_raw = process.system_output('/sbin/lsmod')84    return parse_lsmod_for_module(l_raw, module_name)85def get_submodules(module_name):86    """87    Get all submodules of the module.88    :param module_name: Name of module to search for89    :type module_name: str90    :return: List of the submodules91    :rtype: builtin.list92    """93    module_info = loaded_module_info(module_name)94    module_list = []95    try:96        submodules = module_info["submodules"]97    except KeyError:98        LOG.info("Module %s is not loaded" % module_name)99    else:100        module_list = submodules101        for module in submodules:102            module_list += get_submodules(module)103    return module_list104def unload_module(module_name):105    """106    Removes a module. Handles dependencies. If even then it's not possible107    to remove one of the modules, it will throw an error.CmdError exception.108    :param module_name: Name of the module we want to remove.109    :type module_name: str110    """111    module_info = loaded_module_info(module_name)112    try:113        submodules = module_info['submodules']114    except KeyError:115        LOG.info("Module %s is already unloaded" % module_name)116    else:117        for module in submodules:118            unload_module(module)119        module_info = loaded_module_info(module_name)120        try:121            module_used = module_info['used']122        except KeyError:123            LOG.info("Module %s is already unloaded" % module_name)124            return125        if module_used != 0:126            raise RuntimeError("Module %s is still in use. "127                               "Can not unload it." % module_name)128        process.system("/sbin/modprobe -r %s" % module_name)129        LOG.info("Module %s unloaded" % module_name)130def module_is_loaded(module_name):131    """132    Is module loaded133    :param module_name: Name of module to search for134    :type module_name: str135    :return: True is module is loaded136    :rtype: bool137    """138    module_name = module_name.replace('-', '_')139    return bool(loaded_module_info(module_name))140def get_loaded_modules():141    lsmod_output = process.system_output('/sbin/lsmod').splitlines()[1:]142    return [line.split(None, 1)[0] for line in lsmod_output]143def check_kernel_config(config_name):144    """145    Reports the configuration of $config_name of the current kernel146    :param config_name: Name of kernel config to search147    :type config_name: str148    :return: Config status in running kernel (NOT_SET, BUILTIN, MODULE)149    :rtype: int150    """151    kernel_version = platform.uname()[2]152    config_file = '/boot/config-' + kernel_version153    for line in open(config_file, 'r'):...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
