9549c080650192f8082e627346272b4576124a86
[bootmanager.git] / source / steps / WriteModprobeConfig.py
1 #!/usr/bin/python
2
3 # Copyright (c) 2003 Intel Corporation
4 # All rights reserved.
5 #
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
7 # All rights reserved.
8
9 import os, string
10
11 from Exceptions import *
12 import utils
13 import systeminfo
14 import BootAPI
15 import ModelOptions
16 import notify_messages
17
18 def Run( vars, log, filename = "/etc/modprobe.conf"):
19     """
20     write out the system file /etc/modprobe.conf with the current
21     set of modules.
22
23     returns a tuple of the number of network driver lines and storage
24     driver lines written as (networkcount,storagecount)
25     """
26
27     # write out the modprobe.conf file for the system. make sure
28     # the order of the ethernet devices are listed in the same order
29     # as the boot cd loaded the modules. this is found in /tmp/loadedmodules
30     # ultimately, the order will only match the boot cd order if
31     # the kernel modules have the same name - which should be true for the later
32     # version boot cds because they use the same kernel version.
33     # older boot cds use a 2.4.19 kernel, and its possible some of the network
34     # module names have changed, in which case the system might not boot
35     # if the network modules are activated in a different order that the
36     # boot cd.
37
38     # make sure we have this class loaded
39     
40     try:
41         SYSIMG_PATH= vars["SYSIMG_PATH"]
42         if SYSIMG_PATH == "":
43             raise ValueError, "SYSIMG_PATH"
44
45     except KeyError, var:
46         raise BootManagerException, "Missing variable in vars: %s\n" % var
47     except ValueError, var:
48         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
49
50     sysmods= systeminfo.get_system_modules(vars, log)
51     if sysmods is None:
52         raise BootManagerException, "Unable to get list of system modules."
53         
54     modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "w" )
55     modulesconf_file.write("options ata_generic all_generic_ide=1\n")
56
57     # MEF: I am not sure this is the proper thing to do if there are
58     # two completely different scsi_hostadapter.  I think its ok, but
59     # it seems rather arbitrary.
60     count=0
61     for a_mod in sysmods[systeminfo.MODULE_CLASS_SCSI]:
62         line="alias scsi_hostadapter%d %s\n" % (count,a_mod) 
63         modulesconf_file.write(line)
64         count=count+1
65
66     # This should involve looking at the NodeNetworks associated with
67     # this node and matching on their ethernet address.  Barring that
68     # information order the remaining ethX numbering according to PCI
69     # enumeration order. This should be integrated with
70     # WriteNetworkConfig and integrate.  For now lets just comment out
71     # the 'alias ethX a_mod' lines in modprobe.conf
72     count=0
73     for a_mod in sysmods[systeminfo.MODULE_CLASS_NETWORK]:
74         line="# Want to comment this out in the future.\n"
75         line+="alias eth%d %s\n" % (count,a_mod) 
76         modulesconf_file.write(line)
77         count=count+1
78
79     modulesconf_file.close()
80     modulesconf_file= None
81
82     # dump the modprobe.conf file to the log (not to screen)
83     log.write( "Contents of new modprobe.conf file:\n" )
84     modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "r" )
85     contents= modulesconf_file.read()
86     log.write( contents + "\n" )
87     modulesconf_file.close()
88     modulesconf_file= None
89     log.write( "End contents of new modprobe.conf file.\n" )
90
91     # before we do the real kexec, check to see if we had any
92     # network drivers written to modprobe.conf. if not, return -1,
93     # which will cause this node to be switched to a debug state.
94     scsi_count=len(sysmods[systeminfo.MODULE_CLASS_SCSI])
95     eth_count=len(sysmods[systeminfo.MODULE_CLASS_NETWORK])
96     if eth_count == 0:
97         log.write( "\nIt appears we don't have any network drivers. Aborting.\n" )
98         
99         vars['BOOT_STATE']= 'failboot'
100         vars['STATE_CHANGE_NOTIFY']= 1
101         vars['STATE_CHANGE_NOTIFY_MESSAGE']= \
102              notify_messages.MSG_NO_DETECTED_NETWORK
103         raise BootManagerException, \
104               notify_messages.MSG_NO_DETECTED_NETWORK
105
106