svn:keywords
[bootmanager.git] / source / steps / WriteModprobeConfig.py
1 #!/usr/bin/python
2 #
3 # $Id$
4 # $URL$
5 #
6 # Copyright (c) 2003 Intel Corporation
7 # All rights reserved.
8 #
9 # Copyright (c) 2004-2006 The Trustees of Princeton University
10 # All rights reserved.
11
12 import os, string
13
14 from Exceptions import *
15 import utils
16 import systeminfo
17 import BootAPI
18 import ModelOptions
19 import notify_messages
20 import modprobe
21
22 def Run( vars, log, filename = "/etc/modprobe.conf"):
23     """
24     write out the system file /etc/modprobe.conf with the current
25     set of modules.
26
27     returns a tuple of the number of network driver lines and storage
28     driver lines written as (networkcount,storagecount)
29     """
30
31     # write out the modprobe.conf file for the system. make sure
32     # the order of the ethernet devices are listed in the same order
33     # as the boot cd loaded the modules. this is found in /tmp/loadedmodules
34     # ultimately, the order will only match the boot cd order if
35     # the kernel modules have the same name - which should be true for the later
36     # version boot cds because they use the same kernel version.
37     # older boot cds use a 2.4.19 kernel, and its possible some of the network
38     # module names have changed, in which case the system might not boot
39     # if the network modules are activated in a different order that the
40     # boot cd.
41
42     # make sure we have this class loaded
43     
44     try:
45         SYSIMG_PATH= vars["SYSIMG_PATH"]
46         if SYSIMG_PATH == "":
47             raise ValueError, "SYSIMG_PATH"
48
49     except KeyError, var:
50         raise BootManagerException, "Missing variable in vars: %s\n" % var
51     except ValueError, var:
52         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
53
54     sysmods= systeminfo.get_system_modules(vars, log)
55     if sysmods is None:
56         raise BootManagerException, "Unable to get list of system modules."
57         
58     # parse the existing modprobe.conf file, if one exists
59     mfile = "%s/%s" % (SYSIMG_PATH,filename)
60     m = modprobe.Modprobe()
61     if os.path.exists(mfile):
62         m.input(mfile)
63
64     blacklist = modprobe.Modprobe()
65     blacklistfiles = ("blacklist","blacklist-compat","blacklist-firewire")
66     for blf in blacklistfiles:
67         if os.path.exists("/etc/modprobe.d/%s"%blf):
68             blacklist.input("/etc/modprobe.d/%s"%blf)
69         
70     # storage devices
71     m.optionsset("ata_generic","all_generic_ide=1")
72     scsi_count= 0
73     for a_mod in sysmods[systeminfo.MODULE_CLASS_SCSI]:
74         if m.blacklistget(a_mod) <> None or \
75                blacklist.blacklistget(a_mod) <> None:
76             continue
77         m.aliasset("scsi_hostadapter%d"%scsi_count,a_mod)
78         scsi_count= scsi_count + 1
79
80     # network devices
81     eth_count= 0
82     for a_mod in sysmods[systeminfo.MODULE_CLASS_NETWORK]:
83         if m.blacklistget(a_mod) <> None or \
84                blacklist.blacklistget(a_mod) <> None:
85             continue
86         m.aliasset("eth%d"%eth_count,a_mod)
87         eth_count= eth_count + 1
88     m.output(mfile, "BootManager")
89     m.output("%s.bak"%mfile, "BootManager") # write a backup version of this file
90
91     # dump the modprobe.conf file to the log (not to screen)
92     log.write( "Contents of new modprobe.conf file:\n" )
93     modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "r" )
94     contents= modulesconf_file.read()
95     log.write( contents + "\n" )
96     modulesconf_file.close()
97     modulesconf_file= None
98     log.write( "End contents of new modprobe.conf file.\n" )
99
100     # before we do the real kexec, check to see if we had any
101     # network drivers written to modprobe.conf. if not, return -1,
102     # which will cause this node to be switched to a debug state.
103     if eth_count == 0:
104         log.write( "\nIt appears we don't have any network drivers. Aborting.\n" )
105         
106         vars['RUN_LEVEL']= 'failboot'
107         vars['STATE_CHANGE_NOTIFY']= 1
108         vars['STATE_CHANGE_NOTIFY_MESSAGE']= \
109              notify_messages.MSG_NO_DETECTED_NETWORK
110         raise BootManagerException, \
111               notify_messages.MSG_NO_DETECTED_NETWORK
112
113