Automatically load kernel module dependencies

Before this commit, you'd have to manually insert the kernel module for
OVS or OF kernel modules, and you couldn't run one regression test with
all 3.

Now, these are kmod insert/remove is handled automatically.
This commit is contained in:
Brandon Heller
2010-03-14 03:53:16 -07:00
parent a165881049
commit b055728fd5
6 changed files with 100 additions and 6 deletions
+54
View File
@@ -0,0 +1,54 @@
"Module dependency utility functions for Mininet."
from mininet.util import quietRun
from mininet.log import info, error, debug
def lsmod():
"Return output of lsmod."
return quietRun( 'lsmod' )
def rmmod( mod ):
"""Return output of lsmod.
mod: module string"""
return quietRun( [ 'rmmod', mod ] )
def modprobe( mod ):
"""Return output of modprobe
mod: module string"""
return quietRun( [ 'modprobe', mod ] )
OF_KMOD = 'ofdatapath'
OVS_KMOD = 'openvswitch_mod'
TUN = 'tun'
def moduleDeps( subtract = [], add = [] ):
"""Handle module dependencies.
subtract: string or list of module names to remove, if already loaded
add: string or list of module names to add, if not already loaded"""
if type( subtract ) is str:
subtract = [ subtract ]
if type( add ) is str:
add = [ add ]
for mod in subtract:
if mod in lsmod():
info( '*** Removing ' + mod + '\n' )
rmmodOutput = rmmod( mod )
if rmmodOutput:
error( 'Error removing ' + mod + '\n%s' % rmmodOutput )
exit( 1 )
if mod in lsmod():
error( 'Failed to remove ' + mod + '; still there!\n' )
exit( 1 )
for mod in add:
if mod not in lsmod():
info( '*** Loading ' + mod + '\n' )
modprobeOutput = modprobe( mod )
if modprobeOutput:
error( 'Error inserting ' + mod + ';\n See INSTALL.\n%s' %
modprobeOutput )
exit( 1 )
if mod not in lsmod():
error( 'Failed to insert ' + mod + '\n' )
exit( 1 )
else:
debug( '*** ' + mod + ' already loaded\n' )