summaryrefslogtreecommitdiffstats
path: root/tools/module_manager.py
diff options
context:
space:
mode:
authorMartin Klozik <martinx.klozik@intel.com>2015-10-16 06:29:30 +0100
committerMaryam Tahhan <maryam.tahhan@intel.com>2015-10-20 13:44:52 +0000
commit0bb85c9c85b7aeb74761c6a565e554674a7661c1 (patch)
tree40cf8f6f697877cab7a598838ba40803638e41b4 /tools/module_manager.py
parent6f35ae4f20e2f47fae569b29907fa77102ee9ee2 (diff)
Implement support of 'insmod' and 'modprobe' commands into ModuleManager
Module manager has been enhanced to support both 'insmod' and 'modprobe' commands for kernel module insertion. In case, that .ko suffix is detected then insmod will be used otherwise modprobe will be called. This allows user to specify full path to each module. For example vanilla ovs module can be defined as "OVS_DIR_VANILLA + 'datapath/linux/openvswitch.ko'" to load kernel module matching OVS vanilla source tree version. Change-Id: Ib8d16eca84449ad34d6b307ab836f58d2f0d341b JIRA: VSPERF-116 Signed-off-by: Martin Klozik <martinx.klozik@intel.com> Reviewed-by: Billy O Mahony <billy.o.mahony@intel.com> Reviewed-by: Maryam Tahhan <maryam.tahhan@intel.com> Reviewed-by: Brian Castelli <brian.castelli@spirent.com>
Diffstat (limited to 'tools/module_manager.py')
-rw-r--r--tools/module_manager.py42
1 files changed, 17 insertions, 25 deletions
diff --git a/tools/module_manager.py b/tools/module_manager.py
index 6ed80e93..39ad5cf4 100644
--- a/tools/module_manager.py
+++ b/tools/module_manager.py
@@ -19,34 +19,21 @@ import subprocess
import logging
from tools import tasks
-class KernelModuleInsertMode(object):
- """Module manager type of insert definition.
- """
- MODPROBE = 1
- INSMOD = 2 #NOT IMPLEMENTED
-
class ModuleManager(object):
"""Simple module manager which acts as system wrapper for Kernel Modules.
"""
_logger = logging.getLogger(__name__)
- def __init__(self, insert_mode=KernelModuleInsertMode.MODPROBE):
- """Initializes data and sets insert mode.
-
- :param insert_mode: insert mode defines how modules are going to
- be inserted in system.
+ def __init__(self):
+ """Initializes data
"""
self._modules = None
- self._insert_mode = insert_mode
def insert_modules(self, modules):
- """Method inserts list of modules using defined insert mode.
-
- :param modules: list of modules to be inserted. Each element on
- list should represent format which is expected
- by KernelModuleInsertMode (e.g. for MODPROBE it
- would be module name).
+ """Method inserts list of modules. In case that module name ends
+ with .ko suffix then insmod will be used for its insertion. Otherwise
+ modprobe will be called.
:returns: None
"""
@@ -56,13 +43,12 @@ class ModuleManager(object):
continue
try:
- if self._insert_mode == KernelModuleInsertMode.MODPROBE:
- tasks.run_task(['sudo', 'modprobe', module], self._logger,
- 'Inserting module \'%s\'...' % module, True)
+ if module.endswith('.ko'):
+ tasks.run_task(['sudo', 'insmod', module], self._logger,
+ 'Insmod module \'%s\'...' % module, True)
else:
- self._logger.error(
- "Kernel module insert mode NOT IMPLEMENTED.")
- raise
+ tasks.run_task(['sudo', 'modprobe', module], self._logger,
+ 'Modprobe module \'%s\'...' % module, True)
except subprocess.CalledProcessError:
self._logger.error('Unable to insert module \'%s\'.', module)
@@ -77,6 +63,8 @@ class ModuleManager(object):
continue
try:
+ # rmmod supports both simple module name and full module path
+ # with .ko suffix
tasks.run_task(['sudo', 'rmmod', module], self._logger,
'Removing module \'%s\'...' % module, True)
except subprocess.CalledProcessError:
@@ -87,11 +75,15 @@ class ModuleManager(object):
def is_module_inserted(module):
"""Check if a module is inserted on system.
"""
+ # get module base name, i.e strip path and .ko suffix if possible
+ module_base_name = module.split('.')[0].split('/').pop()
+
+ # get list of modules from kernel
with open('/proc/modules') as mod_file:
loaded_mods = mod_file.readlines()
# first check if module is loaded
for line in loaded_mods:
- if line.startswith(module):
+ if line.startswith(module_base_name):
return True
return False