From b6c22dde0af5cac6cdfaab662a08dd87faa74995 Mon Sep 17 00:00:00 2001 From: Praveen K Pandey Date: Mon, 22 Aug 2016 15:01:21 +0200 Subject: [PATCH] check config in running kernel and return status Signed-off-by: Praveen K Pandey --- avocado/utils/linux_modules.py | 44 +++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/avocado/utils/linux_modules.py b/avocado/utils/linux_modules.py index 16baed8d..7da5a341 100644 --- a/avocado/utils/linux_modules.py +++ b/avocado/utils/linux_modules.py @@ -13,18 +13,31 @@ # # client/base_utils.py # Original author: Ross Brattain +# +# Copyright: 2016 IBM +# Authors : Praveen K Pandey """ -APIs to list and load/unload linux kernel modules. +Linux kernel modules APIs """ import re import logging +import platform from . import process LOG = logging.getLogger('avocado.test') +#: Config commented out or not set +NOT_SET = 0 + +#: Config compiled as loadable module (`=m`) +MODULE = 1 + +#: Config built-in to kernel (`=y`) +BUILTIN = 2 + def load_module(module_name): # Checks if a module has already been loaded @@ -153,3 +166,32 @@ def module_is_loaded(module_name): def get_loaded_modules(): lsmod_output = process.system_output('/sbin/lsmod').splitlines()[1:] return [line.split(None, 1)[0] for line in lsmod_output] + + +def check_kernel_config(config_name): + """ + Reports the configuration of $config_name of the current kernel + + :param config_name: Name of kernel config to search + :type config_name: str + :return: Config status in running kernel (NOT_SET, BUILTIN, MODULE) + :rtype: int + """ + + kernel_version = platform.uname()[2] + + config_file = '/boot/config-' + kernel_version + for line in open(config_file, 'r'): + line = line.split('=') + + if len(line) != 2: + continue + + config = line[0].strip() + if config == config_name: + option = line[1].strip() + if option == "m": + return MODULE + else: + return BUILTIN + return NOT_SET -- GitLab