diff options
author | Martin Klozik <martinx.klozik@intel.com> | 2016-09-20 12:27:13 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2016-09-20 12:27:13 +0000 |
commit | 6dfabefd6cac3cd4b8fd29abf5a5b6ab9e6ae956 (patch) | |
tree | 1372bb6fa418c1844d0e9b2650648aa9b2ad07b1 /tools/module_manager.py | |
parent | a325eb33fbe408243209b19f2d9cc288b2e57548 (diff) | |
parent | 9b1af783ec53050129239102355e1a5c3ceb1d97 (diff) |
Merge "paths: Support binary packages"
Diffstat (limited to 'tools/module_manager.py')
-rw-r--r-- | tools/module_manager.py | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/tools/module_manager.py b/tools/module_manager.py index 2eb4c63d..911f7252 100644 --- a/tools/module_manager.py +++ b/tools/module_manager.py @@ -31,30 +31,40 @@ class ModuleManager(object): """ self._modules = [] - def insert_module(self, module): + def insert_module(self, module, auto_remove=True): """Method inserts given module. In case that module name ends with .ko suffix then insmod will be used for its insertion. Otherwise modprobe will be called. :param module: a name of kernel module + :param auto_remove: if True (by default), then module will be + automatically removed by remove_modules() method """ module_base_name = os.path.basename(os.path.splitext(module)[0]) if self.is_module_inserted(module): self._logger.info('Module already loaded \'%s\'.', module_base_name) # add it to internal list, so we can try to remove it at the end - self._modules.append(module) + if auto_remove: + self._modules.append(module) return try: if module.endswith('.ko'): + # load module dependecies first, but suppress automatic + # module removal at the end; Just for case, that module + # depends on generic module + for depmod in self.get_module_dependecies(module): + self.insert_module(depmod, auto_remove=False) + tasks.run_task(['sudo', 'insmod', module], self._logger, 'Insmod module \'%s\'...' % module_base_name, True) else: tasks.run_task(['sudo', 'modprobe', module], self._logger, 'Modprobe module \'%s\'...' % module_base_name, True) - self._modules.append(module) + if auto_remove: + self._modules.append(module) except subprocess.CalledProcessError: # in case of error, show full module name self._logger.error('Unable to insert module \'%s\'.', module) @@ -68,17 +78,6 @@ class ModuleManager(object): for module in modules: self.insert_module(module) - def insert_module_group(self, module_group, path_prefix): - """Ensure all modules in a group are inserted into the system. - - :param module_group: A name of configuration item containing a list - of module names - :param path_prefix: A name of directory which contains given - group of modules - """ - for (path_suffix, module) in module_group: - self.insert_module(os.path.join(path_prefix, path_suffix, '%s.ko' % module)) - def remove_module(self, module): """Removes a single module. @@ -143,3 +142,26 @@ class ModuleManager(object): return line return None + + @staticmethod + def get_module_dependecies(module): + """Return list of modules, which must be loaded before module itself + + :param module: a name of kernel module + :returns: In case that module has any dependencies, then list of module + names will be returned. Otherwise it returns empty list, i.e. []. + """ + deps = '' + try: + # get list of module dependecies from kernel + deps = subprocess.check_output('modinfo -F depends {}'.format(module), + shell=True).decode().rstrip('\n') + except subprocess.CalledProcessError: + # in case of error, show full module name... + self._logger.info('Unable to get list of dependecies for module \'%s\'.', module) + # ...and try to continue, just for case that dependecies are already loaded + + if len(deps): + return deps.split(',') + else: + return [] |