提交 b6c22dde 编写于 作者: P Praveen K Pandey 提交者: Lukáš Doktor

check config in running kernel and return status

Signed-off-by: NPraveen K Pandey <praveen@linux.vnet.ibm.com>
上级 fa1878df
......@@ -13,18 +13,31 @@
#
# client/base_utils.py
# Original author: Ross Brattain <ross.b.brattain@intel.com>
#
# Copyright: 2016 IBM
# Authors : Praveen K Pandey <praveen@linux.vnet.ibm.com>
"""
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册